Skip to content

Instantly share code, notes, and snippets.

@keesj
Created January 12, 2021 17:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keesj/dcf40e22fd8ff0fc84b49246a9e9e439 to your computer and use it in GitHub Desktop.
Save keesj/dcf40e22fd8ff0fc84b49246a9e9e439 to your computer and use it in GitHub Desktop.
/* Execute a shell command and capture stdout until eof (run with node frida-shell-cmd.js) */
const frida = require('frida');
let device = null;
async function main() {
const deviceManager = frida.getDeviceManager();
device = await deviceManager.addRemoteDevice('192.168.3.105');
device.output.connect(onOutput);
console.log('[*] spawn()');
const pid = await device.spawn('/bin/sh', {
argv: ['/bin/sh', '-c', 'ls /; sleep 2; echo done'],
cwd: '/',
stdio: 'pipe',
aslr: 'auto'
});
console.log(`[*] attach(${pid})`);
const session = await device.attach(pid);
console.log('[*] enableChildGating()');
console.log(`[*] resume(${pid})`);
await device.resume(pid);
}
function onOutput(pid, fd, data) {
let description;
if (data.length > 0) {
description = '"' + data.toString().replace(/\n/g, '\\n') + '"';
} else {
description = '<EOF>';
device.output.disconnect(onOutput);
}
console.log(`[*] onOutput(pid=${pid}, fd=${fd}, data=${description})`);
}
main()
.catch(e => {
console.error(e);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment