Last active
November 11, 2017 16:48
-
-
Save pgmann/50f9719fd92882cd04a1870e479f7e1c to your computer and use it in GitHub Desktop.
A really basic remote shell, written in NodeJS.
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
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shell usage