@profullstack/threatcrush 0.13.73 → 0.13.76

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
@@ -17944,9 +17944,9 @@ function renderCells(data, cols, rows2, opts = {}) {
17944
17944
  const s = targetServer(o, data.servers);
17945
17945
  if (!s) continue;
17946
17946
  const pts = arcSegments(o, s, 64).flat();
17947
- const head = Math.floor(cometPhase(o.ip, now) * pts.length);
17947
+ const head2 = Math.floor(cometPhase(o.ip, now) * pts.length);
17948
17948
  const color = severityColor2(o.severity);
17949
- for (let i = Math.max(0, head - 10); i <= head && i < pts.length; i++) {
17949
+ for (let i = Math.max(0, head2 - 10); i <= head2 && i < pts.length; i++) {
17950
17950
  dot(pts[i].x * W, pts[i].y * H, color, SEVERITY_RANK[o.severity]);
17951
17951
  }
17952
17952
  }
@@ -18041,8 +18041,8 @@ function renderPng(data, width, height, opts = {}) {
18041
18041
  for (let i = 1; i < seg.length; i++) line(r, seg[i - 1], seg[i], width, height, c, 0.18);
18042
18042
  }
18043
18043
  const pts = segs.flat();
18044
- const head = cometPhase(o.ip, now) * (pts.length - 1);
18045
- const h = Math.floor(head);
18044
+ const head2 = cometPhase(o.ip, now) * (pts.length - 1);
18045
+ const h = Math.floor(head2);
18046
18046
  for (let i = Math.max(0, h - 18); i <= h; i++) {
18047
18047
  const t = 1 - (h - i) / 18;
18048
18048
  r.disc(pts[i].x * width, pts[i].y * height, 1 + t * 1.4, c, t * 0.9);
@@ -23787,9 +23787,9 @@ var source_default = chalk;
23787
23787
  // src/index.ts
23788
23788
  var import_readline = __toESM(require("readline"));
23789
23789
  var import_node_child_process29 = require("child_process");
23790
- var import_node_fs74 = require("fs");
23790
+ var import_node_fs75 = require("fs");
23791
23791
  var import_node_path57 = require("path");
23792
- var import_node_os23 = require("os");
23792
+ var import_node_os24 = require("os");
23793
23793
 
23794
23794
  // src/commands/monitor.ts
23795
23795
  var import_node_fs11 = require("fs");
@@ -37030,7 +37030,7 @@ var DISPLAY_STRING = /(\b(?:echo|printf|say|info|warn|error)\s+(?:-[A-Za-z]+\s+)
37030
37030
  function stripDisplayedStrings(line2) {
37031
37031
  return line2.replace(
37032
37032
  DISPLAY_STRING,
37033
- (whole, head, quoted) => /"(?:[^"\\\n]|\\.)*(?:\$\(|`)(?:[^"\\\n]|\\.)*"/.test(quoted) ? whole : `${head}""`
37033
+ (whole, head2, quoted) => /"(?:[^"\\\n]|\\.)*(?:\$\(|`)(?:[^"\\\n]|\\.)*"/.test(quoted) ? whole : `${head2}""`
37034
37034
  );
37035
37035
  }
37036
37036
  var MINIFIED_LINE = 1e3;
@@ -37589,7 +37589,8 @@ var SECRET_RULES = [
37589
37589
  pattern: /-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY(?: BLOCK)?-----/,
37590
37590
  severity: "critical",
37591
37591
  cwe: "CWE-798",
37592
- consequence: "Key material, committed. Rotation is the only remediation."
37592
+ consequence: "Key material, committed. Rotation is the only remediation.",
37593
+ confirm: (lines, index, match) => hasPemBody(lines, index, match)
37593
37594
  },
37594
37595
  {
37595
37596
  id: "secret-slack-token",
@@ -37738,6 +37739,18 @@ var KNOWN_PLACEHOLDERS = [
37738
37739
  function isKnownPlaceholder(text) {
37739
37740
  return KNOWN_PLACEHOLDERS.some((pattern) => pattern.test(text));
37740
37741
  }
37742
+ var PEM_BODY_LOOKAHEAD = 6;
37743
+ var PEM_BODY_RUN = /[A-Za-z0-9+/]{40,}/;
37744
+ var PEM_BODY_LINE = /^[\s'"`+(]*(?:\\n)?[A-Za-z0-9+/]{40,}={0,2}(?:\\n)?['"`,;+)\s]*$/;
37745
+ function hasPemBody(lines, index, match) {
37746
+ const rest = (lines[index] ?? "").slice(match.index + match[0].length).replace(/\\[nr]/g, " ");
37747
+ if (PEM_BODY_RUN.test(rest)) return true;
37748
+ const last = Math.min(lines.length - 1, index + PEM_BODY_LOOKAHEAD);
37749
+ for (let i = index + 1; i <= last; i++) {
37750
+ if (PEM_BODY_LINE.test(lines[i])) return true;
37751
+ }
37752
+ return false;
37753
+ }
37741
37754
  function isPlaceholderAttribute(line2, value) {
37742
37755
  const at = line2.lastIndexOf(value);
37743
37756
  if (at === -1) return false;
@@ -37997,14 +38010,6 @@ function isSuppressed(suppressions, index, ruleId) {
37997
38010
  if (!rules) return false;
37998
38011
  return rules.has("*") || rules.has(ruleId);
37999
38012
  }
38000
- function pemPlaceholder(lines, index) {
38001
- const first = lines[index] ?? "";
38002
- const header2 = /-----BEGIN ((?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY(?: BLOCK)?)-----/.exec(first);
38003
- if (!header2) return false;
38004
- const tail = [first.slice(header2.index + header2[0].length), ...lines.slice(index + 1, index + 21)].join("\n").replace(/\\n/g, "\n");
38005
- const end = tail.indexOf(`-----END ${header2[1]}-----`);
38006
- return end >= 0 && ["your-pem-body-here", "your-private-key-here", "your-private-key-body-here"].includes(tail.slice(0, end).trim().toLowerCase());
38007
- }
38008
38013
  function isTestPath(relativePath) {
38009
38014
  const p = relativePath.replace(/\\/g, "/");
38010
38015
  return /(?:^|\/)(?:tests?|__tests__|__mocks__|spec|specs|fixtures?|mocks?|e2e|testdata|testutils?|harness)\//i.test(p) || /(?:^|\/)(?:test|conftest)_[^/]+$/i.test(p) || /[._-](?:test|spec)\.[a-z]+$/i.test(p) || /_test\.[a-z]+$/i.test(p);
@@ -38192,6 +38197,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
38192
38197
  const match = rule.pattern.exec(line2);
38193
38198
  if (!match) continue;
38194
38199
  if (isKnownPlaceholder(match[0])) continue;
38200
+ if (rule.confirm && !rule.confirm(lines, index, match)) continue;
38195
38201
  if (isSuppressed(suppressions, index, rule.id)) continue;
38196
38202
  const value = match[1] ?? match[0];
38197
38203
  if (isVariableReference(value)) continue;
@@ -38200,7 +38206,9 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
38200
38206
  test: inTests,
38201
38207
  "test-block": inlineTests.has(index),
38202
38208
  suppressed: foreignSecurityMark(line2),
38203
- placeholder: isPlaceholderAttribute(line2, value) || rule.id === "secret-private-key" && pemPlaceholder(lines, index),
38209
+ // A dummy PEM body (`your-pem-body-here`) never reaches here: it is not a
38210
+ // base64 body, so `hasPemBody` already dropped it.
38211
+ placeholder: isPlaceholderAttribute(line2, value),
38204
38212
  "self-describing": rule.keywordShaped === true && describesItsOwnKey(line2, value)
38205
38213
  });
38206
38214
  findings2.push({
@@ -40795,8 +40803,8 @@ async function pentestCommand(targetUrl) {
40795
40803
  }
40796
40804
 
40797
40805
  // src/commands/av.ts
40798
- var import_node_fs27 = require("fs");
40799
- var import_node_os12 = require("os");
40806
+ var import_node_fs28 = require("fs");
40807
+ var import_node_os13 = require("os");
40800
40808
  var import_node_path24 = require("path");
40801
40809
 
40802
40810
  // ../../packages/av/src/sha256.ts
@@ -41308,8 +41316,13 @@ var RULES = [
41308
41316
  ];
41309
41317
  function buildContext(name, bytes, kind, size) {
41310
41318
  let text = "";
41311
- for (let i = 0; i < bytes.length; i += 32768) {
41312
- text += String.fromCharCode.apply(null, bytes.subarray(i, i + 32768));
41319
+ const NodeBuffer = globalThis.Buffer;
41320
+ if (NodeBuffer) {
41321
+ text = NodeBuffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("latin1");
41322
+ } else {
41323
+ for (let i = 0; i < bytes.length; i += 32768) {
41324
+ text += String.fromCharCode.apply(null, bytes.subarray(i, i + 32768));
41325
+ }
41313
41326
  }
41314
41327
  let wide = "";
41315
41328
  if (kind === "pe" || kind === "lnk" || kind === "ole") {
@@ -41372,6 +41385,10 @@ var SignatureSet = class {
41372
41385
  get(sha256) {
41373
41386
  return this.map.get(sha256.toLowerCase());
41374
41387
  }
41388
+ /** Every `[sha256, name]` pair, so a set can be rebuilt in a worker thread. */
41389
+ entries() {
41390
+ return [...this.map];
41391
+ }
41375
41392
  get size() {
41376
41393
  return this.map.size;
41377
41394
  }
@@ -41570,10 +41587,15 @@ var SKIP_DIR_NAMES = /* @__PURE__ */ new Set([
41570
41587
  ".threatcrush"
41571
41588
  ]);
41572
41589
  var SKIP_ROOTS = ["/proc", "/sys", "/dev/pts", "/run", "/snap"];
41573
- async function* walkTargets(targets, opts = {}) {
41574
- const skip = opts.skipDirNames ?? SKIP_DIR_NAMES;
41575
- const seen = /* @__PURE__ */ new Set();
41576
- for (const t of targets) {
41590
+ async function* walkFiles(targets, opts = {}) {
41591
+ const skipNames = opts.skipDirNames ?? SKIP_DIR_NAMES;
41592
+ const limit = Math.max(1, opts.concurrency ?? 8);
41593
+ const HIGH_WATER = 8192;
41594
+ const visited = /* @__PURE__ */ new Map();
41595
+ const fileTargets = /* @__PURE__ */ new Set();
41596
+ const ordered = [...targets].sort((a, b) => a.depth === b.depth ? 0 : b.depth > a.depth ? 1 : -1);
41597
+ const dirs = [];
41598
+ for (const t of ordered) {
41577
41599
  let st;
41578
41600
  try {
41579
41601
  st = await (0, import_promises.lstat)(t.path);
@@ -41582,48 +41604,78 @@ async function* walkTargets(targets, opts = {}) {
41582
41604
  continue;
41583
41605
  }
41584
41606
  if (st.isFile()) {
41585
- if (!seen.has(t.path)) {
41586
- seen.add(t.path);
41587
- yield { path: t.path, size: st.size };
41607
+ if (!fileTargets.has(t.path)) {
41608
+ fileTargets.add(t.path);
41609
+ yield t.path;
41588
41610
  }
41589
- continue;
41590
- }
41591
- if (!st.isDirectory()) continue;
41592
- const stack2 = [[t.path, 0]];
41593
- while (stack2.length) {
41594
- if (opts.signal?.aborted) return;
41595
- const [dir, depth] = stack2.pop();
41596
- if (SKIP_ROOTS.some((r) => dir === r || dir.startsWith(`${r}/`))) continue;
41597
- let handle;
41611
+ } else if (st.isDirectory() && t.depth >= 1) dirs.push(t);
41612
+ }
41613
+ for (const t of dirs) {
41614
+ const stack2 = [[t.path, t.depth]];
41615
+ const out = [];
41616
+ let active2 = 0;
41617
+ let wake = null;
41618
+ const notify = () => {
41619
+ const w = wake;
41620
+ wake = null;
41621
+ w?.();
41622
+ };
41623
+ const readDir = async (dir, remaining, filesToo) => {
41598
41624
  try {
41599
- handle = await (0, import_promises.opendir)(dir);
41625
+ const handle = await (0, import_promises.opendir)(dir, { bufferSize: 256 });
41626
+ for await (const ent of handle) {
41627
+ if (ent.isSymbolicLink()) continue;
41628
+ const p = (0, import_node_path20.join)(dir, ent.name);
41629
+ if (ent.isDirectory()) {
41630
+ if (remaining > 1 && !skipNames.has(ent.name)) stack2.push([p, remaining - 1]);
41631
+ } else if (filesToo && ent.isFile() && !fileTargets.has(p)) {
41632
+ out.push(p);
41633
+ if (out.length >= 512) notify();
41634
+ }
41635
+ }
41600
41636
  } catch (e) {
41601
41637
  opts.onSkip?.(dir, e.code ?? "unreadable");
41602
- continue;
41638
+ } finally {
41639
+ active2--;
41640
+ notify();
41603
41641
  }
41604
- for await (const ent of handle) {
41605
- const p = (0, import_node_path20.join)(dir, ent.name);
41606
- if (ent.isSymbolicLink()) continue;
41607
- if (ent.isDirectory()) {
41608
- if (depth + 1 < t.depth && !skip.has(ent.name)) stack2.push([p, depth + 1]);
41609
- continue;
41610
- }
41611
- if (!ent.isFile() || seen.has(p)) continue;
41612
- seen.add(p);
41613
- try {
41614
- const s = await (0, import_promises.lstat)(p);
41615
- yield { path: p, size: s.size };
41616
- } catch (e) {
41617
- opts.onSkip?.(p, e.code ?? "unreadable");
41618
- }
41642
+ };
41643
+ for (; ; ) {
41644
+ if (opts.signal?.aborted) return;
41645
+ while (active2 < limit && stack2.length && out.length < HIGH_WATER) {
41646
+ const [dir, remaining] = stack2.pop();
41647
+ if (SKIP_ROOTS.some((r) => dir === r || dir.startsWith(`${r}/`))) continue;
41648
+ const before2 = visited.get(dir);
41649
+ if (before2 !== void 0 && before2 >= remaining) continue;
41650
+ visited.set(dir, remaining);
41651
+ active2++;
41652
+ void readDir(dir, remaining, before2 === void 0);
41653
+ }
41654
+ if (out.length) {
41655
+ for (const p of out.splice(0)) yield p;
41656
+ continue;
41619
41657
  }
41658
+ if (!active2 && !stack2.length) break;
41659
+ await new Promise((resolve9) => {
41660
+ wake = resolve9;
41661
+ });
41620
41662
  }
41621
41663
  }
41622
41664
  }
41623
41665
 
41666
+ // ../../packages/av/src/node/scan-file.ts
41667
+ var import_node_crypto6 = require("crypto");
41668
+ var import_node_fs23 = require("fs");
41669
+ var CHUNK = 1 << 20;
41670
+ var OPEN_FLAGS = import_node_fs23.constants.O_RDONLY | (import_node_fs23.constants.O_NOFOLLOW ?? 0) | (import_node_fs23.constants.O_NONBLOCK ?? 0);
41671
+ var head = Buffer.allocUnsafe(64 * 1024);
41672
+
41673
+ // ../../packages/av/src/node/scan-worker.ts
41674
+ var import_node_worker_threads = require("worker_threads");
41675
+
41624
41676
  // ../../packages/av/src/node/clamav.ts
41625
41677
  var import_node_child_process5 = require("child_process");
41626
- var import_node_fs23 = require("fs");
41678
+ var import_node_fs24 = require("fs");
41627
41679
  var import_promises2 = require("fs/promises");
41628
41680
  var import_node_os10 = require("os");
41629
41681
  var import_node_path21 = require("path");
@@ -41635,7 +41687,7 @@ function findBinary(name, env3 = process.env, platform = process.platform) {
41635
41687
  if (platform === "darwin") dirs.push("/opt/homebrew/bin", "/usr/local/bin");
41636
41688
  for (const d of dirs) {
41637
41689
  const p = (0, import_node_path21.join)(d, exe);
41638
- if ((0, import_node_fs23.existsSync)(p)) return p;
41690
+ if ((0, import_node_fs24.existsSync)(p)) return p;
41639
41691
  }
41640
41692
  return null;
41641
41693
  }
@@ -41733,8 +41785,8 @@ function clamInstallHint(platform = process.platform) {
41733
41785
  }
41734
41786
 
41735
41787
  // ../../packages/av/src/node/quarantine.ts
41736
- var import_node_crypto6 = require("crypto");
41737
- var import_node_fs24 = require("fs");
41788
+ var import_node_crypto7 = require("crypto");
41789
+ var import_node_fs25 = require("fs");
41738
41790
  var import_promises3 = require("fs/promises");
41739
41791
  var import_node_os11 = require("os");
41740
41792
  var import_node_path22 = require("path");
@@ -41749,8 +41801,8 @@ function xor(buf) {
41749
41801
  }
41750
41802
  async function quarantineFile(path2, detections = [], dir = quarantineDir()) {
41751
41803
  const data = await (0, import_promises3.readFile)(path2);
41752
- const sha256 = (0, import_node_crypto6.createHash)("sha256").update(data).digest("hex");
41753
- const id = `${(/* @__PURE__ */ new Date()).toISOString().replace(/[-:T.Z]/g, "").slice(0, 14)}-${(0, import_node_crypto6.randomBytes)(4).toString("hex")}`;
41804
+ const sha256 = (0, import_node_crypto7.createHash)("sha256").update(data).digest("hex");
41805
+ const id = `${(/* @__PURE__ */ new Date()).toISOString().replace(/[-:T.Z]/g, "").slice(0, 14)}-${(0, import_node_crypto7.randomBytes)(4).toString("hex")}`;
41754
41806
  await (0, import_promises3.mkdir)(dir, { recursive: true, mode: 448 });
41755
41807
  const entry = {
41756
41808
  id,
@@ -41763,7 +41815,7 @@ async function quarantineFile(path2, detections = [], dir = quarantineDir()) {
41763
41815
  const bin = (0, import_node_path22.join)(dir, `${id}.bin`);
41764
41816
  await (0, import_promises3.writeFile)(bin, xor(data), { mode: 384 });
41765
41817
  const check2 = xor(await (0, import_promises3.readFile)(bin));
41766
- if ((0, import_node_crypto6.createHash)("sha256").update(check2).digest("hex") !== sha256) {
41818
+ if ((0, import_node_crypto7.createHash)("sha256").update(check2).digest("hex") !== sha256) {
41767
41819
  await (0, import_promises3.rm)(bin, { force: true });
41768
41820
  throw new Error("quarantine copy did not verify; original left in place");
41769
41821
  }
@@ -41772,7 +41824,7 @@ async function quarantineFile(path2, detections = [], dir = quarantineDir()) {
41772
41824
  return entry;
41773
41825
  }
41774
41826
  async function listQuarantine(dir = quarantineDir()) {
41775
- if (!(0, import_node_fs24.existsSync)(dir)) return [];
41827
+ if (!(0, import_node_fs25.existsSync)(dir)) return [];
41776
41828
  const out = [];
41777
41829
  for (const f of await (0, import_promises3.readdir)(dir)) {
41778
41830
  if (!f.endsWith(".json")) continue;
@@ -41786,7 +41838,7 @@ async function listQuarantine(dir = quarantineDir()) {
41786
41838
  async function entryOf(id, dir) {
41787
41839
  if (!/^[\w-]+$/.test(id)) throw new Error(`bad quarantine id: ${id}`);
41788
41840
  const p = (0, import_node_path22.join)(dir, `${id}.json`);
41789
- if (!(0, import_node_fs24.existsSync)(p)) throw new Error(`no quarantined file with id ${id}`);
41841
+ if (!(0, import_node_fs25.existsSync)(p)) throw new Error(`no quarantined file with id ${id}`);
41790
41842
  return JSON.parse(await (0, import_promises3.readFile)(p, "utf8"));
41791
41843
  }
41792
41844
  async function restoreQuarantined(id, to, dir = quarantineDir()) {
@@ -41811,77 +41863,106 @@ async function deleteQuarantined(id, dir = quarantineDir()) {
41811
41863
  }
41812
41864
 
41813
41865
  // ../../packages/av/src/node/scan.ts
41814
- var import_node_crypto7 = require("crypto");
41815
- var import_node_fs25 = require("fs");
41866
+ var import_node_crypto8 = require("crypto");
41867
+ var import_node_fs26 = require("fs");
41868
+ var import_promises4 = require("fs/promises");
41869
+ var import_node_os12 = require("os");
41870
+ var import_node_worker_threads2 = require("worker_threads");
41816
41871
  var LOOKUP_KINDS = /* @__PURE__ */ new Set(["pe", "elf", "macho", "script", "lnk", "ole", "zip", "pdf", "dex", "rtf"]);
41817
41872
  var MAX_LOOKUPS = 5e3;
41818
41873
  async function readForScan(path2, size, cap) {
41819
- const hash = (0, import_node_crypto7.createHash)("sha256");
41820
- const head = Buffer.allocUnsafe(Math.min(size, cap));
41874
+ const hash = (0, import_node_crypto8.createHash)("sha256");
41875
+ const head2 = Buffer.allocUnsafe(Math.min(size, cap));
41821
41876
  let filled = 0;
41822
41877
  await new Promise((resolve9, reject) => {
41823
- const s = (0, import_node_fs25.createReadStream)(path2, { highWaterMark: 1 << 20 });
41878
+ const s = (0, import_node_fs26.createReadStream)(path2, { highWaterMark: 1 << 20 });
41824
41879
  s.on("data", (chunk2) => {
41825
41880
  const c = chunk2;
41826
41881
  hash.update(c);
41827
- if (filled < head.length) {
41828
- const n = Math.min(head.length - filled, c.length);
41829
- c.copy(head, filled, 0, n);
41882
+ if (filled < head2.length) {
41883
+ const n = Math.min(head2.length - filled, c.length);
41884
+ c.copy(head2, filled, 0, n);
41830
41885
  filled += n;
41831
41886
  }
41832
41887
  });
41833
41888
  s.on("error", reject);
41834
41889
  s.on("end", () => resolve9());
41835
41890
  });
41836
- return { head: head.subarray(0, filled), sha256: hash.digest("hex") };
41891
+ return { head: head2.subarray(0, filled), sha256: hash.digest("hex") };
41837
41892
  }
41838
41893
  async function scanPaths(targets, opts = {}) {
41839
41894
  const started = /* @__PURE__ */ new Date();
41840
41895
  const cap = opts.heuristicBytes ?? DEFAULT_HEURISTIC_BYTES;
41841
41896
  const maxFile = opts.maxFileBytes ?? 1024 ** 3;
41897
+ const keepClean = opts.keepClean !== false;
41842
41898
  const skipped = [];
41843
41899
  const skip = (path2, reason) => {
41844
41900
  skipped.push({ path: path2, reason });
41845
41901
  opts.onProgress?.({ type: "skip", path: path2, reason });
41846
41902
  };
41847
41903
  let signatures = opts.signatures;
41848
- if (opts.signatureFile && (0, import_node_fs25.existsSync)(opts.signatureFile)) {
41904
+ if (opts.signatureFile && (0, import_node_fs26.existsSync)(opts.signatureFile)) {
41849
41905
  signatures = signatures ?? new SignatureSet();
41850
- signatures.load((0, import_node_fs25.readFileSync)(opts.signatureFile, "utf8"));
41906
+ signatures.load((0, import_node_fs26.readFileSync)(opts.signatureFile, "utf8"));
41851
41907
  }
41852
41908
  const clamav = opts.clamav === "off" ? null : await detectClamAV();
41853
41909
  if (opts.clamav === "require" && !clamav?.available) throw new Error("ClamAV is not installed (or clamscan is not on PATH)");
41910
+ const clamFiles = clamav?.available ? [] : null;
41854
41911
  opts.onProgress?.({ type: "phase", phase: "walking" });
41855
41912
  const results = [];
41856
- const queue = [];
41857
- const limit = Math.max(1, opts.concurrency ?? 4);
41858
- const scanOne = async (path2, size) => {
41859
- try {
41860
- const { head, sha256 } = await readForScan(path2, size, cap);
41861
- const r = await scanBytes({ name: path2, bytes: head, size, sha256 }, { signatures });
41862
- results.push(r);
41863
- opts.onProgress?.({ type: "file", path: path2, scanned: results.length, result: r });
41864
- } catch (e) {
41865
- const code = e.code ?? e.message;
41866
- const r = { path: path2, size, sha256: null, kind: "unknown", verdict: "error", detections: [], note: code };
41867
- results.push(r);
41868
- opts.onProgress?.({ type: "file", path: path2, scanned: results.length, result: r });
41869
- }
41913
+ let scanned = 0;
41914
+ let droppedClean = 0;
41915
+ let cleanLookupsKept = 0;
41916
+ const record = (r) => {
41917
+ scanned++;
41918
+ if (clamFiles && r.verdict !== "error") clamFiles.push(r.path);
41919
+ const keep = keepClean || r.verdict !== "clean" || r.detections.length > 0 || r.sha256 !== null && LOOKUP_KINDS.has(r.kind) && cleanLookupsKept++ < MAX_LOOKUPS;
41920
+ if (keep) results.push(r);
41921
+ else droppedClean++;
41922
+ opts.onProgress?.({ type: "file", path: r.path, scanned, result: r });
41870
41923
  };
41871
- for await (const f of walkTargets(targets, { signal: opts.signal, onSkip: skip })) {
41872
- if (opts.signal?.aborted) break;
41873
- if (f.size === 0) continue;
41874
- if (f.size > maxFile) {
41875
- skip(f.path, `larger than ${Math.round(maxFile / 1048576)} MB`);
41876
- continue;
41877
- }
41878
- const p = scanOne(f.path, f.size).finally(() => {
41879
- queue.splice(queue.indexOf(p), 1);
41924
+ const take = (o) => {
41925
+ if (o.kind === "result") record(o.result);
41926
+ else if (o.kind === "skip") skip(o.path, o.reason);
41927
+ };
41928
+ const walk = () => walkFiles(targets, { signal: opts.signal, onSkip: skip });
41929
+ if (opts.workerScript) {
41930
+ await scanInWorkers(walk(), {
41931
+ script: opts.workerScript,
41932
+ workers: Math.max(1, opts.concurrency ?? (0, import_node_os12.availableParallelism)()),
41933
+ init: { cap, maxFile, signatures: signatures?.entries() },
41934
+ signal: opts.signal,
41935
+ take
41880
41936
  });
41881
- queue.push(p);
41882
- if (queue.length >= limit) await Promise.race(queue);
41937
+ } else {
41938
+ const queue = /* @__PURE__ */ new Set();
41939
+ const limit = Math.max(1, opts.concurrency ?? 4);
41940
+ const scanOne = async (path2) => {
41941
+ let size;
41942
+ try {
41943
+ const st = await (0, import_promises4.lstat)(path2);
41944
+ if (!st.isFile() || st.size === 0) return;
41945
+ size = st.size;
41946
+ } catch {
41947
+ return;
41948
+ }
41949
+ if (size > maxFile) return skip(path2, `larger than ${Math.round(maxFile / 1048576)} MB`);
41950
+ try {
41951
+ const { head: head2, sha256 } = await readForScan(path2, size, cap);
41952
+ record(await scanBytes({ name: path2, bytes: head2, size, sha256 }, { signatures }));
41953
+ } catch (e) {
41954
+ const code = e.code ?? e.message;
41955
+ record({ path: path2, size, sha256: null, kind: "unknown", verdict: "error", detections: [], note: code });
41956
+ }
41957
+ };
41958
+ for await (const path2 of walk()) {
41959
+ if (opts.signal?.aborted) break;
41960
+ const p = scanOne(path2).finally(() => queue.delete(p));
41961
+ queue.add(p);
41962
+ if (queue.size >= limit) await Promise.race(queue);
41963
+ }
41964
+ await Promise.all(queue);
41883
41965
  }
41884
- await Promise.all(queue);
41885
41966
  const engines = ["signature", "heuristic"];
41886
41967
  if (opts.reputation !== false && !opts.signal?.aborted) {
41887
41968
  const wanted = results.filter((r) => r.sha256 && (LOOKUP_KINDS.has(r.kind) || r.detections.length > 0)).slice(0, MAX_LOOKUPS);
@@ -41893,21 +41974,87 @@ async function scanPaths(targets, opts = {}) {
41893
41974
  }
41894
41975
  }
41895
41976
  let clamavError = null;
41896
- if (clamav?.available && !opts.signal?.aborted) {
41897
- const files = results.filter((r) => r.verdict !== "error").map((r) => r.path);
41898
- opts.onProgress?.({ type: "phase", phase: "clamav", detail: `${files.length} files via ${clamav.mode}` });
41899
- const { detections, error: error2 } = await clamScanFiles(clamav, files, { signal: opts.signal });
41977
+ if (clamav?.available && clamFiles && !opts.signal?.aborted) {
41978
+ opts.onProgress?.({ type: "phase", phase: "clamav", detail: `${clamFiles.length} files via ${clamav.mode}` });
41979
+ const { detections, error: error2 } = await clamScanFiles(clamav, clamFiles, { signal: opts.signal });
41900
41980
  clamavError = error2;
41901
41981
  if (!error2) engines.push("clamav");
41902
- for (const r of results) {
41903
- const extra = detections.get(r.path);
41904
- if (!extra) continue;
41982
+ const byPath = new Map(results.map((r) => [r.path, r]));
41983
+ for (const [path2, extra] of detections) {
41984
+ let r = byPath.get(path2);
41985
+ if (!r) {
41986
+ r = { path: path2, size: 0, sha256: null, kind: "unknown", verdict: "clean", detections: [] };
41987
+ results.push(r);
41988
+ droppedClean--;
41989
+ }
41905
41990
  r.detections.push(...extra);
41906
41991
  r.verdict = verdictOf(r.detections);
41907
41992
  }
41908
41993
  }
41909
41994
  opts.onProgress?.({ type: "phase", phase: "done" });
41910
- return { summary: summarize2(results, engines, started, skipped.length), results, clamav, clamavError, skipped };
41995
+ const summary2 = summarize2(results, engines, started, skipped.length);
41996
+ summary2.scanned += droppedClean;
41997
+ summary2.clean += droppedClean;
41998
+ return { summary: summary2, results, clamav, clamavError, skipped };
41999
+ }
42000
+ async function scanInWorkers(paths, o) {
42001
+ const BATCH = 64;
42002
+ const PER_WORKER = 2;
42003
+ let failure = null;
42004
+ const waiting = /* @__PURE__ */ new Map();
42005
+ const fail3 = (e) => {
42006
+ failure ??= e;
42007
+ for (const w of waiting.values()) w.reject(e);
42008
+ waiting.clear();
42009
+ };
42010
+ const slots = Array.from({ length: o.workers }, () => {
42011
+ const worker = new import_node_worker_threads2.Worker(o.script, { workerData: o.init });
42012
+ worker.on("message", (m) => {
42013
+ const w = waiting.get(m.id);
42014
+ waiting.delete(m.id);
42015
+ w?.resolve(m.out);
42016
+ });
42017
+ worker.on("error", fail3);
42018
+ worker.on("exit", (code) => {
42019
+ if (code !== 0) fail3(new Error(`scan worker exited with code ${code}`));
42020
+ });
42021
+ return { worker, busy: 0 };
42022
+ });
42023
+ let nextId = 0;
42024
+ const inflight = /* @__PURE__ */ new Set();
42025
+ const send = (files) => {
42026
+ const slot = slots.reduce((a, b) => b.busy < a.busy ? b : a);
42027
+ slot.busy++;
42028
+ const id = nextId++;
42029
+ const p = new Promise((resolve9, reject) => waiting.set(id, { resolve: resolve9, reject })).then((out) => {
42030
+ for (const x of out) o.take(x);
42031
+ }).finally(() => {
42032
+ slot.busy--;
42033
+ inflight.delete(p);
42034
+ });
42035
+ inflight.add(p);
42036
+ slot.worker.postMessage({ id, files });
42037
+ };
42038
+ try {
42039
+ let batch = [];
42040
+ for await (const path2 of paths) {
42041
+ if (failure) throw failure;
42042
+ if (o.signal?.aborted) break;
42043
+ batch.push(path2);
42044
+ if (batch.length < BATCH) continue;
42045
+ send(batch);
42046
+ batch = [];
42047
+ while (inflight.size >= o.workers * PER_WORKER) await Promise.race(inflight);
42048
+ }
42049
+ if (batch.length && !o.signal?.aborted) send(batch);
42050
+ await Promise.all(inflight);
42051
+ if (failure) throw failure;
42052
+ } finally {
42053
+ for (const p of inflight) p.catch(() => {
42054
+ });
42055
+ slots.forEach((s) => s.worker.removeAllListeners("exit"));
42056
+ await Promise.all(slots.map((s) => s.worker.terminate()));
42057
+ }
41911
42058
  }
41912
42059
  function applyAll(results, reps) {
41913
42060
  for (let i = 0; i < results.length; i++) {
@@ -41917,8 +42064,8 @@ function applyAll(results, reps) {
41917
42064
  }
41918
42065
 
41919
42066
  // ../../packages/av/src/node/watch.ts
41920
- var import_node_fs26 = require("fs");
41921
- var import_promises4 = require("fs/promises");
42067
+ var import_node_fs27 = require("fs");
42068
+ var import_promises5 = require("fs/promises");
41922
42069
  var import_node_path23 = require("path");
41923
42070
  var IN_PROGRESS = /\.(?:crdownload|part|partial|download|tmp)$/i;
41924
42071
  function watchTargets(targets, opts) {
@@ -41929,14 +42076,14 @@ function watchTargets(targets, opts) {
41929
42076
  const scan = async (path2) => {
41930
42077
  timers.delete(path2);
41931
42078
  try {
41932
- const st = await (0, import_promises4.lstat)(path2);
42079
+ const st = await (0, import_promises5.lstat)(path2);
41933
42080
  if (!st.isFile() || st.size === 0 || st.size > (opts.maxFileBytes ?? 1024 ** 3)) return;
41934
42081
  const key = `${st.size}:${st.mtimeMs}`;
41935
42082
  if (lastScanned.get(path2) === key) return;
41936
42083
  lastScanned.set(path2, key);
41937
42084
  if (lastScanned.size > 1e4) lastScanned.delete(lastScanned.keys().next().value);
41938
- const { head, sha256 } = await readForScan(path2, st.size, opts.heuristicBytes ?? 16 * 1024 * 1024);
41939
- let r = await scanBytes({ name: path2, bytes: head, size: st.size, sha256 }, { signatures: opts.signatures });
42085
+ const { head: head2, sha256 } = await readForScan(path2, st.size, opts.heuristicBytes ?? 16 * 1024 * 1024);
42086
+ let r = await scanBytes({ name: path2, bytes: head2, size: st.size, sha256 }, { signatures: opts.signatures });
41940
42087
  if (opts.reputation !== false) {
41941
42088
  const reps = await lookupHashes([sha256], { endpoint: opts.lookupEndpoint, timeoutMs: 8e3 });
41942
42089
  r = applyReputation(r, reps.get(sha256));
@@ -41949,7 +42096,7 @@ function watchTargets(targets, opts) {
41949
42096
  };
41950
42097
  for (const t of targets) {
41951
42098
  try {
41952
- const w = (0, import_node_fs26.watch)(t.path, { recursive: t.depth > 1, persistent: true }, (_event, file) => {
42099
+ const w = (0, import_node_fs27.watch)(t.path, { recursive: t.depth > 1, persistent: true }, (_event, file) => {
41953
42100
  if (!file) return;
41954
42101
  const rel = String(file);
41955
42102
  if (IN_PROGRESS.test(rel)) return;
@@ -41975,7 +42122,12 @@ function watchTargets(targets, opts) {
41975
42122
 
41976
42123
  // src/commands/av.ts
41977
42124
  init_cli_config();
41978
- var SIGNATURE_FILE = (0, import_node_path24.join)((0, import_node_os12.homedir)(), ".threatcrush", "av", "signatures.txt");
42125
+ var SIGNATURE_FILE = (0, import_node_path24.join)((0, import_node_os13.homedir)(), ".threatcrush", "av", "signatures.txt");
42126
+ function avWorkerScript() {
42127
+ if (typeof __dirname === "undefined") return void 0;
42128
+ const p = (0, import_node_path24.join)(__dirname, "av-worker.js");
42129
+ return (0, import_node_fs28.existsSync)(p) ? p : void 0;
42130
+ }
41979
42131
  var icon2 = (v) => v === "malicious" ? source_default.red("\u2716 MALWARE") : v === "suspicious" ? source_default.yellow("\u25B2 SUSPICIOUS") : v === "error" ? source_default.gray("? ERROR") : source_default.green("\u2713 clean");
41980
42132
  async function avScanCommand(paths, opts = {}) {
41981
42133
  let targets;
@@ -41990,7 +42142,7 @@ async function avScanCommand(paths, opts = {}) {
41990
42142
  targets = quickScanTargets();
41991
42143
  label = "quick scan (downloads, desktop, temp and startup locations)";
41992
42144
  }
41993
- const missing = targets.filter((t) => !(0, import_node_fs27.existsSync)(t.path));
42145
+ const missing = targets.filter((t) => !(0, import_node_fs28.existsSync)(t.path));
41994
42146
  if (paths.length && missing.length) {
41995
42147
  console.error(source_default.red(` Not found: ${missing.map((m) => m.path).join(", ")}`));
41996
42148
  process.exitCode = 2;
@@ -41998,12 +42150,16 @@ async function avScanCommand(paths, opts = {}) {
41998
42150
  }
41999
42151
  const spinner = opts.json ? null : ora({ text: `CrushAV ${label}`, discardStdin: false }).start();
42000
42152
  let lastPaint = 0;
42153
+ const startedAt = Date.now();
42001
42154
  const report = await scanPaths(targets, {
42002
42155
  clamav: opts.requireClamav ? "require" : opts.clamav === false ? "off" : "auto",
42003
42156
  reputation: !opts.offline,
42004
42157
  lookupEndpoint: `${apiUrl()}/api/av/lookup`,
42005
42158
  signatureFile: SIGNATURE_FILE,
42006
42159
  maxFileBytes: opts.maxSize ? Number(opts.maxSize) * 1048576 : void 0,
42160
+ workerScript: avWorkerScript(),
42161
+ concurrency: opts.jobs ? Math.max(1, Math.floor(Number(opts.jobs)) || 1) : void 0,
42162
+ keepClean: false,
42007
42163
  onProgress: (e) => {
42008
42164
  if (!spinner) return;
42009
42165
  if (e.type === "phase") {
@@ -42012,7 +42168,9 @@ async function avScanCommand(paths, opts = {}) {
42012
42168
  } else if (e.type === "file" && Date.now() - lastPaint > 120) {
42013
42169
  lastPaint = Date.now();
42014
42170
  const short2 = e.path.length > 70 ? `\u2026${e.path.slice(-69)}` : e.path;
42015
- spinner.text = `${e.scanned} files ${source_default.gray(short2)}`;
42171
+ const secs = (Date.now() - startedAt) / 1e3;
42172
+ const rate = secs > 1 ? ` ${Math.round(e.scanned / secs)}/s` : "";
42173
+ spinner.text = `${e.scanned} files${rate} ${source_default.gray(short2)}`;
42016
42174
  }
42017
42175
  }
42018
42176
  }).catch((e) => {
@@ -42071,7 +42229,7 @@ async function avStatusCommand(opts = {}) {
42071
42229
  const status = {
42072
42230
  engine: "CrushAV",
42073
42231
  heuristic_rules: RULES.length,
42074
- custom_signatures: (0, import_node_fs27.existsSync)(SIGNATURE_FILE) ? SIGNATURE_FILE : null,
42232
+ custom_signatures: (0, import_node_fs28.existsSync)(SIGNATURE_FILE) ? SIGNATURE_FILE : null,
42075
42233
  clamav: clam,
42076
42234
  reputation_endpoint: `${apiUrl()}/api/av/lookup`,
42077
42235
  quarantine_dir: quarantineDir(),
@@ -42178,7 +42336,7 @@ async function avTestCommand() {
42178
42336
  }
42179
42337
 
42180
42338
  // src/commands/ai-scan.ts
42181
- var import_node_fs29 = require("fs");
42339
+ var import_node_fs30 = require("fs");
42182
42340
 
42183
42341
  // src/aiscan/probes.ts
42184
42342
  function makeCanary() {
@@ -42395,8 +42553,8 @@ ${stripShebang(source)}
42395
42553
  }
42396
42554
 
42397
42555
  // src/core/usage-ping.ts
42398
- var import_node_crypto8 = require("crypto");
42399
- var import_node_fs28 = require("fs");
42556
+ var import_node_crypto9 = require("crypto");
42557
+ var import_node_fs29 = require("fs");
42400
42558
  var import_node_path25 = require("path");
42401
42559
  init_cli_config();
42402
42560
  var STATE_FILE = "usage-ping.json";
@@ -42409,14 +42567,14 @@ function usagePingDisabled(env3 = process.env) {
42409
42567
  function installId(dir = CLI_CONFIG_DIR) {
42410
42568
  const file = (0, import_node_path25.join)(dir, STATE_FILE);
42411
42569
  try {
42412
- const j = JSON.parse((0, import_node_fs28.readFileSync)(file, "utf-8"));
42570
+ const j = JSON.parse((0, import_node_fs29.readFileSync)(file, "utf-8"));
42413
42571
  if (j.install_id) return { id: j.install_id, fresh: false };
42414
42572
  } catch {
42415
42573
  }
42416
- const id = (0, import_node_crypto8.randomUUID)();
42574
+ const id = (0, import_node_crypto9.randomUUID)();
42417
42575
  try {
42418
- if (!(0, import_node_fs28.existsSync)(dir)) (0, import_node_fs28.mkdirSync)(dir, { recursive: true });
42419
- (0, import_node_fs28.writeFileSync)(file, JSON.stringify({ install_id: id, created_at: (/* @__PURE__ */ new Date()).toISOString() }) + "\n");
42576
+ if (!(0, import_node_fs29.existsSync)(dir)) (0, import_node_fs29.mkdirSync)(dir, { recursive: true });
42577
+ (0, import_node_fs29.writeFileSync)(file, JSON.stringify({ install_id: id, created_at: (/* @__PURE__ */ new Date()).toISOString() }) + "\n");
42420
42578
  } catch {
42421
42579
  }
42422
42580
  return { id, fresh: true };
@@ -42524,7 +42682,7 @@ async function aiScanMoshCommand(file, args) {
42524
42682
  console.log();
42525
42683
  let source;
42526
42684
  try {
42527
- source = (0, import_node_fs29.readFileSync)(file, "utf-8");
42685
+ source = (0, import_node_fs30.readFileSync)(file, "utf-8");
42528
42686
  } catch (err) {
42529
42687
  logger.error(`Cannot read ${file}: ${err.message}`);
42530
42688
  process.exitCode = 1;
@@ -42553,22 +42711,22 @@ async function aiScanMoshCommand(file, args) {
42553
42711
  }
42554
42712
 
42555
42713
  // src/commands/orgs.ts
42556
- var import_node_os13 = require("os");
42557
- var import_node_fs30 = require("fs");
42714
+ var import_node_os14 = require("os");
42715
+ var import_node_fs31 = require("fs");
42558
42716
  var import_node_path26 = require("path");
42559
42717
  var API_URL3 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
42560
- var CONFIG_PATH = (0, import_node_path26.join)((0, import_node_os13.homedir)(), ".threatcrush", "config.json");
42718
+ var CONFIG_PATH = (0, import_node_path26.join)((0, import_node_os14.homedir)(), ".threatcrush", "config.json");
42561
42719
  function readConfig() {
42562
42720
  try {
42563
- return JSON.parse((0, import_node_fs30.readFileSync)(CONFIG_PATH, "utf-8"));
42721
+ return JSON.parse((0, import_node_fs31.readFileSync)(CONFIG_PATH, "utf-8"));
42564
42722
  } catch {
42565
42723
  return {};
42566
42724
  }
42567
42725
  }
42568
42726
  function writeConfig(config) {
42569
- const dir = (0, import_node_path26.join)((0, import_node_os13.homedir)(), ".threatcrush");
42570
- if (!(0, import_node_fs30.existsSync)(dir)) (0, import_node_fs30.mkdirSync)(dir, { recursive: true });
42571
- (0, import_node_fs30.writeFileSync)(CONFIG_PATH, JSON.stringify(config, null, 2));
42727
+ const dir = (0, import_node_path26.join)((0, import_node_os14.homedir)(), ".threatcrush");
42728
+ if (!(0, import_node_fs31.existsSync)(dir)) (0, import_node_fs31.mkdirSync)(dir, { recursive: true });
42729
+ (0, import_node_fs31.writeFileSync)(CONFIG_PATH, JSON.stringify(config, null, 2));
42572
42730
  }
42573
42731
  function getAuthHeaders() {
42574
42732
  const config = readConfig();
@@ -42703,14 +42861,14 @@ async function useOrganization(slug) {
42703
42861
  }
42704
42862
 
42705
42863
  // src/commands/credits.ts
42706
- var import_node_os14 = require("os");
42707
- var import_node_fs31 = require("fs");
42864
+ var import_node_os15 = require("os");
42865
+ var import_node_fs32 = require("fs");
42708
42866
  var import_node_path27 = require("path");
42709
42867
  var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
42710
- var CONFIG_PATH2 = (0, import_node_path27.join)((0, import_node_os14.homedir)(), ".threatcrush", "config.json");
42868
+ var CONFIG_PATH2 = (0, import_node_path27.join)((0, import_node_os15.homedir)(), ".threatcrush", "config.json");
42711
42869
  function sessionToken() {
42712
42870
  try {
42713
- const cfg = JSON.parse((0, import_node_fs31.readFileSync)(CONFIG_PATH2, "utf-8"));
42871
+ const cfg = JSON.parse((0, import_node_fs32.readFileSync)(CONFIG_PATH2, "utf-8"));
42714
42872
  return cfg.token ?? null;
42715
42873
  } catch {
42716
42874
  return null;
@@ -42779,7 +42937,7 @@ async function invitesCommand(action = "list", arg, f = fetch) {
42779
42937
  }
42780
42938
 
42781
42939
  // src/commands/fleet.ts
42782
- var import_promises5 = require("fs/promises");
42940
+ var import_promises6 = require("fs/promises");
42783
42941
  init_cli_config();
42784
42942
  async function call(path2, init = {}) {
42785
42943
  const res = await cloudFetch(path2, init);
@@ -42818,7 +42976,7 @@ async function readInventorySource(source, f = fetch) {
42818
42976
  if (!res.ok) throw new Error(`${source} answered ${res.status}`);
42819
42977
  return res.text();
42820
42978
  }
42821
- return (0, import_promises5.readFile)(source, "utf-8");
42979
+ return (0, import_promises6.readFile)(source, "utf-8");
42822
42980
  }
42823
42981
  async function fleetImportCommand(source, opts = {}) {
42824
42982
  let text;
@@ -42876,7 +43034,7 @@ function formatTotal(monthly) {
42876
43034
 
42877
43035
  // src/commands/servers.ts
42878
43036
  var import_node_readline2 = __toESM(require("readline"));
42879
- var import_node_os15 = require("os");
43037
+ var import_node_os16 = require("os");
42880
43038
  init_cli_config();
42881
43039
  function connectionStatus(server, now = Date.now()) {
42882
43040
  const seen = server.last_seen ? Date.parse(server.last_seen) : NaN;
@@ -42975,7 +43133,7 @@ async function chooseOrg(orgs, flag, ask2) {
42975
43133
  async function linkServer(opts = {}, ask2 = askChoice) {
42976
43134
  if (!hasSession()) throw new Error("Not logged in. Run: threatcrush login");
42977
43135
  const org = await chooseOrg(await fetchOrgs(), opts.org, ask2);
42978
- const host = opts.hostname ?? (0, import_node_os15.hostname)();
43136
+ const host = opts.hostname ?? (0, import_node_os16.hostname)();
42979
43137
  const listRes = await cloudFetch(`/api/orgs/${org.id}/servers`);
42980
43138
  if (!listRes.ok) throw new Error(`Failed to list servers in /${org.slug} (${listRes.status})`);
42981
43139
  const { servers = [] } = await listRes.json();
@@ -43092,16 +43250,16 @@ function timeAgo(dateStr) {
43092
43250
  }
43093
43251
 
43094
43252
  // src/commands/connect.ts
43095
- var import_node_os16 = require("os");
43096
- var import_node_fs32 = require("fs");
43253
+ var import_node_os17 = require("os");
43254
+ var import_node_fs33 = require("fs");
43097
43255
  var import_node_path28 = require("path");
43098
43256
  var import_node_child_process6 = require("child_process");
43099
43257
  var import_node_net4 = require("net");
43100
43258
  var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
43101
- var CONFIG_PATH3 = (0, import_node_path28.join)((0, import_node_os16.homedir)(), ".threatcrush", "config.json");
43259
+ var CONFIG_PATH3 = (0, import_node_path28.join)((0, import_node_os17.homedir)(), ".threatcrush", "config.json");
43102
43260
  function readConfig2() {
43103
43261
  try {
43104
- return JSON.parse((0, import_node_fs32.readFileSync)(CONFIG_PATH3, "utf-8"));
43262
+ return JSON.parse((0, import_node_fs33.readFileSync)(CONFIG_PATH3, "utf-8"));
43105
43263
  } catch {
43106
43264
  return {};
43107
43265
  }
@@ -43273,21 +43431,21 @@ async function sshConnect(options) {
43273
43431
 
43274
43432
  // src/commands/daemon.ts
43275
43433
  var import_node_child_process21 = require("child_process");
43276
- var import_node_fs58 = require("fs");
43277
- var import_node_path46 = require("path");
43278
43434
  var import_node_fs59 = require("fs");
43435
+ var import_node_path46 = require("path");
43436
+ var import_node_fs60 = require("fs");
43279
43437
 
43280
43438
  // src/daemon/index.ts
43281
- var import_node_fs57 = require("fs");
43439
+ var import_node_fs58 = require("fs");
43282
43440
  var import_node_child_process20 = require("child_process");
43283
- var import_node_os18 = require("os");
43441
+ var import_node_os19 = require("os");
43284
43442
  var import_node_path45 = require("path");
43285
43443
  var import_node_util4 = require("util");
43286
43444
  init_paths();
43287
43445
 
43288
43446
  // src/daemon/ipc-server.ts
43289
43447
  var import_node_net5 = require("net");
43290
- var import_node_fs33 = require("fs");
43448
+ var import_node_fs34 = require("fs");
43291
43449
  init_paths();
43292
43450
  init_control_token();
43293
43451
 
@@ -43345,9 +43503,9 @@ var IpcServer = class {
43345
43503
  controlToken = "";
43346
43504
  async start() {
43347
43505
  this.controlToken = issueControlToken();
43348
- if ((0, import_node_fs33.existsSync)(PATHS.socket)) {
43506
+ if ((0, import_node_fs34.existsSync)(PATHS.socket)) {
43349
43507
  try {
43350
- (0, import_node_fs33.unlinkSync)(PATHS.socket);
43508
+ (0, import_node_fs34.unlinkSync)(PATHS.socket);
43351
43509
  } catch {
43352
43510
  }
43353
43511
  }
@@ -43385,14 +43543,14 @@ var IpcServer = class {
43385
43543
  return new Promise((resolve9) => {
43386
43544
  if (!this.server) {
43387
43545
  try {
43388
- if ((0, import_node_fs33.existsSync)(PATHS.socket)) (0, import_node_fs33.unlinkSync)(PATHS.socket);
43546
+ if ((0, import_node_fs34.existsSync)(PATHS.socket)) (0, import_node_fs34.unlinkSync)(PATHS.socket);
43389
43547
  } catch {
43390
43548
  }
43391
43549
  return resolve9();
43392
43550
  }
43393
43551
  this.server.close(() => {
43394
43552
  try {
43395
- if ((0, import_node_fs33.existsSync)(PATHS.socket)) (0, import_node_fs33.unlinkSync)(PATHS.socket);
43553
+ if ((0, import_node_fs34.existsSync)(PATHS.socket)) (0, import_node_fs34.unlinkSync)(PATHS.socket);
43396
43554
  } catch {
43397
43555
  }
43398
43556
  resolve9();
@@ -43572,7 +43730,7 @@ var IpcServer = class {
43572
43730
  }
43573
43731
  }
43574
43732
  };
43575
- function admGid(readGroup = () => (0, import_node_fs33.readFileSync)("/etc/group", "utf-8"), statAuthLog = () => (0, import_node_fs33.statSync)("/var/log/auth.log")) {
43733
+ function admGid(readGroup = () => (0, import_node_fs34.readFileSync)("/etc/group", "utf-8"), statAuthLog = () => (0, import_node_fs34.statSync)("/var/log/auth.log")) {
43576
43734
  try {
43577
43735
  for (const line2 of readGroup().split("\n")) {
43578
43736
  const [name, , gid] = line2.split(":");
@@ -43588,14 +43746,14 @@ function admGid(readGroup = () => (0, import_node_fs33.readFileSync)("/etc/group
43588
43746
  }
43589
43747
 
43590
43748
  // src/daemon/module-host.ts
43591
- var import_node_fs39 = require("fs");
43749
+ var import_node_fs40 = require("fs");
43592
43750
  var import_node_path30 = require("path");
43593
43751
  var import_node_url = require("url");
43594
43752
  var import_toml4 = __toESM(require_toml());
43595
43753
  init_paths();
43596
43754
 
43597
43755
  // src/daemon/watchers/log-watcher.ts
43598
- var import_node_fs34 = require("fs");
43756
+ var import_node_fs35 = require("fs");
43599
43757
  var DEFAULT_SOURCES = [
43600
43758
  { path: "/var/log/auth.log", module: "ssh-guard", category: "auth" },
43601
43759
  { path: "/var/log/secure", module: "ssh-guard", category: "auth" },
@@ -43618,9 +43776,9 @@ var LogWatcher = class {
43618
43776
  start() {
43619
43777
  const started = [];
43620
43778
  for (const src of this.sources) {
43621
- if (!(0, import_node_fs34.existsSync)(src.path)) continue;
43779
+ if (!(0, import_node_fs35.existsSync)(src.path)) continue;
43622
43780
  try {
43623
- (0, import_node_fs34.accessSync)(src.path, import_node_fs34.constants.R_OK);
43781
+ (0, import_node_fs35.accessSync)(src.path, import_node_fs35.constants.R_OK);
43624
43782
  } catch {
43625
43783
  continue;
43626
43784
  }
@@ -44006,7 +44164,7 @@ function realtimeToDate(rt) {
44006
44164
 
44007
44165
  // src/modules/network-monitor/index.ts
44008
44166
  var import_node_child_process8 = require("child_process");
44009
- var import_node_fs35 = require("fs");
44167
+ var import_node_fs36 = require("fs");
44010
44168
  var NetworkMonitor = class {
44011
44169
  constructor(bus2) {
44012
44170
  this.bus = bus2;
@@ -44070,7 +44228,7 @@ var NetworkMonitor = class {
44070
44228
  hasConntrackOrSs() {
44071
44229
  const ss = (0, import_node_child_process8.spawnSync)("ss", ["--version"], { stdio: "pipe" });
44072
44230
  if (ss.status === 0) return true;
44073
- return (0, import_node_fs35.existsSync)("/proc/net/tcp");
44231
+ return (0, import_node_fs36.existsSync)("/proc/net/tcp");
44074
44232
  }
44075
44233
  /**
44076
44234
  * The TCP ports this host actually listens on.
@@ -44257,18 +44415,18 @@ var NetworkMonitor = class {
44257
44415
  };
44258
44416
 
44259
44417
  // src/modules/dns-monitor/index.ts
44260
- var import_node_fs38 = require("fs");
44418
+ var import_node_fs39 = require("fs");
44261
44419
  var import_node_child_process10 = require("child_process");
44262
44420
  var import_node_readline3 = require("readline");
44263
44421
 
44264
44422
  // src/core/threat-feeds/index.ts
44265
- var import_node_fs37 = require("fs");
44423
+ var import_node_fs38 = require("fs");
44266
44424
  var import_node_path29 = require("path");
44267
44425
  var import_node_net7 = require("net");
44268
44426
 
44269
44427
  // src/daemon/firewall/protected.ts
44270
44428
  var import_node_child_process9 = require("child_process");
44271
- var import_node_fs36 = require("fs");
44429
+ var import_node_fs37 = require("fs");
44272
44430
  var import_node_net6 = require("net");
44273
44431
  var DEFAULT_PROTECTED = [
44274
44432
  "127.0.0.0/8",
@@ -44338,7 +44496,7 @@ function v4ToBytes(ip) {
44338
44496
  function v6ToBytes(ip) {
44339
44497
  const bare = ip.split("%")[0];
44340
44498
  const [headText, tailText] = bare.split("::", 2);
44341
- const head = headText ? headText.split(":") : [];
44499
+ const head2 = headText ? headText.split(":") : [];
44342
44500
  const tail = tailText !== void 0 ? tailText ? tailText.split(":") : [] : null;
44343
44501
  const groups = [];
44344
44502
  const pushGroup = (group) => {
@@ -44352,7 +44510,7 @@ function v6ToBytes(ip) {
44352
44510
  groups.push(parseInt(group, 16));
44353
44511
  return true;
44354
44512
  };
44355
- for (const group of head) if (!pushGroup(group)) return null;
44513
+ for (const group of head2) if (!pushGroup(group)) return null;
44356
44514
  const headCount = groups.length;
44357
44515
  if (tail === null) {
44358
44516
  if (headCount !== 8) return null;
@@ -44430,14 +44588,14 @@ function moshClients(procDir = "/proc") {
44430
44588
  const found = /* @__PURE__ */ new Set();
44431
44589
  let pids = [];
44432
44590
  try {
44433
- pids = (0, import_node_fs36.readdirSync)(procDir).filter((p) => /^\d+$/.test(p));
44591
+ pids = (0, import_node_fs37.readdirSync)(procDir).filter((p) => /^\d+$/.test(p));
44434
44592
  } catch {
44435
44593
  return [];
44436
44594
  }
44437
44595
  for (const pid of pids) {
44438
44596
  try {
44439
- if ((0, import_node_fs36.readFileSync)(`${procDir}/${pid}/comm`, "utf-8").trim() !== "mosh-server") continue;
44440
- const ip = sshClientFromEnviron((0, import_node_fs36.readFileSync)(`${procDir}/${pid}/environ`, "latin1"));
44597
+ if ((0, import_node_fs37.readFileSync)(`${procDir}/${pid}/comm`, "utf-8").trim() !== "mosh-server") continue;
44598
+ const ip = sshClientFromEnviron((0, import_node_fs37.readFileSync)(`${procDir}/${pid}/environ`, "latin1"));
44441
44599
  if (ip) found.add(ip);
44442
44600
  } catch {
44443
44601
  }
@@ -44643,17 +44801,17 @@ async function fetchFeeds(settings, fetchImpl = fetch) {
44643
44801
  }
44644
44802
  function readFeedCache(path2) {
44645
44803
  try {
44646
- const set = JSON.parse((0, import_node_fs37.readFileSync)(path2, "utf-8"));
44804
+ const set = JSON.parse((0, import_node_fs38.readFileSync)(path2, "utf-8"));
44647
44805
  return set && typeof set.ips === "object" && typeof set.domains === "object" ? set : null;
44648
44806
  } catch {
44649
44807
  return null;
44650
44808
  }
44651
44809
  }
44652
44810
  function writeFeedCache(path2, set) {
44653
- (0, import_node_fs37.mkdirSync)((0, import_node_path29.dirname)(path2), { recursive: true });
44811
+ (0, import_node_fs38.mkdirSync)((0, import_node_path29.dirname)(path2), { recursive: true });
44654
44812
  const tmp = `${path2}.tmp`;
44655
- (0, import_node_fs37.writeFileSync)(tmp, JSON.stringify(set));
44656
- (0, import_node_fs37.renameSync)(tmp, path2);
44813
+ (0, import_node_fs38.writeFileSync)(tmp, JSON.stringify(set));
44814
+ (0, import_node_fs38.renameSync)(tmp, path2);
44657
44815
  }
44658
44816
  var RESOLVER_FILES = {
44659
44817
  hosts: "blocked-domains.hosts",
@@ -44778,9 +44936,9 @@ var DnsMonitor = class {
44778
44936
  }
44779
44937
  start() {
44780
44938
  const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
44781
- if (!(0, import_node_fs38.existsSync)(p)) return false;
44939
+ if (!(0, import_node_fs39.existsSync)(p)) return false;
44782
44940
  try {
44783
- (0, import_node_fs38.accessSync)(p, import_node_fs38.constants.R_OK);
44941
+ (0, import_node_fs39.accessSync)(p, import_node_fs39.constants.R_OK);
44784
44942
  return true;
44785
44943
  } catch {
44786
44944
  return false;
@@ -45137,15 +45295,15 @@ var ModuleHost = class {
45137
45295
  }
45138
45296
  }
45139
45297
  async discoverAndStartInstalled() {
45140
- if (!(0, import_node_fs39.existsSync)(PATHS.moduleDir)) return;
45298
+ if (!(0, import_node_fs40.existsSync)(PATHS.moduleDir)) return;
45141
45299
  const configs = loadModuleConfigs(PATHS.confD);
45142
- const entries = (0, import_node_fs39.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
45300
+ const entries = (0, import_node_fs40.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
45143
45301
  for (const entry of entries) {
45144
45302
  if (!entry.isDirectory()) continue;
45145
45303
  const manifestPath = (0, import_node_path30.join)(PATHS.moduleDir, entry.name, "mod.toml");
45146
- if (!(0, import_node_fs39.existsSync)(manifestPath)) continue;
45304
+ if (!(0, import_node_fs40.existsSync)(manifestPath)) continue;
45147
45305
  try {
45148
- const manifest = import_toml4.default.parse((0, import_node_fs39.readFileSync)(manifestPath, "utf-8"));
45306
+ const manifest = import_toml4.default.parse((0, import_node_fs40.readFileSync)(manifestPath, "utf-8"));
45149
45307
  const name = manifest.module?.name || entry.name;
45150
45308
  const defaults = manifest.module?.config?.defaults || {};
45151
45309
  const config = {
@@ -45215,15 +45373,15 @@ var ModuleHost = class {
45215
45373
  installedEntrypoint(modulePath) {
45216
45374
  const packageJson = (0, import_node_path30.join)(modulePath, "package.json");
45217
45375
  const candidates = [];
45218
- if ((0, import_node_fs39.existsSync)(packageJson)) {
45376
+ if ((0, import_node_fs40.existsSync)(packageJson)) {
45219
45377
  try {
45220
- const pkg = JSON.parse((0, import_node_fs39.readFileSync)(packageJson, "utf-8"));
45378
+ const pkg = JSON.parse((0, import_node_fs40.readFileSync)(packageJson, "utf-8"));
45221
45379
  if (pkg.main) candidates.push((0, import_node_path30.join)(modulePath, pkg.main));
45222
45380
  } catch {
45223
45381
  }
45224
45382
  }
45225
45383
  candidates.push((0, import_node_path30.join)(modulePath, "dist", "index.js"), (0, import_node_path30.join)(modulePath, "index.js"));
45226
- return candidates.find((candidate) => (0, import_node_fs39.existsSync)(candidate)) || null;
45384
+ return candidates.find((candidate) => (0, import_node_fs40.existsSync)(candidate)) || null;
45227
45385
  }
45228
45386
  isThreatCrushModule(value) {
45229
45387
  return Boolean(
@@ -45420,11 +45578,11 @@ function pagerdutyChannel(config) {
45420
45578
  }
45421
45579
 
45422
45580
  // src/daemon/alerts/smshub.ts
45423
- var import_node_os17 = require("os");
45581
+ var import_node_os18 = require("os");
45424
45582
  var SEVERITY_RANK6 = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
45425
45583
  var DEDUPE_MS = 10 * 6e4;
45426
45584
  var MAX_PER_HOUR = 6;
45427
- function smshubText(event, host = (0, import_node_os17.hostname)()) {
45585
+ function smshubText(event, host = (0, import_node_os18.hostname)()) {
45428
45586
  const evidence = event.details?.evidence?.message;
45429
45587
  const ip = event.source_ip && ![event.message, evidence ?? ""].some((t) => t.includes(event.source_ip)) ? ` from ${event.source_ip}` : "";
45430
45588
  const text = `ThreatCrush ${event.severity.toUpperCase()} on ${host}: ${event.message}${evidence && !event.message.includes(evidence) ? ` | ${evidence}` : ""}${ip}`;
@@ -45544,14 +45702,14 @@ function slackChannel(webhookUrl) {
45544
45702
  }
45545
45703
 
45546
45704
  // src/daemon/workers/runs-worker.ts
45547
- var import_promises6 = require("dns/promises");
45548
- var import_node_fs40 = require("fs");
45705
+ var import_promises7 = require("dns/promises");
45706
+ var import_node_fs41 = require("fs");
45549
45707
  var import_node_net9 = require("net");
45550
45708
  var import_node_path31 = require("path");
45551
45709
  init_cli_config();
45552
45710
 
45553
45711
  // src/core/cloud-events.ts
45554
- var import_node_crypto9 = require("crypto");
45712
+ var import_node_crypto10 = require("crypto");
45555
45713
  var import_node_net8 = require("net");
45556
45714
  init_cli_config();
45557
45715
  function currentLink() {
@@ -45635,7 +45793,7 @@ function remediationEvent(serverId, event) {
45635
45793
  return {
45636
45794
  type: "remediation",
45637
45795
  server_id: serverId,
45638
- event_id: (0, import_node_crypto9.randomUUID)(),
45796
+ event_id: (0, import_node_crypto10.randomUUID)(),
45639
45797
  action_type: d.action,
45640
45798
  target_value: event.source_ip,
45641
45799
  status: d.failed === true ? "failed" : "executed",
@@ -45679,7 +45837,7 @@ var NOT_PUBLIC = [
45679
45837
  function isPublicTarget(ip) {
45680
45838
  return (0, import_node_net9.isIP)(ip) !== 0 && !isProtected(ip, NOT_PUBLIC);
45681
45839
  }
45682
- async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0, import_promises6.lookup)(h, { all: true })).map((a) => a.address)) {
45840
+ async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0, import_promises7.lookup)(h, { all: true })).map((a) => a.address)) {
45683
45841
  let url;
45684
45842
  try {
45685
45843
  url = new URL(rawUrl.startsWith("http") ? rawUrl : `https://${rawUrl}`);
@@ -45698,7 +45856,7 @@ async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0,
45698
45856
  const inside = addresses.find((a) => !isPublicTarget(a));
45699
45857
  return inside ? `${host} resolves to ${inside}, which is not a public address; dashboard runs never reach inside this network` : null;
45700
45858
  }
45701
- function scanTargetError(target, roots, real = import_node_fs40.realpathSync) {
45859
+ function scanTargetError(target, roots, real = import_node_fs41.realpathSync) {
45702
45860
  if (roots.length === 0) {
45703
45861
  return "dashboard scans of this machine are off; list the directories they may read in [cloud] run_scan_paths";
45704
45862
  }
@@ -45869,8 +46027,8 @@ var RunsWorker = class {
45869
46027
  init_cli_config();
45870
46028
 
45871
46029
  // src/daemon/workers/cloud-spool.ts
45872
- var import_node_fs41 = require("fs");
45873
- var import_promises7 = require("fs/promises");
46030
+ var import_node_fs42 = require("fs");
46031
+ var import_promises8 = require("fs/promises");
45874
46032
  var import_node_path32 = require("path");
45875
46033
  var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
45876
46034
  var CloudSpool = class {
@@ -45878,7 +46036,7 @@ var CloudSpool = class {
45878
46036
  this.path = path2;
45879
46037
  this.limits = limits;
45880
46038
  try {
45881
- (0, import_node_fs41.mkdirSync)((0, import_node_path32.dirname)(path2), { recursive: true });
46039
+ (0, import_node_fs42.mkdirSync)((0, import_node_path32.dirname)(path2), { recursive: true });
45882
46040
  } catch {
45883
46041
  }
45884
46042
  this.load();
@@ -45947,7 +46105,7 @@ var CloudSpool = class {
45947
46105
  load() {
45948
46106
  let raw;
45949
46107
  try {
45950
- raw = (0, import_node_fs41.readFileSync)(this.path, "utf-8");
46108
+ raw = (0, import_node_fs42.readFileSync)(this.path, "utf-8");
45951
46109
  } catch {
45952
46110
  return;
45953
46111
  }
@@ -45978,13 +46136,13 @@ var CloudSpool = class {
45978
46136
  const body = this.lines.length > 0 ? `${this.lines.join("\n")}
45979
46137
  ` : "";
45980
46138
  const tmp = `${this.path}.tmp`;
45981
- await (0, import_promises7.writeFile)(tmp, body, { mode: 384 });
45982
- await (0, import_promises7.rename)(tmp, this.path);
46139
+ await (0, import_promises8.writeFile)(tmp, body, { mode: 384 });
46140
+ await (0, import_promises8.rename)(tmp, this.path);
45983
46141
  } else if (this.pendingAppend.length > 0) {
45984
46142
  const chunk2 = `${this.pendingAppend.join("\n")}
45985
46143
  `;
45986
46144
  this.pendingAppend = [];
45987
- await (0, import_promises7.appendFile)(this.path, chunk2, { mode: 384 });
46145
+ await (0, import_promises8.appendFile)(this.path, chunk2, { mode: 384 });
45988
46146
  }
45989
46147
  }).catch(() => {
45990
46148
  this.needsRewrite = true;
@@ -46192,7 +46350,7 @@ var CloudSync = class {
46192
46350
  };
46193
46351
 
46194
46352
  // src/daemon/workers/abuse-reporter.ts
46195
- var import_node_crypto10 = require("crypto");
46353
+ var import_node_crypto11 = require("crypto");
46196
46354
 
46197
46355
  // src/daemon/workers/abuse-evidence.ts
46198
46356
  var import_node_net10 = require("net");
@@ -46421,7 +46579,7 @@ function resolveConfig(section) {
46421
46579
  }
46422
46580
 
46423
46581
  // src/core/abuse-report-log.ts
46424
- var import_node_fs42 = require("fs");
46582
+ var import_node_fs43 = require("fs");
46425
46583
  var import_node_path33 = require("path");
46426
46584
  init_paths();
46427
46585
  var ABUSE_DIRNAME = "abuse-reports";
@@ -46430,7 +46588,7 @@ function resolveAbuseDir(dir) {
46430
46588
  if (dir) return dir;
46431
46589
  if (process.env.THREATCRUSH_ABUSE_DIR) return process.env.THREATCRUSH_ABUSE_DIR;
46432
46590
  const system = (0, import_node_path33.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
46433
- if ((0, import_node_fs42.existsSync)(system)) return system;
46591
+ if ((0, import_node_fs43.existsSync)(system)) return system;
46434
46592
  return (0, import_node_path33.join)(PATHS.stateDir, ABUSE_DIRNAME);
46435
46593
  }
46436
46594
  function logPath(dir) {
@@ -46438,15 +46596,15 @@ function logPath(dir) {
46438
46596
  }
46439
46597
  function appendReport(record, dir) {
46440
46598
  const path2 = logPath(dir);
46441
- (0, import_node_fs42.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
46442
- (0, import_node_fs42.appendFileSync)(path2, `${JSON.stringify(record)}
46599
+ (0, import_node_fs43.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
46600
+ (0, import_node_fs43.appendFileSync)(path2, `${JSON.stringify(record)}
46443
46601
  `, { mode: 420 });
46444
46602
  }
46445
46603
  function readReports(dir) {
46446
46604
  const path2 = logPath(dir);
46447
46605
  let raw;
46448
46606
  try {
46449
- raw = (0, import_node_fs42.readFileSync)(path2, "utf-8");
46607
+ raw = (0, import_node_fs43.readFileSync)(path2, "utf-8");
46450
46608
  } catch {
46451
46609
  return [];
46452
46610
  }
@@ -46585,7 +46743,7 @@ var AbuseReporter = class {
46585
46743
  const payload = buildPayload(ip, evidence);
46586
46744
  const results = this.cfg.dryRun ? [] : await dispatch(payload, this.cfg.destinations, this.cfg.keys);
46587
46745
  const record = {
46588
- id: (0, import_node_crypto10.randomUUID)().slice(0, 8),
46746
+ id: (0, import_node_crypto11.randomUUID)().slice(0, 8),
46589
46747
  ip,
46590
46748
  reported_at: new Date(now).toISOString(),
46591
46749
  mode: this.cfg.dryRun ? "dry_run" : "live",
@@ -46872,7 +47030,7 @@ var RemediationConsumer = class {
46872
47030
 
46873
47031
  // src/daemon/workers/auto-update.ts
46874
47032
  var import_node_child_process11 = require("child_process");
46875
- var import_node_fs43 = require("fs");
47033
+ var import_node_fs44 = require("fs");
46876
47034
  var import_node_path34 = require("path");
46877
47035
  init_backoff();
46878
47036
  var PKG_NAME = "@profullstack/threatcrush";
@@ -46954,10 +47112,10 @@ function installPlan(opts) {
46954
47112
  }
46955
47113
  function ownerOf(path2, passwd = "/etc/passwd") {
46956
47114
  try {
46957
- const st = (0, import_node_fs43.statSync)(path2);
47115
+ const st = (0, import_node_fs44.statSync)(path2);
46958
47116
  let home = st.uid === 0 ? "/root" : "";
46959
47117
  try {
46960
- for (const line2 of (0, import_node_fs43.readFileSync)(passwd, "utf8").split("\n")) {
47118
+ for (const line2 of (0, import_node_fs44.readFileSync)(passwd, "utf8").split("\n")) {
46961
47119
  const f = line2.split(":");
46962
47120
  if (Number(f[2]) === st.uid && f[5]) home = f[5];
46963
47121
  }
@@ -47067,7 +47225,7 @@ var AutoUpdate = class {
47067
47225
  uid: process.getuid?.() ?? -1,
47068
47226
  owner: ownerOf(this.opts.pkgRoot),
47069
47227
  underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
47070
- npmExists: import_node_fs43.existsSync
47228
+ npmExists: import_node_fs44.existsSync
47071
47229
  });
47072
47230
  if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
47073
47231
  this.recordAttempt(target);
@@ -47103,7 +47261,7 @@ var AutoUpdate = class {
47103
47261
  }
47104
47262
  lastAttempt() {
47105
47263
  try {
47106
- const v = JSON.parse((0, import_node_fs43.readFileSync)(this.opts.statePath, "utf8"));
47264
+ const v = JSON.parse((0, import_node_fs44.readFileSync)(this.opts.statePath, "utf8"));
47107
47265
  return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
47108
47266
  } catch {
47109
47267
  return null;
@@ -47111,7 +47269,7 @@ var AutoUpdate = class {
47111
47269
  }
47112
47270
  recordAttempt(version) {
47113
47271
  try {
47114
- (0, import_node_fs43.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
47272
+ (0, import_node_fs44.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
47115
47273
  } catch (err) {
47116
47274
  this.opts.log(`[update] could not record attempt: ${err.message}`);
47117
47275
  }
@@ -47120,7 +47278,7 @@ var AutoUpdate = class {
47120
47278
 
47121
47279
  // src/daemon/workers/threat-feeds.ts
47122
47280
  var import_node_child_process12 = require("child_process");
47123
- var import_node_fs44 = require("fs");
47281
+ var import_node_fs45 = require("fs");
47124
47282
  var import_node_path35 = require("path");
47125
47283
  var import_node_net13 = require("net");
47126
47284
  init_backoff();
@@ -47299,8 +47457,8 @@ var ThreatFeeds = class {
47299
47457
  const path2 = (0, import_node_path35.join)(dir, name);
47300
47458
  if (this.resolverWritten.get(name) === content) return false;
47301
47459
  try {
47302
- (0, import_node_fs44.writeFileSync)(`${path2}.tmp`, content);
47303
- (0, import_node_fs44.renameSync)(`${path2}.tmp`, path2);
47460
+ (0, import_node_fs45.writeFileSync)(`${path2}.tmp`, content);
47461
+ (0, import_node_fs45.renameSync)(`${path2}.tmp`, path2);
47304
47462
  this.resolverWritten.set(name, content);
47305
47463
  return true;
47306
47464
  } catch (err) {
@@ -47311,11 +47469,11 @@ var ThreatFeeds = class {
47311
47469
  const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
47312
47470
  const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
47313
47471
  const via = [];
47314
- if ((0, import_node_fs44.existsSync)(hooks.dnsmasq)) {
47472
+ if ((0, import_node_fs45.existsSync)(hooks.dnsmasq)) {
47315
47473
  via.push("dnsmasq");
47316
47474
  if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
47317
47475
  }
47318
- if ((0, import_node_fs44.existsSync)(hooks.unbound)) {
47476
+ if ((0, import_node_fs45.existsSync)(hooks.unbound)) {
47319
47477
  via.push("unbound");
47320
47478
  if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
47321
47479
  this.run("systemctl", ["reload", "unbound.service"]);
@@ -47376,12 +47534,12 @@ var ThreatFeeds = class {
47376
47534
  };
47377
47535
 
47378
47536
  // src/daemon/workers/privilege-watch.ts
47379
- var import_node_fs45 = require("fs");
47537
+ var import_node_fs46 = require("fs");
47380
47538
  var import_node_path36 = require("path");
47381
47539
  var import_node_child_process13 = require("child_process");
47382
47540
 
47383
47541
  // src/core/privileges/index.ts
47384
- var import_node_crypto11 = require("crypto");
47542
+ var import_node_crypto12 = require("crypto");
47385
47543
  var ADMIN_GROUPS = ["sudo", "wheel", "admin"];
47386
47544
  function parseUsers(text) {
47387
47545
  const out = [];
@@ -47422,7 +47580,7 @@ function sudoReadsIncluded(name) {
47422
47580
  }
47423
47581
  function keyFingerprint(blobBase64) {
47424
47582
  if (!/^[A-Za-z0-9+/]+=*$/.test(blobBase64)) return null;
47425
- const digest = (0, import_node_crypto11.createHash)("sha256").update(Buffer.from(blobBase64, "base64")).digest("base64");
47583
+ const digest = (0, import_node_crypto12.createHash)("sha256").update(Buffer.from(blobBase64, "base64")).digest("base64");
47426
47584
  return `SHA256:${digest.replace(/=+$/, "")}`;
47427
47585
  }
47428
47586
  function parseAuthorizedKeys(text) {
@@ -47603,31 +47761,31 @@ function countryName(code) {
47603
47761
  var fsIO = {
47604
47762
  readFile: (p) => {
47605
47763
  try {
47606
- return (0, import_node_fs45.readFileSync)(p, "utf-8");
47764
+ return (0, import_node_fs46.readFileSync)(p, "utf-8");
47607
47765
  } catch {
47608
47766
  return null;
47609
47767
  }
47610
47768
  },
47611
47769
  readDir: (p) => {
47612
47770
  try {
47613
- return (0, import_node_fs45.readdirSync)(p);
47771
+ return (0, import_node_fs46.readdirSync)(p);
47614
47772
  } catch {
47615
47773
  return null;
47616
47774
  }
47617
47775
  },
47618
- exists: (p) => (0, import_node_fs45.existsSync)(p)
47776
+ exists: (p) => (0, import_node_fs46.existsSync)(p)
47619
47777
  };
47620
47778
  function readJson(path2) {
47621
47779
  try {
47622
- return JSON.parse((0, import_node_fs45.readFileSync)(path2, "utf-8"));
47780
+ return JSON.parse((0, import_node_fs46.readFileSync)(path2, "utf-8"));
47623
47781
  } catch {
47624
47782
  return null;
47625
47783
  }
47626
47784
  }
47627
47785
  function writeJson(path2, value) {
47628
- (0, import_node_fs45.mkdirSync)((0, import_node_path36.dirname)(path2), { recursive: true });
47629
- (0, import_node_fs45.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
47630
- (0, import_node_fs45.renameSync)(`${path2}.tmp`, path2);
47786
+ (0, import_node_fs46.mkdirSync)((0, import_node_path36.dirname)(path2), { recursive: true });
47787
+ (0, import_node_fs46.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
47788
+ (0, import_node_fs46.renameSync)(`${path2}.tmp`, path2);
47631
47789
  }
47632
47790
  function defaultRun3(cmd, args) {
47633
47791
  const res = (0, import_node_child_process13.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 2e4, maxBuffer: 16 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
@@ -47744,7 +47902,7 @@ var PrivilegeWatch = class {
47744
47902
  for (const dir of dirs) {
47745
47903
  if (this.watchers.has(dir) || !this.io.exists(dir)) continue;
47746
47904
  try {
47747
- const w = (0, import_node_fs45.watch)(dir, { persistent: false }, (_type2, name) => {
47905
+ const w = (0, import_node_fs46.watch)(dir, { persistent: false }, (_type2, name) => {
47748
47906
  if (name && !String(name).startsWith("authorized_keys")) return;
47749
47907
  if (this.debounce) clearTimeout(this.debounce);
47750
47908
  this.debounce = setTimeout(() => {
@@ -47843,7 +48001,7 @@ var PrivilegeWatch = class {
47843
48001
  * raised a "new country" alert on its first run; on dev2 it did, at once.
47844
48002
  */
47845
48003
  async backfillLogins() {
47846
- if ((0, import_node_fs45.existsSync)(this.opts.loginsPath)) return;
48004
+ if ((0, import_node_fs46.existsSync)(this.opts.loginsPath)) return;
47847
48005
  const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
47848
48006
  const byUser = parseAcceptedLogins(out ?? "");
47849
48007
  const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
@@ -47856,7 +48014,7 @@ var PrivilegeWatch = class {
47856
48014
  return;
47857
48015
  }
47858
48016
  }
47859
- if ((0, import_node_fs45.existsSync)(this.opts.loginsPath)) return;
48017
+ if ((0, import_node_fs46.existsSync)(this.opts.loginsPath)) return;
47860
48018
  const at = this.now().toISOString();
47861
48019
  const history = {};
47862
48020
  for (const [user, userIps] of byUser) {
@@ -47908,11 +48066,11 @@ var PrivilegeWatch = class {
47908
48066
  };
47909
48067
 
47910
48068
  // src/daemon/workers/command-history.ts
47911
- var import_node_fs46 = require("fs");
48069
+ var import_node_fs47 = require("fs");
47912
48070
  var import_node_child_process14 = require("child_process");
47913
48071
  var import_node_path37 = require("path");
47914
48072
  var import_node_zlib2 = require("zlib");
47915
- var import_node_crypto12 = require("crypto");
48073
+ var import_node_crypto13 = require("crypto");
47916
48074
  var POLL_MS3 = 6e4;
47917
48075
  var MAX_HISTORY_BYTES = 4 * 1024 * 1024;
47918
48076
  var MAX_COMPRESSED_HISTORY_BYTES = MAX_HISTORY_BYTES + 65536;
@@ -47933,7 +48091,7 @@ function historyAccounts() {
47933
48091
  passwd = (0, import_node_child_process14.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
47934
48092
  } catch {
47935
48093
  try {
47936
- passwd = (0, import_node_fs46.readFileSync)("/etc/passwd", "utf8");
48094
+ passwd = (0, import_node_fs47.readFileSync)("/etc/passwd", "utf8");
47937
48095
  } catch {
47938
48096
  return [];
47939
48097
  }
@@ -47960,17 +48118,17 @@ function descriptorPath(directoryFd, name) {
47960
48118
  }
47961
48119
  function openDirectoryChain(path2) {
47962
48120
  if (!(0, import_node_path37.isAbsolute)(path2) || path2.split(import_node_path37.sep).includes("..")) throw new Error("directory path is not a safe absolute path");
47963
- const flags = import_node_fs46.constants.O_RDONLY | import_node_fs46.constants.O_DIRECTORY | (import_node_fs46.constants.O_NOFOLLOW ?? 0);
47964
- let fd = (0, import_node_fs46.openSync)("/", flags);
48121
+ const flags = import_node_fs47.constants.O_RDONLY | import_node_fs47.constants.O_DIRECTORY | (import_node_fs47.constants.O_NOFOLLOW ?? 0);
48122
+ let fd = (0, import_node_fs47.openSync)("/", flags);
47965
48123
  try {
47966
48124
  for (const part of path2.split(import_node_path37.sep).filter((item) => item && item !== ".")) {
47967
- const next = (0, import_node_fs46.openSync)(descriptorPath(fd, part), flags);
47968
- (0, import_node_fs46.closeSync)(fd);
48125
+ const next = (0, import_node_fs47.openSync)(descriptorPath(fd, part), flags);
48126
+ (0, import_node_fs47.closeSync)(fd);
47969
48127
  fd = next;
47970
48128
  }
47971
48129
  return fd;
47972
48130
  } catch (error2) {
47973
- (0, import_node_fs46.closeSync)(fd);
48131
+ (0, import_node_fs47.closeSync)(fd);
47974
48132
  throw error2;
47975
48133
  }
47976
48134
  }
@@ -47978,68 +48136,68 @@ function readExact(fd, size) {
47978
48136
  const data = Buffer.alloc(size);
47979
48137
  let offset = 0;
47980
48138
  while (offset < data.length) {
47981
- const read = (0, import_node_fs46.readSync)(fd, data, offset, data.length - offset, offset);
48139
+ const read = (0, import_node_fs47.readSync)(fd, data, offset, data.length - offset, offset);
47982
48140
  if (read === 0) break;
47983
48141
  offset += read;
47984
48142
  }
47985
48143
  return offset === data.length ? data : null;
47986
48144
  }
47987
48145
  function privateDirectory(path2) {
47988
- (0, import_node_fs46.mkdirSync)(path2, { recursive: true, mode: 448 });
47989
- const stat = (0, import_node_fs46.lstatSync)(path2);
48146
+ (0, import_node_fs47.mkdirSync)(path2, { recursive: true, mode: 448 });
48147
+ const stat = (0, import_node_fs47.lstatSync)(path2);
47990
48148
  if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error("history storage path is not a directory");
47991
- (0, import_node_fs46.chmodSync)(path2, 448);
48149
+ (0, import_node_fs47.chmodSync)(path2, 448);
47992
48150
  }
47993
48151
  function safeReadHistory(directoryFd, name, uid) {
47994
- const noFollow = import_node_fs46.constants.O_NOFOLLOW ?? 0;
47995
- const fd = (0, import_node_fs46.openSync)(descriptorPath(directoryFd, name), import_node_fs46.constants.O_RDONLY | noFollow);
48152
+ const noFollow = import_node_fs47.constants.O_NOFOLLOW ?? 0;
48153
+ const fd = (0, import_node_fs47.openSync)(descriptorPath(directoryFd, name), import_node_fs47.constants.O_RDONLY | noFollow);
47996
48154
  try {
47997
- const opened = (0, import_node_fs46.fstatSync)(fd);
48155
+ const opened = (0, import_node_fs47.fstatSync)(fd);
47998
48156
  if (!opened.isFile() || opened.nlink !== 1 || opened.uid !== uid) return null;
47999
48157
  if (opened.size > MAX_HISTORY_BYTES) throw new Error(`history file exceeds ${MAX_HISTORY_BYTES} bytes`);
48000
48158
  const data = readExact(fd, opened.size);
48001
48159
  if (data === null) return null;
48002
- const after = (0, import_node_fs46.fstatSync)(fd);
48160
+ const after = (0, import_node_fs47.fstatSync)(fd);
48003
48161
  if (after.size !== opened.size || after.mtimeMs !== opened.mtimeMs) return null;
48004
48162
  return data;
48005
48163
  } finally {
48006
- (0, import_node_fs46.closeSync)(fd);
48164
+ (0, import_node_fs47.closeSync)(fd);
48007
48165
  }
48008
48166
  }
48009
48167
  function atomicWrite(path2, data, mode = 384, owner, parentFd) {
48010
48168
  const dirFd = parentFd ?? openDirectoryChain((0, import_node_path37.dirname)(path2));
48011
48169
  const ownsDirFd = parentFd === void 0;
48012
48170
  const name = (0, import_node_path37.basename)(path2);
48013
- const temp = descriptorPath(dirFd, `${name}.${(0, import_node_crypto12.randomUUID)()}.tmp`);
48171
+ const temp = descriptorPath(dirFd, `${name}.${(0, import_node_crypto13.randomUUID)()}.tmp`);
48014
48172
  const destination = descriptorPath(dirFd, name);
48015
- const noFollow = import_node_fs46.constants.O_NOFOLLOW ?? 0;
48173
+ const noFollow = import_node_fs47.constants.O_NOFOLLOW ?? 0;
48016
48174
  let fd;
48017
48175
  try {
48018
- fd = (0, import_node_fs46.openSync)(temp, import_node_fs46.constants.O_WRONLY | import_node_fs46.constants.O_CREAT | import_node_fs46.constants.O_EXCL | noFollow, mode);
48176
+ fd = (0, import_node_fs47.openSync)(temp, import_node_fs47.constants.O_WRONLY | import_node_fs47.constants.O_CREAT | import_node_fs47.constants.O_EXCL | noFollow, mode);
48019
48177
  let offset = 0;
48020
- while (offset < data.length) offset += (0, import_node_fs46.writeSync)(fd, data, offset, data.length - offset);
48021
- (0, import_node_fs46.fchmodSync)(fd, mode);
48178
+ while (offset < data.length) offset += (0, import_node_fs47.writeSync)(fd, data, offset, data.length - offset);
48179
+ (0, import_node_fs47.fchmodSync)(fd, mode);
48022
48180
  if (owner && typeof process.getuid === "function" && process.getuid() === 0) {
48023
- (0, import_node_fs46.fchownSync)(fd, owner.uid, owner.gid);
48181
+ (0, import_node_fs47.fchownSync)(fd, owner.uid, owner.gid);
48024
48182
  }
48025
- (0, import_node_fs46.fsyncSync)(fd);
48026
- (0, import_node_fs46.closeSync)(fd);
48183
+ (0, import_node_fs47.fsyncSync)(fd);
48184
+ (0, import_node_fs47.closeSync)(fd);
48027
48185
  fd = void 0;
48028
- (0, import_node_fs46.renameSync)(temp, destination);
48186
+ (0, import_node_fs47.renameSync)(temp, destination);
48029
48187
  } catch (error2) {
48030
48188
  if (fd !== void 0) {
48031
48189
  try {
48032
- (0, import_node_fs46.closeSync)(fd);
48190
+ (0, import_node_fs47.closeSync)(fd);
48033
48191
  } catch {
48034
48192
  }
48035
48193
  }
48036
48194
  try {
48037
- (0, import_node_fs46.unlinkSync)(temp);
48195
+ (0, import_node_fs47.unlinkSync)(temp);
48038
48196
  } catch {
48039
48197
  }
48040
48198
  throw error2;
48041
48199
  } finally {
48042
- if (ownsDirFd) (0, import_node_fs46.closeSync)(dirFd);
48200
+ if (ownsDirFd) (0, import_node_fs47.closeSync)(dirFd);
48043
48201
  }
48044
48202
  }
48045
48203
  function readCurrentBackup(path2) {
@@ -48047,20 +48205,20 @@ function readCurrentBackup(path2) {
48047
48205
  try {
48048
48206
  const parentFd = openDirectoryChain((0, import_node_path37.dirname)(path2));
48049
48207
  try {
48050
- fd = (0, import_node_fs46.openSync)(descriptorPath(parentFd, (0, import_node_path37.basename)(path2)), import_node_fs46.constants.O_RDONLY | (import_node_fs46.constants.O_NOFOLLOW ?? 0));
48208
+ fd = (0, import_node_fs47.openSync)(descriptorPath(parentFd, (0, import_node_path37.basename)(path2)), import_node_fs47.constants.O_RDONLY | (import_node_fs47.constants.O_NOFOLLOW ?? 0));
48051
48209
  } finally {
48052
- (0, import_node_fs46.closeSync)(parentFd);
48210
+ (0, import_node_fs47.closeSync)(parentFd);
48053
48211
  }
48054
- const stat = (0, import_node_fs46.fstatSync)(fd);
48212
+ const stat = (0, import_node_fs47.fstatSync)(fd);
48055
48213
  if (!stat.isFile() || stat.nlink !== 1 || stat.size > MAX_COMPRESSED_HISTORY_BYTES) return null;
48056
48214
  const compressed = readExact(fd, stat.size);
48057
- const after = (0, import_node_fs46.fstatSync)(fd);
48215
+ const after = (0, import_node_fs47.fstatSync)(fd);
48058
48216
  if (!compressed || after.size !== stat.size || after.mtimeMs !== stat.mtimeMs) return null;
48059
48217
  return (0, import_node_zlib2.gunzipSync)(compressed, { maxOutputLength: MAX_HISTORY_BYTES });
48060
48218
  } catch {
48061
48219
  return null;
48062
48220
  } finally {
48063
- if (fd !== void 0) (0, import_node_fs46.closeSync)(fd);
48221
+ if (fd !== void 0) (0, import_node_fs47.closeSync)(fd);
48064
48222
  }
48065
48223
  }
48066
48224
  function compactTime(date) {
@@ -48129,7 +48287,7 @@ var CommandHistoryWatcher = class {
48129
48287
  if (targets.has(relative4)) continue;
48130
48288
  const path2 = (0, import_node_path37.join)(account.home, relative4);
48131
48289
  try {
48132
- (0, import_node_fs46.lstatSync)(path2);
48290
+ (0, import_node_fs47.lstatSync)(path2);
48133
48291
  targets.add(relative4);
48134
48292
  continue;
48135
48293
  } catch (error2) {
@@ -48156,7 +48314,7 @@ var CommandHistoryWatcher = class {
48156
48314
  const userPath = descriptorPath(userParentFd, (0, import_node_path37.basename)(path2));
48157
48315
  let status;
48158
48316
  try {
48159
- status = (0, import_node_fs46.lstatSync)(userPath);
48317
+ status = (0, import_node_fs47.lstatSync)(userPath);
48160
48318
  } catch (error2) {
48161
48319
  if (error2.code !== "ENOENT") throw error2;
48162
48320
  }
@@ -48180,13 +48338,13 @@ var CommandHistoryWatcher = class {
48180
48338
  }
48181
48339
  const compressed = (0, import_node_zlib2.gzipSync)(data, { level: 6 });
48182
48340
  const stamp = compactTime(this.now());
48183
- atomicWrite(`${store}.${stamp}-${(0, import_node_crypto12.randomUUID)().slice(0, 8)}.gz`, compressed);
48341
+ atomicWrite(`${store}.${stamp}-${(0, import_node_crypto13.randomUUID)().slice(0, 8)}.gz`, compressed);
48184
48342
  atomicWrite(current, compressed);
48185
48343
  this.pruneSnapshots(store);
48186
48344
  } catch (error2) {
48187
48345
  this.opts.log(`[command-history] could not snapshot uid=${account.uid} ${(0, import_node_path37.basename)(relative4)}: ${error2.message}`);
48188
48346
  } finally {
48189
- (0, import_node_fs46.closeSync)(userParentFd);
48347
+ (0, import_node_fs47.closeSync)(userParentFd);
48190
48348
  }
48191
48349
  }
48192
48350
  restore(path2, content, account, parentFd) {
@@ -48208,13 +48366,13 @@ var CommandHistoryWatcher = class {
48208
48366
  pruneSnapshots(current) {
48209
48367
  const dir = (0, import_node_path37.dirname)(current);
48210
48368
  const prefix = `${(0, import_node_path37.basename)(current).replace(/\.current\.gz$/, "")}.`;
48211
- const snapshots = (0, import_node_fs46.readdirSync)(dir).filter((name) => name !== (0, import_node_path37.basename)(current) && name.startsWith(prefix) && name.endsWith(".gz")).map((name) => ({ path: (0, import_node_path37.join)(dir, name), name, time: (0, import_node_fs46.lstatSync)((0, import_node_path37.join)(dir, name)).mtimeMs })).sort((a, b) => a.time - b.time);
48369
+ const snapshots = (0, import_node_fs47.readdirSync)(dir).filter((name) => name !== (0, import_node_path37.basename)(current) && name.startsWith(prefix) && name.endsWith(".gz")).map((name) => ({ path: (0, import_node_path37.join)(dir, name), name, time: (0, import_node_fs47.lstatSync)((0, import_node_path37.join)(dir, name)).mtimeMs })).sort((a, b) => a.time - b.time);
48212
48370
  const cutoff = this.now().getTime() - SNAPSHOT_RETENTION_MS;
48213
48371
  const removeCount = Math.max(0, snapshots.length - MAX_SNAPSHOTS);
48214
48372
  snapshots.forEach((snapshot, index) => {
48215
48373
  if (snapshot.time < cutoff || index < removeCount) {
48216
48374
  try {
48217
- (0, import_node_fs46.unlinkSync)(snapshot.path);
48375
+ (0, import_node_fs47.unlinkSync)(snapshot.path);
48218
48376
  } catch {
48219
48377
  }
48220
48378
  }
@@ -48223,9 +48381,9 @@ var CommandHistoryWatcher = class {
48223
48381
  };
48224
48382
 
48225
48383
  // src/daemon/workers/file-integrity.ts
48226
- var import_node_fs47 = require("fs");
48227
- var import_promises8 = require("fs/promises");
48228
- var import_node_crypto13 = require("crypto");
48384
+ var import_node_fs48 = require("fs");
48385
+ var import_promises9 = require("fs/promises");
48386
+ var import_node_crypto14 = require("crypto");
48229
48387
  var import_node_path38 = require("path");
48230
48388
  var DEFAULT_POLL_MS = 15 * 6e4;
48231
48389
  var MAX_FILES = 5e4;
@@ -48263,7 +48421,7 @@ function signature(value) {
48263
48421
  }
48264
48422
  async function readState(path2) {
48265
48423
  try {
48266
- const parsed = JSON.parse(await (0, import_promises8.readFile)(path2, "utf8"));
48424
+ const parsed = JSON.parse(await (0, import_promises9.readFile)(path2, "utf8"));
48267
48425
  if (parsed.schema !== 1 || !Array.isArray(parsed.targets) || !parsed.files || typeof parsed.files !== "object") return null;
48268
48426
  return parsed;
48269
48427
  } catch {
@@ -48271,13 +48429,13 @@ async function readState(path2) {
48271
48429
  }
48272
48430
  }
48273
48431
  async function writeState(path2, state) {
48274
- await (0, import_promises8.mkdir)((0, import_node_path38.dirname)(path2), { recursive: true, mode: 448 });
48275
- const temp = `${path2}.${process.pid}.${(0, import_node_crypto13.randomUUID)()}.tmp`;
48276
- await (0, import_promises8.writeFile)(temp, JSON.stringify(state), { mode: 384 });
48277
- await (0, import_promises8.rename)(temp, path2);
48432
+ await (0, import_promises9.mkdir)((0, import_node_path38.dirname)(path2), { recursive: true, mode: 448 });
48433
+ const temp = `${path2}.${process.pid}.${(0, import_node_crypto14.randomUUID)()}.tmp`;
48434
+ await (0, import_promises9.writeFile)(temp, JSON.stringify(state), { mode: 384 });
48435
+ await (0, import_promises9.rename)(temp, path2);
48278
48436
  }
48279
48437
  async function hashFile(path2, handle, size) {
48280
- const hash = (0, import_node_crypto13.createHash)("sha256");
48438
+ const hash = (0, import_node_crypto14.createHash)("sha256");
48281
48439
  const buffer = Buffer.alloc(READ_CHUNK_BYTES);
48282
48440
  const counts = new Uint32Array(256);
48283
48441
  let position = 0;
@@ -48297,19 +48455,19 @@ async function hashFile(path2, handle, size) {
48297
48455
  }
48298
48456
  return { sha256: hash.digest("hex"), entropy };
48299
48457
  }
48300
- var OPEN_FILE_FLAGS = import_promises8.constants.O_RDONLY | import_promises8.constants.O_NONBLOCK | (import_promises8.constants.O_NOFOLLOW ?? 0);
48301
- var OPEN_DIR_FLAGS = OPEN_FILE_FLAGS | import_promises8.constants.O_DIRECTORY;
48302
- var CREATE_FILE_FLAGS = import_promises8.constants.O_WRONLY | import_promises8.constants.O_CREAT | import_promises8.constants.O_EXCL | import_promises8.constants.O_NOFOLLOW;
48458
+ var OPEN_FILE_FLAGS = import_promises9.constants.O_RDONLY | import_promises9.constants.O_NONBLOCK | (import_promises9.constants.O_NOFOLLOW ?? 0);
48459
+ var OPEN_DIR_FLAGS = OPEN_FILE_FLAGS | import_promises9.constants.O_DIRECTORY;
48460
+ var CREATE_FILE_FLAGS = import_promises9.constants.O_WRONLY | import_promises9.constants.O_CREAT | import_promises9.constants.O_EXCL | import_promises9.constants.O_NOFOLLOW;
48303
48461
  function autoCanaryPath(directory) {
48304
48462
  return (0, import_node_path38.join)(directory, ".threatcrush-canary");
48305
48463
  }
48306
48464
  async function openAbsoluteDirectory(path2) {
48307
48465
  const parts = path2.split(import_node_path38.sep).filter((part) => part && part !== ".");
48308
48466
  if (parts.includes("..")) throw new Error("invalid canary directory");
48309
- let directory = await (0, import_promises8.open)("/", OPEN_DIR_FLAGS);
48467
+ let directory = await (0, import_promises9.open)("/", OPEN_DIR_FLAGS);
48310
48468
  try {
48311
48469
  for (const part of parts) {
48312
- const next = await (0, import_promises8.open)(`/proc/self/fd/${directory.fd}/${part}`, OPEN_DIR_FLAGS);
48470
+ const next = await (0, import_promises9.open)(`/proc/self/fd/${directory.fd}/${part}`, OPEN_DIR_FLAGS);
48313
48471
  await directory.close();
48314
48472
  directory = next;
48315
48473
  }
@@ -48329,7 +48487,7 @@ async function createAutoCanary(path2) {
48329
48487
  }
48330
48488
  const directory = await openAbsoluteDirectory((0, import_node_path38.dirname)(path2));
48331
48489
  try {
48332
- const file = await (0, import_promises8.open)(`/proc/self/fd/${directory.fd}/${(0, import_node_path38.basename)(path2)}`, CREATE_FILE_FLAGS, 438);
48490
+ const file = await (0, import_promises9.open)(`/proc/self/fd/${directory.fd}/${(0, import_node_path38.basename)(path2)}`, CREATE_FILE_FLAGS, 438);
48333
48491
  try {
48334
48492
  await file.chmod(438);
48335
48493
  await file.writeFile(CANARY_CONTENT);
@@ -48348,14 +48506,14 @@ async function createAutoCanary(path2) {
48348
48506
  async function openAbsoluteTarget(path2) {
48349
48507
  const parts = path2.split(import_node_path38.sep).filter((part) => part && part !== ".");
48350
48508
  if (parts.length === 0 || parts.includes("..")) throw new Error("invalid file integrity path");
48351
- let directory = await (0, import_promises8.open)("/", OPEN_DIR_FLAGS);
48509
+ let directory = await (0, import_promises9.open)("/", OPEN_DIR_FLAGS);
48352
48510
  try {
48353
48511
  for (const part of parts.slice(0, -1)) {
48354
- const next = await (0, import_promises8.open)(`/proc/self/fd/${directory.fd}/${part}`, OPEN_DIR_FLAGS);
48512
+ const next = await (0, import_promises9.open)(`/proc/self/fd/${directory.fd}/${part}`, OPEN_DIR_FLAGS);
48355
48513
  await directory.close();
48356
48514
  directory = next;
48357
48515
  }
48358
- const target = await (0, import_promises8.open)(`/proc/self/fd/${directory.fd}/${parts.at(-1)}`, OPEN_FILE_FLAGS);
48516
+ const target = await (0, import_promises9.open)(`/proc/self/fd/${directory.fd}/${parts.at(-1)}`, OPEN_FILE_FLAGS);
48359
48517
  await directory.close();
48360
48518
  return target;
48361
48519
  } catch (error2) {
@@ -48381,7 +48539,7 @@ async function scanTargets(targets, canaries) {
48381
48539
  }
48382
48540
  let handle;
48383
48541
  try {
48384
- handle = parent ? await (0, import_promises8.open)(`/proc/self/fd/${parent.fd}/${path2.slice(path2.lastIndexOf(import_node_path38.sep) + 1)}`, OPEN_FILE_FLAGS) : await openAbsoluteTarget(path2);
48542
+ handle = parent ? await (0, import_promises9.open)(`/proc/self/fd/${parent.fd}/${path2.slice(path2.lastIndexOf(import_node_path38.sep) + 1)}`, OPEN_FILE_FLAGS) : await openAbsoluteTarget(path2);
48385
48543
  const stat = await handle.stat();
48386
48544
  if (stat.isDirectory()) {
48387
48545
  directories.push(path2);
@@ -48392,7 +48550,7 @@ async function scanTargets(targets, canaries) {
48392
48550
  }
48393
48551
  let entries;
48394
48552
  try {
48395
- entries = await (0, import_promises8.readdir)(`/proc/self/fd/${handle.fd}`, { withFileTypes: true });
48553
+ entries = await (0, import_promises9.readdir)(`/proc/self/fd/${handle.fd}`, { withFileTypes: true });
48396
48554
  } catch {
48397
48555
  complete = false;
48398
48556
  errors.add(path2);
@@ -48537,7 +48695,7 @@ var FileIntegrityWatch = class {
48537
48695
  for (const path2 of wanted) {
48538
48696
  if (this.watchers.has(path2)) continue;
48539
48697
  try {
48540
- const watcher = (0, import_node_fs47.watch)(path2, { persistent: false }, () => {
48698
+ const watcher = (0, import_node_fs48.watch)(path2, { persistent: false }, () => {
48541
48699
  this.scheduleEventScan();
48542
48700
  });
48543
48701
  watcher.on("error", (error2) => {
@@ -48593,7 +48751,7 @@ var FileIntegrityWatch = class {
48593
48751
  let baselineFilePresent = false;
48594
48752
  if (!baseline) {
48595
48753
  try {
48596
- await (0, import_promises8.lstat)(this.opts.baselinePath);
48754
+ await (0, import_promises9.lstat)(this.opts.baselinePath);
48597
48755
  baselineFilePresent = true;
48598
48756
  } catch (error2) {
48599
48757
  baselineFilePresent = error2.code !== "ENOENT";
@@ -48718,7 +48876,7 @@ var FileIntegrityWatch = class {
48718
48876
  };
48719
48877
 
48720
48878
  // src/daemon/workers/edr.ts
48721
- var import_node_fs48 = require("fs");
48879
+ var import_node_fs49 = require("fs");
48722
48880
  var import_node_path39 = require("path");
48723
48881
  var import_node_child_process15 = require("child_process");
48724
48882
  var DEFAULT_AUDIT_LOG = "/var/log/audit/audit.log";
@@ -48796,7 +48954,7 @@ function accountNames2() {
48796
48954
  raw = (0, import_node_child_process15.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
48797
48955
  } catch {
48798
48956
  try {
48799
- raw = (0, import_node_fs48.readFileSync)("/etc/passwd", "utf8");
48957
+ raw = (0, import_node_fs49.readFileSync)("/etc/passwd", "utf8");
48800
48958
  } catch {
48801
48959
  return /* @__PURE__ */ new Map();
48802
48960
  }
@@ -48814,7 +48972,7 @@ function pathWithin(path2, root) {
48814
48972
  }
48815
48973
  function executableInWorldWritableDirectory(executable) {
48816
48974
  try {
48817
- return ((0, import_node_fs48.statSync)((0, import_node_path39.dirname)(executable)).mode & 2) !== 0;
48975
+ return ((0, import_node_fs49.statSync)((0, import_node_path39.dirname)(executable)).mode & 2) !== 0;
48818
48976
  } catch {
48819
48977
  return false;
48820
48978
  }
@@ -48848,11 +49006,11 @@ var EdrWatch = class {
48848
49006
  this.opts.log("[edr] disabled; set [edr] enabled = true after installing the generated audit rules");
48849
49007
  return;
48850
49008
  }
48851
- if (!(0, import_node_fs48.existsSync)(this.opts.settings.auditLogPath)) {
49009
+ if (!(0, import_node_fs49.existsSync)(this.opts.settings.auditLogPath)) {
48852
49010
  this.opts.log(`[edr] audit log not found at ${this.opts.settings.auditLogPath}; auditd detections are unavailable`);
48853
49011
  } else {
48854
49012
  try {
48855
- (0, import_node_fs48.accessSync)(this.opts.settings.auditLogPath, import_node_fs48.constants.R_OK);
49013
+ (0, import_node_fs49.accessSync)(this.opts.settings.auditLogPath, import_node_fs49.constants.R_OK);
48856
49014
  this.tail = new LogTail(this.opts.settings.auditLogPath);
48857
49015
  this.timer = setInterval(() => this.poll(), this.opts.settings.pollMs);
48858
49016
  this.timer.unref?.();
@@ -48963,7 +49121,7 @@ var EdrWatch = class {
48963
49121
  const path2 = this.opts.networkBaselinePath;
48964
49122
  if (!path2) return;
48965
49123
  try {
48966
- const parsed = JSON.parse((0, import_node_fs48.readFileSync)(path2, "utf8"));
49124
+ const parsed = JSON.parse((0, import_node_fs49.readFileSync)(path2, "utf8"));
48967
49125
  if (Array.isArray(parsed)) {
48968
49126
  for (const value of parsed.slice(0, 1e4)) {
48969
49127
  if (typeof value === "string" && value.startsWith("/")) this.outboundExecutables.add(value);
@@ -48980,9 +49138,9 @@ var EdrWatch = class {
48980
49138
  if (!path2) return;
48981
49139
  try {
48982
49140
  const temp = `${path2}.${process.pid}.tmp`;
48983
- (0, import_node_fs48.writeFileSync)(temp, `${JSON.stringify([...this.outboundExecutables])}
49141
+ (0, import_node_fs49.writeFileSync)(temp, `${JSON.stringify([...this.outboundExecutables])}
48984
49142
  `, { mode: 384 });
48985
- (0, import_node_fs48.renameSync)(temp, path2);
49143
+ (0, import_node_fs49.renameSync)(temp, path2);
48986
49144
  this.baselineWriteFailed = false;
48987
49145
  } catch (error2) {
48988
49146
  if (!this.baselineWriteFailed) this.opts.log(`[edr] could not persist outbound executable baseline: ${error2.message.split("\n")[0]}`);
@@ -49003,7 +49161,7 @@ var EdrWatch = class {
49003
49161
  const current = /* @__PURE__ */ new Map();
49004
49162
  let pids;
49005
49163
  try {
49006
- pids = (0, import_node_fs48.readdirSync)("/proc");
49164
+ pids = (0, import_node_fs49.readdirSync)("/proc");
49007
49165
  } catch {
49008
49166
  return;
49009
49167
  }
@@ -49011,7 +49169,7 @@ var EdrWatch = class {
49011
49169
  if (!/^\d+$/.test(pid)) continue;
49012
49170
  const proc = `/proc/${pid}`;
49013
49171
  try {
49014
- const raw = (0, import_node_fs48.readFileSync)(`${proc}/stat`, "utf8");
49172
+ const raw = (0, import_node_fs49.readFileSync)(`${proc}/stat`, "utf8");
49015
49173
  const end = raw.lastIndexOf(")");
49016
49174
  if (end < 0) continue;
49017
49175
  const fields = raw.slice(end + 1).trim().split(/\s+/);
@@ -49019,7 +49177,7 @@ var EdrWatch = class {
49019
49177
  const systemTicks = Number(fields[12]);
49020
49178
  const startTicks = fields[19];
49021
49179
  if (!Number.isFinite(userTicks) || !Number.isFinite(systemTicks) || !startTicks) continue;
49022
- let executable = (0, import_node_fs48.readlinkSync)(`${proc}/exe`);
49180
+ let executable = (0, import_node_fs49.readlinkSync)(`${proc}/exe`);
49023
49181
  executable = executable.replace(/ \(deleted\)$/, "");
49024
49182
  if (!this.opts.settings.tempExecPaths.some((path2) => pathWithin(executable, path2))) continue;
49025
49183
  const name = (0, import_node_path39.basename)(executable).toLowerCase();
@@ -49058,7 +49216,7 @@ var EdrWatch = class {
49058
49216
  };
49059
49217
 
49060
49218
  // src/daemon/workers/ssh-intrusion.ts
49061
- var import_node_fs49 = require("fs");
49219
+ var import_node_fs50 = require("fs");
49062
49220
  var import_node_path40 = require("path");
49063
49221
  var import_node_child_process16 = require("child_process");
49064
49222
 
@@ -49253,32 +49411,32 @@ function parseKeyLoginsByFingerprint(text) {
49253
49411
  }
49254
49412
  function readJson2(path2) {
49255
49413
  try {
49256
- return JSON.parse((0, import_node_fs49.readFileSync)(path2, "utf-8"));
49414
+ return JSON.parse((0, import_node_fs50.readFileSync)(path2, "utf-8"));
49257
49415
  } catch {
49258
49416
  return null;
49259
49417
  }
49260
49418
  }
49261
49419
  function writeJson2(path2, value) {
49262
- (0, import_node_fs49.mkdirSync)((0, import_node_path40.dirname)(path2), { recursive: true });
49263
- (0, import_node_fs49.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
49264
- (0, import_node_fs49.renameSync)(`${path2}.tmp`, path2);
49420
+ (0, import_node_fs50.mkdirSync)((0, import_node_path40.dirname)(path2), { recursive: true });
49421
+ (0, import_node_fs50.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
49422
+ (0, import_node_fs50.renameSync)(`${path2}.tmp`, path2);
49265
49423
  }
49266
49424
  var fsIO2 = {
49267
49425
  readFile: (p) => {
49268
49426
  try {
49269
- return (0, import_node_fs49.readFileSync)(p, "utf-8");
49427
+ return (0, import_node_fs50.readFileSync)(p, "utf-8");
49270
49428
  } catch {
49271
49429
  return null;
49272
49430
  }
49273
49431
  },
49274
49432
  readDir: (p) => {
49275
49433
  try {
49276
- return (0, import_node_fs49.readdirSync)(p);
49434
+ return (0, import_node_fs50.readdirSync)(p);
49277
49435
  } catch {
49278
49436
  return null;
49279
49437
  }
49280
49438
  },
49281
- exists: (p) => (0, import_node_fs49.existsSync)(p)
49439
+ exists: (p) => (0, import_node_fs50.existsSync)(p)
49282
49440
  };
49283
49441
  function defaultRun4(cmd, args) {
49284
49442
  const res = (0, import_node_child_process16.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 6e4, maxBuffer: 64 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
@@ -49479,23 +49637,23 @@ var SshIntrusionWatch = class {
49479
49637
  };
49480
49638
 
49481
49639
  // src/daemon/key-directory.ts
49482
- var import_node_fs50 = require("fs");
49640
+ var import_node_fs51 = require("fs");
49483
49641
  var fsIO3 = {
49484
49642
  readFile: (p) => {
49485
49643
  try {
49486
- return (0, import_node_fs50.readFileSync)(p, "utf-8");
49644
+ return (0, import_node_fs51.readFileSync)(p, "utf-8");
49487
49645
  } catch {
49488
49646
  return null;
49489
49647
  }
49490
49648
  },
49491
49649
  readDir: (p) => {
49492
49650
  try {
49493
- return (0, import_node_fs50.readdirSync)(p);
49651
+ return (0, import_node_fs51.readdirSync)(p);
49494
49652
  } catch {
49495
49653
  return null;
49496
49654
  }
49497
49655
  },
49498
- exists: (p) => (0, import_node_fs50.existsSync)(p)
49656
+ exists: (p) => (0, import_node_fs51.existsSync)(p)
49499
49657
  };
49500
49658
  var KeyDirectory = class {
49501
49659
  constructor(io = fsIO3, now = Date.now, ttlMs = 3e5) {
@@ -49539,7 +49697,7 @@ function enrichLoginEvent(event, keys) {
49539
49697
  }
49540
49698
 
49541
49699
  // src/daemon/workers/lightning-watch.ts
49542
- var import_node_fs51 = require("fs");
49700
+ var import_node_fs52 = require("fs");
49543
49701
  var DEFAULT_CLN_LOGS = [
49544
49702
  "/home/lightning/.lightning/cln.log",
49545
49703
  "/root/.lightning/cln.log",
@@ -49595,9 +49753,9 @@ var LightningWatch = class {
49595
49753
  if (this.opts.enabled === false) return [];
49596
49754
  const found = [];
49597
49755
  for (const path2 of this.opts.paths?.length ? this.opts.paths : DEFAULT_CLN_LOGS) {
49598
- if (!(0, import_node_fs51.existsSync)(path2)) continue;
49756
+ if (!(0, import_node_fs52.existsSync)(path2)) continue;
49599
49757
  try {
49600
- (0, import_node_fs51.accessSync)(path2, import_node_fs51.constants.R_OK);
49758
+ (0, import_node_fs52.accessSync)(path2, import_node_fs52.constants.R_OK);
49601
49759
  } catch {
49602
49760
  continue;
49603
49761
  }
@@ -49632,7 +49790,7 @@ var LightningWatch = class {
49632
49790
  };
49633
49791
 
49634
49792
  // src/core/tor-exits.ts
49635
- var import_node_fs52 = require("fs");
49793
+ var import_node_fs53 = require("fs");
49636
49794
  var import_node_path41 = require("path");
49637
49795
  var import_node_net15 = require("net");
49638
49796
  var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
@@ -49701,10 +49859,10 @@ var TorExitList = class _TorExitList {
49701
49859
  }
49702
49860
  loadCache() {
49703
49861
  try {
49704
- if (!(0, import_node_fs52.existsSync)(this.opts.cachePath)) return false;
49705
- const parsed = parseTorExitList((0, import_node_fs52.readFileSync)(this.opts.cachePath, "utf-8"));
49862
+ if (!(0, import_node_fs53.existsSync)(this.opts.cachePath)) return false;
49863
+ const parsed = parseTorExitList((0, import_node_fs53.readFileSync)(this.opts.cachePath, "utf-8"));
49706
49864
  if (parsed.size === 0) return false;
49707
- this.load(parsed, (0, import_node_fs52.statSync)(this.opts.cachePath).mtimeMs);
49865
+ this.load(parsed, (0, import_node_fs53.statSync)(this.opts.cachePath).mtimeMs);
49708
49866
  this.log(`[tor] loaded ${parsed.size} Tor exit addresses from cache (${new Date(this.updatedAt).toISOString()})`);
49709
49867
  return true;
49710
49868
  } catch (err) {
@@ -49736,9 +49894,9 @@ var TorExitList = class _TorExitList {
49736
49894
  const before2 = this.exits.size;
49737
49895
  this.load(parsed);
49738
49896
  try {
49739
- (0, import_node_fs52.mkdirSync)((0, import_node_path41.dirname)(this.opts.cachePath), { recursive: true });
49740
- (0, import_node_fs52.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
49741
- (0, import_node_fs52.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
49897
+ (0, import_node_fs53.mkdirSync)((0, import_node_path41.dirname)(this.opts.cachePath), { recursive: true });
49898
+ (0, import_node_fs53.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
49899
+ (0, import_node_fs53.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
49742
49900
  } catch (err) {
49743
49901
  this.log(`[tor] could not save the exit list cache: ${err.message}`);
49744
49902
  }
@@ -49959,7 +50117,7 @@ var RuleEngine = class {
49959
50117
  };
49960
50118
 
49961
50119
  // src/daemon/rules/loader.ts
49962
- var import_node_fs53 = require("fs");
50120
+ var import_node_fs54 = require("fs");
49963
50121
  var import_node_path42 = require("path");
49964
50122
 
49965
50123
  // src/daemon/rules/default-rules.ts
@@ -50605,11 +50763,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
50605
50763
  function loadAllRules(customDir) {
50606
50764
  const rules = [...DEFAULT_RULES];
50607
50765
  const dir = customDir || RULES_DIR;
50608
- if ((0, import_node_fs53.existsSync)(dir)) {
50609
- const files = (0, import_node_fs53.readdirSync)(dir).filter((f) => f.endsWith(".json"));
50766
+ if ((0, import_node_fs54.existsSync)(dir)) {
50767
+ const files = (0, import_node_fs54.readdirSync)(dir).filter((f) => f.endsWith(".json"));
50610
50768
  for (const file of files) {
50611
50769
  try {
50612
- const raw = (0, import_node_fs53.readFileSync)((0, import_node_path42.join)(dir, file), "utf-8");
50770
+ const raw = (0, import_node_fs54.readFileSync)((0, import_node_path42.join)(dir, file), "utf-8");
50613
50771
  const parsed = JSON.parse(raw);
50614
50772
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
50615
50773
  for (const rule of customRules) {
@@ -50641,7 +50799,7 @@ function loadAllRules(customDir) {
50641
50799
 
50642
50800
  // src/daemon/firewall/adapters.ts
50643
50801
  var import_node_child_process17 = require("child_process");
50644
- var import_node_fs54 = require("fs");
50802
+ var import_node_fs55 = require("fs");
50645
50803
  var import_node_path43 = require("path");
50646
50804
  var import_node_net16 = require("net");
50647
50805
  function assertValidFirewallIp(ip) {
@@ -50655,9 +50813,9 @@ function assertBannableIp(ip) {
50655
50813
  }
50656
50814
  }
50657
50815
  function writeIfAbsent(path2, contents) {
50658
- (0, import_node_fs54.mkdirSync)((0, import_node_path43.dirname)(path2), { recursive: true });
50816
+ (0, import_node_fs55.mkdirSync)((0, import_node_path43.dirname)(path2), { recursive: true });
50659
50817
  try {
50660
- (0, import_node_fs54.writeFileSync)(path2, contents, { flag: "wx" });
50818
+ (0, import_node_fs55.writeFileSync)(path2, contents, { flag: "wx" });
50661
50819
  } catch (err) {
50662
50820
  if (err.code !== "EEXIST") throw err;
50663
50821
  }
@@ -50916,7 +51074,7 @@ function detectFirewallAdapter(backend = "auto") {
50916
51074
  }
50917
51075
 
50918
51076
  // src/daemon/firewall/remediation.ts
50919
- var import_node_fs55 = require("fs");
51077
+ var import_node_fs56 = require("fs");
50920
51078
  var import_node_child_process18 = require("child_process");
50921
51079
  var import_node_net17 = require("net");
50922
51080
  init_paths();
@@ -50988,19 +51146,19 @@ var defaultDiscovery = {
50988
51146
  const snapshot = takeSnapshot({
50989
51147
  readFile: (p) => {
50990
51148
  try {
50991
- return (0, import_node_fs55.readFileSync)(p, "utf-8");
51149
+ return (0, import_node_fs56.readFileSync)(p, "utf-8");
50992
51150
  } catch {
50993
51151
  return null;
50994
51152
  }
50995
51153
  },
50996
51154
  readDir: (p) => {
50997
51155
  try {
50998
- return (0, import_node_fs55.readdirSync)(p);
51156
+ return (0, import_node_fs56.readdirSync)(p);
50999
51157
  } catch {
51000
51158
  return null;
51001
51159
  }
51002
51160
  },
51003
- exists: (p) => (0, import_node_fs55.existsSync)(p)
51161
+ exists: (p) => (0, import_node_fs56.existsSync)(p)
51004
51162
  });
51005
51163
  const out = /* @__PURE__ */ new Set();
51006
51164
  for (const keys of Object.values(snapshot.keys)) {
@@ -51513,7 +51671,7 @@ var RemediationManager = class {
51513
51671
  }
51514
51672
  logLine(line2) {
51515
51673
  try {
51516
- (0, import_node_fs55.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
51674
+ (0, import_node_fs56.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
51517
51675
  `);
51518
51676
  } catch {
51519
51677
  }
@@ -51557,13 +51715,13 @@ function remediationSettings(section) {
51557
51715
  init_backoff();
51558
51716
 
51559
51717
  // src/daemon/watchdog-service.ts
51560
- var import_node_fs56 = require("fs");
51718
+ var import_node_fs57 = require("fs");
51561
51719
  var import_node_path44 = require("path");
51562
51720
  function defaultShareGid() {
51563
51721
  const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
51564
51722
  if (!isRoot4) return void 0;
51565
51723
  try {
51566
- return (0, import_node_fs56.statSync)("/var/log/auth.log").gid;
51724
+ return (0, import_node_fs57.statSync)("/var/log/auth.log").gid;
51567
51725
  } catch {
51568
51726
  return void 0;
51569
51727
  }
@@ -51684,7 +51842,7 @@ function versionOfNode(path2) {
51684
51842
  // src/daemon/index.ts
51685
51843
  function readVersion2() {
51686
51844
  try {
51687
- const pkg = JSON.parse((0, import_node_fs57.readFileSync)((0, import_node_path45.join)(__dirname, "..", "package.json"), "utf-8"));
51845
+ const pkg = JSON.parse((0, import_node_fs58.readFileSync)((0, import_node_path45.join)(__dirname, "..", "package.json"), "utf-8"));
51688
51846
  return pkg.version || "0.0.0";
51689
51847
  } catch {
51690
51848
  return "0.0.0";
@@ -51715,7 +51873,7 @@ async function runPatchCheck() {
51715
51873
  }
51716
51874
  function logLine(line2) {
51717
51875
  try {
51718
- (0, import_node_fs57.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
51876
+ (0, import_node_fs58.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
51719
51877
  `);
51720
51878
  } catch {
51721
51879
  }
@@ -51918,7 +52076,7 @@ async function runDaemon() {
51918
52076
  cloudSync = new CloudSync({
51919
52077
  bus,
51920
52078
  version,
51921
- hostname: (0, import_node_os18.hostname)(),
52079
+ hostname: (0, import_node_os19.hostname)(),
51922
52080
  minSeverity,
51923
52081
  spoolPath: (0, import_node_path45.join)(PATHS.stateDir, "cloud-spool.jsonl"),
51924
52082
  log: logLine,
@@ -52085,7 +52243,7 @@ async function daemonStart() {
52085
52243
  return;
52086
52244
  }
52087
52245
  ensureRuntimeDirs();
52088
- if (!(0, import_node_fs58.existsSync)(DAEMON_ENTRY)) {
52246
+ if (!(0, import_node_fs59.existsSync)(DAEMON_ENTRY)) {
52089
52247
  console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
52090
52248
  console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
52091
52249
  return;
@@ -52093,8 +52251,8 @@ async function daemonStart() {
52093
52251
  let out;
52094
52252
  let err;
52095
52253
  try {
52096
- out = (0, import_node_fs59.openSync)(PATHS.logFile, "a");
52097
- err = (0, import_node_fs59.openSync)(PATHS.logFile, "a");
52254
+ out = (0, import_node_fs60.openSync)(PATHS.logFile, "a");
52255
+ err = (0, import_node_fs60.openSync)(PATHS.logFile, "a");
52098
52256
  } catch (e) {
52099
52257
  const code = e.code;
52100
52258
  console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
@@ -52182,12 +52340,12 @@ async function waitForExit(pid, timeoutMs) {
52182
52340
  }
52183
52341
  async function releaseStaleSocket() {
52184
52342
  const deadline = Date.now() + 2e3;
52185
- while ((0, import_node_fs58.existsSync)(PATHS.socket) && Date.now() < deadline) {
52343
+ while ((0, import_node_fs59.existsSync)(PATHS.socket) && Date.now() < deadline) {
52186
52344
  await new Promise((r) => setTimeout(r, 50));
52187
52345
  }
52188
- if ((0, import_node_fs58.existsSync)(PATHS.socket)) {
52346
+ if ((0, import_node_fs59.existsSync)(PATHS.socket)) {
52189
52347
  try {
52190
- (0, import_node_fs58.unlinkSync)(PATHS.socket);
52348
+ (0, import_node_fs59.unlinkSync)(PATHS.socket);
52191
52349
  } catch {
52192
52350
  }
52193
52351
  }
@@ -52195,26 +52353,26 @@ async function releaseStaleSocket() {
52195
52353
 
52196
52354
  // src/commands/service.ts
52197
52355
  var import_node_child_process22 = require("child_process");
52198
- var import_node_fs60 = require("fs");
52356
+ var import_node_fs61 = require("fs");
52199
52357
  var import_node_path47 = require("path");
52200
- var import_node_os19 = require("os");
52358
+ var import_node_os20 = require("os");
52201
52359
  var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
52202
52360
  var DAEMON_UNIT_NAME = "threatcrushd.service";
52203
52361
  function resolveTemplate() {
52204
52362
  const templatePath = (0, import_node_path47.join)(__dirname, "systemd", "threatcrushd.service");
52205
- if (!(0, import_node_fs60.existsSync)(templatePath)) {
52363
+ if (!(0, import_node_fs61.existsSync)(templatePath)) {
52206
52364
  throw new Error(`systemd unit template not found at ${templatePath}`);
52207
52365
  }
52208
- return (0, import_node_fs60.readFileSync)(templatePath, "utf-8");
52366
+ return (0, import_node_fs61.readFileSync)(templatePath, "utf-8");
52209
52367
  }
52210
52368
  function stableBinPath(binPath) {
52211
52369
  const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
52212
52370
  if (stable === binPath) return binPath;
52213
- return (0, import_node_fs60.existsSync)(stable) ? stable : binPath;
52371
+ return (0, import_node_fs61.existsSync)(stable) ? stable : binPath;
52214
52372
  }
52215
52373
  function resolveBinPath() {
52216
52374
  const arg = process.argv[1];
52217
- if (arg && (0, import_node_fs60.existsSync)(arg)) return stableBinPath(arg);
52375
+ if (arg && (0, import_node_fs61.existsSync)(arg)) return stableBinPath(arg);
52218
52376
  try {
52219
52377
  return (0, import_node_child_process22.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
52220
52378
  } catch {
@@ -52224,12 +52382,12 @@ function resolveBinPath() {
52224
52382
  function stableNodePath(execPath) {
52225
52383
  const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
52226
52384
  if (stable === execPath) return execPath;
52227
- return (0, import_node_fs60.existsSync)(stable) ? stable : execPath;
52385
+ return (0, import_node_fs61.existsSync)(stable) ? stable : execPath;
52228
52386
  }
52229
52387
  function looksLikeNodeScript(path2) {
52230
52388
  try {
52231
- const head = (0, import_node_fs60.readFileSync)(path2, "utf-8").slice(0, 120);
52232
- return /^#!.*\bnode\b/.test(head);
52389
+ const head2 = (0, import_node_fs61.readFileSync)(path2, "utf-8").slice(0, 120);
52390
+ return /^#!.*\bnode\b/.test(head2);
52233
52391
  } catch {
52234
52392
  return false;
52235
52393
  }
@@ -52268,7 +52426,7 @@ function callerHome() {
52268
52426
  try {
52269
52427
  const line2 = (0, import_node_child_process22.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
52270
52428
  const home = line2.split(":")[5];
52271
- return home && (0, import_node_fs60.existsSync)(home) ? home : null;
52429
+ return home && (0, import_node_fs61.existsSync)(home) ? home : null;
52272
52430
  } catch {
52273
52431
  return null;
52274
52432
  }
@@ -52279,10 +52437,10 @@ function stopUserModeDaemon() {
52279
52437
  const runDir = (0, import_node_path47.join)(home, ".threatcrush", "run");
52280
52438
  const pidFile = (0, import_node_path47.join)(runDir, "threatcrushd.pid");
52281
52439
  const socket = (0, import_node_path47.join)(runDir, "threatcrushd.sock");
52282
- if (!(0, import_node_fs60.existsSync)(pidFile) && !(0, import_node_fs60.existsSync)(socket)) return;
52440
+ if (!(0, import_node_fs61.existsSync)(pidFile) && !(0, import_node_fs61.existsSync)(socket)) return;
52283
52441
  let pid = null;
52284
52442
  try {
52285
- pid = Number.parseInt((0, import_node_fs60.readFileSync)(pidFile, "utf-8").trim(), 10);
52443
+ pid = Number.parseInt((0, import_node_fs61.readFileSync)(pidFile, "utf-8").trim(), 10);
52286
52444
  } catch {
52287
52445
  pid = null;
52288
52446
  }
@@ -52295,7 +52453,7 @@ function stopUserModeDaemon() {
52295
52453
  }
52296
52454
  for (const path2 of [socket, pidFile]) {
52297
52455
  try {
52298
- if ((0, import_node_fs60.existsSync)(path2)) (0, import_node_fs60.rmSync)(path2);
52456
+ if ((0, import_node_fs61.existsSync)(path2)) (0, import_node_fs61.rmSync)(path2);
52299
52457
  } catch {
52300
52458
  }
52301
52459
  }
@@ -52313,7 +52471,7 @@ async function installServiceCommand() {
52313
52471
  }
52314
52472
  const noSystemd = systemdUnavailableReason({
52315
52473
  hasSystemctl: (0, import_node_child_process22.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
52316
- booted: (0, import_node_fs60.existsSync)("/run/systemd/system")
52474
+ booted: (0, import_node_fs61.existsSync)("/run/systemd/system")
52317
52475
  });
52318
52476
  if (noSystemd) {
52319
52477
  console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
@@ -52335,7 +52493,7 @@ async function installServiceCommand() {
52335
52493
  const isNodeScript = looksLikeNodeScript(binPath);
52336
52494
  let nodePath = stableNodePath(process.execPath);
52337
52495
  if (isNodeScript && nodeVersionDir(binPath)) {
52338
- binPath = (0, import_node_fs60.realpathSync)(binPath);
52496
+ binPath = (0, import_node_fs61.realpathSync)(binPath);
52339
52497
  nodePath = process.execPath;
52340
52498
  }
52341
52499
  if (isNodeScript) {
@@ -52348,11 +52506,11 @@ async function installServiceCommand() {
52348
52506
  }
52349
52507
  }
52350
52508
  const exec = execStartCommand(binPath, nodePath, isNodeScript);
52351
- const configDir = (0, import_node_path47.join)((0, import_node_os19.homedir)(), ".threatcrush");
52509
+ const configDir = (0, import_node_path47.join)((0, import_node_os20.homedir)(), ".threatcrush");
52352
52510
  const commandHistoryEnabled = commandHistorySettings(loadConfig().command_history).enabled;
52353
52511
  const historyPaths = commandHistoryEnabled ? historyWritableHomes() : [];
52354
52512
  const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir, historyPaths });
52355
- (0, import_node_fs60.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
52513
+ (0, import_node_fs61.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
52356
52514
  console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
52357
52515
  console.log(source_default.dim(` ExecStart=${exec}`));
52358
52516
  const nodeDir = nodeVersionDir(nodePath);
@@ -52405,9 +52563,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
52405
52563
  ].join("\n");
52406
52564
  }
52407
52565
  function installLogrotate() {
52408
- if (!(0, import_node_fs60.existsSync)((0, import_node_path47.dirname)(LOGROTATE_PATH))) return;
52566
+ if (!(0, import_node_fs61.existsSync)((0, import_node_path47.dirname)(LOGROTATE_PATH))) return;
52409
52567
  try {
52410
- (0, import_node_fs60.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
52568
+ (0, import_node_fs61.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
52411
52569
  console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
52412
52570
  } catch (err) {
52413
52571
  console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
@@ -52429,20 +52587,20 @@ function ensureSystemDirs(configDir) {
52429
52587
  ];
52430
52588
  let admGid2 = null;
52431
52589
  try {
52432
- admGid2 = (0, import_node_fs60.statSync)("/var/log/auth.log").gid;
52590
+ admGid2 = (0, import_node_fs61.statSync)("/var/log/auth.log").gid;
52433
52591
  } catch {
52434
52592
  }
52435
52593
  for (const { path: path2, groupWritable, sticky } of dirs) {
52436
52594
  try {
52437
- (0, import_node_fs60.mkdirSync)(path2, { recursive: true });
52595
+ (0, import_node_fs61.mkdirSync)(path2, { recursive: true });
52438
52596
  } catch {
52439
52597
  }
52440
52598
  try {
52441
52599
  if (groupWritable && admGid2 !== null) {
52442
- (0, import_node_fs60.chmodSync)(path2, sticky ? 1533 : 509);
52600
+ (0, import_node_fs61.chmodSync)(path2, sticky ? 1533 : 509);
52443
52601
  (0, import_node_child_process22.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
52444
52602
  } else {
52445
- (0, import_node_fs60.chmodSync)(path2, 493);
52603
+ (0, import_node_fs61.chmodSync)(path2, 493);
52446
52604
  }
52447
52605
  } catch {
52448
52606
  }
@@ -52470,7 +52628,7 @@ async function uninstallServiceCommand() {
52470
52628
  } catch {
52471
52629
  }
52472
52630
  try {
52473
- if ((0, import_node_fs60.existsSync)(UNIT_PATH)) {
52631
+ if ((0, import_node_fs61.existsSync)(UNIT_PATH)) {
52474
52632
  (0, import_node_child_process22.execSync)(`rm -f ${UNIT_PATH}`);
52475
52633
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
52476
52634
  }
@@ -52484,7 +52642,7 @@ async function uninstallServiceCommand() {
52484
52642
  }
52485
52643
 
52486
52644
  // src/commands/save.ts
52487
- var import_node_fs61 = require("fs");
52645
+ var import_node_fs62 = require("fs");
52488
52646
  var import_toml5 = __toESM(require_toml());
52489
52647
  init_cli_config();
52490
52648
  init_paths();
@@ -52523,9 +52681,9 @@ async function saveCommand(opts = {}) {
52523
52681
  }
52524
52682
  const path2 = opts.config ?? PATHS.configFile;
52525
52683
  let config = {};
52526
- if ((0, import_node_fs61.existsSync)(path2)) {
52684
+ if ((0, import_node_fs62.existsSync)(path2)) {
52527
52685
  try {
52528
- config = import_toml5.default.parse((0, import_node_fs61.readFileSync)(path2, "utf-8"));
52686
+ config = import_toml5.default.parse((0, import_node_fs62.readFileSync)(path2, "utf-8"));
52529
52687
  } catch (err) {
52530
52688
  console.log(source_default.red(` \u2717 ${path2} is not valid TOML: ${err.message}
52531
52689
  `));
@@ -52638,7 +52796,7 @@ function welcomeCommand() {
52638
52796
  }
52639
52797
 
52640
52798
  // src/commands/properties.ts
52641
- var import_node_fs62 = require("fs");
52799
+ var import_node_fs63 = require("fs");
52642
52800
  var import_node_path48 = require("path");
52643
52801
  var import_node_readline4 = __toESM(require("readline"));
52644
52802
  init_cli_config();
@@ -52970,7 +53128,7 @@ async function propertiesRunsCommand(opts) {
52970
53128
  }
52971
53129
  function parseImportFile(path2) {
52972
53130
  const ext = (0, import_node_path48.extname)(path2).toLowerCase();
52973
- const raw = (0, import_node_fs62.readFileSync)(path2, "utf-8");
53131
+ const raw = (0, import_node_fs63.readFileSync)(path2, "utf-8");
52974
53132
  if (ext === ".json") {
52975
53133
  const parsed = JSON.parse(raw);
52976
53134
  if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
@@ -53165,13 +53323,13 @@ async function rulesCommand(opts) {
53165
53323
  }
53166
53324
 
53167
53325
  // src/commands/harden.ts
53168
- var import_node_fs64 = require("fs");
53326
+ var import_node_fs65 = require("fs");
53169
53327
  var import_node_child_process23 = require("child_process");
53170
53328
  init_cli_config();
53171
53329
 
53172
53330
  // src/commands/cis-report.ts
53173
- var import_node_os20 = require("os");
53174
- var import_node_fs63 = require("fs");
53331
+ var import_node_os21 = require("os");
53332
+ var import_node_fs64 = require("fs");
53175
53333
  var CIS_UBUNTU_URL = "https://www.cisecurity.org/benchmark/ubuntu_linux";
53176
53334
  var CIS_DEBIAN_URL = "https://www.cisecurity.org/benchmark/debian_linux";
53177
53335
  var UBUNTU_2404_CIS_CONTROL_SOURCE = "https://github.com/ComplianceAsCode/content/blob/v0.1.78/controls/cis_ubuntu2404.yml";
@@ -53191,7 +53349,7 @@ var EDITIONS = {
53191
53349
  function osRelease() {
53192
53350
  let raw = "";
53193
53351
  try {
53194
- raw = (0, import_node_fs63.readFileSync)("/etc/os-release", "utf8");
53352
+ raw = (0, import_node_fs64.readFileSync)("/etc/os-release", "utf8");
53195
53353
  } catch {
53196
53354
  return {};
53197
53355
  }
@@ -53264,7 +53422,7 @@ function buildCisEvidenceReport(findings2, score, now = /* @__PURE__ */ new Date
53264
53422
  schema_version: 1,
53265
53423
  generated_at: now.toISOString(),
53266
53424
  benchmark_catalog_checked_at: "2026-11-01",
53267
- host: { hostname: (0, import_node_os20.hostname)(), os_id: id, os_version: version, pretty_name: os4.PRETTY_NAME ?? null },
53425
+ host: { hostname: (0, import_node_os21.hostname)(), os_id: id, os_version: version, pretty_name: os4.PRETTY_NAME ?? null },
53268
53426
  benchmark: edition ? { name: edition.name, version: edition.version, source: edition.source } : null,
53269
53427
  assessment: "partial",
53270
53428
  mapped_controls: mappedControls.size,
@@ -53371,7 +53529,7 @@ function writeCisReport(path2, format2, report) {
53371
53529
  const markdown = renderCisMarkdown(report);
53372
53530
  const content = format2 === "json" ? `${JSON.stringify(report, null, 2)}
53373
53531
  ` : format2 === "pdf" ? renderCisPdf(markdown) : markdown;
53374
- (0, import_node_fs63.writeFileSync)(path2, content);
53532
+ (0, import_node_fs64.writeFileSync)(path2, content);
53375
53533
  }
53376
53534
 
53377
53535
  // src/commands/harden.ts
@@ -53384,7 +53542,7 @@ function tryExec(cmd) {
53384
53542
  }
53385
53543
  function tryRead(path2) {
53386
53544
  try {
53387
- return (0, import_node_fs64.readFileSync)(path2, "utf-8");
53545
+ return (0, import_node_fs65.readFileSync)(path2, "utf-8");
53388
53546
  } catch {
53389
53547
  return null;
53390
53548
  }
@@ -53498,8 +53656,8 @@ function checkSshWeakConfig() {
53498
53656
  };
53499
53657
  }
53500
53658
  function checkAutoUpdates() {
53501
- const unattended = (0, import_node_fs64.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs64.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
53502
- const dnfAuto = (0, import_node_fs64.existsSync)("/etc/dnf/automatic.conf");
53659
+ const unattended = (0, import_node_fs65.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs65.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
53660
+ const dnfAuto = (0, import_node_fs65.existsSync)("/etc/dnf/automatic.conf");
53503
53661
  if (unattended || dnfAuto) {
53504
53662
  return {
53505
53663
  key: "auto-updates",
@@ -53625,7 +53783,7 @@ function checkFail2ban() {
53625
53783
  explanation: "fail2ban is installed and running."
53626
53784
  };
53627
53785
  }
53628
- if ((0, import_node_fs64.existsSync)("/etc/fail2ban/fail2ban.conf")) {
53786
+ if ((0, import_node_fs65.existsSync)("/etc/fail2ban/fail2ban.conf")) {
53629
53787
  return {
53630
53788
  key: checkKey,
53631
53789
  status: "warn",
@@ -53845,7 +54003,7 @@ async function hardenCommand(opts) {
53845
54003
  }
53846
54004
 
53847
54005
  // src/core/patches/index.ts
53848
- var import_node_fs65 = require("fs");
54006
+ var import_node_fs66 = require("fs");
53849
54007
  var import_node_path49 = require("path");
53850
54008
  var import_node_child_process24 = require("child_process");
53851
54009
  var import_node_util5 = require("util");
@@ -54006,9 +54164,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
54006
54164
  function newestReleaseMtime(dir) {
54007
54165
  try {
54008
54166
  let newest = 0;
54009
- for (const name of (0, import_node_fs65.readdirSync)(dir)) {
54167
+ for (const name of (0, import_node_fs66.readdirSync)(dir)) {
54010
54168
  if (!/Release$/.test(name)) continue;
54011
- newest = Math.max(newest, (0, import_node_fs65.statSync)((0, import_node_path49.join)(dir, name)).mtimeMs);
54169
+ newest = Math.max(newest, (0, import_node_fs66.statSync)((0, import_node_path49.join)(dir, name)).mtimeMs);
54012
54170
  }
54013
54171
  return newest > 0 ? new Date(newest) : null;
54014
54172
  } catch {
@@ -54025,7 +54183,7 @@ async function checkPatches(opts = {}) {
54025
54183
  let osText = opts.osRelease;
54026
54184
  if (osText === void 0) {
54027
54185
  try {
54028
- osText = (0, import_node_fs65.readFileSync)("/etc/os-release", "utf-8");
54186
+ osText = (0, import_node_fs66.readFileSync)("/etc/os-release", "utf-8");
54029
54187
  } catch {
54030
54188
  osText = "";
54031
54189
  }
@@ -54257,19 +54415,19 @@ init_paths();
54257
54415
 
54258
54416
  // src/commands/feeds-resolver.ts
54259
54417
  var import_node_child_process25 = require("child_process");
54260
- var import_node_fs66 = require("fs");
54418
+ var import_node_fs67 = require("fs");
54261
54419
  var import_node_path50 = require("path");
54262
54420
  var realIO = {
54263
- exists: (p) => (0, import_node_fs66.existsSync)(p),
54421
+ exists: (p) => (0, import_node_fs67.existsSync)(p),
54264
54422
  read: (p) => {
54265
54423
  try {
54266
- return (0, import_node_fs66.readFileSync)(p, "utf-8");
54424
+ return (0, import_node_fs67.readFileSync)(p, "utf-8");
54267
54425
  } catch {
54268
54426
  return null;
54269
54427
  }
54270
54428
  },
54271
- write: (p, c) => (0, import_node_fs66.writeFileSync)(p, c),
54272
- remove: (p) => (0, import_node_fs66.rmSync)(p, { force: true }),
54429
+ write: (p, c) => (0, import_node_fs67.writeFileSync)(p, c),
54430
+ remove: (p) => (0, import_node_fs67.rmSync)(p, { force: true }),
54273
54431
  run: (cmd, args) => {
54274
54432
  const r = (0, import_node_child_process25.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
54275
54433
  return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
@@ -54278,9 +54436,9 @@ var realIO = {
54278
54436
  var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
54279
54437
  var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
54280
54438
  function hookContent(resolver, stateDir) {
54281
- const head = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
54282
- return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path50.join)(stateDir, RESOLVER_FILES.hosts)}
54283
- ` : `${head}include: "${(0, import_node_path50.join)(stateDir, RESOLVER_FILES.unbound)}"
54439
+ const head2 = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
54440
+ return resolver === "dnsmasq" ? `${head2}addn-hosts=${(0, import_node_path50.join)(stateDir, RESOLVER_FILES.hosts)}
54441
+ ` : `${head2}include: "${(0, import_node_path50.join)(stateDir, RESOLVER_FILES.unbound)}"
54284
54442
  `;
54285
54443
  }
54286
54444
  function apparmorRule(stateDir) {
@@ -54424,7 +54582,7 @@ async function feedsCommand(action, value, opts) {
54424
54582
  }
54425
54583
 
54426
54584
  // src/commands/tor.ts
54427
- var import_node_fs67 = require("fs");
54585
+ var import_node_fs68 = require("fs");
54428
54586
  var import_node_net19 = require("net");
54429
54587
  var import_node_path52 = require("path");
54430
54588
  init_paths();
@@ -54435,10 +54593,10 @@ async function torCommand(action, value, opts) {
54435
54593
  for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
54436
54594
  const path2 = (0, import_node_path52.join)(dir, "tor-exits.txt");
54437
54595
  try {
54438
- if (!(0, import_node_fs67.existsSync)(path2)) continue;
54439
- exits = parseTorExitList((0, import_node_fs67.readFileSync)(path2, "utf-8"));
54596
+ if (!(0, import_node_fs68.existsSync)(path2)) continue;
54597
+ exits = parseTorExitList((0, import_node_fs68.readFileSync)(path2, "utf-8"));
54440
54598
  from = path2;
54441
- updated = (0, import_node_fs67.statSync)(path2).mtime;
54599
+ updated = (0, import_node_fs68.statSync)(path2).mtime;
54442
54600
  break;
54443
54601
  } catch {
54444
54602
  }
@@ -54485,14 +54643,14 @@ async function torCommand(action, value, opts) {
54485
54643
  }
54486
54644
 
54487
54645
  // src/commands/reputation.ts
54488
- var import_node_os21 = require("os");
54489
- var import_node_fs68 = require("fs");
54646
+ var import_node_os22 = require("os");
54647
+ var import_node_fs69 = require("fs");
54490
54648
  var import_node_path53 = require("path");
54491
54649
  var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
54492
- var CONFIG_PATH4 = (0, import_node_path53.join)((0, import_node_os21.homedir)(), ".threatcrush", "config.json");
54650
+ var CONFIG_PATH4 = (0, import_node_path53.join)((0, import_node_os22.homedir)(), ".threatcrush", "config.json");
54493
54651
  function readConfig3() {
54494
54652
  try {
54495
- return JSON.parse((0, import_node_fs68.readFileSync)(CONFIG_PATH4, "utf-8"));
54653
+ return JSON.parse((0, import_node_fs69.readFileSync)(CONFIG_PATH4, "utf-8"));
54496
54654
  } catch {
54497
54655
  return {};
54498
54656
  }
@@ -54505,8 +54663,8 @@ function authFor(env3 = process.env, config = readConfig3()) {
54505
54663
  }
54506
54664
  function formatReport(r) {
54507
54665
  const lines = [];
54508
- const head = r.listed ? source_default.red(`LISTED score ${r.score}/100`) : source_default.green("not listed");
54509
- lines.push(` ${source_default.bold(r.ip)} ${head} ${source_default.dim(`(${r.tier})`)}`);
54666
+ const head2 = r.listed ? source_default.red(`LISTED score ${r.score}/100`) : source_default.green("not listed");
54667
+ lines.push(` ${source_default.bold(r.ip)} ${head2} ${source_default.dim(`(${r.tier})`)}`);
54510
54668
  if (r.reports) {
54511
54669
  lines.push(
54512
54670
  ` ${r.severity} \xB7 ${r.reports} reports from ${r.reporters} reporter${r.reporters === 1 ? "" : "s"} \xB7 last seen ${String(r.last_seen ?? "").slice(0, 10)}${r.country ? ` \xB7 ${r.country}` : ""}`
@@ -54527,8 +54685,8 @@ function formatReport(r) {
54527
54685
  }
54528
54686
  function formatAny(r) {
54529
54687
  if (r.type !== "domain") return formatReport(r);
54530
- const head = r.listed ? source_default.red(`LISTED score ${r.score}/100`) : source_default.green("not listed");
54531
- const lines = [` ${source_default.bold(r.domain)} ${head} ${source_default.dim(`(${r.tier})`)}`];
54688
+ const head2 = r.listed ? source_default.red(`LISTED score ${r.score}/100`) : source_default.green("not listed");
54689
+ const lines = [` ${source_default.bold(r.domain)} ${head2} ${source_default.dim(`(${r.tier})`)}`];
54532
54690
  for (const reason of r.reasons) lines.push(` \xB7 ${reason}`);
54533
54691
  for (const a of r.addresses) lines.push(` ${a.ip}: ${a.listed ? source_default.red(`listed, ${a.score}/100`) : "not listed"}`);
54534
54692
  lines.push(source_default.dim(` public record: ${r.public_record}`));
@@ -54680,7 +54838,7 @@ async function reputationSubscribeCommand(opts) {
54680
54838
  }
54681
54839
 
54682
54840
  // src/commands/privileged.ts
54683
- var import_node_fs69 = require("fs");
54841
+ var import_node_fs70 = require("fs");
54684
54842
  init_paths();
54685
54843
  var SEV2 = {
54686
54844
  critical: source_default.red.bold,
@@ -54693,19 +54851,19 @@ async function privilegedCommand(opts) {
54693
54851
  const snapshot = takeSnapshot({
54694
54852
  readFile: (p) => {
54695
54853
  try {
54696
- return (0, import_node_fs69.readFileSync)(p, "utf-8");
54854
+ return (0, import_node_fs70.readFileSync)(p, "utf-8");
54697
54855
  } catch {
54698
54856
  return null;
54699
54857
  }
54700
54858
  },
54701
54859
  readDir: (p) => {
54702
54860
  try {
54703
- return (0, import_node_fs69.readdirSync)(p);
54861
+ return (0, import_node_fs70.readdirSync)(p);
54704
54862
  } catch {
54705
54863
  return null;
54706
54864
  }
54707
54865
  },
54708
- exists: (p) => (0, import_node_fs69.existsSync)(p)
54866
+ exists: (p) => (0, import_node_fs70.existsSync)(p)
54709
54867
  });
54710
54868
  let events = [];
54711
54869
  let ledgerNote = "";
@@ -54747,12 +54905,12 @@ async function privilegedCommand(opts) {
54747
54905
  }
54748
54906
 
54749
54907
  // src/commands/integrity.ts
54750
- var import_node_fs70 = require("fs");
54908
+ var import_node_fs71 = require("fs");
54751
54909
  var import_node_path54 = require("path");
54752
54910
  init_paths();
54753
54911
  function readState2(path2) {
54754
54912
  try {
54755
- return JSON.parse((0, import_node_fs70.readFileSync)(path2, "utf8"));
54913
+ return JSON.parse((0, import_node_fs71.readFileSync)(path2, "utf8"));
54756
54914
  } catch {
54757
54915
  return null;
54758
54916
  }
@@ -54773,7 +54931,7 @@ async function integrityCommand(action = "status", opts = {}) {
54773
54931
  const config = loadConfig();
54774
54932
  const settings = fileIntegritySettings(config.file_integrity);
54775
54933
  const systemBaseline = (0, import_node_path54.join)(SYSTEM_PATHS.stateDir, "file-integrity-baseline.json");
54776
- const useSystemState = PATHS.mode === "system" || systemDaemonPresent() || (0, import_node_fs70.existsSync)(systemBaseline);
54934
+ const useSystemState = PATHS.mode === "system" || systemDaemonPresent() || (0, import_node_fs71.existsSync)(systemBaseline);
54777
54935
  const stateDir = useSystemState ? SYSTEM_PATHS.stateDir : PATHS.stateDir;
54778
54936
  const baselinePath = (0, import_node_path54.join)(stateDir, "file-integrity-baseline.json");
54779
54937
  const observedPath = (0, import_node_path54.join)(stateDir, "file-integrity-observed.json");
@@ -54844,11 +55002,11 @@ async function integrityCommand(action = "status", opts = {}) {
54844
55002
  }
54845
55003
 
54846
55004
  // src/commands/edr.ts
54847
- var import_node_fs72 = require("fs");
55005
+ var import_node_fs73 = require("fs");
54848
55006
  init_paths();
54849
55007
 
54850
55008
  // src/daemon/auditd/rules.ts
54851
- var import_node_fs71 = require("fs");
55009
+ var import_node_fs72 = require("fs");
54852
55010
  var import_node_child_process26 = require("child_process");
54853
55011
  var import_node_path55 = require("path");
54854
55012
  var WEB_TOOLS = ["sh", "bash", "dash", "zsh", "curl", "wget"];
@@ -54861,7 +55019,7 @@ function passwdByName() {
54861
55019
  raw = (0, import_node_child_process26.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
54862
55020
  } catch {
54863
55021
  try {
54864
- raw = (0, import_node_fs71.readFileSync)("/etc/passwd", "utf8");
55022
+ raw = (0, import_node_fs72.readFileSync)("/etc/passwd", "utf8");
54865
55023
  } catch {
54866
55024
  return /* @__PURE__ */ new Map();
54867
55025
  }
@@ -54880,8 +55038,8 @@ function existingExecutables(names) {
54880
55038
  for (const prefix of ["/bin", "/usr/bin", "/usr/local/bin"]) {
54881
55039
  const candidate = `${prefix}/${name}`;
54882
55040
  try {
54883
- if (!(0, import_node_fs71.existsSync)(candidate) || !(0, import_node_fs71.statSync)(candidate).isFile()) continue;
54884
- paths.add((0, import_node_fs71.realpathSync)(candidate));
55041
+ if (!(0, import_node_fs72.existsSync)(candidate) || !(0, import_node_fs72.statSync)(candidate).isFile()) continue;
55042
+ paths.add((0, import_node_fs72.realpathSync)(candidate));
54885
55043
  } catch {
54886
55044
  }
54887
55045
  }
@@ -54892,7 +55050,7 @@ function existingDirectories(paths) {
54892
55050
  return [...new Set(paths)].filter((path2) => {
54893
55051
  if (!(0, import_node_path55.isAbsolute)(path2) || /[\s\r\n]/.test(path2)) return false;
54894
55052
  try {
54895
- return (0, import_node_fs71.statSync)(path2).isDirectory();
55053
+ return (0, import_node_fs72.statSync)(path2).isDirectory();
54896
55054
  } catch {
54897
55055
  return false;
54898
55056
  }
@@ -54953,8 +55111,8 @@ async function edrCommand(action = "status", opts = {}) {
54953
55111
  }
54954
55112
  let readable = false;
54955
55113
  try {
54956
- if ((0, import_node_fs72.existsSync)(settings.auditLogPath)) (0, import_node_fs72.accessSync)(settings.auditLogPath, import_node_fs72.constants.R_OK);
54957
- readable = (0, import_node_fs72.existsSync)(settings.auditLogPath);
55114
+ if ((0, import_node_fs73.existsSync)(settings.auditLogPath)) (0, import_node_fs73.accessSync)(settings.auditLogPath, import_node_fs73.constants.R_OK);
55115
+ readable = (0, import_node_fs73.existsSync)(settings.auditLogPath);
54958
55116
  } catch {
54959
55117
  }
54960
55118
  let events = [];
@@ -55140,7 +55298,7 @@ async function allowlistCommand(opts) {
55140
55298
  }
55141
55299
 
55142
55300
  // src/commands/abuse.ts
55143
- var import_node_fs73 = require("fs");
55301
+ var import_node_fs74 = require("fs");
55144
55302
  init_paths();
55145
55303
  function rows(records) {
55146
55304
  if (records.length === 0) {
@@ -55200,7 +55358,7 @@ function abuseRetractCommand(id, opts = {}) {
55200
55358
  );
55201
55359
  }
55202
55360
  function abuseStatusCommand(opts = {}) {
55203
- const config = loadConfig((0, import_node_fs73.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
55361
+ const config = loadConfig((0, import_node_fs74.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
55204
55362
  const cfg = resolveConfig(config.abuse_reporter);
55205
55363
  const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
55206
55364
  const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
@@ -55369,7 +55527,7 @@ function installUserAgent(target = globalThis) {
55369
55527
 
55370
55528
  // src/core/cloud-upload.ts
55371
55529
  var import_node_child_process28 = require("child_process");
55372
- var import_node_os22 = require("os");
55530
+ var import_node_os23 = require("os");
55373
55531
  var import_node_path56 = require("path");
55374
55532
  init_cli_config();
55375
55533
  function uploadDisabled(upload, env3 = process.env) {
@@ -55403,9 +55561,9 @@ function repoTarget(path2, run2 = (args) => (0, import_node_child_process28.exec
55403
55561
  const m = /^(?:[a-z+]+:\/\/)?(?:[^@/]+@)?([^/:]+)[:/](.+?)(?:\.git)?\/?$/i.exec(remote);
55404
55562
  if (m) return { target: `${m[1]}/${m[2]}`, root, sub };
55405
55563
  }
55406
- return { target: `${(0, import_node_os22.hostname)()}:${root}`, root, sub };
55564
+ return { target: `${(0, import_node_os23.hostname)()}:${root}`, root, sub };
55407
55565
  } catch {
55408
- return { target: `${(0, import_node_os22.hostname)()}:${abs}`, root: abs, sub: "." };
55566
+ return { target: `${(0, import_node_os23.hostname)()}:${abs}`, root: abs, sub: "." };
55409
55567
  }
55410
55568
  }
55411
55569
  async function uploadResult(result, opts) {
@@ -55762,7 +55920,7 @@ ${source_default.dim(" C R U S H")}
55762
55920
  var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
55763
55921
  var PKG_NAME2 = "@profullstack/threatcrush";
55764
55922
  var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
55765
- var INSTALL_CONFIG_PATH = (0, import_node_path57.join)((0, import_node_os23.homedir)(), ".threatcrush", "install.json");
55923
+ var INSTALL_CONFIG_PATH = (0, import_node_path57.join)((0, import_node_os24.homedir)(), ".threatcrush", "install.json");
55766
55924
  function detectPackageManager() {
55767
55925
  try {
55768
55926
  const npmGlobal = (0, import_node_child_process29.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
@@ -55788,7 +55946,7 @@ function detectPackageManager() {
55788
55946
  }
55789
55947
  function readInstallConfig() {
55790
55948
  try {
55791
- return JSON.parse((0, import_node_fs74.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
55949
+ return JSON.parse((0, import_node_fs75.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
55792
55950
  } catch {
55793
55951
  return {};
55794
55952
  }
@@ -56067,7 +56225,7 @@ program2.command("scan").description("Scan codebase for vulnerabilities and secr
56067
56225
  }
56068
56226
  });
56069
56227
  var av = program2.command("av").alias("antivirus").description("CrushAV: free open-source antivirus (heuristics + ClamAV + hash reputation), Windows/macOS/Linux");
56070
- av.command("scan").description("Scan files or folders for malware; no paths = quick scan of downloads, desktop, temp and startup items").argument("[paths...]", "files or folders to scan").option("--full", "scan the whole home folder plus system startup and temp locations").option("--no-clamav", "do not use ClamAV even when it is installed").option("--require-clamav", "fail if ClamAV is not installed").option("--offline", "do not send file hashes to threatcrush.com for reputation lookups").option("--quarantine", "move malware into quarantine (reversible with `av quarantine restore`)").option("--max-size <mb>", "skip files larger than this many MB (default 1024)").option("--json", "emit JSON").action(async (paths, opts) => {
56228
+ av.command("scan").description("Scan files or folders for malware; no paths = quick scan of downloads, desktop, temp and startup items").argument("[paths...]", "files or folders to scan").option("--full", "scan the whole home folder plus system startup and temp locations").option("--no-clamav", "do not use ClamAV even when it is installed").option("--require-clamav", "fail if ClamAV is not installed").option("--offline", "do not send file hashes to threatcrush.com for reputation lookups").option("--quarantine", "move malware into quarantine (reversible with `av quarantine restore`)").option("--max-size <mb>", "skip files larger than this many MB (default 1024)").option("-j, --jobs <n>", "files scanned in parallel worker threads (default: one per CPU core)").option("--json", "emit JSON").action(async (paths, opts) => {
56071
56229
  await avScanCommand(paths, opts);
56072
56230
  });
56073
56231
  av.command("watch").description("Real-time protection: scan new and changed files as they land (default: downloads, desktop, temp, startup)").argument("[paths...]", "folders to watch instead of the defaults").option("--quarantine", "quarantine malware the moment it is detected").option("--offline", "do not send file hashes to threatcrush.com").option("--json", "one JSON line per scanned file").action(async (paths, opts) => avWatchCommand(paths, opts));
@@ -56219,7 +56377,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
56219
56377
  program2.command("logs").description("Tail daemon logs").action(async () => {
56220
56378
  console.log(LOGO2);
56221
56379
  const logPath2 = PATHS.logFile;
56222
- if (!(0, import_node_fs74.existsSync)(logPath2)) {
56380
+ if (!(0, import_node_fs75.existsSync)(logPath2)) {
56223
56381
  console.log(source_default.yellow(` No log file found at ${logPath2}`));
56224
56382
  console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
56225
56383
  return;
@@ -56392,10 +56550,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
56392
56550
  });
56393
56551
  storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
56394
56552
  console.log(LOGO2);
56395
- const configPath = (0, import_node_path57.join)((0, import_node_os23.homedir)(), ".threatcrush", "config.json");
56553
+ const configPath = (0, import_node_path57.join)((0, import_node_os24.homedir)(), ".threatcrush", "config.json");
56396
56554
  let email = "";
56397
56555
  try {
56398
- const config = JSON.parse((0, import_node_fs74.readFileSync)(configPath, "utf-8"));
56556
+ const config = JSON.parse((0, import_node_fs75.readFileSync)(configPath, "utf-8"));
56399
56557
  email = config.email || "";
56400
56558
  } catch {
56401
56559
  }
@@ -56412,9 +56570,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
56412
56570
  return;
56413
56571
  }
56414
56572
  try {
56415
- const dir = (0, import_node_path57.join)((0, import_node_os23.homedir)(), ".threatcrush");
56416
- if (!(0, import_node_fs74.existsSync)(dir)) (0, import_node_fs74.mkdirSync)(dir, { recursive: true });
56417
- (0, import_node_fs74.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
56573
+ const dir = (0, import_node_path57.join)((0, import_node_os24.homedir)(), ".threatcrush");
56574
+ if (!(0, import_node_fs75.existsSync)(dir)) (0, import_node_fs75.mkdirSync)(dir, { recursive: true });
56575
+ (0, import_node_fs75.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
56418
56576
  console.log(source_default.dim(` Saved email to ${configPath}`));
56419
56577
  } catch {
56420
56578
  }