@profullstack/threatcrush 0.13.51 → 0.13.53

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_fs55 = require("fs");
23430
+ var import_node_path41 = 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");
@@ -40314,7 +40314,7 @@ async function pentestCommand(targetUrl) {
40314
40314
  }
40315
40315
 
40316
40316
  // src/commands/ai-scan.ts
40317
- var import_node_fs22 = require("fs");
40317
+ var import_node_fs23 = require("fs");
40318
40318
 
40319
40319
  // src/aiscan/probes.ts
40320
40320
  function makeCanary() {
@@ -40530,6 +40530,66 @@ ${stripShebang(source)}
40530
40530
  return { scans };
40531
40531
  }
40532
40532
 
40533
+ // src/core/usage-ping.ts
40534
+ var import_node_crypto6 = require("crypto");
40535
+ var import_node_fs22 = require("fs");
40536
+ var import_node_path19 = require("path");
40537
+ init_cli_config();
40538
+ var STATE_FILE = "usage-ping.json";
40539
+ function usagePingDisabled(env3 = process.env) {
40540
+ const v = (env3.THREATCRUSH_TELEMETRY ?? "").trim().toLowerCase();
40541
+ if (["0", "off", "false", "no"].includes(v)) return true;
40542
+ const dnt = (env3.DO_NOT_TRACK ?? "").trim().toLowerCase();
40543
+ return dnt !== "" && dnt !== "0" && dnt !== "false";
40544
+ }
40545
+ function installId(dir = CLI_CONFIG_DIR) {
40546
+ const file = (0, import_node_path19.join)(dir, STATE_FILE);
40547
+ try {
40548
+ const j = JSON.parse((0, import_node_fs22.readFileSync)(file, "utf-8"));
40549
+ if (j.install_id) return { id: j.install_id, fresh: false };
40550
+ } catch {
40551
+ }
40552
+ const id = (0, import_node_crypto6.randomUUID)();
40553
+ try {
40554
+ if (!(0, import_node_fs22.existsSync)(dir)) (0, import_node_fs22.mkdirSync)(dir, { recursive: true });
40555
+ (0, import_node_fs22.writeFileSync)(file, JSON.stringify({ install_id: id, created_at: (/* @__PURE__ */ new Date()).toISOString() }) + "\n");
40556
+ } catch {
40557
+ }
40558
+ return { id, fresh: true };
40559
+ }
40560
+ function pingBody(p, id, env3 = process.env) {
40561
+ return {
40562
+ ...p,
40563
+ version: PKG_VERSION,
40564
+ platform: process.platform,
40565
+ arch: process.arch,
40566
+ node: process.version,
40567
+ ci: Boolean(env3.CI || env3.GITHUB_ACTIONS),
40568
+ install_id: id
40569
+ };
40570
+ }
40571
+ async function sendUsagePing(p, opts = {}) {
40572
+ const env3 = opts.env ?? process.env;
40573
+ if (usagePingDisabled(env3)) return false;
40574
+ try {
40575
+ const { id, fresh } = installId(opts.dir);
40576
+ if (fresh) {
40577
+ (opts.notice ?? ((s) => process.stderr.write(s + "\n")))(
40578
+ "threatcrush: sends an anonymous usage count per ai-scan run (no targets, no findings text). Turn off with THREATCRUSH_TELEMETRY=0."
40579
+ );
40580
+ }
40581
+ const res = await (opts.fetchImpl ?? fetch)(`${apiUrl()}/api/telemetry`, {
40582
+ method: "POST",
40583
+ headers: { "content-type": "application/json" },
40584
+ body: JSON.stringify(pingBody(p, id, env3)),
40585
+ signal: AbortSignal.timeout(opts.timeoutMs ?? 2e3)
40586
+ });
40587
+ return res.ok;
40588
+ } catch {
40589
+ return false;
40590
+ }
40591
+ }
40592
+
40533
40593
  // src/commands/ai-scan.ts
40534
40594
  function parseHeaders(pairs = []) {
40535
40595
  const out = {};
@@ -40557,6 +40617,7 @@ async function aiScanCommand(url, opts) {
40557
40617
  logger.info(`Probing ${source_default.white(url)} with ${probes.length} check(s)...
40558
40618
  `);
40559
40619
  const spinner = ora({ text: "Running probes...", color: "green" }).start();
40620
+ const t0 = Date.now();
40560
40621
  const result = await runAiScan(url, send, {
40561
40622
  categories,
40562
40623
  delayMs: opts.delay ? Number(opts.delay) : 0,
@@ -40565,6 +40626,14 @@ async function aiScanCommand(url, opts) {
40565
40626
  }
40566
40627
  });
40567
40628
  spinner.stop();
40629
+ await sendUsagePing({
40630
+ event: "ai-scan",
40631
+ probes: probes.length,
40632
+ findings: result.findings.length,
40633
+ severity: result.severity_summary,
40634
+ duration_ms: Date.now() - t0,
40635
+ failed: Boolean(result.error)
40636
+ });
40568
40637
  if (opts.json) {
40569
40638
  console.log(JSON.stringify(result, null, 2));
40570
40639
  return result;
@@ -40591,13 +40660,21 @@ async function aiScanMoshCommand(file, args) {
40591
40660
  console.log();
40592
40661
  let source;
40593
40662
  try {
40594
- source = (0, import_node_fs22.readFileSync)(file, "utf-8");
40663
+ source = (0, import_node_fs23.readFileSync)(file, "utf-8");
40595
40664
  } catch (err) {
40596
40665
  logger.error(`Cannot read ${file}: ${err.message}`);
40597
40666
  process.exitCode = 1;
40598
40667
  return;
40599
40668
  }
40669
+ const t0 = Date.now();
40600
40670
  const res = await runMosh(source, { argv: args, out: (s) => console.log(" " + s) });
40671
+ await sendUsagePing({
40672
+ event: "ai-scan-run",
40673
+ scans: res.scans.length,
40674
+ findings: res.scans.reduce((n, s) => n + s.findings.length, 0),
40675
+ duration_ms: Date.now() - t0,
40676
+ failed: Boolean(res.failed)
40677
+ });
40601
40678
  if (res.failed) {
40602
40679
  console.log();
40603
40680
  console.log(` ${source_default.red("\u2717 script failed:")} ${res.failed}`);
@@ -40612,21 +40689,21 @@ async function aiScanMoshCommand(file, args) {
40612
40689
 
40613
40690
  // src/commands/orgs.ts
40614
40691
  var import_node_os9 = require("os");
40615
- var import_node_fs23 = require("fs");
40616
- var import_node_path19 = require("path");
40692
+ var import_node_fs24 = require("fs");
40693
+ var import_node_path20 = require("path");
40617
40694
  var API_URL3 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
40618
- var CONFIG_PATH = (0, import_node_path19.join)((0, import_node_os9.homedir)(), ".threatcrush", "config.json");
40695
+ var CONFIG_PATH = (0, import_node_path20.join)((0, import_node_os9.homedir)(), ".threatcrush", "config.json");
40619
40696
  function readConfig() {
40620
40697
  try {
40621
- return JSON.parse((0, import_node_fs23.readFileSync)(CONFIG_PATH, "utf-8"));
40698
+ return JSON.parse((0, import_node_fs24.readFileSync)(CONFIG_PATH, "utf-8"));
40622
40699
  } catch {
40623
40700
  return {};
40624
40701
  }
40625
40702
  }
40626
40703
  function writeConfig(config) {
40627
- const dir = (0, import_node_path19.join)((0, import_node_os9.homedir)(), ".threatcrush");
40628
- if (!(0, import_node_fs23.existsSync)(dir)) (0, import_node_fs23.mkdirSync)(dir, { recursive: true });
40629
- (0, import_node_fs23.writeFileSync)(CONFIG_PATH, JSON.stringify(config, null, 2));
40704
+ const dir = (0, import_node_path20.join)((0, import_node_os9.homedir)(), ".threatcrush");
40705
+ if (!(0, import_node_fs24.existsSync)(dir)) (0, import_node_fs24.mkdirSync)(dir, { recursive: true });
40706
+ (0, import_node_fs24.writeFileSync)(CONFIG_PATH, JSON.stringify(config, null, 2));
40630
40707
  }
40631
40708
  function getAuthHeaders() {
40632
40709
  const config = readConfig();
@@ -40760,9 +40837,85 @@ async function useOrganization(slug) {
40760
40837
  }
40761
40838
  }
40762
40839
 
40840
+ // src/commands/credits.ts
40841
+ var import_node_os10 = require("os");
40842
+ var import_node_fs25 = require("fs");
40843
+ var import_node_path21 = require("path");
40844
+ var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
40845
+ var CONFIG_PATH2 = (0, import_node_path21.join)((0, import_node_os10.homedir)(), ".threatcrush", "config.json");
40846
+ function sessionToken() {
40847
+ try {
40848
+ const cfg = JSON.parse((0, import_node_fs25.readFileSync)(CONFIG_PATH2, "utf-8"));
40849
+ return cfg.token ?? null;
40850
+ } catch {
40851
+ return null;
40852
+ }
40853
+ }
40854
+ async function api(path2, init = {}, f = fetch) {
40855
+ const token = sessionToken();
40856
+ if (!token) {
40857
+ console.error(source_default.red(" Not signed in. Run `threatcrush login` first."));
40858
+ process.exitCode = 1;
40859
+ return { ok: false, status: 401, body: {} };
40860
+ }
40861
+ const res = await f(`${API_URL4}${path2}`, {
40862
+ ...init,
40863
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, ...init.headers ?? {} }
40864
+ });
40865
+ const body = await res.json().catch(() => ({}));
40866
+ if (res.status === 401) console.error(source_default.red(" Session expired. Run `threatcrush login` again."));
40867
+ return { ok: res.ok, status: res.status, body };
40868
+ }
40869
+ function fail(body, fallback) {
40870
+ console.error(source_default.red(` ${String(body.error ?? fallback)}`));
40871
+ process.exitCode = 1;
40872
+ }
40873
+ async function redeemCommand(code, f = fetch) {
40874
+ const r = await api("/api/credits/redeem", { method: "POST", body: JSON.stringify({ code }) }, f);
40875
+ if (r.status === 401 && !r.body.error) return;
40876
+ if (!r.ok) return fail(r.body, "Could not redeem the code.");
40877
+ console.log(source_default.green(` ${String(r.body.message)}`));
40878
+ if (typeof r.body.balance_usd === "number") console.log(` Credit balance: $${r.body.balance_usd.toFixed(2)}`);
40879
+ }
40880
+ async function invitesCommand(action = "list", arg, f = fetch) {
40881
+ if (action === "create") {
40882
+ const r2 = await api("/api/credits/invites", { method: "POST", body: JSON.stringify({ note: arg ?? "" }) }, f);
40883
+ if (!r2.ok) return fail(r2.body, "Could not create an invite.");
40884
+ console.log(source_default.green(" Invite created. Send this link (it is shown once):"));
40885
+ console.log(` ${source_default.bold(String(r2.body.url))}`);
40886
+ return;
40887
+ }
40888
+ if (action === "accept") {
40889
+ if (!arg) return fail({}, "Usage: threatcrush invites accept <code>");
40890
+ const r2 = await api("/api/credits/invites/accept", { method: "POST", body: JSON.stringify({ code: arg }) }, f);
40891
+ if (!r2.ok) return fail(r2.body, "Could not accept the invite.");
40892
+ console.log(source_default.green(` ${String(r2.body.message)}`));
40893
+ return;
40894
+ }
40895
+ if (action === "revoke") {
40896
+ if (!arg) return fail({}, "Usage: threatcrush invites revoke <id>");
40897
+ const r2 = await api(`/api/credits/invites/${encodeURIComponent(arg)}`, { method: "DELETE" }, f);
40898
+ if (!r2.ok) return fail(r2.body, "Could not withdraw the invite.");
40899
+ console.log(source_default.green(" Invite withdrawn."));
40900
+ return;
40901
+ }
40902
+ const r = await api("/api/credits/invites", {}, f);
40903
+ if (!r.ok) return fail(r.body, "Could not load invites.");
40904
+ const q = r.body.quota;
40905
+ console.log(` Invites left: ${source_default.bold(`${q.left} / ${q.total}`)} (bonus: ${String(r.body.bonusCredits)} credits each)`);
40906
+ if (!r.body.canInvite) {
40907
+ console.log(source_default.yellow(r.body.unlocksAt ? ` Invites unlock on ${String(r.body.unlocksAt).slice(0, 10)}.` : ` Cannot invite: ${String(r.body.blockedReason)}`));
40908
+ }
40909
+ for (const i of r.body.invites ?? []) {
40910
+ const who = i.usedByEmail ? ` ${i.usedByEmail}` : "";
40911
+ const bonus = i.status === "used" ? ` (credits ${i.bonus})` : "";
40912
+ console.log(` ${source_default.dim(i.id)} ${new Date(i.createdAt).toISOString().slice(0, 10)} ${i.status}${who}${bonus} ${i.note}`);
40913
+ }
40914
+ }
40915
+
40763
40916
  // src/commands/servers.ts
40764
40917
  var import_node_readline2 = __toESM(require("readline"));
40765
- var import_node_os10 = require("os");
40918
+ var import_node_os11 = require("os");
40766
40919
  init_cli_config();
40767
40920
  function connectionStatus(server, now = Date.now()) {
40768
40921
  const seen = server.last_seen ? Date.parse(server.last_seen) : NaN;
@@ -40861,7 +41014,7 @@ async function chooseOrg(orgs, flag, ask2) {
40861
41014
  async function linkServer(opts = {}, ask2 = askChoice) {
40862
41015
  if (!hasSession()) throw new Error("Not logged in. Run: threatcrush login");
40863
41016
  const org = await chooseOrg(await fetchOrgs(), opts.org, ask2);
40864
- const host = opts.hostname ?? (0, import_node_os10.hostname)();
41017
+ const host = opts.hostname ?? (0, import_node_os11.hostname)();
40865
41018
  const listRes = await cloudFetch(`/api/orgs/${org.id}/servers`);
40866
41019
  if (!listRes.ok) throw new Error(`Failed to list servers in /${org.slug} (${listRes.status})`);
40867
41020
  const { servers = [] } = await listRes.json();
@@ -40978,15 +41131,15 @@ function timeAgo(dateStr) {
40978
41131
  }
40979
41132
 
40980
41133
  // src/commands/connect.ts
40981
- var import_node_os11 = require("os");
40982
- var import_node_fs24 = require("fs");
40983
- var import_node_path20 = require("path");
41134
+ var import_node_os12 = require("os");
41135
+ var import_node_fs26 = require("fs");
41136
+ var import_node_path22 = require("path");
40984
41137
  var import_node_child_process5 = require("child_process");
40985
- var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
40986
- var CONFIG_PATH2 = (0, import_node_path20.join)((0, import_node_os11.homedir)(), ".threatcrush", "config.json");
41138
+ var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
41139
+ var CONFIG_PATH3 = (0, import_node_path22.join)((0, import_node_os12.homedir)(), ".threatcrush", "config.json");
40987
41140
  function readConfig2() {
40988
41141
  try {
40989
- return JSON.parse((0, import_node_fs24.readFileSync)(CONFIG_PATH2, "utf-8"));
41142
+ return JSON.parse((0, import_node_fs26.readFileSync)(CONFIG_PATH3, "utf-8"));
40990
41143
  } catch {
40991
41144
  return {};
40992
41145
  }
@@ -41028,7 +41181,7 @@ async function connectCommand(options) {
41028
41181
  async function interactiveConnect(orgSlug) {
41029
41182
  const config = readConfig2();
41030
41183
  try {
41031
- const orgsRes = await fetch(`${API_URL4}/api/orgs`, { headers: getAuthHeaders2() });
41184
+ const orgsRes = await fetch(`${API_URL5}/api/orgs`, { headers: getAuthHeaders2() });
41032
41185
  if (!orgsRes.ok) {
41033
41186
  console.log(source_default.red(" Failed to fetch organizations. Are you logged in?\n"));
41034
41187
  return;
@@ -41050,7 +41203,7 @@ async function interactiveConnect(orgSlug) {
41050
41203
  if (!orgId) {
41051
41204
  orgId = orgs[0].id;
41052
41205
  }
41053
- const serversRes = await fetch(`${API_URL4}/api/orgs/${orgId}/servers`, { headers: getAuthHeaders2() });
41206
+ const serversRes = await fetch(`${API_URL5}/api/orgs/${orgId}/servers`, { headers: getAuthHeaders2() });
41054
41207
  if (!serversRes.ok) {
41055
41208
  console.log(source_default.red(" Failed to fetch servers.\n"));
41056
41209
  return;
@@ -41083,7 +41236,7 @@ async function resolveServer(nameOrSlug, orgSlug) {
41083
41236
  try {
41084
41237
  let orgId = config.current_org_id;
41085
41238
  if (orgSlug) {
41086
- const orgsRes = await fetch(`${API_URL4}/api/orgs`, { headers: getAuthHeaders2() });
41239
+ const orgsRes = await fetch(`${API_URL5}/api/orgs`, { headers: getAuthHeaders2() });
41087
41240
  if (!orgsRes.ok) return null;
41088
41241
  const orgsData = await orgsRes.json();
41089
41242
  const org = (orgsData.organizations || []).find((o) => o.slug === orgSlug);
@@ -41091,13 +41244,13 @@ async function resolveServer(nameOrSlug, orgSlug) {
41091
41244
  orgId = org.id;
41092
41245
  }
41093
41246
  if (!orgId) {
41094
- const orgsRes = await fetch(`${API_URL4}/api/orgs`, { headers: getAuthHeaders2() });
41247
+ const orgsRes = await fetch(`${API_URL5}/api/orgs`, { headers: getAuthHeaders2() });
41095
41248
  if (!orgsRes.ok) return null;
41096
41249
  const orgsData = await orgsRes.json();
41097
41250
  orgId = (orgsData.organizations || [])[0]?.id;
41098
41251
  if (!orgId) return null;
41099
41252
  }
41100
- const serversRes = await fetch(`${API_URL4}/api/orgs/${orgId}/servers`, { headers: getAuthHeaders2() });
41253
+ const serversRes = await fetch(`${API_URL5}/api/orgs/${orgId}/servers`, { headers: getAuthHeaders2() });
41101
41254
  if (!serversRes.ok) return null;
41102
41255
  const serversData = await serversRes.json();
41103
41256
  const servers = serversData.servers || [];
@@ -41141,21 +41294,21 @@ async function sshConnect(options) {
41141
41294
 
41142
41295
  // src/commands/daemon.ts
41143
41296
  var import_node_child_process17 = require("child_process");
41144
- var import_node_fs42 = require("fs");
41145
- var import_node_path32 = require("path");
41146
- var import_node_fs43 = require("fs");
41297
+ var import_node_fs44 = require("fs");
41298
+ var import_node_path34 = require("path");
41299
+ var import_node_fs45 = require("fs");
41147
41300
 
41148
41301
  // src/daemon/index.ts
41149
- var import_node_fs41 = require("fs");
41302
+ var import_node_fs43 = require("fs");
41150
41303
  var import_node_child_process16 = require("child_process");
41151
- var import_node_os12 = require("os");
41152
- var import_node_path31 = require("path");
41304
+ var import_node_os13 = require("os");
41305
+ var import_node_path33 = require("path");
41153
41306
  var import_node_util4 = require("util");
41154
41307
  init_paths();
41155
41308
 
41156
41309
  // src/daemon/ipc-server.ts
41157
41310
  var import_node_net3 = require("net");
41158
- var import_node_fs25 = require("fs");
41311
+ var import_node_fs27 = require("fs");
41159
41312
  init_paths();
41160
41313
  init_control_token();
41161
41314
 
@@ -41209,9 +41362,9 @@ var IpcServer = class {
41209
41362
  controlToken = "";
41210
41363
  async start() {
41211
41364
  this.controlToken = issueControlToken();
41212
- if ((0, import_node_fs25.existsSync)(PATHS.socket)) {
41365
+ if ((0, import_node_fs27.existsSync)(PATHS.socket)) {
41213
41366
  try {
41214
- (0, import_node_fs25.unlinkSync)(PATHS.socket);
41367
+ (0, import_node_fs27.unlinkSync)(PATHS.socket);
41215
41368
  } catch {
41216
41369
  }
41217
41370
  }
@@ -41249,14 +41402,14 @@ var IpcServer = class {
41249
41402
  return new Promise((resolve6) => {
41250
41403
  if (!this.server) {
41251
41404
  try {
41252
- if ((0, import_node_fs25.existsSync)(PATHS.socket)) (0, import_node_fs25.unlinkSync)(PATHS.socket);
41405
+ if ((0, import_node_fs27.existsSync)(PATHS.socket)) (0, import_node_fs27.unlinkSync)(PATHS.socket);
41253
41406
  } catch {
41254
41407
  }
41255
41408
  return resolve6();
41256
41409
  }
41257
41410
  this.server.close(() => {
41258
41411
  try {
41259
- if ((0, import_node_fs25.existsSync)(PATHS.socket)) (0, import_node_fs25.unlinkSync)(PATHS.socket);
41412
+ if ((0, import_node_fs27.existsSync)(PATHS.socket)) (0, import_node_fs27.unlinkSync)(PATHS.socket);
41260
41413
  } catch {
41261
41414
  }
41262
41415
  resolve6();
@@ -41436,7 +41589,7 @@ var IpcServer = class {
41436
41589
  }
41437
41590
  }
41438
41591
  };
41439
- function admGid(readGroup = () => (0, import_node_fs25.readFileSync)("/etc/group", "utf-8"), statAuthLog = () => (0, import_node_fs25.statSync)("/var/log/auth.log")) {
41592
+ function admGid(readGroup = () => (0, import_node_fs27.readFileSync)("/etc/group", "utf-8"), statAuthLog = () => (0, import_node_fs27.statSync)("/var/log/auth.log")) {
41440
41593
  try {
41441
41594
  for (const line2 of readGroup().split("\n")) {
41442
41595
  const [name, , gid] = line2.split(":");
@@ -41452,14 +41605,14 @@ function admGid(readGroup = () => (0, import_node_fs25.readFileSync)("/etc/group
41452
41605
  }
41453
41606
 
41454
41607
  // src/daemon/module-host.ts
41455
- var import_node_fs31 = require("fs");
41456
- var import_node_path22 = require("path");
41608
+ var import_node_fs33 = require("fs");
41609
+ var import_node_path24 = require("path");
41457
41610
  var import_node_url = require("url");
41458
41611
  var import_toml4 = __toESM(require_toml());
41459
41612
  init_paths();
41460
41613
 
41461
41614
  // src/daemon/watchers/log-watcher.ts
41462
- var import_node_fs26 = require("fs");
41615
+ var import_node_fs28 = require("fs");
41463
41616
  var DEFAULT_SOURCES = [
41464
41617
  { path: "/var/log/auth.log", module: "ssh-guard", category: "auth" },
41465
41618
  { path: "/var/log/secure", module: "ssh-guard", category: "auth" },
@@ -41479,9 +41632,9 @@ var LogWatcher = class {
41479
41632
  start() {
41480
41633
  const started = [];
41481
41634
  for (const src of this.sources) {
41482
- if (!(0, import_node_fs26.existsSync)(src.path)) continue;
41635
+ if (!(0, import_node_fs28.existsSync)(src.path)) continue;
41483
41636
  try {
41484
- (0, import_node_fs26.accessSync)(src.path, import_node_fs26.constants.R_OK);
41637
+ (0, import_node_fs28.accessSync)(src.path, import_node_fs28.constants.R_OK);
41485
41638
  } catch {
41486
41639
  continue;
41487
41640
  }
@@ -41778,7 +41931,7 @@ function realtimeToDate(rt) {
41778
41931
 
41779
41932
  // src/modules/network-monitor/index.ts
41780
41933
  var import_node_child_process7 = require("child_process");
41781
- var import_node_fs27 = require("fs");
41934
+ var import_node_fs29 = require("fs");
41782
41935
  var NetworkMonitor = class {
41783
41936
  constructor(bus2) {
41784
41937
  this.bus = bus2;
@@ -41842,7 +41995,7 @@ var NetworkMonitor = class {
41842
41995
  hasConntrackOrSs() {
41843
41996
  const ss = (0, import_node_child_process7.spawnSync)("ss", ["--version"], { stdio: "pipe" });
41844
41997
  if (ss.status === 0) return true;
41845
- return (0, import_node_fs27.existsSync)("/proc/net/tcp");
41998
+ return (0, import_node_fs29.existsSync)("/proc/net/tcp");
41846
41999
  }
41847
42000
  /**
41848
42001
  * The TCP ports this host actually listens on.
@@ -42029,18 +42182,18 @@ var NetworkMonitor = class {
42029
42182
  };
42030
42183
 
42031
42184
  // src/modules/dns-monitor/index.ts
42032
- var import_node_fs30 = require("fs");
42185
+ var import_node_fs32 = require("fs");
42033
42186
  var import_node_child_process9 = require("child_process");
42034
42187
  var import_node_readline3 = require("readline");
42035
42188
 
42036
42189
  // src/core/threat-feeds/index.ts
42037
- var import_node_fs29 = require("fs");
42038
- var import_node_path21 = require("path");
42190
+ var import_node_fs31 = require("fs");
42191
+ var import_node_path23 = require("path");
42039
42192
  var import_node_net5 = require("net");
42040
42193
 
42041
42194
  // src/daemon/firewall/protected.ts
42042
42195
  var import_node_child_process8 = require("child_process");
42043
- var import_node_fs28 = require("fs");
42196
+ var import_node_fs30 = require("fs");
42044
42197
  var import_node_net4 = require("net");
42045
42198
  var DEFAULT_PROTECTED = [
42046
42199
  "127.0.0.0/8",
@@ -42196,14 +42349,14 @@ function moshClients(procDir = "/proc") {
42196
42349
  const found = /* @__PURE__ */ new Set();
42197
42350
  let pids = [];
42198
42351
  try {
42199
- pids = (0, import_node_fs28.readdirSync)(procDir).filter((p) => /^\d+$/.test(p));
42352
+ pids = (0, import_node_fs30.readdirSync)(procDir).filter((p) => /^\d+$/.test(p));
42200
42353
  } catch {
42201
42354
  return [];
42202
42355
  }
42203
42356
  for (const pid of pids) {
42204
42357
  try {
42205
- if ((0, import_node_fs28.readFileSync)(`${procDir}/${pid}/comm`, "utf-8").trim() !== "mosh-server") continue;
42206
- const ip = sshClientFromEnviron((0, import_node_fs28.readFileSync)(`${procDir}/${pid}/environ`, "latin1"));
42358
+ if ((0, import_node_fs30.readFileSync)(`${procDir}/${pid}/comm`, "utf-8").trim() !== "mosh-server") continue;
42359
+ const ip = sshClientFromEnviron((0, import_node_fs30.readFileSync)(`${procDir}/${pid}/environ`, "latin1"));
42207
42360
  if (ip) found.add(ip);
42208
42361
  } catch {
42209
42362
  }
@@ -42409,17 +42562,17 @@ async function fetchFeeds(settings, fetchImpl = fetch) {
42409
42562
  }
42410
42563
  function readFeedCache(path2) {
42411
42564
  try {
42412
- const set = JSON.parse((0, import_node_fs29.readFileSync)(path2, "utf-8"));
42565
+ const set = JSON.parse((0, import_node_fs31.readFileSync)(path2, "utf-8"));
42413
42566
  return set && typeof set.ips === "object" && typeof set.domains === "object" ? set : null;
42414
42567
  } catch {
42415
42568
  return null;
42416
42569
  }
42417
42570
  }
42418
42571
  function writeFeedCache(path2, set) {
42419
- (0, import_node_fs29.mkdirSync)((0, import_node_path21.dirname)(path2), { recursive: true });
42572
+ (0, import_node_fs31.mkdirSync)((0, import_node_path23.dirname)(path2), { recursive: true });
42420
42573
  const tmp = `${path2}.tmp`;
42421
- (0, import_node_fs29.writeFileSync)(tmp, JSON.stringify(set));
42422
- (0, import_node_fs29.renameSync)(tmp, path2);
42574
+ (0, import_node_fs31.writeFileSync)(tmp, JSON.stringify(set));
42575
+ (0, import_node_fs31.renameSync)(tmp, path2);
42423
42576
  }
42424
42577
  var RESOLVER_FILES = {
42425
42578
  hosts: "blocked-domains.hosts",
@@ -42544,9 +42697,9 @@ var DnsMonitor = class {
42544
42697
  }
42545
42698
  start() {
42546
42699
  const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
42547
- if (!(0, import_node_fs30.existsSync)(p)) return false;
42700
+ if (!(0, import_node_fs32.existsSync)(p)) return false;
42548
42701
  try {
42549
- (0, import_node_fs30.accessSync)(p, import_node_fs30.constants.R_OK);
42702
+ (0, import_node_fs32.accessSync)(p, import_node_fs32.constants.R_OK);
42550
42703
  return true;
42551
42704
  } catch {
42552
42705
  return false;
@@ -42903,15 +43056,15 @@ var ModuleHost = class {
42903
43056
  }
42904
43057
  }
42905
43058
  async discoverAndStartInstalled() {
42906
- if (!(0, import_node_fs31.existsSync)(PATHS.moduleDir)) return;
43059
+ if (!(0, import_node_fs33.existsSync)(PATHS.moduleDir)) return;
42907
43060
  const configs = loadModuleConfigs(PATHS.confD);
42908
- const entries = (0, import_node_fs31.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
43061
+ const entries = (0, import_node_fs33.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
42909
43062
  for (const entry of entries) {
42910
43063
  if (!entry.isDirectory()) continue;
42911
- const manifestPath = (0, import_node_path22.join)(PATHS.moduleDir, entry.name, "mod.toml");
42912
- if (!(0, import_node_fs31.existsSync)(manifestPath)) continue;
43064
+ const manifestPath = (0, import_node_path24.join)(PATHS.moduleDir, entry.name, "mod.toml");
43065
+ if (!(0, import_node_fs33.existsSync)(manifestPath)) continue;
42913
43066
  try {
42914
- const manifest = import_toml4.default.parse((0, import_node_fs31.readFileSync)(manifestPath, "utf-8"));
43067
+ const manifest = import_toml4.default.parse((0, import_node_fs33.readFileSync)(manifestPath, "utf-8"));
42915
43068
  const name = manifest.module?.name || entry.name;
42916
43069
  const defaults = manifest.module?.config?.defaults || {};
42917
43070
  const config = {
@@ -42925,7 +43078,7 @@ var ModuleHost = class {
42925
43078
  source: "installed",
42926
43079
  status: config.enabled === false ? "disabled" : "loaded",
42927
43080
  events: 0,
42928
- path: (0, import_node_path22.join)(PATHS.moduleDir, entry.name),
43081
+ path: (0, import_node_path24.join)(PATHS.moduleDir, entry.name),
42929
43082
  config
42930
43083
  };
42931
43084
  this.modules.set(name, hosted);
@@ -42940,7 +43093,7 @@ var ModuleHost = class {
42940
43093
  status: "error",
42941
43094
  events: 0,
42942
43095
  detail: `manifest load failed: ${String(err.message || err)}`,
42943
- path: (0, import_node_path22.join)(PATHS.moduleDir, entry.name)
43096
+ path: (0, import_node_path24.join)(PATHS.moduleDir, entry.name)
42944
43097
  });
42945
43098
  }
42946
43099
  }
@@ -42979,17 +43132,17 @@ var ModuleHost = class {
42979
43132
  }
42980
43133
  }
42981
43134
  installedEntrypoint(modulePath) {
42982
- const packageJson = (0, import_node_path22.join)(modulePath, "package.json");
43135
+ const packageJson = (0, import_node_path24.join)(modulePath, "package.json");
42983
43136
  const candidates = [];
42984
- if ((0, import_node_fs31.existsSync)(packageJson)) {
43137
+ if ((0, import_node_fs33.existsSync)(packageJson)) {
42985
43138
  try {
42986
- const pkg = JSON.parse((0, import_node_fs31.readFileSync)(packageJson, "utf-8"));
42987
- if (pkg.main) candidates.push((0, import_node_path22.join)(modulePath, pkg.main));
43139
+ const pkg = JSON.parse((0, import_node_fs33.readFileSync)(packageJson, "utf-8"));
43140
+ if (pkg.main) candidates.push((0, import_node_path24.join)(modulePath, pkg.main));
42988
43141
  } catch {
42989
43142
  }
42990
43143
  }
42991
- candidates.push((0, import_node_path22.join)(modulePath, "dist", "index.js"), (0, import_node_path22.join)(modulePath, "index.js"));
42992
- return candidates.find((candidate) => (0, import_node_fs31.existsSync)(candidate)) || null;
43144
+ candidates.push((0, import_node_path24.join)(modulePath, "dist", "index.js"), (0, import_node_path24.join)(modulePath, "index.js"));
43145
+ return candidates.find((candidate) => (0, import_node_fs33.existsSync)(candidate)) || null;
42993
43146
  }
42994
43147
  isThreatCrushModule(value) {
42995
43148
  return Boolean(
@@ -43397,7 +43550,7 @@ var RunsWorker = class {
43397
43550
  init_cli_config();
43398
43551
 
43399
43552
  // src/core/cloud-events.ts
43400
- var import_node_crypto6 = require("crypto");
43553
+ var import_node_crypto7 = require("crypto");
43401
43554
  var import_node_net6 = require("net");
43402
43555
  init_cli_config();
43403
43556
  function currentLink() {
@@ -43471,7 +43624,7 @@ function remediationEvent(serverId, event) {
43471
43624
  return {
43472
43625
  type: "remediation",
43473
43626
  server_id: serverId,
43474
- event_id: (0, import_node_crypto6.randomUUID)(),
43627
+ event_id: (0, import_node_crypto7.randomUUID)(),
43475
43628
  action_type: d.action,
43476
43629
  target_value: event.source_ip,
43477
43630
  status: d.failed === true ? "failed" : "executed",
@@ -43498,16 +43651,16 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
43498
43651
  }
43499
43652
 
43500
43653
  // src/daemon/workers/cloud-spool.ts
43501
- var import_node_fs32 = require("fs");
43654
+ var import_node_fs34 = require("fs");
43502
43655
  var import_promises = require("fs/promises");
43503
- var import_node_path23 = require("path");
43656
+ var import_node_path25 = require("path");
43504
43657
  var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
43505
43658
  var CloudSpool = class {
43506
43659
  constructor(path2, limits = DEFAULT_SPOOL_LIMITS) {
43507
43660
  this.path = path2;
43508
43661
  this.limits = limits;
43509
43662
  try {
43510
- (0, import_node_fs32.mkdirSync)((0, import_node_path23.dirname)(path2), { recursive: true });
43663
+ (0, import_node_fs34.mkdirSync)((0, import_node_path25.dirname)(path2), { recursive: true });
43511
43664
  } catch {
43512
43665
  }
43513
43666
  this.load();
@@ -43576,7 +43729,7 @@ var CloudSpool = class {
43576
43729
  load() {
43577
43730
  let raw;
43578
43731
  try {
43579
- raw = (0, import_node_fs32.readFileSync)(this.path, "utf-8");
43732
+ raw = (0, import_node_fs34.readFileSync)(this.path, "utf-8");
43580
43733
  } catch {
43581
43734
  return;
43582
43735
  }
@@ -43814,7 +43967,7 @@ var CloudSync = class {
43814
43967
  };
43815
43968
 
43816
43969
  // src/daemon/workers/abuse-reporter.ts
43817
- var import_node_crypto7 = require("crypto");
43970
+ var import_node_crypto8 = require("crypto");
43818
43971
 
43819
43972
  // src/daemon/workers/abuse-evidence.ts
43820
43973
  var import_node_net7 = require("net");
@@ -44043,32 +44196,32 @@ function resolveConfig(section) {
44043
44196
  }
44044
44197
 
44045
44198
  // src/core/abuse-report-log.ts
44046
- var import_node_fs33 = require("fs");
44047
- var import_node_path24 = require("path");
44199
+ var import_node_fs35 = require("fs");
44200
+ var import_node_path26 = require("path");
44048
44201
  init_paths();
44049
44202
  var ABUSE_DIRNAME = "abuse-reports";
44050
44203
  var LOG_FILE2 = "reports.jsonl";
44051
44204
  function resolveAbuseDir(dir) {
44052
44205
  if (dir) return dir;
44053
44206
  if (process.env.THREATCRUSH_ABUSE_DIR) return process.env.THREATCRUSH_ABUSE_DIR;
44054
- const system = (0, import_node_path24.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
44055
- if ((0, import_node_fs33.existsSync)(system)) return system;
44056
- return (0, import_node_path24.join)(PATHS.stateDir, ABUSE_DIRNAME);
44207
+ const system = (0, import_node_path26.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
44208
+ if ((0, import_node_fs35.existsSync)(system)) return system;
44209
+ return (0, import_node_path26.join)(PATHS.stateDir, ABUSE_DIRNAME);
44057
44210
  }
44058
44211
  function logPath(dir) {
44059
- return (0, import_node_path24.join)(resolveAbuseDir(dir), LOG_FILE2);
44212
+ return (0, import_node_path26.join)(resolveAbuseDir(dir), LOG_FILE2);
44060
44213
  }
44061
44214
  function appendReport(record, dir) {
44062
44215
  const path2 = logPath(dir);
44063
- (0, import_node_fs33.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
44064
- (0, import_node_fs33.appendFileSync)(path2, `${JSON.stringify(record)}
44216
+ (0, import_node_fs35.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
44217
+ (0, import_node_fs35.appendFileSync)(path2, `${JSON.stringify(record)}
44065
44218
  `, { mode: 420 });
44066
44219
  }
44067
44220
  function readReports(dir) {
44068
44221
  const path2 = logPath(dir);
44069
44222
  let raw;
44070
44223
  try {
44071
- raw = (0, import_node_fs33.readFileSync)(path2, "utf-8");
44224
+ raw = (0, import_node_fs35.readFileSync)(path2, "utf-8");
44072
44225
  } catch {
44073
44226
  return [];
44074
44227
  }
@@ -44207,7 +44360,7 @@ var AbuseReporter = class {
44207
44360
  const payload = buildPayload(ip, evidence);
44208
44361
  const results = this.cfg.dryRun ? [] : await dispatch(payload, this.cfg.destinations, this.cfg.keys);
44209
44362
  const record = {
44210
- id: (0, import_node_crypto7.randomUUID)().slice(0, 8),
44363
+ id: (0, import_node_crypto8.randomUUID)().slice(0, 8),
44211
44364
  ip,
44212
44365
  reported_at: new Date(now).toISOString(),
44213
44366
  mode: this.cfg.dryRun ? "dry_run" : "live",
@@ -44465,8 +44618,8 @@ var RemediationConsumer = class {
44465
44618
 
44466
44619
  // src/daemon/workers/auto-update.ts
44467
44620
  var import_node_child_process10 = require("child_process");
44468
- var import_node_fs34 = require("fs");
44469
- var import_node_path25 = require("path");
44621
+ var import_node_fs36 = require("fs");
44622
+ var import_node_path27 = require("path");
44470
44623
  init_backoff();
44471
44624
  var PKG_NAME = "@profullstack/threatcrush";
44472
44625
  var REGISTRY = `https://registry.npmjs.org/${PKG_NAME}`;
@@ -44510,12 +44663,12 @@ function pickUpdate(doc, current, opts) {
44510
44663
  return { version: null, reason: `${latest} is younger than min_age, and nothing older is newer than ${current}; waiting` };
44511
44664
  }
44512
44665
  function installPlan(opts) {
44513
- const expected = `${import_node_path25.sep}lib${import_node_path25.sep}node_modules${import_node_path25.sep}@profullstack${import_node_path25.sep}threatcrush`;
44666
+ const expected = `${import_node_path27.sep}lib${import_node_path27.sep}node_modules${import_node_path27.sep}@profullstack${import_node_path27.sep}threatcrush`;
44514
44667
  if (!opts.pkgRoot.endsWith(expected)) {
44515
44668
  return { kind: "unsupported", reason: `not an npm global install (${opts.pkgRoot}); run \`threatcrush update\`` };
44516
44669
  }
44517
- const nodeBin = (0, import_node_path25.dirname)(opts.execPath);
44518
- const npm = (0, import_node_path25.join)(nodeBin, "npm");
44670
+ const nodeBin = (0, import_node_path27.dirname)(opts.execPath);
44671
+ const npm = (0, import_node_path27.join)(nodeBin, "npm");
44519
44672
  if (!opts.npmExists(npm)) return { kind: "unsupported", reason: `no npm beside ${opts.execPath}` };
44520
44673
  if (!opts.owner) return { kind: "unsupported", reason: `cannot tell who owns ${opts.pkgRoot}` };
44521
44674
  const npmArgs = [npm, "i", "-g", `${PKG_NAME}@${opts.version}`, "--no-fund", "--no-audit"];
@@ -44547,10 +44700,10 @@ function installPlan(opts) {
44547
44700
  }
44548
44701
  function ownerOf(path2, passwd = "/etc/passwd") {
44549
44702
  try {
44550
- const st = (0, import_node_fs34.statSync)(path2);
44703
+ const st = (0, import_node_fs36.statSync)(path2);
44551
44704
  let home = st.uid === 0 ? "/root" : "";
44552
44705
  try {
44553
- for (const line2 of (0, import_node_fs34.readFileSync)(passwd, "utf8").split("\n")) {
44706
+ for (const line2 of (0, import_node_fs36.readFileSync)(passwd, "utf8").split("\n")) {
44554
44707
  const f = line2.split(":");
44555
44708
  if (Number(f[2]) === st.uid && f[5]) home = f[5];
44556
44709
  }
@@ -44655,7 +44808,7 @@ var AutoUpdate = class {
44655
44808
  uid: process.getuid?.() ?? -1,
44656
44809
  owner: ownerOf(this.opts.pkgRoot),
44657
44810
  underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
44658
- npmExists: import_node_fs34.existsSync
44811
+ npmExists: import_node_fs36.existsSync
44659
44812
  });
44660
44813
  if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
44661
44814
  this.recordAttempt(target);
@@ -44690,7 +44843,7 @@ var AutoUpdate = class {
44690
44843
  }
44691
44844
  lastAttempt() {
44692
44845
  try {
44693
- const v = JSON.parse((0, import_node_fs34.readFileSync)(this.opts.statePath, "utf8"));
44846
+ const v = JSON.parse((0, import_node_fs36.readFileSync)(this.opts.statePath, "utf8"));
44694
44847
  return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
44695
44848
  } catch {
44696
44849
  return null;
@@ -44698,7 +44851,7 @@ var AutoUpdate = class {
44698
44851
  }
44699
44852
  recordAttempt(version) {
44700
44853
  try {
44701
- (0, import_node_fs34.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
44854
+ (0, import_node_fs36.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
44702
44855
  } catch (err) {
44703
44856
  this.opts.log(`[update] could not record attempt: ${err.message}`);
44704
44857
  }
@@ -44707,8 +44860,8 @@ var AutoUpdate = class {
44707
44860
 
44708
44861
  // src/daemon/workers/threat-feeds.ts
44709
44862
  var import_node_child_process11 = require("child_process");
44710
- var import_node_fs35 = require("fs");
44711
- var import_node_path26 = require("path");
44863
+ var import_node_fs37 = require("fs");
44864
+ var import_node_path28 = require("path");
44712
44865
  var import_node_net10 = require("net");
44713
44866
  init_backoff();
44714
44867
  var EGRESS_TABLE = "threatcrush_egress";
@@ -44880,14 +45033,14 @@ var ThreatFeeds = class {
44880
45033
  */
44881
45034
  writeResolverFiles(set) {
44882
45035
  const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
44883
- const dir = this.opts.resolverDir ?? (0, import_node_path26.dirname)(this.opts.cachePath);
45036
+ const dir = this.opts.resolverDir ?? (0, import_node_path28.dirname)(this.opts.cachePath);
44884
45037
  const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
44885
45038
  const write = (name, content) => {
44886
- const path2 = (0, import_node_path26.join)(dir, name);
45039
+ const path2 = (0, import_node_path28.join)(dir, name);
44887
45040
  if (this.resolverWritten.get(name) === content) return false;
44888
45041
  try {
44889
- (0, import_node_fs35.writeFileSync)(`${path2}.tmp`, content);
44890
- (0, import_node_fs35.renameSync)(`${path2}.tmp`, path2);
45042
+ (0, import_node_fs37.writeFileSync)(`${path2}.tmp`, content);
45043
+ (0, import_node_fs37.renameSync)(`${path2}.tmp`, path2);
44891
45044
  this.resolverWritten.set(name, content);
44892
45045
  return true;
44893
45046
  } catch (err) {
@@ -44898,11 +45051,11 @@ var ThreatFeeds = class {
44898
45051
  const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
44899
45052
  const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
44900
45053
  const via = [];
44901
- if ((0, import_node_fs35.existsSync)(hooks.dnsmasq)) {
45054
+ if ((0, import_node_fs37.existsSync)(hooks.dnsmasq)) {
44902
45055
  via.push("dnsmasq");
44903
45056
  if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
44904
45057
  }
44905
- if ((0, import_node_fs35.existsSync)(hooks.unbound)) {
45058
+ if ((0, import_node_fs37.existsSync)(hooks.unbound)) {
44906
45059
  via.push("unbound");
44907
45060
  if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
44908
45061
  this.run("systemctl", ["reload", "unbound.service"]);
@@ -44963,12 +45116,12 @@ var ThreatFeeds = class {
44963
45116
  };
44964
45117
 
44965
45118
  // src/daemon/workers/privilege-watch.ts
44966
- var import_node_fs36 = require("fs");
44967
- var import_node_path27 = require("path");
45119
+ var import_node_fs38 = require("fs");
45120
+ var import_node_path29 = require("path");
44968
45121
  var import_node_child_process12 = require("child_process");
44969
45122
 
44970
45123
  // src/core/privileges/index.ts
44971
- var import_node_crypto8 = require("crypto");
45124
+ var import_node_crypto9 = require("crypto");
44972
45125
  var ADMIN_GROUPS = ["sudo", "wheel", "admin"];
44973
45126
  function parseUsers(text) {
44974
45127
  const out = [];
@@ -45009,7 +45162,7 @@ function sudoReadsIncluded(name) {
45009
45162
  }
45010
45163
  function keyFingerprint(blobBase64) {
45011
45164
  if (!/^[A-Za-z0-9+/]+=*$/.test(blobBase64)) return null;
45012
- const digest = (0, import_node_crypto8.createHash)("sha256").update(Buffer.from(blobBase64, "base64")).digest("base64");
45165
+ const digest = (0, import_node_crypto9.createHash)("sha256").update(Buffer.from(blobBase64, "base64")).digest("base64");
45013
45166
  return `SHA256:${digest.replace(/=+$/, "")}`;
45014
45167
  }
45015
45168
  function parseAuthorizedKeys(text) {
@@ -45155,31 +45308,31 @@ function countryName(code) {
45155
45308
  var fsIO = {
45156
45309
  readFile: (p) => {
45157
45310
  try {
45158
- return (0, import_node_fs36.readFileSync)(p, "utf-8");
45311
+ return (0, import_node_fs38.readFileSync)(p, "utf-8");
45159
45312
  } catch {
45160
45313
  return null;
45161
45314
  }
45162
45315
  },
45163
45316
  readDir: (p) => {
45164
45317
  try {
45165
- return (0, import_node_fs36.readdirSync)(p);
45318
+ return (0, import_node_fs38.readdirSync)(p);
45166
45319
  } catch {
45167
45320
  return null;
45168
45321
  }
45169
45322
  },
45170
- exists: (p) => (0, import_node_fs36.existsSync)(p)
45323
+ exists: (p) => (0, import_node_fs38.existsSync)(p)
45171
45324
  };
45172
45325
  function readJson(path2) {
45173
45326
  try {
45174
- return JSON.parse((0, import_node_fs36.readFileSync)(path2, "utf-8"));
45327
+ return JSON.parse((0, import_node_fs38.readFileSync)(path2, "utf-8"));
45175
45328
  } catch {
45176
45329
  return null;
45177
45330
  }
45178
45331
  }
45179
45332
  function writeJson(path2, value) {
45180
- (0, import_node_fs36.mkdirSync)((0, import_node_path27.dirname)(path2), { recursive: true });
45181
- (0, import_node_fs36.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
45182
- (0, import_node_fs36.renameSync)(`${path2}.tmp`, path2);
45333
+ (0, import_node_fs38.mkdirSync)((0, import_node_path29.dirname)(path2), { recursive: true });
45334
+ (0, import_node_fs38.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
45335
+ (0, import_node_fs38.renameSync)(`${path2}.tmp`, path2);
45183
45336
  }
45184
45337
  function defaultRun3(cmd, args) {
45185
45338
  const res = (0, import_node_child_process12.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 2e4, maxBuffer: 16 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
@@ -45335,7 +45488,7 @@ var PrivilegeWatch = class {
45335
45488
  * raised a "new country" alert on its first run; on dev2 it did, at once.
45336
45489
  */
45337
45490
  async backfillLogins() {
45338
- if ((0, import_node_fs36.existsSync)(this.opts.loginsPath)) return;
45491
+ if ((0, import_node_fs38.existsSync)(this.opts.loginsPath)) return;
45339
45492
  const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
45340
45493
  const byUser = parseAcceptedLogins(out ?? "");
45341
45494
  const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
@@ -45348,7 +45501,7 @@ var PrivilegeWatch = class {
45348
45501
  return;
45349
45502
  }
45350
45503
  }
45351
- if ((0, import_node_fs36.existsSync)(this.opts.loginsPath)) return;
45504
+ if ((0, import_node_fs38.existsSync)(this.opts.loginsPath)) return;
45352
45505
  const at = this.now().toISOString();
45353
45506
  const history = {};
45354
45507
  for (const [user, userIps] of byUser) {
@@ -45560,8 +45713,8 @@ var RuleEngine = class {
45560
45713
  };
45561
45714
 
45562
45715
  // src/daemon/rules/loader.ts
45563
- var import_node_fs37 = require("fs");
45564
- var import_node_path28 = require("path");
45716
+ var import_node_fs39 = require("fs");
45717
+ var import_node_path30 = require("path");
45565
45718
 
45566
45719
  // src/daemon/rules/default-rules.ts
45567
45720
  var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
@@ -46031,11 +46184,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
46031
46184
  function loadAllRules(customDir) {
46032
46185
  const rules = [...DEFAULT_RULES];
46033
46186
  const dir = customDir || RULES_DIR;
46034
- if ((0, import_node_fs37.existsSync)(dir)) {
46035
- const files = (0, import_node_fs37.readdirSync)(dir).filter((f) => f.endsWith(".json"));
46187
+ if ((0, import_node_fs39.existsSync)(dir)) {
46188
+ const files = (0, import_node_fs39.readdirSync)(dir).filter((f) => f.endsWith(".json"));
46036
46189
  for (const file of files) {
46037
46190
  try {
46038
- const raw = (0, import_node_fs37.readFileSync)((0, import_node_path28.join)(dir, file), "utf-8");
46191
+ const raw = (0, import_node_fs39.readFileSync)((0, import_node_path30.join)(dir, file), "utf-8");
46039
46192
  const parsed = JSON.parse(raw);
46040
46193
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
46041
46194
  for (const rule of customRules) {
@@ -46067,8 +46220,8 @@ function loadAllRules(customDir) {
46067
46220
 
46068
46221
  // src/daemon/firewall/adapters.ts
46069
46222
  var import_node_child_process13 = require("child_process");
46070
- var import_node_fs38 = require("fs");
46071
- var import_node_path29 = require("path");
46223
+ var import_node_fs40 = require("fs");
46224
+ var import_node_path31 = require("path");
46072
46225
  var import_node_net11 = require("net");
46073
46226
  function assertValidFirewallIp(ip) {
46074
46227
  if ((0, import_node_net11.isIP)(ip) !== 4) {
@@ -46081,9 +46234,9 @@ function assertBannableIp(ip) {
46081
46234
  }
46082
46235
  }
46083
46236
  function writeIfAbsent(path2, contents) {
46084
- (0, import_node_fs38.mkdirSync)((0, import_node_path29.dirname)(path2), { recursive: true });
46237
+ (0, import_node_fs40.mkdirSync)((0, import_node_path31.dirname)(path2), { recursive: true });
46085
46238
  try {
46086
- (0, import_node_fs38.writeFileSync)(path2, contents, { flag: "wx" });
46239
+ (0, import_node_fs40.writeFileSync)(path2, contents, { flag: "wx" });
46087
46240
  } catch (err) {
46088
46241
  if (err.code !== "EEXIST") throw err;
46089
46242
  }
@@ -46342,7 +46495,7 @@ function detectFirewallAdapter(backend = "auto") {
46342
46495
  }
46343
46496
 
46344
46497
  // src/daemon/firewall/remediation.ts
46345
- var import_node_fs39 = require("fs");
46498
+ var import_node_fs41 = require("fs");
46346
46499
  var import_node_child_process14 = require("child_process");
46347
46500
  var import_node_net12 = require("net");
46348
46501
  init_paths();
@@ -46413,19 +46566,19 @@ var defaultDiscovery = {
46413
46566
  const snapshot = takeSnapshot({
46414
46567
  readFile: (p) => {
46415
46568
  try {
46416
- return (0, import_node_fs39.readFileSync)(p, "utf-8");
46569
+ return (0, import_node_fs41.readFileSync)(p, "utf-8");
46417
46570
  } catch {
46418
46571
  return null;
46419
46572
  }
46420
46573
  },
46421
46574
  readDir: (p) => {
46422
46575
  try {
46423
- return (0, import_node_fs39.readdirSync)(p);
46576
+ return (0, import_node_fs41.readdirSync)(p);
46424
46577
  } catch {
46425
46578
  return null;
46426
46579
  }
46427
46580
  },
46428
- exists: (p) => (0, import_node_fs39.existsSync)(p)
46581
+ exists: (p) => (0, import_node_fs41.existsSync)(p)
46429
46582
  });
46430
46583
  const out = /* @__PURE__ */ new Set();
46431
46584
  for (const keys of Object.values(snapshot.keys)) {
@@ -46866,7 +47019,7 @@ var RemediationManager = class {
46866
47019
  }
46867
47020
  logLine(line2) {
46868
47021
  try {
46869
- (0, import_node_fs39.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47022
+ (0, import_node_fs41.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
46870
47023
  `);
46871
47024
  } catch {
46872
47025
  }
@@ -46909,19 +47062,19 @@ function remediationSettings(section) {
46909
47062
  init_backoff();
46910
47063
 
46911
47064
  // src/daemon/watchdog-service.ts
46912
- var import_node_fs40 = require("fs");
46913
- var import_node_path30 = require("path");
47065
+ var import_node_fs42 = require("fs");
47066
+ var import_node_path32 = require("path");
46914
47067
  function defaultShareGid() {
46915
47068
  const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
46916
47069
  if (!isRoot4) return void 0;
46917
47070
  try {
46918
- return (0, import_node_fs40.statSync)("/var/log/auth.log").gid;
47071
+ return (0, import_node_fs42.statSync)("/var/log/auth.log").gid;
46919
47072
  } catch {
46920
47073
  return void 0;
46921
47074
  }
46922
47075
  }
46923
47076
  function startWatchdog(opts) {
46924
- const dir = opts.config?.dir ?? (0, import_node_path30.join)(opts.stateDir, WATCHDOG_DIRNAME);
47077
+ const dir = opts.config?.dir ?? (0, import_node_path32.join)(opts.stateDir, WATCHDOG_DIRNAME);
46925
47078
  const base = { dir, logged: 0, answered: 0, errored: 0 };
46926
47079
  if (opts.config?.enabled === false) {
46927
47080
  opts.log("[watchdog] off ([watchdog] enabled = false)");
@@ -47036,7 +47189,7 @@ function versionOfNode(path2) {
47036
47189
  // src/daemon/index.ts
47037
47190
  function readVersion2() {
47038
47191
  try {
47039
- const pkg = JSON.parse((0, import_node_fs41.readFileSync)((0, import_node_path31.join)(__dirname, "..", "package.json"), "utf-8"));
47192
+ const pkg = JSON.parse((0, import_node_fs43.readFileSync)((0, import_node_path33.join)(__dirname, "..", "package.json"), "utf-8"));
47040
47193
  return pkg.version || "0.0.0";
47041
47194
  } catch {
47042
47195
  return "0.0.0";
@@ -47045,7 +47198,7 @@ function readVersion2() {
47045
47198
  async function runHardeningChecks() {
47046
47199
  const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process16.execFile)(
47047
47200
  process.execPath,
47048
- [(0, import_node_path31.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
47201
+ [(0, import_node_path33.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
47049
47202
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
47050
47203
  );
47051
47204
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -47059,7 +47212,7 @@ async function runHardeningChecks() {
47059
47212
  async function runPatchCheck() {
47060
47213
  const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process16.execFile)(
47061
47214
  process.execPath,
47062
- [(0, import_node_path31.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
47215
+ [(0, import_node_path33.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
47063
47216
  { timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
47064
47217
  );
47065
47218
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -47067,7 +47220,7 @@ async function runPatchCheck() {
47067
47220
  }
47068
47221
  function logLine(line2) {
47069
47222
  try {
47070
- (0, import_node_fs41.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47223
+ (0, import_node_fs43.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47071
47224
  `);
47072
47225
  } catch {
47073
47226
  }
@@ -47109,7 +47262,7 @@ async function runDaemon() {
47109
47262
  } catch (err) {
47110
47263
  logLine(`[daemon] state db unavailable: ${err.message}`);
47111
47264
  }
47112
- const config = loadConfig((0, import_node_fs41.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
47265
+ const config = loadConfig((0, import_node_fs43.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
47113
47266
  configureAttackDetection(config.detection);
47114
47267
  const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
47115
47268
  const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
@@ -47173,7 +47326,7 @@ async function runDaemon() {
47173
47326
  const threatFeeds = new ThreatFeeds({
47174
47327
  settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
47175
47328
  enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
47176
- cachePath: (0, import_node_path31.join)(PATHS.stateDir, "threat-feeds.json"),
47329
+ cachePath: (0, import_node_path33.join)(PATHS.stateDir, "threat-feeds.json"),
47177
47330
  bus,
47178
47331
  log: logLine
47179
47332
  });
@@ -47181,9 +47334,9 @@ async function runDaemon() {
47181
47334
  const privilegeWatch = new PrivilegeWatch({
47182
47335
  settings: privilegeSettings(config.privileged),
47183
47336
  bus,
47184
- snapshotPath: (0, import_node_path31.join)(PATHS.stateDir, "privileges.json"),
47185
- loginsPath: (0, import_node_path31.join)(PATHS.stateDir, "login-countries.json"),
47186
- cursorPath: (0, import_node_path31.join)(PATHS.stateDir, "sudo-cursor.json"),
47337
+ snapshotPath: (0, import_node_path33.join)(PATHS.stateDir, "privileges.json"),
47338
+ loginsPath: (0, import_node_path33.join)(PATHS.stateDir, "login-countries.json"),
47339
+ cursorPath: (0, import_node_path33.join)(PATHS.stateDir, "sudo-cursor.json"),
47187
47340
  log: logLine
47188
47341
  });
47189
47342
  privilegeWatch.start();
@@ -47204,9 +47357,9 @@ async function runDaemon() {
47204
47357
  cloudSync = new CloudSync({
47205
47358
  bus,
47206
47359
  version,
47207
- hostname: (0, import_node_os12.hostname)(),
47360
+ hostname: (0, import_node_os13.hostname)(),
47208
47361
  minSeverity,
47209
- spoolPath: (0, import_node_path31.join)(PATHS.stateDir, "cloud-spool.jsonl"),
47362
+ spoolPath: (0, import_node_path33.join)(PATHS.stateDir, "cloud-spool.jsonl"),
47210
47363
  log: logLine,
47211
47364
  ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
47212
47365
  runHardening: runHardeningChecks
@@ -47225,8 +47378,8 @@ async function runDaemon() {
47225
47378
  const autoUpdate = new AutoUpdate({
47226
47379
  version,
47227
47380
  settings: updateSettings(config.update),
47228
- pkgRoot: (0, import_node_path31.join)(__dirname, ".."),
47229
- statePath: (0, import_node_path31.join)(PATHS.stateDir, "auto-update.json"),
47381
+ pkgRoot: (0, import_node_path33.join)(__dirname, ".."),
47382
+ statePath: (0, import_node_path33.join)(PATHS.stateDir, "auto-update.json"),
47230
47383
  bus,
47231
47384
  log: logLine,
47232
47385
  restartDaemon
@@ -47316,7 +47469,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
47316
47469
  function isRoot2() {
47317
47470
  return typeof process.getuid === "function" && process.getuid() === 0;
47318
47471
  }
47319
- var DAEMON_ENTRY = (0, import_node_path32.join)(__dirname, "daemon.js");
47472
+ var DAEMON_ENTRY = (0, import_node_path34.join)(__dirname, "daemon.js");
47320
47473
  async function daemonForeground() {
47321
47474
  await runDaemon();
47322
47475
  }
@@ -47337,7 +47490,7 @@ async function daemonStart() {
47337
47490
  return;
47338
47491
  }
47339
47492
  ensureRuntimeDirs();
47340
- if (!(0, import_node_fs42.existsSync)(DAEMON_ENTRY)) {
47493
+ if (!(0, import_node_fs44.existsSync)(DAEMON_ENTRY)) {
47341
47494
  console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
47342
47495
  console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
47343
47496
  return;
@@ -47345,8 +47498,8 @@ async function daemonStart() {
47345
47498
  let out;
47346
47499
  let err;
47347
47500
  try {
47348
- out = (0, import_node_fs43.openSync)(PATHS.logFile, "a");
47349
- err = (0, import_node_fs43.openSync)(PATHS.logFile, "a");
47501
+ out = (0, import_node_fs45.openSync)(PATHS.logFile, "a");
47502
+ err = (0, import_node_fs45.openSync)(PATHS.logFile, "a");
47350
47503
  } catch (e) {
47351
47504
  const code = e.code;
47352
47505
  console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
@@ -47434,12 +47587,12 @@ async function waitForExit(pid, timeoutMs) {
47434
47587
  }
47435
47588
  async function releaseStaleSocket() {
47436
47589
  const deadline = Date.now() + 2e3;
47437
- while ((0, import_node_fs42.existsSync)(PATHS.socket) && Date.now() < deadline) {
47590
+ while ((0, import_node_fs44.existsSync)(PATHS.socket) && Date.now() < deadline) {
47438
47591
  await new Promise((r) => setTimeout(r, 50));
47439
47592
  }
47440
- if ((0, import_node_fs42.existsSync)(PATHS.socket)) {
47593
+ if ((0, import_node_fs44.existsSync)(PATHS.socket)) {
47441
47594
  try {
47442
- (0, import_node_fs42.unlinkSync)(PATHS.socket);
47595
+ (0, import_node_fs44.unlinkSync)(PATHS.socket);
47443
47596
  } catch {
47444
47597
  }
47445
47598
  }
@@ -47447,26 +47600,26 @@ async function releaseStaleSocket() {
47447
47600
 
47448
47601
  // src/commands/service.ts
47449
47602
  var import_node_child_process18 = require("child_process");
47450
- var import_node_fs44 = require("fs");
47451
- var import_node_path33 = require("path");
47452
- var import_node_os13 = require("os");
47603
+ var import_node_fs46 = require("fs");
47604
+ var import_node_path35 = require("path");
47605
+ var import_node_os14 = require("os");
47453
47606
  var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
47454
47607
  var DAEMON_UNIT_NAME = "threatcrushd.service";
47455
47608
  function resolveTemplate() {
47456
- const templatePath = (0, import_node_path33.join)(__dirname, "systemd", "threatcrushd.service");
47457
- if (!(0, import_node_fs44.existsSync)(templatePath)) {
47609
+ const templatePath = (0, import_node_path35.join)(__dirname, "systemd", "threatcrushd.service");
47610
+ if (!(0, import_node_fs46.existsSync)(templatePath)) {
47458
47611
  throw new Error(`systemd unit template not found at ${templatePath}`);
47459
47612
  }
47460
- return (0, import_node_fs44.readFileSync)(templatePath, "utf-8");
47613
+ return (0, import_node_fs46.readFileSync)(templatePath, "utf-8");
47461
47614
  }
47462
47615
  function stableBinPath(binPath) {
47463
47616
  const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
47464
47617
  if (stable === binPath) return binPath;
47465
- return (0, import_node_fs44.existsSync)(stable) ? stable : binPath;
47618
+ return (0, import_node_fs46.existsSync)(stable) ? stable : binPath;
47466
47619
  }
47467
47620
  function resolveBinPath() {
47468
47621
  const arg = process.argv[1];
47469
- if (arg && (0, import_node_fs44.existsSync)(arg)) return stableBinPath(arg);
47622
+ if (arg && (0, import_node_fs46.existsSync)(arg)) return stableBinPath(arg);
47470
47623
  try {
47471
47624
  return (0, import_node_child_process18.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
47472
47625
  } catch {
@@ -47476,11 +47629,11 @@ function resolveBinPath() {
47476
47629
  function stableNodePath(execPath) {
47477
47630
  const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
47478
47631
  if (stable === execPath) return execPath;
47479
- return (0, import_node_fs44.existsSync)(stable) ? stable : execPath;
47632
+ return (0, import_node_fs46.existsSync)(stable) ? stable : execPath;
47480
47633
  }
47481
47634
  function looksLikeNodeScript(path2) {
47482
47635
  try {
47483
- const head = (0, import_node_fs44.readFileSync)(path2, "utf-8").slice(0, 120);
47636
+ const head = (0, import_node_fs46.readFileSync)(path2, "utf-8").slice(0, 120);
47484
47637
  return /^#!.*\bnode\b/.test(head);
47485
47638
  } catch {
47486
47639
  return false;
@@ -47520,7 +47673,7 @@ function callerHome() {
47520
47673
  try {
47521
47674
  const line2 = (0, import_node_child_process18.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
47522
47675
  const home = line2.split(":")[5];
47523
- return home && (0, import_node_fs44.existsSync)(home) ? home : null;
47676
+ return home && (0, import_node_fs46.existsSync)(home) ? home : null;
47524
47677
  } catch {
47525
47678
  return null;
47526
47679
  }
@@ -47528,13 +47681,13 @@ function callerHome() {
47528
47681
  function stopUserModeDaemon() {
47529
47682
  const home = callerHome();
47530
47683
  if (!home) return;
47531
- const runDir = (0, import_node_path33.join)(home, ".threatcrush", "run");
47532
- const pidFile = (0, import_node_path33.join)(runDir, "threatcrushd.pid");
47533
- const socket = (0, import_node_path33.join)(runDir, "threatcrushd.sock");
47534
- if (!(0, import_node_fs44.existsSync)(pidFile) && !(0, import_node_fs44.existsSync)(socket)) return;
47684
+ const runDir = (0, import_node_path35.join)(home, ".threatcrush", "run");
47685
+ const pidFile = (0, import_node_path35.join)(runDir, "threatcrushd.pid");
47686
+ const socket = (0, import_node_path35.join)(runDir, "threatcrushd.sock");
47687
+ if (!(0, import_node_fs46.existsSync)(pidFile) && !(0, import_node_fs46.existsSync)(socket)) return;
47535
47688
  let pid = null;
47536
47689
  try {
47537
- pid = Number.parseInt((0, import_node_fs44.readFileSync)(pidFile, "utf-8").trim(), 10);
47690
+ pid = Number.parseInt((0, import_node_fs46.readFileSync)(pidFile, "utf-8").trim(), 10);
47538
47691
  } catch {
47539
47692
  pid = null;
47540
47693
  }
@@ -47547,7 +47700,7 @@ function stopUserModeDaemon() {
47547
47700
  }
47548
47701
  for (const path2 of [socket, pidFile]) {
47549
47702
  try {
47550
- if ((0, import_node_fs44.existsSync)(path2)) (0, import_node_fs44.rmSync)(path2);
47703
+ if ((0, import_node_fs46.existsSync)(path2)) (0, import_node_fs46.rmSync)(path2);
47551
47704
  } catch {
47552
47705
  }
47553
47706
  }
@@ -47565,7 +47718,7 @@ async function installServiceCommand() {
47565
47718
  }
47566
47719
  const noSystemd = systemdUnavailableReason({
47567
47720
  hasSystemctl: (0, import_node_child_process18.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
47568
- booted: (0, import_node_fs44.existsSync)("/run/systemd/system")
47721
+ booted: (0, import_node_fs46.existsSync)("/run/systemd/system")
47569
47722
  });
47570
47723
  if (noSystemd) {
47571
47724
  console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
@@ -47587,7 +47740,7 @@ async function installServiceCommand() {
47587
47740
  const isNodeScript = looksLikeNodeScript(binPath);
47588
47741
  let nodePath = stableNodePath(process.execPath);
47589
47742
  if (isNodeScript && nodeVersionDir(binPath)) {
47590
- binPath = (0, import_node_fs44.realpathSync)(binPath);
47743
+ binPath = (0, import_node_fs46.realpathSync)(binPath);
47591
47744
  nodePath = process.execPath;
47592
47745
  }
47593
47746
  if (isNodeScript) {
@@ -47600,9 +47753,9 @@ async function installServiceCommand() {
47600
47753
  }
47601
47754
  }
47602
47755
  const exec = execStartCommand(binPath, nodePath, isNodeScript);
47603
- const configDir = (0, import_node_path33.join)((0, import_node_os13.homedir)(), ".threatcrush");
47756
+ const configDir = (0, import_node_path35.join)((0, import_node_os14.homedir)(), ".threatcrush");
47604
47757
  const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
47605
- (0, import_node_fs44.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
47758
+ (0, import_node_fs46.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
47606
47759
  console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
47607
47760
  console.log(source_default.dim(` ExecStart=${exec}`));
47608
47761
  const nodeDir = nodeVersionDir(nodePath);
@@ -47655,9 +47808,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
47655
47808
  ].join("\n");
47656
47809
  }
47657
47810
  function installLogrotate() {
47658
- if (!(0, import_node_fs44.existsSync)((0, import_node_path33.dirname)(LOGROTATE_PATH))) return;
47811
+ if (!(0, import_node_fs46.existsSync)((0, import_node_path35.dirname)(LOGROTATE_PATH))) return;
47659
47812
  try {
47660
- (0, import_node_fs44.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
47813
+ (0, import_node_fs46.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
47661
47814
  console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
47662
47815
  } catch (err) {
47663
47816
  console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
@@ -47679,20 +47832,20 @@ function ensureSystemDirs(configDir) {
47679
47832
  ];
47680
47833
  let admGid2 = null;
47681
47834
  try {
47682
- admGid2 = (0, import_node_fs44.statSync)("/var/log/auth.log").gid;
47835
+ admGid2 = (0, import_node_fs46.statSync)("/var/log/auth.log").gid;
47683
47836
  } catch {
47684
47837
  }
47685
47838
  for (const { path: path2, groupWritable, sticky } of dirs) {
47686
47839
  try {
47687
- (0, import_node_fs44.mkdirSync)(path2, { recursive: true });
47840
+ (0, import_node_fs46.mkdirSync)(path2, { recursive: true });
47688
47841
  } catch {
47689
47842
  }
47690
47843
  try {
47691
47844
  if (groupWritable && admGid2 !== null) {
47692
- (0, import_node_fs44.chmodSync)(path2, sticky ? 1533 : 509);
47845
+ (0, import_node_fs46.chmodSync)(path2, sticky ? 1533 : 509);
47693
47846
  (0, import_node_child_process18.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
47694
47847
  } else {
47695
- (0, import_node_fs44.chmodSync)(path2, 493);
47848
+ (0, import_node_fs46.chmodSync)(path2, 493);
47696
47849
  }
47697
47850
  } catch {
47698
47851
  }
@@ -47720,7 +47873,7 @@ async function uninstallServiceCommand() {
47720
47873
  } catch {
47721
47874
  }
47722
47875
  try {
47723
- if ((0, import_node_fs44.existsSync)(UNIT_PATH)) {
47876
+ if ((0, import_node_fs46.existsSync)(UNIT_PATH)) {
47724
47877
  (0, import_node_child_process18.execSync)(`rm -f ${UNIT_PATH}`);
47725
47878
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
47726
47879
  }
@@ -47734,7 +47887,7 @@ async function uninstallServiceCommand() {
47734
47887
  }
47735
47888
 
47736
47889
  // src/commands/save.ts
47737
- var import_node_fs45 = require("fs");
47890
+ var import_node_fs47 = require("fs");
47738
47891
  var import_toml5 = __toESM(require_toml());
47739
47892
  init_cli_config();
47740
47893
  init_paths();
@@ -47773,9 +47926,9 @@ async function saveCommand(opts = {}) {
47773
47926
  }
47774
47927
  const path2 = opts.config ?? PATHS.configFile;
47775
47928
  let config = {};
47776
- if ((0, import_node_fs45.existsSync)(path2)) {
47929
+ if ((0, import_node_fs47.existsSync)(path2)) {
47777
47930
  try {
47778
- config = import_toml5.default.parse((0, import_node_fs45.readFileSync)(path2, "utf-8"));
47931
+ config = import_toml5.default.parse((0, import_node_fs47.readFileSync)(path2, "utf-8"));
47779
47932
  } catch (err) {
47780
47933
  console.log(source_default.red(` \u2717 ${path2} is not valid TOML: ${err.message}
47781
47934
  `));
@@ -47888,11 +48041,11 @@ function welcomeCommand() {
47888
48041
  }
47889
48042
 
47890
48043
  // src/commands/properties.ts
47891
- var import_node_fs46 = require("fs");
47892
- var import_node_path34 = require("path");
48044
+ var import_node_fs48 = require("fs");
48045
+ var import_node_path36 = require("path");
47893
48046
  var import_node_readline4 = __toESM(require("readline"));
47894
48047
  init_cli_config();
47895
- var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
48048
+ var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
47896
48049
  var KINDS = ["url", "api", "domain", "ip", "repo"];
47897
48050
  function prompt(question) {
47898
48051
  const rl = import_node_readline4.default.createInterface({ input: process.stdin, output: process.stdout });
@@ -47915,7 +48068,7 @@ async function resolveOrgId(orgFlag) {
47915
48068
  }
47916
48069
  let orgs = [];
47917
48070
  try {
47918
- const res = await fetch(`${API_URL5}/api/orgs`, { headers: authHeaders() });
48071
+ const res = await fetch(`${API_URL6}/api/orgs`, { headers: authHeaders() });
47919
48072
  if (!res.ok) {
47920
48073
  console.log(source_default.red(` Failed to list organizations (${res.status})
47921
48074
  `));
@@ -47945,7 +48098,7 @@ async function resolveOrgId(orgFlag) {
47945
48098
  }
47946
48099
  async function fetchProperties(orgId, kind) {
47947
48100
  const qs = kind ? `?kind=${kind}` : "";
47948
- const res = await fetch(`${API_URL5}/api/orgs/${orgId}/properties${qs}`, { headers: authHeaders() });
48101
+ const res = await fetch(`${API_URL6}/api/orgs/${orgId}/properties${qs}`, { headers: authHeaders() });
47949
48102
  if (!res.ok) {
47950
48103
  const body = await res.json().catch(() => ({ error: res.statusText }));
47951
48104
  console.log(source_default.red(` ${body.error || "Failed to load properties"}
@@ -48026,7 +48179,7 @@ async function propertiesAddCommand(name, target, opts) {
48026
48179
  };
48027
48180
  const spinner = ora({ text: `Creating property ${source_default.white(name)}...`, color: "green" }).start();
48028
48181
  try {
48029
- const res = await fetch(`${API_URL5}/api/orgs/${resolved.org.id}/properties`, {
48182
+ const res = await fetch(`${API_URL6}/api/orgs/${resolved.org.id}/properties`, {
48030
48183
  method: "POST",
48031
48184
  headers: authHeaders(),
48032
48185
  body: JSON.stringify(body)
@@ -48062,7 +48215,7 @@ async function propertiesRemoveCommand(nameOrId, opts) {
48062
48215
  return;
48063
48216
  }
48064
48217
  }
48065
- const res = await fetch(`${API_URL5}/api/orgs/${resolved.org.id}/properties/${match.id}`, {
48218
+ const res = await fetch(`${API_URL6}/api/orgs/${resolved.org.id}/properties/${match.id}`, {
48066
48219
  method: "DELETE",
48067
48220
  headers: authHeaders()
48068
48221
  });
@@ -48077,7 +48230,7 @@ async function propertiesRemoveCommand(nameOrId, opts) {
48077
48230
  }
48078
48231
  async function enqueueRun(orgId, propertyId, type, trigger = "cli") {
48079
48232
  try {
48080
- const res = await fetch(`${API_URL5}/api/orgs/${orgId}/properties/${propertyId}/runs`, {
48233
+ const res = await fetch(`${API_URL6}/api/orgs/${orgId}/properties/${propertyId}/runs`, {
48081
48234
  method: "POST",
48082
48235
  headers: authHeaders(),
48083
48236
  body: JSON.stringify({ type, trigger })
@@ -48090,7 +48243,7 @@ async function enqueueRun(orgId, propertyId, type, trigger = "cli") {
48090
48243
  }
48091
48244
  async function finalizeRun(orgId, propertyId, runId, result) {
48092
48245
  try {
48093
- await fetch(`${API_URL5}/api/orgs/${orgId}/properties/${propertyId}/runs/${runId}`, {
48246
+ await fetch(`${API_URL6}/api/orgs/${orgId}/properties/${propertyId}/runs/${runId}`, {
48094
48247
  method: "PATCH",
48095
48248
  headers: authHeaders(),
48096
48249
  body: JSON.stringify({
@@ -48194,7 +48347,7 @@ async function propertiesRunsCommand(opts) {
48194
48347
  let total = 0;
48195
48348
  for (const prop of propsToShow) {
48196
48349
  const res = await fetch(
48197
- `${API_URL5}/api/orgs/${resolved.org.id}/properties/${prop.id}/runs?limit=${limit}`,
48350
+ `${API_URL6}/api/orgs/${resolved.org.id}/properties/${prop.id}/runs?limit=${limit}`,
48198
48351
  { headers: authHeaders() }
48199
48352
  );
48200
48353
  if (!res.ok) continue;
@@ -48219,8 +48372,8 @@ async function propertiesRunsCommand(opts) {
48219
48372
  }
48220
48373
  }
48221
48374
  function parseImportFile(path2) {
48222
- const ext = (0, import_node_path34.extname)(path2).toLowerCase();
48223
- const raw = (0, import_node_fs46.readFileSync)(path2, "utf-8");
48375
+ const ext = (0, import_node_path36.extname)(path2).toLowerCase();
48376
+ const raw = (0, import_node_fs48.readFileSync)(path2, "utf-8");
48224
48377
  if (ext === ".json") {
48225
48378
  const parsed = JSON.parse(raw);
48226
48379
  if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
@@ -48298,7 +48451,7 @@ async function propertiesImportCommand(filePath, opts) {
48298
48451
  continue;
48299
48452
  }
48300
48453
  try {
48301
- const res = await fetch(`${API_URL5}/api/orgs/${resolved.org.id}/properties`, {
48454
+ const res = await fetch(`${API_URL6}/api/orgs/${resolved.org.id}/properties`, {
48302
48455
  method: "POST",
48303
48456
  headers: authHeaders(),
48304
48457
  body: JSON.stringify({
@@ -48415,7 +48568,7 @@ async function rulesCommand(opts) {
48415
48568
  }
48416
48569
 
48417
48570
  // src/commands/harden.ts
48418
- var import_node_fs47 = require("fs");
48571
+ var import_node_fs49 = require("fs");
48419
48572
  var import_node_child_process19 = require("child_process");
48420
48573
  init_cli_config();
48421
48574
  function tryExec(cmd) {
@@ -48427,7 +48580,7 @@ function tryExec(cmd) {
48427
48580
  }
48428
48581
  function tryRead(path2) {
48429
48582
  try {
48430
- return (0, import_node_fs47.readFileSync)(path2, "utf-8");
48583
+ return (0, import_node_fs49.readFileSync)(path2, "utf-8");
48431
48584
  } catch {
48432
48585
  return null;
48433
48586
  }
@@ -48531,8 +48684,8 @@ function checkSshWeakConfig() {
48531
48684
  };
48532
48685
  }
48533
48686
  function checkAutoUpdates() {
48534
- 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");
48535
- const dnfAuto = (0, import_node_fs47.existsSync)("/etc/dnf/automatic.conf");
48687
+ const unattended = (0, import_node_fs49.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs49.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
48688
+ const dnfAuto = (0, import_node_fs49.existsSync)("/etc/dnf/automatic.conf");
48536
48689
  if (unattended || dnfAuto) {
48537
48690
  return {
48538
48691
  key: "auto-updates",
@@ -48658,7 +48811,7 @@ function checkFail2ban() {
48658
48811
  explanation: "fail2ban is installed and running."
48659
48812
  };
48660
48813
  }
48661
- if ((0, import_node_fs47.existsSync)("/etc/fail2ban/fail2ban.conf")) {
48814
+ if ((0, import_node_fs49.existsSync)("/etc/fail2ban/fail2ban.conf")) {
48662
48815
  return {
48663
48816
  key: checkKey,
48664
48817
  status: "warn",
@@ -48844,8 +48997,8 @@ async function hardenCommand(opts) {
48844
48997
  }
48845
48998
 
48846
48999
  // src/core/patches/index.ts
48847
- var import_node_fs48 = require("fs");
48848
- var import_node_path35 = require("path");
49000
+ var import_node_fs50 = require("fs");
49001
+ var import_node_path37 = require("path");
48849
49002
  var import_node_child_process20 = require("child_process");
48850
49003
  var import_node_util5 = require("util");
48851
49004
 
@@ -49005,9 +49158,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
49005
49158
  function newestReleaseMtime(dir) {
49006
49159
  try {
49007
49160
  let newest = 0;
49008
- for (const name of (0, import_node_fs48.readdirSync)(dir)) {
49161
+ for (const name of (0, import_node_fs50.readdirSync)(dir)) {
49009
49162
  if (!/Release$/.test(name)) continue;
49010
- newest = Math.max(newest, (0, import_node_fs48.statSync)((0, import_node_path35.join)(dir, name)).mtimeMs);
49163
+ newest = Math.max(newest, (0, import_node_fs50.statSync)((0, import_node_path37.join)(dir, name)).mtimeMs);
49011
49164
  }
49012
49165
  return newest > 0 ? new Date(newest) : null;
49013
49166
  } catch {
@@ -49024,7 +49177,7 @@ async function checkPatches(opts = {}) {
49024
49177
  let osText = opts.osRelease;
49025
49178
  if (osText === void 0) {
49026
49179
  try {
49027
- osText = (0, import_node_fs48.readFileSync)("/etc/os-release", "utf-8");
49180
+ osText = (0, import_node_fs50.readFileSync)("/etc/os-release", "utf-8");
49028
49181
  } catch {
49029
49182
  osText = "";
49030
49183
  }
@@ -49251,24 +49404,24 @@ async function patchesCommand(opts) {
49251
49404
 
49252
49405
  // src/commands/feeds.ts
49253
49406
  var import_node_net13 = require("net");
49254
- var import_node_path37 = require("path");
49407
+ var import_node_path39 = require("path");
49255
49408
  init_paths();
49256
49409
 
49257
49410
  // src/commands/feeds-resolver.ts
49258
49411
  var import_node_child_process21 = require("child_process");
49259
- var import_node_fs49 = require("fs");
49260
- var import_node_path36 = require("path");
49412
+ var import_node_fs51 = require("fs");
49413
+ var import_node_path38 = require("path");
49261
49414
  var realIO = {
49262
- exists: (p) => (0, import_node_fs49.existsSync)(p),
49415
+ exists: (p) => (0, import_node_fs51.existsSync)(p),
49263
49416
  read: (p) => {
49264
49417
  try {
49265
- return (0, import_node_fs49.readFileSync)(p, "utf-8");
49418
+ return (0, import_node_fs51.readFileSync)(p, "utf-8");
49266
49419
  } catch {
49267
49420
  return null;
49268
49421
  }
49269
49422
  },
49270
- write: (p, c) => (0, import_node_fs49.writeFileSync)(p, c),
49271
- remove: (p) => (0, import_node_fs49.rmSync)(p, { force: true }),
49423
+ write: (p, c) => (0, import_node_fs51.writeFileSync)(p, c),
49424
+ remove: (p) => (0, import_node_fs51.rmSync)(p, { force: true }),
49272
49425
  run: (cmd, args) => {
49273
49426
  const r = (0, import_node_child_process21.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
49274
49427
  return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
@@ -49278,17 +49431,17 @@ var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
49278
49431
  var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
49279
49432
  function hookContent(resolver, stateDir) {
49280
49433
  const head = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
49281
- return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path36.join)(stateDir, RESOLVER_FILES.hosts)}
49282
- ` : `${head}include: "${(0, import_node_path36.join)(stateDir, RESOLVER_FILES.unbound)}"
49434
+ return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path38.join)(stateDir, RESOLVER_FILES.hosts)}
49435
+ ` : `${head}include: "${(0, import_node_path38.join)(stateDir, RESOLVER_FILES.unbound)}"
49283
49436
  `;
49284
49437
  }
49285
49438
  function apparmorRule(stateDir) {
49286
- return ` ${(0, import_node_path36.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
49439
+ return ` ${(0, import_node_path38.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
49287
49440
  }
49288
49441
  function detectResolvers(io = realIO) {
49289
49442
  const found = [];
49290
- if (io.exists((0, import_node_path36.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
49291
- if (io.exists((0, import_node_path36.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
49443
+ if (io.exists((0, import_node_path38.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
49444
+ if (io.exists((0, import_node_path38.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
49292
49445
  return found;
49293
49446
  }
49294
49447
  function check(resolver, io) {
@@ -49301,7 +49454,7 @@ function restartIfActive(resolver, io) {
49301
49454
  }
49302
49455
  function installHook(resolver, stateDir, io = realIO) {
49303
49456
  const hook = RESOLVER_HOOKS[resolver];
49304
- const file = (0, import_node_path36.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
49457
+ const file = (0, import_node_path38.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
49305
49458
  if (!io.exists(file)) io.write(file, resolver === "dnsmasq" ? hostsBlocklist([]) : unboundBlocklist([]));
49306
49459
  io.write(hook, hookContent(resolver, stateDir));
49307
49460
  if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
@@ -49362,8 +49515,8 @@ function resolverCommand(sub, stateDir, io = realIO) {
49362
49515
  }
49363
49516
  return failed ? 1 : 0;
49364
49517
  }
49365
- const hosts = io.read((0, import_node_path36.join)(stateDir, RESOLVER_FILES.hosts));
49366
- const unbound = io.read((0, import_node_path36.join)(stateDir, RESOLVER_FILES.unbound));
49518
+ const hosts = io.read((0, import_node_path38.join)(stateDir, RESOLVER_FILES.hosts));
49519
+ const unbound = io.read((0, import_node_path38.join)(stateDir, RESOLVER_FILES.unbound));
49367
49520
  console.log(` resolvers here: ${found.join(", ") || "none that can block (systemd-resolved only?)"}`);
49368
49521
  for (const r of ["dnsmasq", "unbound"]) {
49369
49522
  console.log(` ${r.padEnd(8)} hook ${io.exists(RESOLVER_HOOKS[r]) ? source_default.green("installed") : source_default.gray("not installed")}`);
@@ -49375,11 +49528,11 @@ function resolverCommand(sub, stateDir, io = realIO) {
49375
49528
  // src/commands/feeds.ts
49376
49529
  async function loadSet() {
49377
49530
  for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
49378
- const path2 = (0, import_node_path37.join)(dir, "threat-feeds.json");
49531
+ const path2 = (0, import_node_path39.join)(dir, "threat-feeds.json");
49379
49532
  const set = readFeedCache(path2);
49380
49533
  if (set) return { set, from: path2 };
49381
49534
  }
49382
- const settings = threatFeedSettings(loadConfig((0, import_node_path37.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
49535
+ const settings = threatFeedSettings(loadConfig((0, import_node_path39.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
49383
49536
  return { set: await fetchFeeds(settings), from: "abuse.ch (live; no daemon cache readable)" };
49384
49537
  }
49385
49538
  async function feedsCommand(action, value, opts) {
@@ -49423,14 +49576,14 @@ async function feedsCommand(action, value, opts) {
49423
49576
  }
49424
49577
 
49425
49578
  // src/commands/reputation.ts
49426
- var import_node_os14 = require("os");
49427
- var import_node_fs50 = require("fs");
49428
- var import_node_path38 = require("path");
49429
- var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
49430
- var CONFIG_PATH3 = (0, import_node_path38.join)((0, import_node_os14.homedir)(), ".threatcrush", "config.json");
49579
+ var import_node_os15 = require("os");
49580
+ var import_node_fs52 = require("fs");
49581
+ var import_node_path40 = require("path");
49582
+ var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
49583
+ var CONFIG_PATH4 = (0, import_node_path40.join)((0, import_node_os15.homedir)(), ".threatcrush", "config.json");
49431
49584
  function readConfig3() {
49432
49585
  try {
49433
- return JSON.parse((0, import_node_fs50.readFileSync)(CONFIG_PATH3, "utf-8"));
49586
+ return JSON.parse((0, import_node_fs52.readFileSync)(CONFIG_PATH4, "utf-8"));
49434
49587
  } catch {
49435
49588
  return {};
49436
49589
  }
@@ -49486,7 +49639,7 @@ async function reputationLookupCommand(indicators, opts) {
49486
49639
  const org = opts.org ?? auth.orgId;
49487
49640
  let reports;
49488
49641
  if (indicators.length === 1) {
49489
- const url = `${API_URL6}/api/v1/reputation/${encodeURIComponent(indicators[0])}${org ? `?org=${encodeURIComponent(org)}` : ""}`;
49642
+ const url = `${API_URL7}/api/v1/reputation/${encodeURIComponent(indicators[0])}${org ? `?org=${encodeURIComponent(org)}` : ""}`;
49490
49643
  const res = await fetch(url, { headers: auth.headers });
49491
49644
  const body = await res.json().catch(() => ({}));
49492
49645
  if (!res.ok) {
@@ -49497,7 +49650,7 @@ async function reputationLookupCommand(indicators, opts) {
49497
49650
  }
49498
49651
  reports = [body];
49499
49652
  } else {
49500
- const res = await fetch(`${API_URL6}/api/v1/reputation/bulk`, {
49653
+ const res = await fetch(`${API_URL7}/api/v1/reputation/bulk`, {
49501
49654
  method: "POST",
49502
49655
  headers: { ...auth.headers, "Content-Type": "application/json" },
49503
49656
  body: JSON.stringify({ indicators, org: org ?? void 0 })
@@ -49539,7 +49692,7 @@ async function reputationWatchCommand(action, indicator, opts) {
49539
49692
  process.exitCode = 2;
49540
49693
  return;
49541
49694
  }
49542
- res = await fetch(`${API_URL6}/api/v1/reputation/watches`, {
49695
+ res = await fetch(`${API_URL7}/api/v1/reputation/watches`, {
49543
49696
  method: "POST",
49544
49697
  headers: { ...auth.headers, "Content-Type": "application/json" },
49545
49698
  body: JSON.stringify({ indicator, note: opts.note, destination_id: opts.destination, org: org ?? void 0 })
@@ -49550,12 +49703,12 @@ async function reputationWatchCommand(action, indicator, opts) {
49550
49703
  process.exitCode = 2;
49551
49704
  return;
49552
49705
  }
49553
- res = await fetch(`${API_URL6}/api/v1/reputation/watches?indicator=${encodeURIComponent(indicator)}${qs ? `&${qs}` : ""}`, {
49706
+ res = await fetch(`${API_URL7}/api/v1/reputation/watches?indicator=${encodeURIComponent(indicator)}${qs ? `&${qs}` : ""}`, {
49554
49707
  method: "DELETE",
49555
49708
  headers: auth.headers
49556
49709
  });
49557
49710
  } else {
49558
- res = await fetch(`${API_URL6}/api/v1/reputation/watches${qs ? `?${qs}` : ""}`, { headers: auth.headers });
49711
+ res = await fetch(`${API_URL7}/api/v1/reputation/watches${qs ? `?${qs}` : ""}`, { headers: auth.headers });
49559
49712
  }
49560
49713
  const body = await res.json().catch(() => ({}));
49561
49714
  if (!res.ok) {
@@ -49589,7 +49742,7 @@ async function reputationSubscribeCommand(opts) {
49589
49742
  process.exitCode = 2;
49590
49743
  return;
49591
49744
  }
49592
- const res = await fetch(`${API_URL6}/api/v1/reputation/subscribe`, {
49745
+ const res = await fetch(`${API_URL7}/api/v1/reputation/subscribe`, {
49593
49746
  method: "POST",
49594
49747
  headers: { ...auth.headers, "Content-Type": "application/json" },
49595
49748
  body: JSON.stringify({
@@ -49618,7 +49771,7 @@ async function reputationSubscribeCommand(opts) {
49618
49771
  }
49619
49772
 
49620
49773
  // src/commands/privileged.ts
49621
- var import_node_fs51 = require("fs");
49774
+ var import_node_fs53 = require("fs");
49622
49775
  init_paths();
49623
49776
  var SEV2 = {
49624
49777
  critical: source_default.red.bold,
@@ -49631,19 +49784,19 @@ async function privilegedCommand(opts) {
49631
49784
  const snapshot = takeSnapshot({
49632
49785
  readFile: (p) => {
49633
49786
  try {
49634
- return (0, import_node_fs51.readFileSync)(p, "utf-8");
49787
+ return (0, import_node_fs53.readFileSync)(p, "utf-8");
49635
49788
  } catch {
49636
49789
  return null;
49637
49790
  }
49638
49791
  },
49639
49792
  readDir: (p) => {
49640
49793
  try {
49641
- return (0, import_node_fs51.readdirSync)(p);
49794
+ return (0, import_node_fs53.readdirSync)(p);
49642
49795
  } catch {
49643
49796
  return null;
49644
49797
  }
49645
49798
  },
49646
- exists: (p) => (0, import_node_fs51.existsSync)(p)
49799
+ exists: (p) => (0, import_node_fs53.existsSync)(p)
49647
49800
  });
49648
49801
  let events = [];
49649
49802
  let ledgerNote = "";
@@ -49825,7 +49978,7 @@ async function allowlistCommand(opts) {
49825
49978
  }
49826
49979
 
49827
49980
  // src/commands/abuse.ts
49828
- var import_node_fs52 = require("fs");
49981
+ var import_node_fs54 = require("fs");
49829
49982
  init_paths();
49830
49983
  function rows(records) {
49831
49984
  if (records.length === 0) {
@@ -49885,7 +50038,7 @@ function abuseRetractCommand(id, opts = {}) {
49885
50038
  );
49886
50039
  }
49887
50040
  function abuseStatusCommand(opts = {}) {
49888
- const config = loadConfig((0, import_node_fs52.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
50041
+ const config = loadConfig((0, import_node_fs54.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
49889
50042
  const cfg = resolveConfig(config.abuse_reporter);
49890
50043
  const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
49891
50044
  const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
@@ -50015,6 +50168,45 @@ function shadowedUpdateWarning(latest, active2, activePath) {
50015
50168
 
50016
50169
  // src/index.ts
50017
50170
  init_ipc_client();
50171
+
50172
+ // src/core/user-agent.ts
50173
+ init_cli_config();
50174
+ var USER_AGENT = `threatcrush/${PKG_VERSION} (node ${process.version}; ${process.platform})`;
50175
+ function isOurHost(url, api2 = apiUrl()) {
50176
+ let host;
50177
+ try {
50178
+ host = new URL(url).hostname.toLowerCase();
50179
+ } catch {
50180
+ return false;
50181
+ }
50182
+ let apiHost = "";
50183
+ try {
50184
+ apiHost = new URL(api2).hostname.toLowerCase();
50185
+ } catch {
50186
+ }
50187
+ return host === apiHost || host === "threatcrush.com" || host.endsWith(".threatcrush.com");
50188
+ }
50189
+ function urlOf(input) {
50190
+ if (typeof input === "string") return input;
50191
+ if (input instanceof URL) return input.href;
50192
+ return input.url;
50193
+ }
50194
+ function installUserAgent(target = globalThis) {
50195
+ const base = target.fetch;
50196
+ if (!base || base.__threatcrushUA) return;
50197
+ const wrapped = ((input, init) => {
50198
+ if (!isOurHost(urlOf(input))) return base(input, init);
50199
+ const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
50200
+ if (headers.has("user-agent")) return base(input, init);
50201
+ headers.set("user-agent", USER_AGENT);
50202
+ return base(input, { ...init, headers });
50203
+ });
50204
+ wrapped.__threatcrushUA = true;
50205
+ target.fetch = wrapped;
50206
+ }
50207
+
50208
+ // src/index.ts
50209
+ installUserAgent();
50018
50210
  var LOGO2 = `
50019
50211
  ${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")}
50020
50212
  ${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")}
@@ -50024,10 +50216,10 @@ ${source_default.green(" \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u25
50024
50216
  ${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")}
50025
50217
  ${source_default.dim(" C R U S H")}
50026
50218
  `;
50027
- var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
50219
+ var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
50028
50220
  var PKG_NAME2 = "@profullstack/threatcrush";
50029
50221
  var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
50030
- var INSTALL_CONFIG_PATH = (0, import_node_path39.join)((0, import_node_os15.homedir)(), ".threatcrush", "install.json");
50222
+ var INSTALL_CONFIG_PATH = (0, import_node_path41.join)((0, import_node_os16.homedir)(), ".threatcrush", "install.json");
50031
50223
  function detectPackageManager() {
50032
50224
  try {
50033
50225
  const npmGlobal = (0, import_node_child_process23.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
@@ -50053,7 +50245,7 @@ function detectPackageManager() {
50053
50245
  }
50054
50246
  function readInstallConfig() {
50055
50247
  try {
50056
- return JSON.parse((0, import_node_fs53.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
50248
+ return JSON.parse((0, import_node_fs55.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
50057
50249
  } catch {
50058
50250
  return {};
50059
50251
  }
@@ -50393,7 +50585,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
50393
50585
  program2.command("logs").description("Tail daemon logs").action(async () => {
50394
50586
  console.log(LOGO2);
50395
50587
  const logPath2 = PATHS.logFile;
50396
- if (!(0, import_node_fs53.existsSync)(logPath2)) {
50588
+ if (!(0, import_node_fs55.existsSync)(logPath2)) {
50397
50589
  console.log(source_default.yellow(` No log file found at ${logPath2}`));
50398
50590
  console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
50399
50591
  return;
@@ -50514,7 +50706,7 @@ var storeCmd = program2.command("store").description("Browse the module marketpl
50514
50706
  console.log(source_default.green(" Module Marketplace\n"));
50515
50707
  console.log(source_default.dim(" Loading available modules..."));
50516
50708
  try {
50517
- const res = await fetch(`${API_URL7}/api/modules`);
50709
+ const res = await fetch(`${API_URL8}/api/modules`);
50518
50710
  if (!res.ok) {
50519
50711
  console.log(source_default.red(` \u2717 Failed to load modules: ${res.statusText}
50520
50712
  `));
@@ -50541,7 +50733,7 @@ storeCmd.command("search <query>").description("Search for modules in the store"
50541
50733
  console.log(source_default.green(` Searching for "${query}"...
50542
50734
  `));
50543
50735
  try {
50544
- const res = await fetch(`${API_URL7}/api/modules?q=${encodeURIComponent(query)}`);
50736
+ const res = await fetch(`${API_URL8}/api/modules?q=${encodeURIComponent(query)}`);
50545
50737
  if (!res.ok) {
50546
50738
  console.log(source_default.red(` \u2717 Search failed: ${res.statusText}
50547
50739
  `));
@@ -50566,10 +50758,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
50566
50758
  });
50567
50759
  storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
50568
50760
  console.log(LOGO2);
50569
- const configPath = (0, import_node_path39.join)((0, import_node_os15.homedir)(), ".threatcrush", "config.json");
50761
+ const configPath = (0, import_node_path41.join)((0, import_node_os16.homedir)(), ".threatcrush", "config.json");
50570
50762
  let email = "";
50571
50763
  try {
50572
- const config = JSON.parse((0, import_node_fs53.readFileSync)(configPath, "utf-8"));
50764
+ const config = JSON.parse((0, import_node_fs55.readFileSync)(configPath, "utf-8"));
50573
50765
  email = config.email || "";
50574
50766
  } catch {
50575
50767
  }
@@ -50586,9 +50778,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
50586
50778
  return;
50587
50779
  }
50588
50780
  try {
50589
- const dir = (0, import_node_path39.join)((0, import_node_os15.homedir)(), ".threatcrush");
50590
- if (!(0, import_node_fs53.existsSync)(dir)) (0, import_node_fs53.mkdirSync)(dir, { recursive: true });
50591
- (0, import_node_fs53.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
50781
+ const dir = (0, import_node_path41.join)((0, import_node_os16.homedir)(), ".threatcrush");
50782
+ if (!(0, import_node_fs55.existsSync)(dir)) (0, import_node_fs55.mkdirSync)(dir, { recursive: true });
50783
+ (0, import_node_fs55.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
50592
50784
  console.log(source_default.dim(` Saved email to ${configPath}`));
50593
50785
  } catch {
50594
50786
  }
@@ -50598,7 +50790,7 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
50598
50790
  `));
50599
50791
  let meta;
50600
50792
  try {
50601
- const res = await fetch(`${API_URL7}/api/modules/fetch-meta`, {
50793
+ const res = await fetch(`${API_URL8}/api/modules/fetch-meta`, {
50602
50794
  method: "POST",
50603
50795
  headers: { "Content-Type": "application/json" },
50604
50796
  body: JSON.stringify({ url, git_url: url })
@@ -50644,7 +50836,7 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
50644
50836
  }
50645
50837
  console.log(source_default.dim("\n Publishing..."));
50646
50838
  try {
50647
- const res = await fetch(`${API_URL7}/api/modules`, {
50839
+ const res = await fetch(`${API_URL8}/api/modules`, {
50648
50840
  method: "POST",
50649
50841
  headers: { "Content-Type": "application/json" },
50650
50842
  body: JSON.stringify({
@@ -50665,7 +50857,7 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
50665
50857
  const slug = mod?.slug || meta.name;
50666
50858
  console.log(source_default.green(`
50667
50859
  \u2713 Module submitted for review. It appears in the store once approved.`));
50668
- console.log(source_default.dim(` ${API_URL7}/store/${slug}
50860
+ console.log(source_default.dim(` ${API_URL8}/store/${slug}
50669
50861
  `));
50670
50862
  } catch (err) {
50671
50863
  console.log(source_default.red(`
@@ -50736,6 +50928,12 @@ propsCmd.command("runs").alias("history").description("Show recent scan/pentest
50736
50928
  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) => {
50737
50929
  await propertiesImportCommand(file, { org: opts.org, dryRun: opts.dryRun });
50738
50930
  });
50931
+ 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) => {
50932
+ await redeemCommand(code);
50933
+ });
50934
+ 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) => {
50935
+ await invitesCommand(action, arg);
50936
+ });
50739
50937
  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) => {
50740
50938
  await connectCommand({
50741
50939
  target,