@profullstack/threatcrush 0.13.50 → 0.13.52

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.
package/dist/index.js CHANGED
@@ -23426,9 +23426,9 @@ var source_default = chalk;
23426
23426
  // src/index.ts
23427
23427
  var import_readline = __toESM(require("readline"));
23428
23428
  var import_node_child_process23 = require("child_process");
23429
- var import_node_fs53 = require("fs");
23430
- var import_node_path39 = require("path");
23431
- var import_node_os15 = require("os");
23429
+ var import_node_fs54 = require("fs");
23430
+ var import_node_path40 = require("path");
23431
+ var import_node_os16 = require("os");
23432
23432
 
23433
23433
  // src/commands/monitor.ts
23434
23434
  var import_node_fs11 = require("fs");
@@ -29242,6 +29242,74 @@ var THREATCRUSH_RULES = [
29242
29242
  "flags": "i",
29243
29243
  "negated": false
29244
29244
  }
29245
+ },
29246
+ {
29247
+ "id": 10002,
29248
+ "msg": "PHPUnit eval-stdin.php remote code execution probe (CVE-2017-9841)",
29249
+ "severity": "CRITICAL",
29250
+ "tags": [
29251
+ "attack-rce",
29252
+ "threatcrush",
29253
+ "cve-2017-9841"
29254
+ ],
29255
+ "targets": [
29256
+ "REQUEST_FILENAME"
29257
+ ],
29258
+ "transforms": [
29259
+ "utf8toUnicode",
29260
+ "urlDecodeUni",
29261
+ "normalizePathWin"
29262
+ ],
29263
+ "op": {
29264
+ "type": "rx",
29265
+ "source": "/src/util/php/eval-stdin\\.php",
29266
+ "flags": "i",
29267
+ "negated": false
29268
+ }
29269
+ },
29270
+ {
29271
+ "id": 10003,
29272
+ "msg": "ThinkPHP namespace routing remote code execution probe",
29273
+ "severity": "CRITICAL",
29274
+ "tags": [
29275
+ "attack-rce",
29276
+ "threatcrush",
29277
+ "cve-2022-47945"
29278
+ ],
29279
+ "targets": [
29280
+ "ARGS"
29281
+ ],
29282
+ "transforms": [
29283
+ "urlDecodeUni"
29284
+ ],
29285
+ "op": {
29286
+ "type": "rx",
29287
+ "source": "\\\\think\\\\(?:app|container|request|module|template\\\\driver\\\\file)\\b",
29288
+ "flags": "i",
29289
+ "negated": false
29290
+ }
29291
+ },
29292
+ {
29293
+ "id": 10004,
29294
+ "msg": "XWiki macro injection remote code execution probe (CVE-2025-24893)",
29295
+ "severity": "CRITICAL",
29296
+ "tags": [
29297
+ "attack-rce",
29298
+ "threatcrush",
29299
+ "cve-2025-24893"
29300
+ ],
29301
+ "targets": [
29302
+ "ARGS"
29303
+ ],
29304
+ "transforms": [
29305
+ "urlDecodeUni"
29306
+ ],
29307
+ "op": {
29308
+ "type": "rx",
29309
+ "source": "\\{\\{\\s*(?:groovy|python|async|velocity)\\b",
29310
+ "flags": "i",
29311
+ "negated": false
29312
+ }
29245
29313
  }
29246
29314
  ];
29247
29315
 
@@ -35713,6 +35781,43 @@ var CODE_RULES = [
35713
35781
  languages: ["javascript", "typescript"],
35714
35782
  pattern: /\[\s*['"]__proto__['"]\s*\]|\bObject\s*\.\s*assign\s*\(\s*[\w.$]*\.prototype\b|\.\s*__proto__\s*=/
35715
35783
  },
35784
+ // ── GitHub Actions ───────────────────────────────────────────────────────
35785
+ //
35786
+ // A workflow runs with the repository's secrets on every push, so writing one
35787
+ // is the shortest path from "can commit" to "has every credential". In
35788
+ // October 2026 a public repository's hidden instructions got ChatGPT's GitHub
35789
+ // connector to commit exactly that into a victim's private repository; the
35790
+ // same file arrives by a compromised maintainer token or a careless merge.
35791
+ // Both rules look for the exfiltration itself, not for secrets being used:
35792
+ // `Authorization: Bearer ${{ secrets.X }}` to the API it belongs to is the
35793
+ // whole point of a secret and stays silent.
35794
+ {
35795
+ id: "gha-all-secrets-serialized",
35796
+ inherent: true,
35797
+ title: "every repository secret serialised into one value",
35798
+ consequence: "toJSON(secrets) is the full secret store as one string. Whatever step receives it can send every credential the repository holds anywhere it likes, and the runner masks it in logs, so nobody sees it leave.",
35799
+ cwe: "CWE-200",
35800
+ severity: "high",
35801
+ languages: ["config"],
35802
+ pattern: /\btoJSON\s*\(\s*secrets\s*\)/,
35803
+ fileRequires: /^\s*runs-on\s*:/m,
35804
+ guard: false
35805
+ },
35806
+ {
35807
+ id: "gha-secret-to-collector",
35808
+ inherent: true,
35809
+ title: "workflow sends secrets to a request-capture service",
35810
+ consequence: "The step posts repository secrets to a public request catcher, which is how stolen CI credentials are collected. Treat every secret the workflow can read as leaked and rotate it.",
35811
+ cwe: "CWE-200",
35812
+ severity: "critical",
35813
+ languages: ["config"],
35814
+ pattern: /\b(?:webhook\.site|requestbin\.(?:com|net)|[\w-]+\.m\.pipedream\.net|pipedream\.net|[\w-]+\.(?:ngrok(?:-free)?\.(?:io|app|dev)|trycloudflare\.com)|[\w-]+\.(?:oast\.(?:fun|live|me|online|pro|site)|interact\.sh|burpcollaborator\.net)|beeceptor\.com|hookbin\.com|requestcatcher\.com)\b/i,
35815
+ requires: /\$\{\{\s*(?:toJSON\s*\(\s*)?secrets\b/,
35816
+ fileRequires: /^\s*runs-on\s*:/m,
35817
+ guard: false,
35818
+ guardBack: 12,
35819
+ guardForward: 4
35820
+ },
35716
35821
  // ── Shell ────────────────────────────────────────────────────────────────
35717
35822
  //
35718
35823
  // `shell` was a language the type system knew about and no rule targeted, so
@@ -40655,9 +40760,85 @@ async function useOrganization(slug) {
40655
40760
  }
40656
40761
  }
40657
40762
 
40763
+ // src/commands/credits.ts
40764
+ var import_node_os10 = require("os");
40765
+ var import_node_fs24 = require("fs");
40766
+ var import_node_path20 = require("path");
40767
+ var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
40768
+ var CONFIG_PATH2 = (0, import_node_path20.join)((0, import_node_os10.homedir)(), ".threatcrush", "config.json");
40769
+ function sessionToken() {
40770
+ try {
40771
+ const cfg = JSON.parse((0, import_node_fs24.readFileSync)(CONFIG_PATH2, "utf-8"));
40772
+ return cfg.token ?? null;
40773
+ } catch {
40774
+ return null;
40775
+ }
40776
+ }
40777
+ async function api(path2, init = {}, f = fetch) {
40778
+ const token = sessionToken();
40779
+ if (!token) {
40780
+ console.error(source_default.red(" Not signed in. Run `threatcrush login` first."));
40781
+ process.exitCode = 1;
40782
+ return { ok: false, status: 401, body: {} };
40783
+ }
40784
+ const res = await f(`${API_URL4}${path2}`, {
40785
+ ...init,
40786
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, ...init.headers ?? {} }
40787
+ });
40788
+ const body = await res.json().catch(() => ({}));
40789
+ if (res.status === 401) console.error(source_default.red(" Session expired. Run `threatcrush login` again."));
40790
+ return { ok: res.ok, status: res.status, body };
40791
+ }
40792
+ function fail(body, fallback) {
40793
+ console.error(source_default.red(` ${String(body.error ?? fallback)}`));
40794
+ process.exitCode = 1;
40795
+ }
40796
+ async function redeemCommand(code, f = fetch) {
40797
+ const r = await api("/api/credits/redeem", { method: "POST", body: JSON.stringify({ code }) }, f);
40798
+ if (r.status === 401 && !r.body.error) return;
40799
+ if (!r.ok) return fail(r.body, "Could not redeem the code.");
40800
+ console.log(source_default.green(` ${String(r.body.message)}`));
40801
+ if (typeof r.body.balance_usd === "number") console.log(` Credit balance: $${r.body.balance_usd.toFixed(2)}`);
40802
+ }
40803
+ async function invitesCommand(action = "list", arg, f = fetch) {
40804
+ if (action === "create") {
40805
+ const r2 = await api("/api/credits/invites", { method: "POST", body: JSON.stringify({ note: arg ?? "" }) }, f);
40806
+ if (!r2.ok) return fail(r2.body, "Could not create an invite.");
40807
+ console.log(source_default.green(" Invite created. Send this link (it is shown once):"));
40808
+ console.log(` ${source_default.bold(String(r2.body.url))}`);
40809
+ return;
40810
+ }
40811
+ if (action === "accept") {
40812
+ if (!arg) return fail({}, "Usage: threatcrush invites accept <code>");
40813
+ const r2 = await api("/api/credits/invites/accept", { method: "POST", body: JSON.stringify({ code: arg }) }, f);
40814
+ if (!r2.ok) return fail(r2.body, "Could not accept the invite.");
40815
+ console.log(source_default.green(` ${String(r2.body.message)}`));
40816
+ return;
40817
+ }
40818
+ if (action === "revoke") {
40819
+ if (!arg) return fail({}, "Usage: threatcrush invites revoke <id>");
40820
+ const r2 = await api(`/api/credits/invites/${encodeURIComponent(arg)}`, { method: "DELETE" }, f);
40821
+ if (!r2.ok) return fail(r2.body, "Could not withdraw the invite.");
40822
+ console.log(source_default.green(" Invite withdrawn."));
40823
+ return;
40824
+ }
40825
+ const r = await api("/api/credits/invites", {}, f);
40826
+ if (!r.ok) return fail(r.body, "Could not load invites.");
40827
+ const q = r.body.quota;
40828
+ console.log(` Invites left: ${source_default.bold(`${q.left} / ${q.total}`)} (bonus: ${String(r.body.bonusCredits)} credits each)`);
40829
+ if (!r.body.canInvite) {
40830
+ console.log(source_default.yellow(r.body.unlocksAt ? ` Invites unlock on ${String(r.body.unlocksAt).slice(0, 10)}.` : ` Cannot invite: ${String(r.body.blockedReason)}`));
40831
+ }
40832
+ for (const i of r.body.invites ?? []) {
40833
+ const who = i.usedByEmail ? ` ${i.usedByEmail}` : "";
40834
+ const bonus = i.status === "used" ? ` (credits ${i.bonus})` : "";
40835
+ console.log(` ${source_default.dim(i.id)} ${new Date(i.createdAt).toISOString().slice(0, 10)} ${i.status}${who}${bonus} ${i.note}`);
40836
+ }
40837
+ }
40838
+
40658
40839
  // src/commands/servers.ts
40659
40840
  var import_node_readline2 = __toESM(require("readline"));
40660
- var import_node_os10 = require("os");
40841
+ var import_node_os11 = require("os");
40661
40842
  init_cli_config();
40662
40843
  function connectionStatus(server, now = Date.now()) {
40663
40844
  const seen = server.last_seen ? Date.parse(server.last_seen) : NaN;
@@ -40756,7 +40937,7 @@ async function chooseOrg(orgs, flag, ask2) {
40756
40937
  async function linkServer(opts = {}, ask2 = askChoice) {
40757
40938
  if (!hasSession()) throw new Error("Not logged in. Run: threatcrush login");
40758
40939
  const org = await chooseOrg(await fetchOrgs(), opts.org, ask2);
40759
- const host = opts.hostname ?? (0, import_node_os10.hostname)();
40940
+ const host = opts.hostname ?? (0, import_node_os11.hostname)();
40760
40941
  const listRes = await cloudFetch(`/api/orgs/${org.id}/servers`);
40761
40942
  if (!listRes.ok) throw new Error(`Failed to list servers in /${org.slug} (${listRes.status})`);
40762
40943
  const { servers = [] } = await listRes.json();
@@ -40873,15 +41054,15 @@ function timeAgo(dateStr) {
40873
41054
  }
40874
41055
 
40875
41056
  // src/commands/connect.ts
40876
- var import_node_os11 = require("os");
40877
- var import_node_fs24 = require("fs");
40878
- var import_node_path20 = require("path");
41057
+ var import_node_os12 = require("os");
41058
+ var import_node_fs25 = require("fs");
41059
+ var import_node_path21 = require("path");
40879
41060
  var import_node_child_process5 = require("child_process");
40880
- var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
40881
- var CONFIG_PATH2 = (0, import_node_path20.join)((0, import_node_os11.homedir)(), ".threatcrush", "config.json");
41061
+ var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
41062
+ var CONFIG_PATH3 = (0, import_node_path21.join)((0, import_node_os12.homedir)(), ".threatcrush", "config.json");
40882
41063
  function readConfig2() {
40883
41064
  try {
40884
- return JSON.parse((0, import_node_fs24.readFileSync)(CONFIG_PATH2, "utf-8"));
41065
+ return JSON.parse((0, import_node_fs25.readFileSync)(CONFIG_PATH3, "utf-8"));
40885
41066
  } catch {
40886
41067
  return {};
40887
41068
  }
@@ -40923,7 +41104,7 @@ async function connectCommand(options) {
40923
41104
  async function interactiveConnect(orgSlug) {
40924
41105
  const config = readConfig2();
40925
41106
  try {
40926
- const orgsRes = await fetch(`${API_URL4}/api/orgs`, { headers: getAuthHeaders2() });
41107
+ const orgsRes = await fetch(`${API_URL5}/api/orgs`, { headers: getAuthHeaders2() });
40927
41108
  if (!orgsRes.ok) {
40928
41109
  console.log(source_default.red(" Failed to fetch organizations. Are you logged in?\n"));
40929
41110
  return;
@@ -40945,7 +41126,7 @@ async function interactiveConnect(orgSlug) {
40945
41126
  if (!orgId) {
40946
41127
  orgId = orgs[0].id;
40947
41128
  }
40948
- const serversRes = await fetch(`${API_URL4}/api/orgs/${orgId}/servers`, { headers: getAuthHeaders2() });
41129
+ const serversRes = await fetch(`${API_URL5}/api/orgs/${orgId}/servers`, { headers: getAuthHeaders2() });
40949
41130
  if (!serversRes.ok) {
40950
41131
  console.log(source_default.red(" Failed to fetch servers.\n"));
40951
41132
  return;
@@ -40978,7 +41159,7 @@ async function resolveServer(nameOrSlug, orgSlug) {
40978
41159
  try {
40979
41160
  let orgId = config.current_org_id;
40980
41161
  if (orgSlug) {
40981
- const orgsRes = await fetch(`${API_URL4}/api/orgs`, { headers: getAuthHeaders2() });
41162
+ const orgsRes = await fetch(`${API_URL5}/api/orgs`, { headers: getAuthHeaders2() });
40982
41163
  if (!orgsRes.ok) return null;
40983
41164
  const orgsData = await orgsRes.json();
40984
41165
  const org = (orgsData.organizations || []).find((o) => o.slug === orgSlug);
@@ -40986,13 +41167,13 @@ async function resolveServer(nameOrSlug, orgSlug) {
40986
41167
  orgId = org.id;
40987
41168
  }
40988
41169
  if (!orgId) {
40989
- const orgsRes = await fetch(`${API_URL4}/api/orgs`, { headers: getAuthHeaders2() });
41170
+ const orgsRes = await fetch(`${API_URL5}/api/orgs`, { headers: getAuthHeaders2() });
40990
41171
  if (!orgsRes.ok) return null;
40991
41172
  const orgsData = await orgsRes.json();
40992
41173
  orgId = (orgsData.organizations || [])[0]?.id;
40993
41174
  if (!orgId) return null;
40994
41175
  }
40995
- const serversRes = await fetch(`${API_URL4}/api/orgs/${orgId}/servers`, { headers: getAuthHeaders2() });
41176
+ const serversRes = await fetch(`${API_URL5}/api/orgs/${orgId}/servers`, { headers: getAuthHeaders2() });
40996
41177
  if (!serversRes.ok) return null;
40997
41178
  const serversData = await serversRes.json();
40998
41179
  const servers = serversData.servers || [];
@@ -41036,21 +41217,21 @@ async function sshConnect(options) {
41036
41217
 
41037
41218
  // src/commands/daemon.ts
41038
41219
  var import_node_child_process17 = require("child_process");
41039
- var import_node_fs42 = require("fs");
41040
- var import_node_path32 = require("path");
41041
41220
  var import_node_fs43 = require("fs");
41221
+ var import_node_path33 = require("path");
41222
+ var import_node_fs44 = require("fs");
41042
41223
 
41043
41224
  // src/daemon/index.ts
41044
- var import_node_fs41 = require("fs");
41225
+ var import_node_fs42 = require("fs");
41045
41226
  var import_node_child_process16 = require("child_process");
41046
- var import_node_os12 = require("os");
41047
- var import_node_path31 = require("path");
41227
+ var import_node_os13 = require("os");
41228
+ var import_node_path32 = require("path");
41048
41229
  var import_node_util4 = require("util");
41049
41230
  init_paths();
41050
41231
 
41051
41232
  // src/daemon/ipc-server.ts
41052
41233
  var import_node_net3 = require("net");
41053
- var import_node_fs25 = require("fs");
41234
+ var import_node_fs26 = require("fs");
41054
41235
  init_paths();
41055
41236
  init_control_token();
41056
41237
 
@@ -41104,9 +41285,9 @@ var IpcServer = class {
41104
41285
  controlToken = "";
41105
41286
  async start() {
41106
41287
  this.controlToken = issueControlToken();
41107
- if ((0, import_node_fs25.existsSync)(PATHS.socket)) {
41288
+ if ((0, import_node_fs26.existsSync)(PATHS.socket)) {
41108
41289
  try {
41109
- (0, import_node_fs25.unlinkSync)(PATHS.socket);
41290
+ (0, import_node_fs26.unlinkSync)(PATHS.socket);
41110
41291
  } catch {
41111
41292
  }
41112
41293
  }
@@ -41144,14 +41325,14 @@ var IpcServer = class {
41144
41325
  return new Promise((resolve6) => {
41145
41326
  if (!this.server) {
41146
41327
  try {
41147
- if ((0, import_node_fs25.existsSync)(PATHS.socket)) (0, import_node_fs25.unlinkSync)(PATHS.socket);
41328
+ if ((0, import_node_fs26.existsSync)(PATHS.socket)) (0, import_node_fs26.unlinkSync)(PATHS.socket);
41148
41329
  } catch {
41149
41330
  }
41150
41331
  return resolve6();
41151
41332
  }
41152
41333
  this.server.close(() => {
41153
41334
  try {
41154
- if ((0, import_node_fs25.existsSync)(PATHS.socket)) (0, import_node_fs25.unlinkSync)(PATHS.socket);
41335
+ if ((0, import_node_fs26.existsSync)(PATHS.socket)) (0, import_node_fs26.unlinkSync)(PATHS.socket);
41155
41336
  } catch {
41156
41337
  }
41157
41338
  resolve6();
@@ -41331,7 +41512,7 @@ var IpcServer = class {
41331
41512
  }
41332
41513
  }
41333
41514
  };
41334
- function admGid(readGroup = () => (0, import_node_fs25.readFileSync)("/etc/group", "utf-8"), statAuthLog = () => (0, import_node_fs25.statSync)("/var/log/auth.log")) {
41515
+ function admGid(readGroup = () => (0, import_node_fs26.readFileSync)("/etc/group", "utf-8"), statAuthLog = () => (0, import_node_fs26.statSync)("/var/log/auth.log")) {
41335
41516
  try {
41336
41517
  for (const line2 of readGroup().split("\n")) {
41337
41518
  const [name, , gid] = line2.split(":");
@@ -41347,14 +41528,14 @@ function admGid(readGroup = () => (0, import_node_fs25.readFileSync)("/etc/group
41347
41528
  }
41348
41529
 
41349
41530
  // src/daemon/module-host.ts
41350
- var import_node_fs31 = require("fs");
41351
- var import_node_path22 = require("path");
41531
+ var import_node_fs32 = require("fs");
41532
+ var import_node_path23 = require("path");
41352
41533
  var import_node_url = require("url");
41353
41534
  var import_toml4 = __toESM(require_toml());
41354
41535
  init_paths();
41355
41536
 
41356
41537
  // src/daemon/watchers/log-watcher.ts
41357
- var import_node_fs26 = require("fs");
41538
+ var import_node_fs27 = require("fs");
41358
41539
  var DEFAULT_SOURCES = [
41359
41540
  { path: "/var/log/auth.log", module: "ssh-guard", category: "auth" },
41360
41541
  { path: "/var/log/secure", module: "ssh-guard", category: "auth" },
@@ -41374,9 +41555,9 @@ var LogWatcher = class {
41374
41555
  start() {
41375
41556
  const started = [];
41376
41557
  for (const src of this.sources) {
41377
- if (!(0, import_node_fs26.existsSync)(src.path)) continue;
41558
+ if (!(0, import_node_fs27.existsSync)(src.path)) continue;
41378
41559
  try {
41379
- (0, import_node_fs26.accessSync)(src.path, import_node_fs26.constants.R_OK);
41560
+ (0, import_node_fs27.accessSync)(src.path, import_node_fs27.constants.R_OK);
41380
41561
  } catch {
41381
41562
  continue;
41382
41563
  }
@@ -41673,7 +41854,7 @@ function realtimeToDate(rt) {
41673
41854
 
41674
41855
  // src/modules/network-monitor/index.ts
41675
41856
  var import_node_child_process7 = require("child_process");
41676
- var import_node_fs27 = require("fs");
41857
+ var import_node_fs28 = require("fs");
41677
41858
  var NetworkMonitor = class {
41678
41859
  constructor(bus2) {
41679
41860
  this.bus = bus2;
@@ -41737,7 +41918,7 @@ var NetworkMonitor = class {
41737
41918
  hasConntrackOrSs() {
41738
41919
  const ss = (0, import_node_child_process7.spawnSync)("ss", ["--version"], { stdio: "pipe" });
41739
41920
  if (ss.status === 0) return true;
41740
- return (0, import_node_fs27.existsSync)("/proc/net/tcp");
41921
+ return (0, import_node_fs28.existsSync)("/proc/net/tcp");
41741
41922
  }
41742
41923
  /**
41743
41924
  * The TCP ports this host actually listens on.
@@ -41924,18 +42105,18 @@ var NetworkMonitor = class {
41924
42105
  };
41925
42106
 
41926
42107
  // src/modules/dns-monitor/index.ts
41927
- var import_node_fs30 = require("fs");
42108
+ var import_node_fs31 = require("fs");
41928
42109
  var import_node_child_process9 = require("child_process");
41929
42110
  var import_node_readline3 = require("readline");
41930
42111
 
41931
42112
  // src/core/threat-feeds/index.ts
41932
- var import_node_fs29 = require("fs");
41933
- var import_node_path21 = require("path");
42113
+ var import_node_fs30 = require("fs");
42114
+ var import_node_path22 = require("path");
41934
42115
  var import_node_net5 = require("net");
41935
42116
 
41936
42117
  // src/daemon/firewall/protected.ts
41937
42118
  var import_node_child_process8 = require("child_process");
41938
- var import_node_fs28 = require("fs");
42119
+ var import_node_fs29 = require("fs");
41939
42120
  var import_node_net4 = require("net");
41940
42121
  var DEFAULT_PROTECTED = [
41941
42122
  "127.0.0.0/8",
@@ -42091,14 +42272,14 @@ function moshClients(procDir = "/proc") {
42091
42272
  const found = /* @__PURE__ */ new Set();
42092
42273
  let pids = [];
42093
42274
  try {
42094
- pids = (0, import_node_fs28.readdirSync)(procDir).filter((p) => /^\d+$/.test(p));
42275
+ pids = (0, import_node_fs29.readdirSync)(procDir).filter((p) => /^\d+$/.test(p));
42095
42276
  } catch {
42096
42277
  return [];
42097
42278
  }
42098
42279
  for (const pid of pids) {
42099
42280
  try {
42100
- if ((0, import_node_fs28.readFileSync)(`${procDir}/${pid}/comm`, "utf-8").trim() !== "mosh-server") continue;
42101
- const ip = sshClientFromEnviron((0, import_node_fs28.readFileSync)(`${procDir}/${pid}/environ`, "latin1"));
42281
+ if ((0, import_node_fs29.readFileSync)(`${procDir}/${pid}/comm`, "utf-8").trim() !== "mosh-server") continue;
42282
+ const ip = sshClientFromEnviron((0, import_node_fs29.readFileSync)(`${procDir}/${pid}/environ`, "latin1"));
42102
42283
  if (ip) found.add(ip);
42103
42284
  } catch {
42104
42285
  }
@@ -42304,17 +42485,17 @@ async function fetchFeeds(settings, fetchImpl = fetch) {
42304
42485
  }
42305
42486
  function readFeedCache(path2) {
42306
42487
  try {
42307
- const set = JSON.parse((0, import_node_fs29.readFileSync)(path2, "utf-8"));
42488
+ const set = JSON.parse((0, import_node_fs30.readFileSync)(path2, "utf-8"));
42308
42489
  return set && typeof set.ips === "object" && typeof set.domains === "object" ? set : null;
42309
42490
  } catch {
42310
42491
  return null;
42311
42492
  }
42312
42493
  }
42313
42494
  function writeFeedCache(path2, set) {
42314
- (0, import_node_fs29.mkdirSync)((0, import_node_path21.dirname)(path2), { recursive: true });
42495
+ (0, import_node_fs30.mkdirSync)((0, import_node_path22.dirname)(path2), { recursive: true });
42315
42496
  const tmp = `${path2}.tmp`;
42316
- (0, import_node_fs29.writeFileSync)(tmp, JSON.stringify(set));
42317
- (0, import_node_fs29.renameSync)(tmp, path2);
42497
+ (0, import_node_fs30.writeFileSync)(tmp, JSON.stringify(set));
42498
+ (0, import_node_fs30.renameSync)(tmp, path2);
42318
42499
  }
42319
42500
  var RESOLVER_FILES = {
42320
42501
  hosts: "blocked-domains.hosts",
@@ -42439,9 +42620,9 @@ var DnsMonitor = class {
42439
42620
  }
42440
42621
  start() {
42441
42622
  const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
42442
- if (!(0, import_node_fs30.existsSync)(p)) return false;
42623
+ if (!(0, import_node_fs31.existsSync)(p)) return false;
42443
42624
  try {
42444
- (0, import_node_fs30.accessSync)(p, import_node_fs30.constants.R_OK);
42625
+ (0, import_node_fs31.accessSync)(p, import_node_fs31.constants.R_OK);
42445
42626
  return true;
42446
42627
  } catch {
42447
42628
  return false;
@@ -42798,15 +42979,15 @@ var ModuleHost = class {
42798
42979
  }
42799
42980
  }
42800
42981
  async discoverAndStartInstalled() {
42801
- if (!(0, import_node_fs31.existsSync)(PATHS.moduleDir)) return;
42982
+ if (!(0, import_node_fs32.existsSync)(PATHS.moduleDir)) return;
42802
42983
  const configs = loadModuleConfigs(PATHS.confD);
42803
- const entries = (0, import_node_fs31.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
42984
+ const entries = (0, import_node_fs32.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
42804
42985
  for (const entry of entries) {
42805
42986
  if (!entry.isDirectory()) continue;
42806
- const manifestPath = (0, import_node_path22.join)(PATHS.moduleDir, entry.name, "mod.toml");
42807
- if (!(0, import_node_fs31.existsSync)(manifestPath)) continue;
42987
+ const manifestPath = (0, import_node_path23.join)(PATHS.moduleDir, entry.name, "mod.toml");
42988
+ if (!(0, import_node_fs32.existsSync)(manifestPath)) continue;
42808
42989
  try {
42809
- const manifest = import_toml4.default.parse((0, import_node_fs31.readFileSync)(manifestPath, "utf-8"));
42990
+ const manifest = import_toml4.default.parse((0, import_node_fs32.readFileSync)(manifestPath, "utf-8"));
42810
42991
  const name = manifest.module?.name || entry.name;
42811
42992
  const defaults = manifest.module?.config?.defaults || {};
42812
42993
  const config = {
@@ -42820,7 +43001,7 @@ var ModuleHost = class {
42820
43001
  source: "installed",
42821
43002
  status: config.enabled === false ? "disabled" : "loaded",
42822
43003
  events: 0,
42823
- path: (0, import_node_path22.join)(PATHS.moduleDir, entry.name),
43004
+ path: (0, import_node_path23.join)(PATHS.moduleDir, entry.name),
42824
43005
  config
42825
43006
  };
42826
43007
  this.modules.set(name, hosted);
@@ -42835,7 +43016,7 @@ var ModuleHost = class {
42835
43016
  status: "error",
42836
43017
  events: 0,
42837
43018
  detail: `manifest load failed: ${String(err.message || err)}`,
42838
- path: (0, import_node_path22.join)(PATHS.moduleDir, entry.name)
43019
+ path: (0, import_node_path23.join)(PATHS.moduleDir, entry.name)
42839
43020
  });
42840
43021
  }
42841
43022
  }
@@ -42874,17 +43055,17 @@ var ModuleHost = class {
42874
43055
  }
42875
43056
  }
42876
43057
  installedEntrypoint(modulePath) {
42877
- const packageJson = (0, import_node_path22.join)(modulePath, "package.json");
43058
+ const packageJson = (0, import_node_path23.join)(modulePath, "package.json");
42878
43059
  const candidates = [];
42879
- if ((0, import_node_fs31.existsSync)(packageJson)) {
43060
+ if ((0, import_node_fs32.existsSync)(packageJson)) {
42880
43061
  try {
42881
- const pkg = JSON.parse((0, import_node_fs31.readFileSync)(packageJson, "utf-8"));
42882
- if (pkg.main) candidates.push((0, import_node_path22.join)(modulePath, pkg.main));
43062
+ const pkg = JSON.parse((0, import_node_fs32.readFileSync)(packageJson, "utf-8"));
43063
+ if (pkg.main) candidates.push((0, import_node_path23.join)(modulePath, pkg.main));
42883
43064
  } catch {
42884
43065
  }
42885
43066
  }
42886
- candidates.push((0, import_node_path22.join)(modulePath, "dist", "index.js"), (0, import_node_path22.join)(modulePath, "index.js"));
42887
- return candidates.find((candidate) => (0, import_node_fs31.existsSync)(candidate)) || null;
43067
+ candidates.push((0, import_node_path23.join)(modulePath, "dist", "index.js"), (0, import_node_path23.join)(modulePath, "index.js"));
43068
+ return candidates.find((candidate) => (0, import_node_fs32.existsSync)(candidate)) || null;
42888
43069
  }
42889
43070
  isThreatCrushModule(value) {
42890
43071
  return Boolean(
@@ -43393,16 +43574,16 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
43393
43574
  }
43394
43575
 
43395
43576
  // src/daemon/workers/cloud-spool.ts
43396
- var import_node_fs32 = require("fs");
43577
+ var import_node_fs33 = require("fs");
43397
43578
  var import_promises = require("fs/promises");
43398
- var import_node_path23 = require("path");
43579
+ var import_node_path24 = require("path");
43399
43580
  var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
43400
43581
  var CloudSpool = class {
43401
43582
  constructor(path2, limits = DEFAULT_SPOOL_LIMITS) {
43402
43583
  this.path = path2;
43403
43584
  this.limits = limits;
43404
43585
  try {
43405
- (0, import_node_fs32.mkdirSync)((0, import_node_path23.dirname)(path2), { recursive: true });
43586
+ (0, import_node_fs33.mkdirSync)((0, import_node_path24.dirname)(path2), { recursive: true });
43406
43587
  } catch {
43407
43588
  }
43408
43589
  this.load();
@@ -43471,7 +43652,7 @@ var CloudSpool = class {
43471
43652
  load() {
43472
43653
  let raw;
43473
43654
  try {
43474
- raw = (0, import_node_fs32.readFileSync)(this.path, "utf-8");
43655
+ raw = (0, import_node_fs33.readFileSync)(this.path, "utf-8");
43475
43656
  } catch {
43476
43657
  return;
43477
43658
  }
@@ -43938,32 +44119,32 @@ function resolveConfig(section) {
43938
44119
  }
43939
44120
 
43940
44121
  // src/core/abuse-report-log.ts
43941
- var import_node_fs33 = require("fs");
43942
- var import_node_path24 = require("path");
44122
+ var import_node_fs34 = require("fs");
44123
+ var import_node_path25 = require("path");
43943
44124
  init_paths();
43944
44125
  var ABUSE_DIRNAME = "abuse-reports";
43945
44126
  var LOG_FILE2 = "reports.jsonl";
43946
44127
  function resolveAbuseDir(dir) {
43947
44128
  if (dir) return dir;
43948
44129
  if (process.env.THREATCRUSH_ABUSE_DIR) return process.env.THREATCRUSH_ABUSE_DIR;
43949
- const system = (0, import_node_path24.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
43950
- if ((0, import_node_fs33.existsSync)(system)) return system;
43951
- return (0, import_node_path24.join)(PATHS.stateDir, ABUSE_DIRNAME);
44130
+ const system = (0, import_node_path25.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
44131
+ if ((0, import_node_fs34.existsSync)(system)) return system;
44132
+ return (0, import_node_path25.join)(PATHS.stateDir, ABUSE_DIRNAME);
43952
44133
  }
43953
44134
  function logPath(dir) {
43954
- return (0, import_node_path24.join)(resolveAbuseDir(dir), LOG_FILE2);
44135
+ return (0, import_node_path25.join)(resolveAbuseDir(dir), LOG_FILE2);
43955
44136
  }
43956
44137
  function appendReport(record, dir) {
43957
44138
  const path2 = logPath(dir);
43958
- (0, import_node_fs33.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
43959
- (0, import_node_fs33.appendFileSync)(path2, `${JSON.stringify(record)}
44139
+ (0, import_node_fs34.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
44140
+ (0, import_node_fs34.appendFileSync)(path2, `${JSON.stringify(record)}
43960
44141
  `, { mode: 420 });
43961
44142
  }
43962
44143
  function readReports(dir) {
43963
44144
  const path2 = logPath(dir);
43964
44145
  let raw;
43965
44146
  try {
43966
- raw = (0, import_node_fs33.readFileSync)(path2, "utf-8");
44147
+ raw = (0, import_node_fs34.readFileSync)(path2, "utf-8");
43967
44148
  } catch {
43968
44149
  return [];
43969
44150
  }
@@ -44360,8 +44541,8 @@ var RemediationConsumer = class {
44360
44541
 
44361
44542
  // src/daemon/workers/auto-update.ts
44362
44543
  var import_node_child_process10 = require("child_process");
44363
- var import_node_fs34 = require("fs");
44364
- var import_node_path25 = require("path");
44544
+ var import_node_fs35 = require("fs");
44545
+ var import_node_path26 = require("path");
44365
44546
  init_backoff();
44366
44547
  var PKG_NAME = "@profullstack/threatcrush";
44367
44548
  var REGISTRY = `https://registry.npmjs.org/${PKG_NAME}`;
@@ -44405,12 +44586,12 @@ function pickUpdate(doc, current, opts) {
44405
44586
  return { version: null, reason: `${latest} is younger than min_age, and nothing older is newer than ${current}; waiting` };
44406
44587
  }
44407
44588
  function installPlan(opts) {
44408
- const expected = `${import_node_path25.sep}lib${import_node_path25.sep}node_modules${import_node_path25.sep}@profullstack${import_node_path25.sep}threatcrush`;
44589
+ const expected = `${import_node_path26.sep}lib${import_node_path26.sep}node_modules${import_node_path26.sep}@profullstack${import_node_path26.sep}threatcrush`;
44409
44590
  if (!opts.pkgRoot.endsWith(expected)) {
44410
44591
  return { kind: "unsupported", reason: `not an npm global install (${opts.pkgRoot}); run \`threatcrush update\`` };
44411
44592
  }
44412
- const nodeBin = (0, import_node_path25.dirname)(opts.execPath);
44413
- const npm = (0, import_node_path25.join)(nodeBin, "npm");
44593
+ const nodeBin = (0, import_node_path26.dirname)(opts.execPath);
44594
+ const npm = (0, import_node_path26.join)(nodeBin, "npm");
44414
44595
  if (!opts.npmExists(npm)) return { kind: "unsupported", reason: `no npm beside ${opts.execPath}` };
44415
44596
  if (!opts.owner) return { kind: "unsupported", reason: `cannot tell who owns ${opts.pkgRoot}` };
44416
44597
  const npmArgs = [npm, "i", "-g", `${PKG_NAME}@${opts.version}`, "--no-fund", "--no-audit"];
@@ -44442,10 +44623,10 @@ function installPlan(opts) {
44442
44623
  }
44443
44624
  function ownerOf(path2, passwd = "/etc/passwd") {
44444
44625
  try {
44445
- const st = (0, import_node_fs34.statSync)(path2);
44626
+ const st = (0, import_node_fs35.statSync)(path2);
44446
44627
  let home = st.uid === 0 ? "/root" : "";
44447
44628
  try {
44448
- for (const line2 of (0, import_node_fs34.readFileSync)(passwd, "utf8").split("\n")) {
44629
+ for (const line2 of (0, import_node_fs35.readFileSync)(passwd, "utf8").split("\n")) {
44449
44630
  const f = line2.split(":");
44450
44631
  if (Number(f[2]) === st.uid && f[5]) home = f[5];
44451
44632
  }
@@ -44550,7 +44731,7 @@ var AutoUpdate = class {
44550
44731
  uid: process.getuid?.() ?? -1,
44551
44732
  owner: ownerOf(this.opts.pkgRoot),
44552
44733
  underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
44553
- npmExists: import_node_fs34.existsSync
44734
+ npmExists: import_node_fs35.existsSync
44554
44735
  });
44555
44736
  if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
44556
44737
  this.recordAttempt(target);
@@ -44585,7 +44766,7 @@ var AutoUpdate = class {
44585
44766
  }
44586
44767
  lastAttempt() {
44587
44768
  try {
44588
- const v = JSON.parse((0, import_node_fs34.readFileSync)(this.opts.statePath, "utf8"));
44769
+ const v = JSON.parse((0, import_node_fs35.readFileSync)(this.opts.statePath, "utf8"));
44589
44770
  return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
44590
44771
  } catch {
44591
44772
  return null;
@@ -44593,7 +44774,7 @@ var AutoUpdate = class {
44593
44774
  }
44594
44775
  recordAttempt(version) {
44595
44776
  try {
44596
- (0, import_node_fs34.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
44777
+ (0, import_node_fs35.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
44597
44778
  } catch (err) {
44598
44779
  this.opts.log(`[update] could not record attempt: ${err.message}`);
44599
44780
  }
@@ -44602,8 +44783,8 @@ var AutoUpdate = class {
44602
44783
 
44603
44784
  // src/daemon/workers/threat-feeds.ts
44604
44785
  var import_node_child_process11 = require("child_process");
44605
- var import_node_fs35 = require("fs");
44606
- var import_node_path26 = require("path");
44786
+ var import_node_fs36 = require("fs");
44787
+ var import_node_path27 = require("path");
44607
44788
  var import_node_net10 = require("net");
44608
44789
  init_backoff();
44609
44790
  var EGRESS_TABLE = "threatcrush_egress";
@@ -44775,14 +44956,14 @@ var ThreatFeeds = class {
44775
44956
  */
44776
44957
  writeResolverFiles(set) {
44777
44958
  const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
44778
- const dir = this.opts.resolverDir ?? (0, import_node_path26.dirname)(this.opts.cachePath);
44959
+ const dir = this.opts.resolverDir ?? (0, import_node_path27.dirname)(this.opts.cachePath);
44779
44960
  const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
44780
44961
  const write = (name, content) => {
44781
- const path2 = (0, import_node_path26.join)(dir, name);
44962
+ const path2 = (0, import_node_path27.join)(dir, name);
44782
44963
  if (this.resolverWritten.get(name) === content) return false;
44783
44964
  try {
44784
- (0, import_node_fs35.writeFileSync)(`${path2}.tmp`, content);
44785
- (0, import_node_fs35.renameSync)(`${path2}.tmp`, path2);
44965
+ (0, import_node_fs36.writeFileSync)(`${path2}.tmp`, content);
44966
+ (0, import_node_fs36.renameSync)(`${path2}.tmp`, path2);
44786
44967
  this.resolverWritten.set(name, content);
44787
44968
  return true;
44788
44969
  } catch (err) {
@@ -44793,11 +44974,11 @@ var ThreatFeeds = class {
44793
44974
  const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
44794
44975
  const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
44795
44976
  const via = [];
44796
- if ((0, import_node_fs35.existsSync)(hooks.dnsmasq)) {
44977
+ if ((0, import_node_fs36.existsSync)(hooks.dnsmasq)) {
44797
44978
  via.push("dnsmasq");
44798
44979
  if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
44799
44980
  }
44800
- if ((0, import_node_fs35.existsSync)(hooks.unbound)) {
44981
+ if ((0, import_node_fs36.existsSync)(hooks.unbound)) {
44801
44982
  via.push("unbound");
44802
44983
  if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
44803
44984
  this.run("systemctl", ["reload", "unbound.service"]);
@@ -44858,8 +45039,8 @@ var ThreatFeeds = class {
44858
45039
  };
44859
45040
 
44860
45041
  // src/daemon/workers/privilege-watch.ts
44861
- var import_node_fs36 = require("fs");
44862
- var import_node_path27 = require("path");
45042
+ var import_node_fs37 = require("fs");
45043
+ var import_node_path28 = require("path");
44863
45044
  var import_node_child_process12 = require("child_process");
44864
45045
 
44865
45046
  // src/core/privileges/index.ts
@@ -45050,31 +45231,31 @@ function countryName(code) {
45050
45231
  var fsIO = {
45051
45232
  readFile: (p) => {
45052
45233
  try {
45053
- return (0, import_node_fs36.readFileSync)(p, "utf-8");
45234
+ return (0, import_node_fs37.readFileSync)(p, "utf-8");
45054
45235
  } catch {
45055
45236
  return null;
45056
45237
  }
45057
45238
  },
45058
45239
  readDir: (p) => {
45059
45240
  try {
45060
- return (0, import_node_fs36.readdirSync)(p);
45241
+ return (0, import_node_fs37.readdirSync)(p);
45061
45242
  } catch {
45062
45243
  return null;
45063
45244
  }
45064
45245
  },
45065
- exists: (p) => (0, import_node_fs36.existsSync)(p)
45246
+ exists: (p) => (0, import_node_fs37.existsSync)(p)
45066
45247
  };
45067
45248
  function readJson(path2) {
45068
45249
  try {
45069
- return JSON.parse((0, import_node_fs36.readFileSync)(path2, "utf-8"));
45250
+ return JSON.parse((0, import_node_fs37.readFileSync)(path2, "utf-8"));
45070
45251
  } catch {
45071
45252
  return null;
45072
45253
  }
45073
45254
  }
45074
45255
  function writeJson(path2, value) {
45075
- (0, import_node_fs36.mkdirSync)((0, import_node_path27.dirname)(path2), { recursive: true });
45076
- (0, import_node_fs36.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
45077
- (0, import_node_fs36.renameSync)(`${path2}.tmp`, path2);
45256
+ (0, import_node_fs37.mkdirSync)((0, import_node_path28.dirname)(path2), { recursive: true });
45257
+ (0, import_node_fs37.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
45258
+ (0, import_node_fs37.renameSync)(`${path2}.tmp`, path2);
45078
45259
  }
45079
45260
  function defaultRun3(cmd, args) {
45080
45261
  const res = (0, import_node_child_process12.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 2e4, maxBuffer: 16 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
@@ -45230,7 +45411,7 @@ var PrivilegeWatch = class {
45230
45411
  * raised a "new country" alert on its first run; on dev2 it did, at once.
45231
45412
  */
45232
45413
  async backfillLogins() {
45233
- if ((0, import_node_fs36.existsSync)(this.opts.loginsPath)) return;
45414
+ if ((0, import_node_fs37.existsSync)(this.opts.loginsPath)) return;
45234
45415
  const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
45235
45416
  const byUser = parseAcceptedLogins(out ?? "");
45236
45417
  const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
@@ -45243,7 +45424,7 @@ var PrivilegeWatch = class {
45243
45424
  return;
45244
45425
  }
45245
45426
  }
45246
- if ((0, import_node_fs36.existsSync)(this.opts.loginsPath)) return;
45427
+ if ((0, import_node_fs37.existsSync)(this.opts.loginsPath)) return;
45247
45428
  const at = this.now().toISOString();
45248
45429
  const history = {};
45249
45430
  for (const [user, userIps] of byUser) {
@@ -45455,8 +45636,8 @@ var RuleEngine = class {
45455
45636
  };
45456
45637
 
45457
45638
  // src/daemon/rules/loader.ts
45458
- var import_node_fs37 = require("fs");
45459
- var import_node_path28 = require("path");
45639
+ var import_node_fs38 = require("fs");
45640
+ var import_node_path29 = require("path");
45460
45641
 
45461
45642
  // src/daemon/rules/default-rules.ts
45462
45643
  var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
@@ -45926,11 +46107,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
45926
46107
  function loadAllRules(customDir) {
45927
46108
  const rules = [...DEFAULT_RULES];
45928
46109
  const dir = customDir || RULES_DIR;
45929
- if ((0, import_node_fs37.existsSync)(dir)) {
45930
- const files = (0, import_node_fs37.readdirSync)(dir).filter((f) => f.endsWith(".json"));
46110
+ if ((0, import_node_fs38.existsSync)(dir)) {
46111
+ const files = (0, import_node_fs38.readdirSync)(dir).filter((f) => f.endsWith(".json"));
45931
46112
  for (const file of files) {
45932
46113
  try {
45933
- const raw = (0, import_node_fs37.readFileSync)((0, import_node_path28.join)(dir, file), "utf-8");
46114
+ const raw = (0, import_node_fs38.readFileSync)((0, import_node_path29.join)(dir, file), "utf-8");
45934
46115
  const parsed = JSON.parse(raw);
45935
46116
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
45936
46117
  for (const rule of customRules) {
@@ -45962,8 +46143,8 @@ function loadAllRules(customDir) {
45962
46143
 
45963
46144
  // src/daemon/firewall/adapters.ts
45964
46145
  var import_node_child_process13 = require("child_process");
45965
- var import_node_fs38 = require("fs");
45966
- var import_node_path29 = require("path");
46146
+ var import_node_fs39 = require("fs");
46147
+ var import_node_path30 = require("path");
45967
46148
  var import_node_net11 = require("net");
45968
46149
  function assertValidFirewallIp(ip) {
45969
46150
  if ((0, import_node_net11.isIP)(ip) !== 4) {
@@ -45976,9 +46157,9 @@ function assertBannableIp(ip) {
45976
46157
  }
45977
46158
  }
45978
46159
  function writeIfAbsent(path2, contents) {
45979
- (0, import_node_fs38.mkdirSync)((0, import_node_path29.dirname)(path2), { recursive: true });
46160
+ (0, import_node_fs39.mkdirSync)((0, import_node_path30.dirname)(path2), { recursive: true });
45980
46161
  try {
45981
- (0, import_node_fs38.writeFileSync)(path2, contents, { flag: "wx" });
46162
+ (0, import_node_fs39.writeFileSync)(path2, contents, { flag: "wx" });
45982
46163
  } catch (err) {
45983
46164
  if (err.code !== "EEXIST") throw err;
45984
46165
  }
@@ -46237,7 +46418,7 @@ function detectFirewallAdapter(backend = "auto") {
46237
46418
  }
46238
46419
 
46239
46420
  // src/daemon/firewall/remediation.ts
46240
- var import_node_fs39 = require("fs");
46421
+ var import_node_fs40 = require("fs");
46241
46422
  var import_node_child_process14 = require("child_process");
46242
46423
  var import_node_net12 = require("net");
46243
46424
  init_paths();
@@ -46308,19 +46489,19 @@ var defaultDiscovery = {
46308
46489
  const snapshot = takeSnapshot({
46309
46490
  readFile: (p) => {
46310
46491
  try {
46311
- return (0, import_node_fs39.readFileSync)(p, "utf-8");
46492
+ return (0, import_node_fs40.readFileSync)(p, "utf-8");
46312
46493
  } catch {
46313
46494
  return null;
46314
46495
  }
46315
46496
  },
46316
46497
  readDir: (p) => {
46317
46498
  try {
46318
- return (0, import_node_fs39.readdirSync)(p);
46499
+ return (0, import_node_fs40.readdirSync)(p);
46319
46500
  } catch {
46320
46501
  return null;
46321
46502
  }
46322
46503
  },
46323
- exists: (p) => (0, import_node_fs39.existsSync)(p)
46504
+ exists: (p) => (0, import_node_fs40.existsSync)(p)
46324
46505
  });
46325
46506
  const out = /* @__PURE__ */ new Set();
46326
46507
  for (const keys of Object.values(snapshot.keys)) {
@@ -46761,7 +46942,7 @@ var RemediationManager = class {
46761
46942
  }
46762
46943
  logLine(line2) {
46763
46944
  try {
46764
- (0, import_node_fs39.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
46945
+ (0, import_node_fs40.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
46765
46946
  `);
46766
46947
  } catch {
46767
46948
  }
@@ -46804,19 +46985,19 @@ function remediationSettings(section) {
46804
46985
  init_backoff();
46805
46986
 
46806
46987
  // src/daemon/watchdog-service.ts
46807
- var import_node_fs40 = require("fs");
46808
- var import_node_path30 = require("path");
46988
+ var import_node_fs41 = require("fs");
46989
+ var import_node_path31 = require("path");
46809
46990
  function defaultShareGid() {
46810
46991
  const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
46811
46992
  if (!isRoot4) return void 0;
46812
46993
  try {
46813
- return (0, import_node_fs40.statSync)("/var/log/auth.log").gid;
46994
+ return (0, import_node_fs41.statSync)("/var/log/auth.log").gid;
46814
46995
  } catch {
46815
46996
  return void 0;
46816
46997
  }
46817
46998
  }
46818
46999
  function startWatchdog(opts) {
46819
- const dir = opts.config?.dir ?? (0, import_node_path30.join)(opts.stateDir, WATCHDOG_DIRNAME);
47000
+ const dir = opts.config?.dir ?? (0, import_node_path31.join)(opts.stateDir, WATCHDOG_DIRNAME);
46820
47001
  const base = { dir, logged: 0, answered: 0, errored: 0 };
46821
47002
  if (opts.config?.enabled === false) {
46822
47003
  opts.log("[watchdog] off ([watchdog] enabled = false)");
@@ -46931,7 +47112,7 @@ function versionOfNode(path2) {
46931
47112
  // src/daemon/index.ts
46932
47113
  function readVersion2() {
46933
47114
  try {
46934
- const pkg = JSON.parse((0, import_node_fs41.readFileSync)((0, import_node_path31.join)(__dirname, "..", "package.json"), "utf-8"));
47115
+ const pkg = JSON.parse((0, import_node_fs42.readFileSync)((0, import_node_path32.join)(__dirname, "..", "package.json"), "utf-8"));
46935
47116
  return pkg.version || "0.0.0";
46936
47117
  } catch {
46937
47118
  return "0.0.0";
@@ -46940,7 +47121,7 @@ function readVersion2() {
46940
47121
  async function runHardeningChecks() {
46941
47122
  const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process16.execFile)(
46942
47123
  process.execPath,
46943
- [(0, import_node_path31.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
47124
+ [(0, import_node_path32.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
46944
47125
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
46945
47126
  );
46946
47127
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -46954,7 +47135,7 @@ async function runHardeningChecks() {
46954
47135
  async function runPatchCheck() {
46955
47136
  const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process16.execFile)(
46956
47137
  process.execPath,
46957
- [(0, import_node_path31.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
47138
+ [(0, import_node_path32.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
46958
47139
  { timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
46959
47140
  );
46960
47141
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -46962,7 +47143,7 @@ async function runPatchCheck() {
46962
47143
  }
46963
47144
  function logLine(line2) {
46964
47145
  try {
46965
- (0, import_node_fs41.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47146
+ (0, import_node_fs42.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
46966
47147
  `);
46967
47148
  } catch {
46968
47149
  }
@@ -47004,7 +47185,7 @@ async function runDaemon() {
47004
47185
  } catch (err) {
47005
47186
  logLine(`[daemon] state db unavailable: ${err.message}`);
47006
47187
  }
47007
- const config = loadConfig((0, import_node_fs41.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
47188
+ const config = loadConfig((0, import_node_fs42.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
47008
47189
  configureAttackDetection(config.detection);
47009
47190
  const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
47010
47191
  const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
@@ -47068,7 +47249,7 @@ async function runDaemon() {
47068
47249
  const threatFeeds = new ThreatFeeds({
47069
47250
  settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
47070
47251
  enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
47071
- cachePath: (0, import_node_path31.join)(PATHS.stateDir, "threat-feeds.json"),
47252
+ cachePath: (0, import_node_path32.join)(PATHS.stateDir, "threat-feeds.json"),
47072
47253
  bus,
47073
47254
  log: logLine
47074
47255
  });
@@ -47076,9 +47257,9 @@ async function runDaemon() {
47076
47257
  const privilegeWatch = new PrivilegeWatch({
47077
47258
  settings: privilegeSettings(config.privileged),
47078
47259
  bus,
47079
- snapshotPath: (0, import_node_path31.join)(PATHS.stateDir, "privileges.json"),
47080
- loginsPath: (0, import_node_path31.join)(PATHS.stateDir, "login-countries.json"),
47081
- cursorPath: (0, import_node_path31.join)(PATHS.stateDir, "sudo-cursor.json"),
47260
+ snapshotPath: (0, import_node_path32.join)(PATHS.stateDir, "privileges.json"),
47261
+ loginsPath: (0, import_node_path32.join)(PATHS.stateDir, "login-countries.json"),
47262
+ cursorPath: (0, import_node_path32.join)(PATHS.stateDir, "sudo-cursor.json"),
47082
47263
  log: logLine
47083
47264
  });
47084
47265
  privilegeWatch.start();
@@ -47099,9 +47280,9 @@ async function runDaemon() {
47099
47280
  cloudSync = new CloudSync({
47100
47281
  bus,
47101
47282
  version,
47102
- hostname: (0, import_node_os12.hostname)(),
47283
+ hostname: (0, import_node_os13.hostname)(),
47103
47284
  minSeverity,
47104
- spoolPath: (0, import_node_path31.join)(PATHS.stateDir, "cloud-spool.jsonl"),
47285
+ spoolPath: (0, import_node_path32.join)(PATHS.stateDir, "cloud-spool.jsonl"),
47105
47286
  log: logLine,
47106
47287
  ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
47107
47288
  runHardening: runHardeningChecks
@@ -47120,8 +47301,8 @@ async function runDaemon() {
47120
47301
  const autoUpdate = new AutoUpdate({
47121
47302
  version,
47122
47303
  settings: updateSettings(config.update),
47123
- pkgRoot: (0, import_node_path31.join)(__dirname, ".."),
47124
- statePath: (0, import_node_path31.join)(PATHS.stateDir, "auto-update.json"),
47304
+ pkgRoot: (0, import_node_path32.join)(__dirname, ".."),
47305
+ statePath: (0, import_node_path32.join)(PATHS.stateDir, "auto-update.json"),
47125
47306
  bus,
47126
47307
  log: logLine,
47127
47308
  restartDaemon
@@ -47211,7 +47392,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
47211
47392
  function isRoot2() {
47212
47393
  return typeof process.getuid === "function" && process.getuid() === 0;
47213
47394
  }
47214
- var DAEMON_ENTRY = (0, import_node_path32.join)(__dirname, "daemon.js");
47395
+ var DAEMON_ENTRY = (0, import_node_path33.join)(__dirname, "daemon.js");
47215
47396
  async function daemonForeground() {
47216
47397
  await runDaemon();
47217
47398
  }
@@ -47232,7 +47413,7 @@ async function daemonStart() {
47232
47413
  return;
47233
47414
  }
47234
47415
  ensureRuntimeDirs();
47235
- if (!(0, import_node_fs42.existsSync)(DAEMON_ENTRY)) {
47416
+ if (!(0, import_node_fs43.existsSync)(DAEMON_ENTRY)) {
47236
47417
  console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
47237
47418
  console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
47238
47419
  return;
@@ -47240,8 +47421,8 @@ async function daemonStart() {
47240
47421
  let out;
47241
47422
  let err;
47242
47423
  try {
47243
- out = (0, import_node_fs43.openSync)(PATHS.logFile, "a");
47244
- err = (0, import_node_fs43.openSync)(PATHS.logFile, "a");
47424
+ out = (0, import_node_fs44.openSync)(PATHS.logFile, "a");
47425
+ err = (0, import_node_fs44.openSync)(PATHS.logFile, "a");
47245
47426
  } catch (e) {
47246
47427
  const code = e.code;
47247
47428
  console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
@@ -47329,12 +47510,12 @@ async function waitForExit(pid, timeoutMs) {
47329
47510
  }
47330
47511
  async function releaseStaleSocket() {
47331
47512
  const deadline = Date.now() + 2e3;
47332
- while ((0, import_node_fs42.existsSync)(PATHS.socket) && Date.now() < deadline) {
47513
+ while ((0, import_node_fs43.existsSync)(PATHS.socket) && Date.now() < deadline) {
47333
47514
  await new Promise((r) => setTimeout(r, 50));
47334
47515
  }
47335
- if ((0, import_node_fs42.existsSync)(PATHS.socket)) {
47516
+ if ((0, import_node_fs43.existsSync)(PATHS.socket)) {
47336
47517
  try {
47337
- (0, import_node_fs42.unlinkSync)(PATHS.socket);
47518
+ (0, import_node_fs43.unlinkSync)(PATHS.socket);
47338
47519
  } catch {
47339
47520
  }
47340
47521
  }
@@ -47342,26 +47523,26 @@ async function releaseStaleSocket() {
47342
47523
 
47343
47524
  // src/commands/service.ts
47344
47525
  var import_node_child_process18 = require("child_process");
47345
- var import_node_fs44 = require("fs");
47346
- var import_node_path33 = require("path");
47347
- var import_node_os13 = require("os");
47526
+ var import_node_fs45 = require("fs");
47527
+ var import_node_path34 = require("path");
47528
+ var import_node_os14 = require("os");
47348
47529
  var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
47349
47530
  var DAEMON_UNIT_NAME = "threatcrushd.service";
47350
47531
  function resolveTemplate() {
47351
- const templatePath = (0, import_node_path33.join)(__dirname, "systemd", "threatcrushd.service");
47352
- if (!(0, import_node_fs44.existsSync)(templatePath)) {
47532
+ const templatePath = (0, import_node_path34.join)(__dirname, "systemd", "threatcrushd.service");
47533
+ if (!(0, import_node_fs45.existsSync)(templatePath)) {
47353
47534
  throw new Error(`systemd unit template not found at ${templatePath}`);
47354
47535
  }
47355
- return (0, import_node_fs44.readFileSync)(templatePath, "utf-8");
47536
+ return (0, import_node_fs45.readFileSync)(templatePath, "utf-8");
47356
47537
  }
47357
47538
  function stableBinPath(binPath) {
47358
47539
  const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
47359
47540
  if (stable === binPath) return binPath;
47360
- return (0, import_node_fs44.existsSync)(stable) ? stable : binPath;
47541
+ return (0, import_node_fs45.existsSync)(stable) ? stable : binPath;
47361
47542
  }
47362
47543
  function resolveBinPath() {
47363
47544
  const arg = process.argv[1];
47364
- if (arg && (0, import_node_fs44.existsSync)(arg)) return stableBinPath(arg);
47545
+ if (arg && (0, import_node_fs45.existsSync)(arg)) return stableBinPath(arg);
47365
47546
  try {
47366
47547
  return (0, import_node_child_process18.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
47367
47548
  } catch {
@@ -47371,11 +47552,11 @@ function resolveBinPath() {
47371
47552
  function stableNodePath(execPath) {
47372
47553
  const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
47373
47554
  if (stable === execPath) return execPath;
47374
- return (0, import_node_fs44.existsSync)(stable) ? stable : execPath;
47555
+ return (0, import_node_fs45.existsSync)(stable) ? stable : execPath;
47375
47556
  }
47376
47557
  function looksLikeNodeScript(path2) {
47377
47558
  try {
47378
- const head = (0, import_node_fs44.readFileSync)(path2, "utf-8").slice(0, 120);
47559
+ const head = (0, import_node_fs45.readFileSync)(path2, "utf-8").slice(0, 120);
47379
47560
  return /^#!.*\bnode\b/.test(head);
47380
47561
  } catch {
47381
47562
  return false;
@@ -47415,7 +47596,7 @@ function callerHome() {
47415
47596
  try {
47416
47597
  const line2 = (0, import_node_child_process18.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
47417
47598
  const home = line2.split(":")[5];
47418
- return home && (0, import_node_fs44.existsSync)(home) ? home : null;
47599
+ return home && (0, import_node_fs45.existsSync)(home) ? home : null;
47419
47600
  } catch {
47420
47601
  return null;
47421
47602
  }
@@ -47423,13 +47604,13 @@ function callerHome() {
47423
47604
  function stopUserModeDaemon() {
47424
47605
  const home = callerHome();
47425
47606
  if (!home) return;
47426
- const runDir = (0, import_node_path33.join)(home, ".threatcrush", "run");
47427
- const pidFile = (0, import_node_path33.join)(runDir, "threatcrushd.pid");
47428
- const socket = (0, import_node_path33.join)(runDir, "threatcrushd.sock");
47429
- if (!(0, import_node_fs44.existsSync)(pidFile) && !(0, import_node_fs44.existsSync)(socket)) return;
47607
+ const runDir = (0, import_node_path34.join)(home, ".threatcrush", "run");
47608
+ const pidFile = (0, import_node_path34.join)(runDir, "threatcrushd.pid");
47609
+ const socket = (0, import_node_path34.join)(runDir, "threatcrushd.sock");
47610
+ if (!(0, import_node_fs45.existsSync)(pidFile) && !(0, import_node_fs45.existsSync)(socket)) return;
47430
47611
  let pid = null;
47431
47612
  try {
47432
- pid = Number.parseInt((0, import_node_fs44.readFileSync)(pidFile, "utf-8").trim(), 10);
47613
+ pid = Number.parseInt((0, import_node_fs45.readFileSync)(pidFile, "utf-8").trim(), 10);
47433
47614
  } catch {
47434
47615
  pid = null;
47435
47616
  }
@@ -47442,7 +47623,7 @@ function stopUserModeDaemon() {
47442
47623
  }
47443
47624
  for (const path2 of [socket, pidFile]) {
47444
47625
  try {
47445
- if ((0, import_node_fs44.existsSync)(path2)) (0, import_node_fs44.rmSync)(path2);
47626
+ if ((0, import_node_fs45.existsSync)(path2)) (0, import_node_fs45.rmSync)(path2);
47446
47627
  } catch {
47447
47628
  }
47448
47629
  }
@@ -47460,7 +47641,7 @@ async function installServiceCommand() {
47460
47641
  }
47461
47642
  const noSystemd = systemdUnavailableReason({
47462
47643
  hasSystemctl: (0, import_node_child_process18.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
47463
- booted: (0, import_node_fs44.existsSync)("/run/systemd/system")
47644
+ booted: (0, import_node_fs45.existsSync)("/run/systemd/system")
47464
47645
  });
47465
47646
  if (noSystemd) {
47466
47647
  console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
@@ -47482,7 +47663,7 @@ async function installServiceCommand() {
47482
47663
  const isNodeScript = looksLikeNodeScript(binPath);
47483
47664
  let nodePath = stableNodePath(process.execPath);
47484
47665
  if (isNodeScript && nodeVersionDir(binPath)) {
47485
- binPath = (0, import_node_fs44.realpathSync)(binPath);
47666
+ binPath = (0, import_node_fs45.realpathSync)(binPath);
47486
47667
  nodePath = process.execPath;
47487
47668
  }
47488
47669
  if (isNodeScript) {
@@ -47495,9 +47676,9 @@ async function installServiceCommand() {
47495
47676
  }
47496
47677
  }
47497
47678
  const exec = execStartCommand(binPath, nodePath, isNodeScript);
47498
- const configDir = (0, import_node_path33.join)((0, import_node_os13.homedir)(), ".threatcrush");
47679
+ const configDir = (0, import_node_path34.join)((0, import_node_os14.homedir)(), ".threatcrush");
47499
47680
  const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
47500
- (0, import_node_fs44.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
47681
+ (0, import_node_fs45.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
47501
47682
  console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
47502
47683
  console.log(source_default.dim(` ExecStart=${exec}`));
47503
47684
  const nodeDir = nodeVersionDir(nodePath);
@@ -47550,9 +47731,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
47550
47731
  ].join("\n");
47551
47732
  }
47552
47733
  function installLogrotate() {
47553
- if (!(0, import_node_fs44.existsSync)((0, import_node_path33.dirname)(LOGROTATE_PATH))) return;
47734
+ if (!(0, import_node_fs45.existsSync)((0, import_node_path34.dirname)(LOGROTATE_PATH))) return;
47554
47735
  try {
47555
- (0, import_node_fs44.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
47736
+ (0, import_node_fs45.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
47556
47737
  console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
47557
47738
  } catch (err) {
47558
47739
  console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
@@ -47574,20 +47755,20 @@ function ensureSystemDirs(configDir) {
47574
47755
  ];
47575
47756
  let admGid2 = null;
47576
47757
  try {
47577
- admGid2 = (0, import_node_fs44.statSync)("/var/log/auth.log").gid;
47758
+ admGid2 = (0, import_node_fs45.statSync)("/var/log/auth.log").gid;
47578
47759
  } catch {
47579
47760
  }
47580
47761
  for (const { path: path2, groupWritable, sticky } of dirs) {
47581
47762
  try {
47582
- (0, import_node_fs44.mkdirSync)(path2, { recursive: true });
47763
+ (0, import_node_fs45.mkdirSync)(path2, { recursive: true });
47583
47764
  } catch {
47584
47765
  }
47585
47766
  try {
47586
47767
  if (groupWritable && admGid2 !== null) {
47587
- (0, import_node_fs44.chmodSync)(path2, sticky ? 1533 : 509);
47768
+ (0, import_node_fs45.chmodSync)(path2, sticky ? 1533 : 509);
47588
47769
  (0, import_node_child_process18.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
47589
47770
  } else {
47590
- (0, import_node_fs44.chmodSync)(path2, 493);
47771
+ (0, import_node_fs45.chmodSync)(path2, 493);
47591
47772
  }
47592
47773
  } catch {
47593
47774
  }
@@ -47615,7 +47796,7 @@ async function uninstallServiceCommand() {
47615
47796
  } catch {
47616
47797
  }
47617
47798
  try {
47618
- if ((0, import_node_fs44.existsSync)(UNIT_PATH)) {
47799
+ if ((0, import_node_fs45.existsSync)(UNIT_PATH)) {
47619
47800
  (0, import_node_child_process18.execSync)(`rm -f ${UNIT_PATH}`);
47620
47801
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
47621
47802
  }
@@ -47629,7 +47810,7 @@ async function uninstallServiceCommand() {
47629
47810
  }
47630
47811
 
47631
47812
  // src/commands/save.ts
47632
- var import_node_fs45 = require("fs");
47813
+ var import_node_fs46 = require("fs");
47633
47814
  var import_toml5 = __toESM(require_toml());
47634
47815
  init_cli_config();
47635
47816
  init_paths();
@@ -47668,9 +47849,9 @@ async function saveCommand(opts = {}) {
47668
47849
  }
47669
47850
  const path2 = opts.config ?? PATHS.configFile;
47670
47851
  let config = {};
47671
- if ((0, import_node_fs45.existsSync)(path2)) {
47852
+ if ((0, import_node_fs46.existsSync)(path2)) {
47672
47853
  try {
47673
- config = import_toml5.default.parse((0, import_node_fs45.readFileSync)(path2, "utf-8"));
47854
+ config = import_toml5.default.parse((0, import_node_fs46.readFileSync)(path2, "utf-8"));
47674
47855
  } catch (err) {
47675
47856
  console.log(source_default.red(` \u2717 ${path2} is not valid TOML: ${err.message}
47676
47857
  `));
@@ -47783,11 +47964,11 @@ function welcomeCommand() {
47783
47964
  }
47784
47965
 
47785
47966
  // src/commands/properties.ts
47786
- var import_node_fs46 = require("fs");
47787
- var import_node_path34 = require("path");
47967
+ var import_node_fs47 = require("fs");
47968
+ var import_node_path35 = require("path");
47788
47969
  var import_node_readline4 = __toESM(require("readline"));
47789
47970
  init_cli_config();
47790
- var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
47971
+ var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
47791
47972
  var KINDS = ["url", "api", "domain", "ip", "repo"];
47792
47973
  function prompt(question) {
47793
47974
  const rl = import_node_readline4.default.createInterface({ input: process.stdin, output: process.stdout });
@@ -47810,7 +47991,7 @@ async function resolveOrgId(orgFlag) {
47810
47991
  }
47811
47992
  let orgs = [];
47812
47993
  try {
47813
- const res = await fetch(`${API_URL5}/api/orgs`, { headers: authHeaders() });
47994
+ const res = await fetch(`${API_URL6}/api/orgs`, { headers: authHeaders() });
47814
47995
  if (!res.ok) {
47815
47996
  console.log(source_default.red(` Failed to list organizations (${res.status})
47816
47997
  `));
@@ -47840,7 +48021,7 @@ async function resolveOrgId(orgFlag) {
47840
48021
  }
47841
48022
  async function fetchProperties(orgId, kind) {
47842
48023
  const qs = kind ? `?kind=${kind}` : "";
47843
- const res = await fetch(`${API_URL5}/api/orgs/${orgId}/properties${qs}`, { headers: authHeaders() });
48024
+ const res = await fetch(`${API_URL6}/api/orgs/${orgId}/properties${qs}`, { headers: authHeaders() });
47844
48025
  if (!res.ok) {
47845
48026
  const body = await res.json().catch(() => ({ error: res.statusText }));
47846
48027
  console.log(source_default.red(` ${body.error || "Failed to load properties"}
@@ -47921,7 +48102,7 @@ async function propertiesAddCommand(name, target, opts) {
47921
48102
  };
47922
48103
  const spinner = ora({ text: `Creating property ${source_default.white(name)}...`, color: "green" }).start();
47923
48104
  try {
47924
- const res = await fetch(`${API_URL5}/api/orgs/${resolved.org.id}/properties`, {
48105
+ const res = await fetch(`${API_URL6}/api/orgs/${resolved.org.id}/properties`, {
47925
48106
  method: "POST",
47926
48107
  headers: authHeaders(),
47927
48108
  body: JSON.stringify(body)
@@ -47957,7 +48138,7 @@ async function propertiesRemoveCommand(nameOrId, opts) {
47957
48138
  return;
47958
48139
  }
47959
48140
  }
47960
- const res = await fetch(`${API_URL5}/api/orgs/${resolved.org.id}/properties/${match.id}`, {
48141
+ const res = await fetch(`${API_URL6}/api/orgs/${resolved.org.id}/properties/${match.id}`, {
47961
48142
  method: "DELETE",
47962
48143
  headers: authHeaders()
47963
48144
  });
@@ -47972,7 +48153,7 @@ async function propertiesRemoveCommand(nameOrId, opts) {
47972
48153
  }
47973
48154
  async function enqueueRun(orgId, propertyId, type, trigger = "cli") {
47974
48155
  try {
47975
- const res = await fetch(`${API_URL5}/api/orgs/${orgId}/properties/${propertyId}/runs`, {
48156
+ const res = await fetch(`${API_URL6}/api/orgs/${orgId}/properties/${propertyId}/runs`, {
47976
48157
  method: "POST",
47977
48158
  headers: authHeaders(),
47978
48159
  body: JSON.stringify({ type, trigger })
@@ -47985,7 +48166,7 @@ async function enqueueRun(orgId, propertyId, type, trigger = "cli") {
47985
48166
  }
47986
48167
  async function finalizeRun(orgId, propertyId, runId, result) {
47987
48168
  try {
47988
- await fetch(`${API_URL5}/api/orgs/${orgId}/properties/${propertyId}/runs/${runId}`, {
48169
+ await fetch(`${API_URL6}/api/orgs/${orgId}/properties/${propertyId}/runs/${runId}`, {
47989
48170
  method: "PATCH",
47990
48171
  headers: authHeaders(),
47991
48172
  body: JSON.stringify({
@@ -48089,7 +48270,7 @@ async function propertiesRunsCommand(opts) {
48089
48270
  let total = 0;
48090
48271
  for (const prop of propsToShow) {
48091
48272
  const res = await fetch(
48092
- `${API_URL5}/api/orgs/${resolved.org.id}/properties/${prop.id}/runs?limit=${limit}`,
48273
+ `${API_URL6}/api/orgs/${resolved.org.id}/properties/${prop.id}/runs?limit=${limit}`,
48093
48274
  { headers: authHeaders() }
48094
48275
  );
48095
48276
  if (!res.ok) continue;
@@ -48114,8 +48295,8 @@ async function propertiesRunsCommand(opts) {
48114
48295
  }
48115
48296
  }
48116
48297
  function parseImportFile(path2) {
48117
- const ext = (0, import_node_path34.extname)(path2).toLowerCase();
48118
- const raw = (0, import_node_fs46.readFileSync)(path2, "utf-8");
48298
+ const ext = (0, import_node_path35.extname)(path2).toLowerCase();
48299
+ const raw = (0, import_node_fs47.readFileSync)(path2, "utf-8");
48119
48300
  if (ext === ".json") {
48120
48301
  const parsed = JSON.parse(raw);
48121
48302
  if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
@@ -48193,7 +48374,7 @@ async function propertiesImportCommand(filePath, opts) {
48193
48374
  continue;
48194
48375
  }
48195
48376
  try {
48196
- const res = await fetch(`${API_URL5}/api/orgs/${resolved.org.id}/properties`, {
48377
+ const res = await fetch(`${API_URL6}/api/orgs/${resolved.org.id}/properties`, {
48197
48378
  method: "POST",
48198
48379
  headers: authHeaders(),
48199
48380
  body: JSON.stringify({
@@ -48310,7 +48491,7 @@ async function rulesCommand(opts) {
48310
48491
  }
48311
48492
 
48312
48493
  // src/commands/harden.ts
48313
- var import_node_fs47 = require("fs");
48494
+ var import_node_fs48 = require("fs");
48314
48495
  var import_node_child_process19 = require("child_process");
48315
48496
  init_cli_config();
48316
48497
  function tryExec(cmd) {
@@ -48322,7 +48503,7 @@ function tryExec(cmd) {
48322
48503
  }
48323
48504
  function tryRead(path2) {
48324
48505
  try {
48325
- return (0, import_node_fs47.readFileSync)(path2, "utf-8");
48506
+ return (0, import_node_fs48.readFileSync)(path2, "utf-8");
48326
48507
  } catch {
48327
48508
  return null;
48328
48509
  }
@@ -48426,8 +48607,8 @@ function checkSshWeakConfig() {
48426
48607
  };
48427
48608
  }
48428
48609
  function checkAutoUpdates() {
48429
- const unattended = (0, import_node_fs47.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs47.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
48430
- const dnfAuto = (0, import_node_fs47.existsSync)("/etc/dnf/automatic.conf");
48610
+ const unattended = (0, import_node_fs48.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs48.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
48611
+ const dnfAuto = (0, import_node_fs48.existsSync)("/etc/dnf/automatic.conf");
48431
48612
  if (unattended || dnfAuto) {
48432
48613
  return {
48433
48614
  key: "auto-updates",
@@ -48553,7 +48734,7 @@ function checkFail2ban() {
48553
48734
  explanation: "fail2ban is installed and running."
48554
48735
  };
48555
48736
  }
48556
- if ((0, import_node_fs47.existsSync)("/etc/fail2ban/fail2ban.conf")) {
48737
+ if ((0, import_node_fs48.existsSync)("/etc/fail2ban/fail2ban.conf")) {
48557
48738
  return {
48558
48739
  key: checkKey,
48559
48740
  status: "warn",
@@ -48739,8 +48920,8 @@ async function hardenCommand(opts) {
48739
48920
  }
48740
48921
 
48741
48922
  // src/core/patches/index.ts
48742
- var import_node_fs48 = require("fs");
48743
- var import_node_path35 = require("path");
48923
+ var import_node_fs49 = require("fs");
48924
+ var import_node_path36 = require("path");
48744
48925
  var import_node_child_process20 = require("child_process");
48745
48926
  var import_node_util5 = require("util");
48746
48927
 
@@ -48900,9 +49081,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
48900
49081
  function newestReleaseMtime(dir) {
48901
49082
  try {
48902
49083
  let newest = 0;
48903
- for (const name of (0, import_node_fs48.readdirSync)(dir)) {
49084
+ for (const name of (0, import_node_fs49.readdirSync)(dir)) {
48904
49085
  if (!/Release$/.test(name)) continue;
48905
- newest = Math.max(newest, (0, import_node_fs48.statSync)((0, import_node_path35.join)(dir, name)).mtimeMs);
49086
+ newest = Math.max(newest, (0, import_node_fs49.statSync)((0, import_node_path36.join)(dir, name)).mtimeMs);
48906
49087
  }
48907
49088
  return newest > 0 ? new Date(newest) : null;
48908
49089
  } catch {
@@ -48919,7 +49100,7 @@ async function checkPatches(opts = {}) {
48919
49100
  let osText = opts.osRelease;
48920
49101
  if (osText === void 0) {
48921
49102
  try {
48922
- osText = (0, import_node_fs48.readFileSync)("/etc/os-release", "utf-8");
49103
+ osText = (0, import_node_fs49.readFileSync)("/etc/os-release", "utf-8");
48923
49104
  } catch {
48924
49105
  osText = "";
48925
49106
  }
@@ -49146,24 +49327,24 @@ async function patchesCommand(opts) {
49146
49327
 
49147
49328
  // src/commands/feeds.ts
49148
49329
  var import_node_net13 = require("net");
49149
- var import_node_path37 = require("path");
49330
+ var import_node_path38 = require("path");
49150
49331
  init_paths();
49151
49332
 
49152
49333
  // src/commands/feeds-resolver.ts
49153
49334
  var import_node_child_process21 = require("child_process");
49154
- var import_node_fs49 = require("fs");
49155
- var import_node_path36 = require("path");
49335
+ var import_node_fs50 = require("fs");
49336
+ var import_node_path37 = require("path");
49156
49337
  var realIO = {
49157
- exists: (p) => (0, import_node_fs49.existsSync)(p),
49338
+ exists: (p) => (0, import_node_fs50.existsSync)(p),
49158
49339
  read: (p) => {
49159
49340
  try {
49160
- return (0, import_node_fs49.readFileSync)(p, "utf-8");
49341
+ return (0, import_node_fs50.readFileSync)(p, "utf-8");
49161
49342
  } catch {
49162
49343
  return null;
49163
49344
  }
49164
49345
  },
49165
- write: (p, c) => (0, import_node_fs49.writeFileSync)(p, c),
49166
- remove: (p) => (0, import_node_fs49.rmSync)(p, { force: true }),
49346
+ write: (p, c) => (0, import_node_fs50.writeFileSync)(p, c),
49347
+ remove: (p) => (0, import_node_fs50.rmSync)(p, { force: true }),
49167
49348
  run: (cmd, args) => {
49168
49349
  const r = (0, import_node_child_process21.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
49169
49350
  return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
@@ -49173,17 +49354,17 @@ var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
49173
49354
  var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
49174
49355
  function hookContent(resolver, stateDir) {
49175
49356
  const head = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
49176
- return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path36.join)(stateDir, RESOLVER_FILES.hosts)}
49177
- ` : `${head}include: "${(0, import_node_path36.join)(stateDir, RESOLVER_FILES.unbound)}"
49357
+ return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path37.join)(stateDir, RESOLVER_FILES.hosts)}
49358
+ ` : `${head}include: "${(0, import_node_path37.join)(stateDir, RESOLVER_FILES.unbound)}"
49178
49359
  `;
49179
49360
  }
49180
49361
  function apparmorRule(stateDir) {
49181
- return ` ${(0, import_node_path36.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
49362
+ return ` ${(0, import_node_path37.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
49182
49363
  }
49183
49364
  function detectResolvers(io = realIO) {
49184
49365
  const found = [];
49185
- if (io.exists((0, import_node_path36.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
49186
- if (io.exists((0, import_node_path36.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
49366
+ if (io.exists((0, import_node_path37.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
49367
+ if (io.exists((0, import_node_path37.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
49187
49368
  return found;
49188
49369
  }
49189
49370
  function check(resolver, io) {
@@ -49196,7 +49377,7 @@ function restartIfActive(resolver, io) {
49196
49377
  }
49197
49378
  function installHook(resolver, stateDir, io = realIO) {
49198
49379
  const hook = RESOLVER_HOOKS[resolver];
49199
- const file = (0, import_node_path36.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
49380
+ const file = (0, import_node_path37.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
49200
49381
  if (!io.exists(file)) io.write(file, resolver === "dnsmasq" ? hostsBlocklist([]) : unboundBlocklist([]));
49201
49382
  io.write(hook, hookContent(resolver, stateDir));
49202
49383
  if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
@@ -49257,8 +49438,8 @@ function resolverCommand(sub, stateDir, io = realIO) {
49257
49438
  }
49258
49439
  return failed ? 1 : 0;
49259
49440
  }
49260
- const hosts = io.read((0, import_node_path36.join)(stateDir, RESOLVER_FILES.hosts));
49261
- const unbound = io.read((0, import_node_path36.join)(stateDir, RESOLVER_FILES.unbound));
49441
+ const hosts = io.read((0, import_node_path37.join)(stateDir, RESOLVER_FILES.hosts));
49442
+ const unbound = io.read((0, import_node_path37.join)(stateDir, RESOLVER_FILES.unbound));
49262
49443
  console.log(` resolvers here: ${found.join(", ") || "none that can block (systemd-resolved only?)"}`);
49263
49444
  for (const r of ["dnsmasq", "unbound"]) {
49264
49445
  console.log(` ${r.padEnd(8)} hook ${io.exists(RESOLVER_HOOKS[r]) ? source_default.green("installed") : source_default.gray("not installed")}`);
@@ -49270,11 +49451,11 @@ function resolverCommand(sub, stateDir, io = realIO) {
49270
49451
  // src/commands/feeds.ts
49271
49452
  async function loadSet() {
49272
49453
  for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
49273
- const path2 = (0, import_node_path37.join)(dir, "threat-feeds.json");
49454
+ const path2 = (0, import_node_path38.join)(dir, "threat-feeds.json");
49274
49455
  const set = readFeedCache(path2);
49275
49456
  if (set) return { set, from: path2 };
49276
49457
  }
49277
- const settings = threatFeedSettings(loadConfig((0, import_node_path37.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
49458
+ const settings = threatFeedSettings(loadConfig((0, import_node_path38.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
49278
49459
  return { set: await fetchFeeds(settings), from: "abuse.ch (live; no daemon cache readable)" };
49279
49460
  }
49280
49461
  async function feedsCommand(action, value, opts) {
@@ -49318,14 +49499,14 @@ async function feedsCommand(action, value, opts) {
49318
49499
  }
49319
49500
 
49320
49501
  // src/commands/reputation.ts
49321
- var import_node_os14 = require("os");
49322
- var import_node_fs50 = require("fs");
49323
- var import_node_path38 = require("path");
49324
- var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
49325
- var CONFIG_PATH3 = (0, import_node_path38.join)((0, import_node_os14.homedir)(), ".threatcrush", "config.json");
49502
+ var import_node_os15 = require("os");
49503
+ var import_node_fs51 = require("fs");
49504
+ var import_node_path39 = require("path");
49505
+ var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
49506
+ var CONFIG_PATH4 = (0, import_node_path39.join)((0, import_node_os15.homedir)(), ".threatcrush", "config.json");
49326
49507
  function readConfig3() {
49327
49508
  try {
49328
- return JSON.parse((0, import_node_fs50.readFileSync)(CONFIG_PATH3, "utf-8"));
49509
+ return JSON.parse((0, import_node_fs51.readFileSync)(CONFIG_PATH4, "utf-8"));
49329
49510
  } catch {
49330
49511
  return {};
49331
49512
  }
@@ -49381,7 +49562,7 @@ async function reputationLookupCommand(indicators, opts) {
49381
49562
  const org = opts.org ?? auth.orgId;
49382
49563
  let reports;
49383
49564
  if (indicators.length === 1) {
49384
- const url = `${API_URL6}/api/v1/reputation/${encodeURIComponent(indicators[0])}${org ? `?org=${encodeURIComponent(org)}` : ""}`;
49565
+ const url = `${API_URL7}/api/v1/reputation/${encodeURIComponent(indicators[0])}${org ? `?org=${encodeURIComponent(org)}` : ""}`;
49385
49566
  const res = await fetch(url, { headers: auth.headers });
49386
49567
  const body = await res.json().catch(() => ({}));
49387
49568
  if (!res.ok) {
@@ -49392,7 +49573,7 @@ async function reputationLookupCommand(indicators, opts) {
49392
49573
  }
49393
49574
  reports = [body];
49394
49575
  } else {
49395
- const res = await fetch(`${API_URL6}/api/v1/reputation/bulk`, {
49576
+ const res = await fetch(`${API_URL7}/api/v1/reputation/bulk`, {
49396
49577
  method: "POST",
49397
49578
  headers: { ...auth.headers, "Content-Type": "application/json" },
49398
49579
  body: JSON.stringify({ indicators, org: org ?? void 0 })
@@ -49434,7 +49615,7 @@ async function reputationWatchCommand(action, indicator, opts) {
49434
49615
  process.exitCode = 2;
49435
49616
  return;
49436
49617
  }
49437
- res = await fetch(`${API_URL6}/api/v1/reputation/watches`, {
49618
+ res = await fetch(`${API_URL7}/api/v1/reputation/watches`, {
49438
49619
  method: "POST",
49439
49620
  headers: { ...auth.headers, "Content-Type": "application/json" },
49440
49621
  body: JSON.stringify({ indicator, note: opts.note, destination_id: opts.destination, org: org ?? void 0 })
@@ -49445,12 +49626,12 @@ async function reputationWatchCommand(action, indicator, opts) {
49445
49626
  process.exitCode = 2;
49446
49627
  return;
49447
49628
  }
49448
- res = await fetch(`${API_URL6}/api/v1/reputation/watches?indicator=${encodeURIComponent(indicator)}${qs ? `&${qs}` : ""}`, {
49629
+ res = await fetch(`${API_URL7}/api/v1/reputation/watches?indicator=${encodeURIComponent(indicator)}${qs ? `&${qs}` : ""}`, {
49449
49630
  method: "DELETE",
49450
49631
  headers: auth.headers
49451
49632
  });
49452
49633
  } else {
49453
- res = await fetch(`${API_URL6}/api/v1/reputation/watches${qs ? `?${qs}` : ""}`, { headers: auth.headers });
49634
+ res = await fetch(`${API_URL7}/api/v1/reputation/watches${qs ? `?${qs}` : ""}`, { headers: auth.headers });
49454
49635
  }
49455
49636
  const body = await res.json().catch(() => ({}));
49456
49637
  if (!res.ok) {
@@ -49484,7 +49665,7 @@ async function reputationSubscribeCommand(opts) {
49484
49665
  process.exitCode = 2;
49485
49666
  return;
49486
49667
  }
49487
- const res = await fetch(`${API_URL6}/api/v1/reputation/subscribe`, {
49668
+ const res = await fetch(`${API_URL7}/api/v1/reputation/subscribe`, {
49488
49669
  method: "POST",
49489
49670
  headers: { ...auth.headers, "Content-Type": "application/json" },
49490
49671
  body: JSON.stringify({
@@ -49513,7 +49694,7 @@ async function reputationSubscribeCommand(opts) {
49513
49694
  }
49514
49695
 
49515
49696
  // src/commands/privileged.ts
49516
- var import_node_fs51 = require("fs");
49697
+ var import_node_fs52 = require("fs");
49517
49698
  init_paths();
49518
49699
  var SEV2 = {
49519
49700
  critical: source_default.red.bold,
@@ -49526,19 +49707,19 @@ async function privilegedCommand(opts) {
49526
49707
  const snapshot = takeSnapshot({
49527
49708
  readFile: (p) => {
49528
49709
  try {
49529
- return (0, import_node_fs51.readFileSync)(p, "utf-8");
49710
+ return (0, import_node_fs52.readFileSync)(p, "utf-8");
49530
49711
  } catch {
49531
49712
  return null;
49532
49713
  }
49533
49714
  },
49534
49715
  readDir: (p) => {
49535
49716
  try {
49536
- return (0, import_node_fs51.readdirSync)(p);
49717
+ return (0, import_node_fs52.readdirSync)(p);
49537
49718
  } catch {
49538
49719
  return null;
49539
49720
  }
49540
49721
  },
49541
- exists: (p) => (0, import_node_fs51.existsSync)(p)
49722
+ exists: (p) => (0, import_node_fs52.existsSync)(p)
49542
49723
  });
49543
49724
  let events = [];
49544
49725
  let ledgerNote = "";
@@ -49720,7 +49901,7 @@ async function allowlistCommand(opts) {
49720
49901
  }
49721
49902
 
49722
49903
  // src/commands/abuse.ts
49723
- var import_node_fs52 = require("fs");
49904
+ var import_node_fs53 = require("fs");
49724
49905
  init_paths();
49725
49906
  function rows(records) {
49726
49907
  if (records.length === 0) {
@@ -49780,7 +49961,7 @@ function abuseRetractCommand(id, opts = {}) {
49780
49961
  );
49781
49962
  }
49782
49963
  function abuseStatusCommand(opts = {}) {
49783
- const config = loadConfig((0, import_node_fs52.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
49964
+ const config = loadConfig((0, import_node_fs53.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
49784
49965
  const cfg = resolveConfig(config.abuse_reporter);
49785
49966
  const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
49786
49967
  const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
@@ -49910,6 +50091,45 @@ function shadowedUpdateWarning(latest, active2, activePath) {
49910
50091
 
49911
50092
  // src/index.ts
49912
50093
  init_ipc_client();
50094
+
50095
+ // src/core/user-agent.ts
50096
+ init_cli_config();
50097
+ var USER_AGENT = `threatcrush/${PKG_VERSION} (node ${process.version}; ${process.platform})`;
50098
+ function isOurHost(url, api2 = apiUrl()) {
50099
+ let host;
50100
+ try {
50101
+ host = new URL(url).hostname.toLowerCase();
50102
+ } catch {
50103
+ return false;
50104
+ }
50105
+ let apiHost = "";
50106
+ try {
50107
+ apiHost = new URL(api2).hostname.toLowerCase();
50108
+ } catch {
50109
+ }
50110
+ return host === apiHost || host === "threatcrush.com" || host.endsWith(".threatcrush.com");
50111
+ }
50112
+ function urlOf(input) {
50113
+ if (typeof input === "string") return input;
50114
+ if (input instanceof URL) return input.href;
50115
+ return input.url;
50116
+ }
50117
+ function installUserAgent(target = globalThis) {
50118
+ const base = target.fetch;
50119
+ if (!base || base.__threatcrushUA) return;
50120
+ const wrapped = ((input, init) => {
50121
+ if (!isOurHost(urlOf(input))) return base(input, init);
50122
+ const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
50123
+ if (headers.has("user-agent")) return base(input, init);
50124
+ headers.set("user-agent", USER_AGENT);
50125
+ return base(input, { ...init, headers });
50126
+ });
50127
+ wrapped.__threatcrushUA = true;
50128
+ target.fetch = wrapped;
50129
+ }
50130
+
50131
+ // src/index.ts
50132
+ installUserAgent();
49913
50133
  var LOGO2 = `
49914
50134
  ${source_default.green(" \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557")}
49915
50135
  ${source_default.green(" \u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D")}
@@ -49919,10 +50139,10 @@ ${source_default.green(" \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u25
49919
50139
  ${source_default.green(" \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D")}
49920
50140
  ${source_default.dim(" C R U S H")}
49921
50141
  `;
49922
- var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
50142
+ var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
49923
50143
  var PKG_NAME2 = "@profullstack/threatcrush";
49924
50144
  var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
49925
- var INSTALL_CONFIG_PATH = (0, import_node_path39.join)((0, import_node_os15.homedir)(), ".threatcrush", "install.json");
50145
+ var INSTALL_CONFIG_PATH = (0, import_node_path40.join)((0, import_node_os16.homedir)(), ".threatcrush", "install.json");
49926
50146
  function detectPackageManager() {
49927
50147
  try {
49928
50148
  const npmGlobal = (0, import_node_child_process23.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
@@ -49948,7 +50168,7 @@ function detectPackageManager() {
49948
50168
  }
49949
50169
  function readInstallConfig() {
49950
50170
  try {
49951
- return JSON.parse((0, import_node_fs53.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
50171
+ return JSON.parse((0, import_node_fs54.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
49952
50172
  } catch {
49953
50173
  return {};
49954
50174
  }
@@ -50288,7 +50508,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
50288
50508
  program2.command("logs").description("Tail daemon logs").action(async () => {
50289
50509
  console.log(LOGO2);
50290
50510
  const logPath2 = PATHS.logFile;
50291
- if (!(0, import_node_fs53.existsSync)(logPath2)) {
50511
+ if (!(0, import_node_fs54.existsSync)(logPath2)) {
50292
50512
  console.log(source_default.yellow(` No log file found at ${logPath2}`));
50293
50513
  console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
50294
50514
  return;
@@ -50409,7 +50629,7 @@ var storeCmd = program2.command("store").description("Browse the module marketpl
50409
50629
  console.log(source_default.green(" Module Marketplace\n"));
50410
50630
  console.log(source_default.dim(" Loading available modules..."));
50411
50631
  try {
50412
- const res = await fetch(`${API_URL7}/api/modules`);
50632
+ const res = await fetch(`${API_URL8}/api/modules`);
50413
50633
  if (!res.ok) {
50414
50634
  console.log(source_default.red(` \u2717 Failed to load modules: ${res.statusText}
50415
50635
  `));
@@ -50436,7 +50656,7 @@ storeCmd.command("search <query>").description("Search for modules in the store"
50436
50656
  console.log(source_default.green(` Searching for "${query}"...
50437
50657
  `));
50438
50658
  try {
50439
- const res = await fetch(`${API_URL7}/api/modules?q=${encodeURIComponent(query)}`);
50659
+ const res = await fetch(`${API_URL8}/api/modules?q=${encodeURIComponent(query)}`);
50440
50660
  if (!res.ok) {
50441
50661
  console.log(source_default.red(` \u2717 Search failed: ${res.statusText}
50442
50662
  `));
@@ -50461,10 +50681,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
50461
50681
  });
50462
50682
  storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
50463
50683
  console.log(LOGO2);
50464
- const configPath = (0, import_node_path39.join)((0, import_node_os15.homedir)(), ".threatcrush", "config.json");
50684
+ const configPath = (0, import_node_path40.join)((0, import_node_os16.homedir)(), ".threatcrush", "config.json");
50465
50685
  let email = "";
50466
50686
  try {
50467
- const config = JSON.parse((0, import_node_fs53.readFileSync)(configPath, "utf-8"));
50687
+ const config = JSON.parse((0, import_node_fs54.readFileSync)(configPath, "utf-8"));
50468
50688
  email = config.email || "";
50469
50689
  } catch {
50470
50690
  }
@@ -50481,9 +50701,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
50481
50701
  return;
50482
50702
  }
50483
50703
  try {
50484
- const dir = (0, import_node_path39.join)((0, import_node_os15.homedir)(), ".threatcrush");
50485
- if (!(0, import_node_fs53.existsSync)(dir)) (0, import_node_fs53.mkdirSync)(dir, { recursive: true });
50486
- (0, import_node_fs53.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
50704
+ const dir = (0, import_node_path40.join)((0, import_node_os16.homedir)(), ".threatcrush");
50705
+ if (!(0, import_node_fs54.existsSync)(dir)) (0, import_node_fs54.mkdirSync)(dir, { recursive: true });
50706
+ (0, import_node_fs54.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
50487
50707
  console.log(source_default.dim(` Saved email to ${configPath}`));
50488
50708
  } catch {
50489
50709
  }
@@ -50493,7 +50713,7 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
50493
50713
  `));
50494
50714
  let meta;
50495
50715
  try {
50496
- const res = await fetch(`${API_URL7}/api/modules/fetch-meta`, {
50716
+ const res = await fetch(`${API_URL8}/api/modules/fetch-meta`, {
50497
50717
  method: "POST",
50498
50718
  headers: { "Content-Type": "application/json" },
50499
50719
  body: JSON.stringify({ url, git_url: url })
@@ -50539,7 +50759,7 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
50539
50759
  }
50540
50760
  console.log(source_default.dim("\n Publishing..."));
50541
50761
  try {
50542
- const res = await fetch(`${API_URL7}/api/modules`, {
50762
+ const res = await fetch(`${API_URL8}/api/modules`, {
50543
50763
  method: "POST",
50544
50764
  headers: { "Content-Type": "application/json" },
50545
50765
  body: JSON.stringify({
@@ -50560,7 +50780,7 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
50560
50780
  const slug = mod?.slug || meta.name;
50561
50781
  console.log(source_default.green(`
50562
50782
  \u2713 Module submitted for review. It appears in the store once approved.`));
50563
- console.log(source_default.dim(` ${API_URL7}/store/${slug}
50783
+ console.log(source_default.dim(` ${API_URL8}/store/${slug}
50564
50784
  `));
50565
50785
  } catch (err) {
50566
50786
  console.log(source_default.red(`
@@ -50631,6 +50851,12 @@ propsCmd.command("runs").alias("history").description("Show recent scan/pentest
50631
50851
  propsCmd.command("import <file>").description("Bulk-import properties from a .json, .csv, or .tsv file").option("--org <slug>", "Organization slug").option("-n, --dry-run", "Preview without writing").action(async (file, opts) => {
50632
50852
  await propertiesImportCommand(file, { org: opts.org, dryRun: opts.dryRun });
50633
50853
  });
50854
+ program2.command("redeem").description("Redeem a ThreatCrush credit code into your credit balance (needs `threatcrush login`)").argument("<code>", "Credit code, e.g. CR-XXXX-XXXX-XXXX-XXXX").action(async (code) => {
50855
+ await redeemCommand(code);
50856
+ });
50857
+ program2.command("invites").description("Your invites (3 per account): list, create [note], accept <code>, revoke <id>").argument("[action]", "list | create | accept | revoke", "list").argument("[arg]", "note for create, code for accept, id for revoke").action(async (action, arg) => {
50858
+ await invitesCommand(action, arg);
50859
+ });
50634
50860
  program2.command("connect").description("Connect to a ThreatCrush server via SSH").argument("[target]", "Server name, user@hostname, or hostname").option("--org <slug>", "Organization slug").option("-u, --user <user>", "SSH username").option("-p, --port <port>", "SSH port", "22").option("-i, --identity <path>", "SSH identity file").action(async (target, opts) => {
50635
50861
  await connectCommand({
50636
50862
  target,