Skip to content

Instantly share code, notes, and snippets.

@pgmann
Last active November 11, 2017 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgmann/50f9719fd92882cd04a1870e479f7e1c to your computer and use it in GitHub Desktop.
Save pgmann/50f9719fd92882cd04a1870e479f7e1c to your computer and use it in GitHub Desktop.
A really basic remote shell, written in NodeJS.
var http = require('http');
var fs = require('fs');
var exec = require('child_process').exec;
var parse = require('url').parse;
function execute(command, callback){
exec(command, function(error, stdout, stderr){ callback(stdout); });
};
http.createServer(function (req, res) {
var url = parse(req.url,true);
if(url.query.cmd == null) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<form action="/" method="get"><input type="text" name="cmd" placeholder="Enter command..." /><input type="submit"></form>');
} else {
res.writeHead(200, {'Content-Type': 'text/plain'});
execute(url.query.cmd, function(output) {
res.end(output);
});
}
}).listen(9615);
@pgmann
Copy link
Author

pgmann commented Jul 26, 2017

Shell usage

# save to file before running
wget https://goo.gl/4XFqNK -O console.js;chmod 755 console.js;nodejs console.js

# run directly from stdout without saving
wget -O - https://goo.gl/4XFqNK | nodejs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment