@profullstack/threatcrush 0.13.74 → 0.13.77

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");
23791
- var import_node_path57 = require("path");
23792
- var import_node_os23 = require("os");
23790
+ var import_node_fs75 = require("fs");
23791
+ var import_node_path58 = require("path");
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;
@@ -40803,8 +40803,8 @@ async function pentestCommand(targetUrl) {
40803
40803
  }
40804
40804
 
40805
40805
  // src/commands/av.ts
40806
- var import_node_fs27 = require("fs");
40807
- var import_node_os12 = require("os");
40806
+ var import_node_fs28 = require("fs");
40807
+ var import_node_os13 = require("os");
40808
40808
  var import_node_path24 = require("path");
40809
40809
 
40810
40810
  // ../../packages/av/src/sha256.ts
@@ -41316,8 +41316,13 @@ var RULES = [
41316
41316
  ];
41317
41317
  function buildContext(name, bytes, kind, size) {
41318
41318
  let text = "";
41319
- for (let i = 0; i < bytes.length; i += 32768) {
41320
- 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
+ }
41321
41326
  }
41322
41327
  let wide = "";
41323
41328
  if (kind === "pe" || kind === "lnk" || kind === "ole") {
@@ -41380,6 +41385,10 @@ var SignatureSet = class {
41380
41385
  get(sha256) {
41381
41386
  return this.map.get(sha256.toLowerCase());
41382
41387
  }
41388
+ /** Every `[sha256, name]` pair, so a set can be rebuilt in a worker thread. */
41389
+ entries() {
41390
+ return [...this.map];
41391
+ }
41383
41392
  get size() {
41384
41393
  return this.map.size;
41385
41394
  }
@@ -41578,10 +41587,15 @@ var SKIP_DIR_NAMES = /* @__PURE__ */ new Set([
41578
41587
  ".threatcrush"
41579
41588
  ]);
41580
41589
  var SKIP_ROOTS = ["/proc", "/sys", "/dev/pts", "/run", "/snap"];
41581
- async function* walkTargets(targets, opts = {}) {
41582
- const skip = opts.skipDirNames ?? SKIP_DIR_NAMES;
41583
- const seen = /* @__PURE__ */ new Set();
41584
- 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) {
41585
41599
  let st;
41586
41600
  try {
41587
41601
  st = await (0, import_promises.lstat)(t.path);
@@ -41590,48 +41604,78 @@ async function* walkTargets(targets, opts = {}) {
41590
41604
  continue;
41591
41605
  }
41592
41606
  if (st.isFile()) {
41593
- if (!seen.has(t.path)) {
41594
- seen.add(t.path);
41595
- yield { path: t.path, size: st.size };
41607
+ if (!fileTargets.has(t.path)) {
41608
+ fileTargets.add(t.path);
41609
+ yield t.path;
41596
41610
  }
41597
- continue;
41598
- }
41599
- if (!st.isDirectory()) continue;
41600
- const stack2 = [[t.path, 0]];
41601
- while (stack2.length) {
41602
- if (opts.signal?.aborted) return;
41603
- const [dir, depth] = stack2.pop();
41604
- if (SKIP_ROOTS.some((r) => dir === r || dir.startsWith(`${r}/`))) continue;
41605
- 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) => {
41606
41624
  try {
41607
- 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
+ }
41608
41636
  } catch (e) {
41609
41637
  opts.onSkip?.(dir, e.code ?? "unreadable");
41610
- continue;
41638
+ } finally {
41639
+ active2--;
41640
+ notify();
41611
41641
  }
41612
- for await (const ent of handle) {
41613
- const p = (0, import_node_path20.join)(dir, ent.name);
41614
- if (ent.isSymbolicLink()) continue;
41615
- if (ent.isDirectory()) {
41616
- if (depth + 1 < t.depth && !skip.has(ent.name)) stack2.push([p, depth + 1]);
41617
- continue;
41618
- }
41619
- if (!ent.isFile() || seen.has(p)) continue;
41620
- seen.add(p);
41621
- try {
41622
- const s = await (0, import_promises.lstat)(p);
41623
- yield { path: p, size: s.size };
41624
- } catch (e) {
41625
- opts.onSkip?.(p, e.code ?? "unreadable");
41626
- }
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;
41627
41657
  }
41658
+ if (!active2 && !stack2.length) break;
41659
+ await new Promise((resolve9) => {
41660
+ wake = resolve9;
41661
+ });
41628
41662
  }
41629
41663
  }
41630
41664
  }
41631
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
+
41632
41676
  // ../../packages/av/src/node/clamav.ts
41633
41677
  var import_node_child_process5 = require("child_process");
41634
- var import_node_fs23 = require("fs");
41678
+ var import_node_fs24 = require("fs");
41635
41679
  var import_promises2 = require("fs/promises");
41636
41680
  var import_node_os10 = require("os");
41637
41681
  var import_node_path21 = require("path");
@@ -41643,7 +41687,7 @@ function findBinary(name, env3 = process.env, platform = process.platform) {
41643
41687
  if (platform === "darwin") dirs.push("/opt/homebrew/bin", "/usr/local/bin");
41644
41688
  for (const d of dirs) {
41645
41689
  const p = (0, import_node_path21.join)(d, exe);
41646
- if ((0, import_node_fs23.existsSync)(p)) return p;
41690
+ if ((0, import_node_fs24.existsSync)(p)) return p;
41647
41691
  }
41648
41692
  return null;
41649
41693
  }
@@ -41741,8 +41785,8 @@ function clamInstallHint(platform = process.platform) {
41741
41785
  }
41742
41786
 
41743
41787
  // ../../packages/av/src/node/quarantine.ts
41744
- var import_node_crypto6 = require("crypto");
41745
- var import_node_fs24 = require("fs");
41788
+ var import_node_crypto7 = require("crypto");
41789
+ var import_node_fs25 = require("fs");
41746
41790
  var import_promises3 = require("fs/promises");
41747
41791
  var import_node_os11 = require("os");
41748
41792
  var import_node_path22 = require("path");
@@ -41757,8 +41801,8 @@ function xor(buf) {
41757
41801
  }
41758
41802
  async function quarantineFile(path2, detections = [], dir = quarantineDir()) {
41759
41803
  const data = await (0, import_promises3.readFile)(path2);
41760
- const sha256 = (0, import_node_crypto6.createHash)("sha256").update(data).digest("hex");
41761
- 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")}`;
41762
41806
  await (0, import_promises3.mkdir)(dir, { recursive: true, mode: 448 });
41763
41807
  const entry = {
41764
41808
  id,
@@ -41771,7 +41815,7 @@ async function quarantineFile(path2, detections = [], dir = quarantineDir()) {
41771
41815
  const bin = (0, import_node_path22.join)(dir, `${id}.bin`);
41772
41816
  await (0, import_promises3.writeFile)(bin, xor(data), { mode: 384 });
41773
41817
  const check2 = xor(await (0, import_promises3.readFile)(bin));
41774
- 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) {
41775
41819
  await (0, import_promises3.rm)(bin, { force: true });
41776
41820
  throw new Error("quarantine copy did not verify; original left in place");
41777
41821
  }
@@ -41780,7 +41824,7 @@ async function quarantineFile(path2, detections = [], dir = quarantineDir()) {
41780
41824
  return entry;
41781
41825
  }
41782
41826
  async function listQuarantine(dir = quarantineDir()) {
41783
- if (!(0, import_node_fs24.existsSync)(dir)) return [];
41827
+ if (!(0, import_node_fs25.existsSync)(dir)) return [];
41784
41828
  const out = [];
41785
41829
  for (const f of await (0, import_promises3.readdir)(dir)) {
41786
41830
  if (!f.endsWith(".json")) continue;
@@ -41794,7 +41838,7 @@ async function listQuarantine(dir = quarantineDir()) {
41794
41838
  async function entryOf(id, dir) {
41795
41839
  if (!/^[\w-]+$/.test(id)) throw new Error(`bad quarantine id: ${id}`);
41796
41840
  const p = (0, import_node_path22.join)(dir, `${id}.json`);
41797
- 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}`);
41798
41842
  return JSON.parse(await (0, import_promises3.readFile)(p, "utf8"));
41799
41843
  }
41800
41844
  async function restoreQuarantined(id, to, dir = quarantineDir()) {
@@ -41819,77 +41863,106 @@ async function deleteQuarantined(id, dir = quarantineDir()) {
41819
41863
  }
41820
41864
 
41821
41865
  // ../../packages/av/src/node/scan.ts
41822
- var import_node_crypto7 = require("crypto");
41823
- 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");
41824
41871
  var LOOKUP_KINDS = /* @__PURE__ */ new Set(["pe", "elf", "macho", "script", "lnk", "ole", "zip", "pdf", "dex", "rtf"]);
41825
41872
  var MAX_LOOKUPS = 5e3;
41826
41873
  async function readForScan(path2, size, cap) {
41827
- const hash = (0, import_node_crypto7.createHash)("sha256");
41828
- 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));
41829
41876
  let filled = 0;
41830
41877
  await new Promise((resolve9, reject) => {
41831
- const s = (0, import_node_fs25.createReadStream)(path2, { highWaterMark: 1 << 20 });
41878
+ const s = (0, import_node_fs26.createReadStream)(path2, { highWaterMark: 1 << 20 });
41832
41879
  s.on("data", (chunk2) => {
41833
41880
  const c = chunk2;
41834
41881
  hash.update(c);
41835
- if (filled < head.length) {
41836
- const n = Math.min(head.length - filled, c.length);
41837
- 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);
41838
41885
  filled += n;
41839
41886
  }
41840
41887
  });
41841
41888
  s.on("error", reject);
41842
41889
  s.on("end", () => resolve9());
41843
41890
  });
41844
- return { head: head.subarray(0, filled), sha256: hash.digest("hex") };
41891
+ return { head: head2.subarray(0, filled), sha256: hash.digest("hex") };
41845
41892
  }
41846
41893
  async function scanPaths(targets, opts = {}) {
41847
41894
  const started = /* @__PURE__ */ new Date();
41848
41895
  const cap = opts.heuristicBytes ?? DEFAULT_HEURISTIC_BYTES;
41849
41896
  const maxFile = opts.maxFileBytes ?? 1024 ** 3;
41897
+ const keepClean = opts.keepClean !== false;
41850
41898
  const skipped = [];
41851
41899
  const skip = (path2, reason) => {
41852
41900
  skipped.push({ path: path2, reason });
41853
41901
  opts.onProgress?.({ type: "skip", path: path2, reason });
41854
41902
  };
41855
41903
  let signatures = opts.signatures;
41856
- if (opts.signatureFile && (0, import_node_fs25.existsSync)(opts.signatureFile)) {
41904
+ if (opts.signatureFile && (0, import_node_fs26.existsSync)(opts.signatureFile)) {
41857
41905
  signatures = signatures ?? new SignatureSet();
41858
- signatures.load((0, import_node_fs25.readFileSync)(opts.signatureFile, "utf8"));
41906
+ signatures.load((0, import_node_fs26.readFileSync)(opts.signatureFile, "utf8"));
41859
41907
  }
41860
41908
  const clamav = opts.clamav === "off" ? null : await detectClamAV();
41861
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;
41862
41911
  opts.onProgress?.({ type: "phase", phase: "walking" });
41863
41912
  const results = [];
41864
- const queue = [];
41865
- const limit = Math.max(1, opts.concurrency ?? 4);
41866
- const scanOne = async (path2, size) => {
41867
- try {
41868
- const { head, sha256 } = await readForScan(path2, size, cap);
41869
- const r = await scanBytes({ name: path2, bytes: head, size, sha256 }, { signatures });
41870
- results.push(r);
41871
- opts.onProgress?.({ type: "file", path: path2, scanned: results.length, result: r });
41872
- } catch (e) {
41873
- const code = e.code ?? e.message;
41874
- const r = { path: path2, size, sha256: null, kind: "unknown", verdict: "error", detections: [], note: code };
41875
- results.push(r);
41876
- opts.onProgress?.({ type: "file", path: path2, scanned: results.length, result: r });
41877
- }
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 });
41878
41923
  };
41879
- for await (const f of walkTargets(targets, { signal: opts.signal, onSkip: skip })) {
41880
- if (opts.signal?.aborted) break;
41881
- if (f.size === 0) continue;
41882
- if (f.size > maxFile) {
41883
- skip(f.path, `larger than ${Math.round(maxFile / 1048576)} MB`);
41884
- continue;
41885
- }
41886
- const p = scanOne(f.path, f.size).finally(() => {
41887
- 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
41888
41936
  });
41889
- queue.push(p);
41890
- 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);
41891
41965
  }
41892
- await Promise.all(queue);
41893
41966
  const engines = ["signature", "heuristic"];
41894
41967
  if (opts.reputation !== false && !opts.signal?.aborted) {
41895
41968
  const wanted = results.filter((r) => r.sha256 && (LOOKUP_KINDS.has(r.kind) || r.detections.length > 0)).slice(0, MAX_LOOKUPS);
@@ -41901,21 +41974,87 @@ async function scanPaths(targets, opts = {}) {
41901
41974
  }
41902
41975
  }
41903
41976
  let clamavError = null;
41904
- if (clamav?.available && !opts.signal?.aborted) {
41905
- const files = results.filter((r) => r.verdict !== "error").map((r) => r.path);
41906
- opts.onProgress?.({ type: "phase", phase: "clamav", detail: `${files.length} files via ${clamav.mode}` });
41907
- 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 });
41908
41980
  clamavError = error2;
41909
41981
  if (!error2) engines.push("clamav");
41910
- for (const r of results) {
41911
- const extra = detections.get(r.path);
41912
- 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
+ }
41913
41990
  r.detections.push(...extra);
41914
41991
  r.verdict = verdictOf(r.detections);
41915
41992
  }
41916
41993
  }
41917
41994
  opts.onProgress?.({ type: "phase", phase: "done" });
41918
- 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
+ }
41919
42058
  }
41920
42059
  function applyAll(results, reps) {
41921
42060
  for (let i = 0; i < results.length; i++) {
@@ -41925,8 +42064,8 @@ function applyAll(results, reps) {
41925
42064
  }
41926
42065
 
41927
42066
  // ../../packages/av/src/node/watch.ts
41928
- var import_node_fs26 = require("fs");
41929
- var import_promises4 = require("fs/promises");
42067
+ var import_node_fs27 = require("fs");
42068
+ var import_promises5 = require("fs/promises");
41930
42069
  var import_node_path23 = require("path");
41931
42070
  var IN_PROGRESS = /\.(?:crdownload|part|partial|download|tmp)$/i;
41932
42071
  function watchTargets(targets, opts) {
@@ -41937,14 +42076,14 @@ function watchTargets(targets, opts) {
41937
42076
  const scan = async (path2) => {
41938
42077
  timers.delete(path2);
41939
42078
  try {
41940
- const st = await (0, import_promises4.lstat)(path2);
42079
+ const st = await (0, import_promises5.lstat)(path2);
41941
42080
  if (!st.isFile() || st.size === 0 || st.size > (opts.maxFileBytes ?? 1024 ** 3)) return;
41942
42081
  const key = `${st.size}:${st.mtimeMs}`;
41943
42082
  if (lastScanned.get(path2) === key) return;
41944
42083
  lastScanned.set(path2, key);
41945
42084
  if (lastScanned.size > 1e4) lastScanned.delete(lastScanned.keys().next().value);
41946
- const { head, sha256 } = await readForScan(path2, st.size, opts.heuristicBytes ?? 16 * 1024 * 1024);
41947
- 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 });
41948
42087
  if (opts.reputation !== false) {
41949
42088
  const reps = await lookupHashes([sha256], { endpoint: opts.lookupEndpoint, timeoutMs: 8e3 });
41950
42089
  r = applyReputation(r, reps.get(sha256));
@@ -41957,7 +42096,7 @@ function watchTargets(targets, opts) {
41957
42096
  };
41958
42097
  for (const t of targets) {
41959
42098
  try {
41960
- 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) => {
41961
42100
  if (!file) return;
41962
42101
  const rel = String(file);
41963
42102
  if (IN_PROGRESS.test(rel)) return;
@@ -41983,7 +42122,12 @@ function watchTargets(targets, opts) {
41983
42122
 
41984
42123
  // src/commands/av.ts
41985
42124
  init_cli_config();
41986
- 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
+ }
41987
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");
41988
42132
  async function avScanCommand(paths, opts = {}) {
41989
42133
  let targets;
@@ -41998,7 +42142,7 @@ async function avScanCommand(paths, opts = {}) {
41998
42142
  targets = quickScanTargets();
41999
42143
  label = "quick scan (downloads, desktop, temp and startup locations)";
42000
42144
  }
42001
- 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));
42002
42146
  if (paths.length && missing.length) {
42003
42147
  console.error(source_default.red(` Not found: ${missing.map((m) => m.path).join(", ")}`));
42004
42148
  process.exitCode = 2;
@@ -42006,12 +42150,16 @@ async function avScanCommand(paths, opts = {}) {
42006
42150
  }
42007
42151
  const spinner = opts.json ? null : ora({ text: `CrushAV ${label}`, discardStdin: false }).start();
42008
42152
  let lastPaint = 0;
42153
+ const startedAt = Date.now();
42009
42154
  const report = await scanPaths(targets, {
42010
42155
  clamav: opts.requireClamav ? "require" : opts.clamav === false ? "off" : "auto",
42011
42156
  reputation: !opts.offline,
42012
42157
  lookupEndpoint: `${apiUrl()}/api/av/lookup`,
42013
42158
  signatureFile: SIGNATURE_FILE,
42014
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,
42015
42163
  onProgress: (e) => {
42016
42164
  if (!spinner) return;
42017
42165
  if (e.type === "phase") {
@@ -42020,7 +42168,9 @@ async function avScanCommand(paths, opts = {}) {
42020
42168
  } else if (e.type === "file" && Date.now() - lastPaint > 120) {
42021
42169
  lastPaint = Date.now();
42022
42170
  const short2 = e.path.length > 70 ? `\u2026${e.path.slice(-69)}` : e.path;
42023
- 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)}`;
42024
42174
  }
42025
42175
  }
42026
42176
  }).catch((e) => {
@@ -42079,7 +42229,7 @@ async function avStatusCommand(opts = {}) {
42079
42229
  const status = {
42080
42230
  engine: "CrushAV",
42081
42231
  heuristic_rules: RULES.length,
42082
- 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,
42083
42233
  clamav: clam,
42084
42234
  reputation_endpoint: `${apiUrl()}/api/av/lookup`,
42085
42235
  quarantine_dir: quarantineDir(),
@@ -42186,7 +42336,7 @@ async function avTestCommand() {
42186
42336
  }
42187
42337
 
42188
42338
  // src/commands/ai-scan.ts
42189
- var import_node_fs29 = require("fs");
42339
+ var import_node_fs30 = require("fs");
42190
42340
 
42191
42341
  // src/aiscan/probes.ts
42192
42342
  function makeCanary() {
@@ -42403,8 +42553,8 @@ ${stripShebang(source)}
42403
42553
  }
42404
42554
 
42405
42555
  // src/core/usage-ping.ts
42406
- var import_node_crypto8 = require("crypto");
42407
- var import_node_fs28 = require("fs");
42556
+ var import_node_crypto9 = require("crypto");
42557
+ var import_node_fs29 = require("fs");
42408
42558
  var import_node_path25 = require("path");
42409
42559
  init_cli_config();
42410
42560
  var STATE_FILE = "usage-ping.json";
@@ -42417,14 +42567,14 @@ function usagePingDisabled(env3 = process.env) {
42417
42567
  function installId(dir = CLI_CONFIG_DIR) {
42418
42568
  const file = (0, import_node_path25.join)(dir, STATE_FILE);
42419
42569
  try {
42420
- 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"));
42421
42571
  if (j.install_id) return { id: j.install_id, fresh: false };
42422
42572
  } catch {
42423
42573
  }
42424
- const id = (0, import_node_crypto8.randomUUID)();
42574
+ const id = (0, import_node_crypto9.randomUUID)();
42425
42575
  try {
42426
- if (!(0, import_node_fs28.existsSync)(dir)) (0, import_node_fs28.mkdirSync)(dir, { recursive: true });
42427
- (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");
42428
42578
  } catch {
42429
42579
  }
42430
42580
  return { id, fresh: true };
@@ -42532,7 +42682,7 @@ async function aiScanMoshCommand(file, args) {
42532
42682
  console.log();
42533
42683
  let source;
42534
42684
  try {
42535
- source = (0, import_node_fs29.readFileSync)(file, "utf-8");
42685
+ source = (0, import_node_fs30.readFileSync)(file, "utf-8");
42536
42686
  } catch (err) {
42537
42687
  logger.error(`Cannot read ${file}: ${err.message}`);
42538
42688
  process.exitCode = 1;
@@ -42561,22 +42711,22 @@ async function aiScanMoshCommand(file, args) {
42561
42711
  }
42562
42712
 
42563
42713
  // src/commands/orgs.ts
42564
- var import_node_os13 = require("os");
42565
- var import_node_fs30 = require("fs");
42714
+ var import_node_os14 = require("os");
42715
+ var import_node_fs31 = require("fs");
42566
42716
  var import_node_path26 = require("path");
42567
42717
  var API_URL3 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
42568
- 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");
42569
42719
  function readConfig() {
42570
42720
  try {
42571
- 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"));
42572
42722
  } catch {
42573
42723
  return {};
42574
42724
  }
42575
42725
  }
42576
42726
  function writeConfig(config) {
42577
- const dir = (0, import_node_path26.join)((0, import_node_os13.homedir)(), ".threatcrush");
42578
- if (!(0, import_node_fs30.existsSync)(dir)) (0, import_node_fs30.mkdirSync)(dir, { recursive: true });
42579
- (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));
42580
42730
  }
42581
42731
  function getAuthHeaders() {
42582
42732
  const config = readConfig();
@@ -42711,14 +42861,14 @@ async function useOrganization(slug) {
42711
42861
  }
42712
42862
 
42713
42863
  // src/commands/credits.ts
42714
- var import_node_os14 = require("os");
42715
- var import_node_fs31 = require("fs");
42864
+ var import_node_os15 = require("os");
42865
+ var import_node_fs32 = require("fs");
42716
42866
  var import_node_path27 = require("path");
42717
42867
  var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
42718
- 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");
42719
42869
  function sessionToken() {
42720
42870
  try {
42721
- 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"));
42722
42872
  return cfg.token ?? null;
42723
42873
  } catch {
42724
42874
  return null;
@@ -42787,7 +42937,7 @@ async function invitesCommand(action = "list", arg, f = fetch) {
42787
42937
  }
42788
42938
 
42789
42939
  // src/commands/fleet.ts
42790
- var import_promises5 = require("fs/promises");
42940
+ var import_promises6 = require("fs/promises");
42791
42941
  init_cli_config();
42792
42942
  async function call(path2, init = {}) {
42793
42943
  const res = await cloudFetch(path2, init);
@@ -42826,7 +42976,7 @@ async function readInventorySource(source, f = fetch) {
42826
42976
  if (!res.ok) throw new Error(`${source} answered ${res.status}`);
42827
42977
  return res.text();
42828
42978
  }
42829
- return (0, import_promises5.readFile)(source, "utf-8");
42979
+ return (0, import_promises6.readFile)(source, "utf-8");
42830
42980
  }
42831
42981
  async function fleetImportCommand(source, opts = {}) {
42832
42982
  let text;
@@ -42884,7 +43034,7 @@ function formatTotal(monthly) {
42884
43034
 
42885
43035
  // src/commands/servers.ts
42886
43036
  var import_node_readline2 = __toESM(require("readline"));
42887
- var import_node_os15 = require("os");
43037
+ var import_node_os16 = require("os");
42888
43038
  init_cli_config();
42889
43039
  function connectionStatus(server, now = Date.now()) {
42890
43040
  const seen = server.last_seen ? Date.parse(server.last_seen) : NaN;
@@ -42983,7 +43133,7 @@ async function chooseOrg(orgs, flag, ask2) {
42983
43133
  async function linkServer(opts = {}, ask2 = askChoice) {
42984
43134
  if (!hasSession()) throw new Error("Not logged in. Run: threatcrush login");
42985
43135
  const org = await chooseOrg(await fetchOrgs(), opts.org, ask2);
42986
- const host = opts.hostname ?? (0, import_node_os15.hostname)();
43136
+ const host = opts.hostname ?? (0, import_node_os16.hostname)();
42987
43137
  const listRes = await cloudFetch(`/api/orgs/${org.id}/servers`);
42988
43138
  if (!listRes.ok) throw new Error(`Failed to list servers in /${org.slug} (${listRes.status})`);
42989
43139
  const { servers = [] } = await listRes.json();
@@ -43100,16 +43250,16 @@ function timeAgo(dateStr) {
43100
43250
  }
43101
43251
 
43102
43252
  // src/commands/connect.ts
43103
- var import_node_os16 = require("os");
43104
- var import_node_fs32 = require("fs");
43253
+ var import_node_os17 = require("os");
43254
+ var import_node_fs33 = require("fs");
43105
43255
  var import_node_path28 = require("path");
43106
43256
  var import_node_child_process6 = require("child_process");
43107
43257
  var import_node_net4 = require("net");
43108
43258
  var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
43109
- 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");
43110
43260
  function readConfig2() {
43111
43261
  try {
43112
- 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"));
43113
43263
  } catch {
43114
43264
  return {};
43115
43265
  }
@@ -43281,21 +43431,21 @@ async function sshConnect(options) {
43281
43431
 
43282
43432
  // src/commands/daemon.ts
43283
43433
  var import_node_child_process21 = require("child_process");
43284
- var import_node_fs58 = require("fs");
43285
- var import_node_path46 = require("path");
43286
43434
  var import_node_fs59 = require("fs");
43435
+ var import_node_path47 = require("path");
43436
+ var import_node_fs60 = require("fs");
43287
43437
 
43288
43438
  // src/daemon/index.ts
43289
- var import_node_fs57 = require("fs");
43439
+ var import_node_fs58 = require("fs");
43290
43440
  var import_node_child_process20 = require("child_process");
43291
- var import_node_os18 = require("os");
43292
- var import_node_path45 = require("path");
43441
+ var import_node_os19 = require("os");
43442
+ var import_node_path46 = require("path");
43293
43443
  var import_node_util4 = require("util");
43294
43444
  init_paths();
43295
43445
 
43296
43446
  // src/daemon/ipc-server.ts
43297
43447
  var import_node_net5 = require("net");
43298
- var import_node_fs33 = require("fs");
43448
+ var import_node_fs34 = require("fs");
43299
43449
  init_paths();
43300
43450
  init_control_token();
43301
43451
 
@@ -43353,9 +43503,9 @@ var IpcServer = class {
43353
43503
  controlToken = "";
43354
43504
  async start() {
43355
43505
  this.controlToken = issueControlToken();
43356
- if ((0, import_node_fs33.existsSync)(PATHS.socket)) {
43506
+ if ((0, import_node_fs34.existsSync)(PATHS.socket)) {
43357
43507
  try {
43358
- (0, import_node_fs33.unlinkSync)(PATHS.socket);
43508
+ (0, import_node_fs34.unlinkSync)(PATHS.socket);
43359
43509
  } catch {
43360
43510
  }
43361
43511
  }
@@ -43393,14 +43543,14 @@ var IpcServer = class {
43393
43543
  return new Promise((resolve9) => {
43394
43544
  if (!this.server) {
43395
43545
  try {
43396
- 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);
43397
43547
  } catch {
43398
43548
  }
43399
43549
  return resolve9();
43400
43550
  }
43401
43551
  this.server.close(() => {
43402
43552
  try {
43403
- 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);
43404
43554
  } catch {
43405
43555
  }
43406
43556
  resolve9();
@@ -43580,7 +43730,7 @@ var IpcServer = class {
43580
43730
  }
43581
43731
  }
43582
43732
  };
43583
- 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")) {
43584
43734
  try {
43585
43735
  for (const line2 of readGroup().split("\n")) {
43586
43736
  const [name, , gid] = line2.split(":");
@@ -43596,14 +43746,16 @@ function admGid(readGroup = () => (0, import_node_fs33.readFileSync)("/etc/group
43596
43746
  }
43597
43747
 
43598
43748
  // src/daemon/module-host.ts
43599
- var import_node_fs39 = require("fs");
43600
- var import_node_path30 = require("path");
43749
+ var import_node_fs40 = require("fs");
43750
+ var import_node_path31 = require("path");
43601
43751
  var import_node_url = require("url");
43602
- var import_toml4 = __toESM(require_toml());
43752
+ var import_toml5 = __toESM(require_toml());
43603
43753
  init_paths();
43604
43754
 
43605
43755
  // src/daemon/watchers/log-watcher.ts
43606
- var import_node_fs34 = require("fs");
43756
+ var import_node_fs35 = require("fs");
43757
+ var import_node_path29 = require("path");
43758
+ var import_toml4 = __toESM(require_toml());
43607
43759
  var DEFAULT_SOURCES = [
43608
43760
  { path: "/var/log/auth.log", module: "ssh-guard", category: "auth" },
43609
43761
  { path: "/var/log/secure", module: "ssh-guard", category: "auth" },
@@ -43611,6 +43763,39 @@ var DEFAULT_SOURCES = [
43611
43763
  { path: "/var/log/caddy/agent.database.pit.world.access.log", module: "log-watcher", category: "web" },
43612
43764
  { path: "/var/log/syslog", module: "log-watcher", category: "system" }
43613
43765
  ];
43766
+ function configuredWebSources(configFile, confD) {
43767
+ const paths = [];
43768
+ const take = (v) => {
43769
+ if (!Array.isArray(v)) return;
43770
+ for (const p of v) if (typeof p === "string" && p.startsWith("/")) paths.push(p);
43771
+ };
43772
+ const read = (file) => {
43773
+ try {
43774
+ return import_toml4.default.parse((0, import_node_fs35.readFileSync)(file, "utf-8"));
43775
+ } catch {
43776
+ return null;
43777
+ }
43778
+ };
43779
+ const main = (0, import_node_fs35.existsSync)(configFile) ? read(configFile) : null;
43780
+ take(main?.modules?.["log-watcher"]?.paths);
43781
+ take(main?.["log-watcher"]?.paths);
43782
+ if ((0, import_node_fs35.existsSync)(confD)) {
43783
+ let files = [];
43784
+ try {
43785
+ files = (0, import_node_fs35.readdirSync)(confD).filter((f) => f.endsWith(".conf")).sort();
43786
+ } catch {
43787
+ }
43788
+ for (const f of files) take(read((0, import_node_path29.join)(confD, f))?.["log-watcher"]?.paths);
43789
+ }
43790
+ const known = new Set(DEFAULT_SOURCES.map((s) => s.path));
43791
+ const out = [];
43792
+ for (const path2 of paths) {
43793
+ if (known.has(path2)) continue;
43794
+ known.add(path2);
43795
+ out.push({ path: path2, module: "log-watcher", category: "web" });
43796
+ }
43797
+ return out;
43798
+ }
43614
43799
  var AGENTDB_API_PATH = /^\/v1\/(?:list_databases|inspect_schema|query_readonly|explain_query|cluster_health|backup_status|audit\/events|backup\/(?:create|verify)|tokens(?:\/revoke)?)$/;
43615
43800
  var AGENTDB_HOST = "agent.database.pit.world";
43616
43801
  var LogWatcher = class {
@@ -43626,9 +43811,9 @@ var LogWatcher = class {
43626
43811
  start() {
43627
43812
  const started = [];
43628
43813
  for (const src of this.sources) {
43629
- if (!(0, import_node_fs34.existsSync)(src.path)) continue;
43814
+ if (!(0, import_node_fs35.existsSync)(src.path)) continue;
43630
43815
  try {
43631
- (0, import_node_fs34.accessSync)(src.path, import_node_fs34.constants.R_OK);
43816
+ (0, import_node_fs35.accessSync)(src.path, import_node_fs35.constants.R_OK);
43632
43817
  } catch {
43633
43818
  continue;
43634
43819
  }
@@ -44014,7 +44199,7 @@ function realtimeToDate(rt) {
44014
44199
 
44015
44200
  // src/modules/network-monitor/index.ts
44016
44201
  var import_node_child_process8 = require("child_process");
44017
- var import_node_fs35 = require("fs");
44202
+ var import_node_fs36 = require("fs");
44018
44203
  var NetworkMonitor = class {
44019
44204
  constructor(bus2) {
44020
44205
  this.bus = bus2;
@@ -44078,7 +44263,7 @@ var NetworkMonitor = class {
44078
44263
  hasConntrackOrSs() {
44079
44264
  const ss = (0, import_node_child_process8.spawnSync)("ss", ["--version"], { stdio: "pipe" });
44080
44265
  if (ss.status === 0) return true;
44081
- return (0, import_node_fs35.existsSync)("/proc/net/tcp");
44266
+ return (0, import_node_fs36.existsSync)("/proc/net/tcp");
44082
44267
  }
44083
44268
  /**
44084
44269
  * The TCP ports this host actually listens on.
@@ -44265,18 +44450,18 @@ var NetworkMonitor = class {
44265
44450
  };
44266
44451
 
44267
44452
  // src/modules/dns-monitor/index.ts
44268
- var import_node_fs38 = require("fs");
44453
+ var import_node_fs39 = require("fs");
44269
44454
  var import_node_child_process10 = require("child_process");
44270
44455
  var import_node_readline3 = require("readline");
44271
44456
 
44272
44457
  // src/core/threat-feeds/index.ts
44273
- var import_node_fs37 = require("fs");
44274
- var import_node_path29 = require("path");
44458
+ var import_node_fs38 = require("fs");
44459
+ var import_node_path30 = require("path");
44275
44460
  var import_node_net7 = require("net");
44276
44461
 
44277
44462
  // src/daemon/firewall/protected.ts
44278
44463
  var import_node_child_process9 = require("child_process");
44279
- var import_node_fs36 = require("fs");
44464
+ var import_node_fs37 = require("fs");
44280
44465
  var import_node_net6 = require("net");
44281
44466
  var DEFAULT_PROTECTED = [
44282
44467
  "127.0.0.0/8",
@@ -44346,7 +44531,7 @@ function v4ToBytes(ip) {
44346
44531
  function v6ToBytes(ip) {
44347
44532
  const bare = ip.split("%")[0];
44348
44533
  const [headText, tailText] = bare.split("::", 2);
44349
- const head = headText ? headText.split(":") : [];
44534
+ const head2 = headText ? headText.split(":") : [];
44350
44535
  const tail = tailText !== void 0 ? tailText ? tailText.split(":") : [] : null;
44351
44536
  const groups = [];
44352
44537
  const pushGroup = (group) => {
@@ -44360,7 +44545,7 @@ function v6ToBytes(ip) {
44360
44545
  groups.push(parseInt(group, 16));
44361
44546
  return true;
44362
44547
  };
44363
- for (const group of head) if (!pushGroup(group)) return null;
44548
+ for (const group of head2) if (!pushGroup(group)) return null;
44364
44549
  const headCount = groups.length;
44365
44550
  if (tail === null) {
44366
44551
  if (headCount !== 8) return null;
@@ -44438,14 +44623,14 @@ function moshClients(procDir = "/proc") {
44438
44623
  const found = /* @__PURE__ */ new Set();
44439
44624
  let pids = [];
44440
44625
  try {
44441
- pids = (0, import_node_fs36.readdirSync)(procDir).filter((p) => /^\d+$/.test(p));
44626
+ pids = (0, import_node_fs37.readdirSync)(procDir).filter((p) => /^\d+$/.test(p));
44442
44627
  } catch {
44443
44628
  return [];
44444
44629
  }
44445
44630
  for (const pid of pids) {
44446
44631
  try {
44447
- if ((0, import_node_fs36.readFileSync)(`${procDir}/${pid}/comm`, "utf-8").trim() !== "mosh-server") continue;
44448
- const ip = sshClientFromEnviron((0, import_node_fs36.readFileSync)(`${procDir}/${pid}/environ`, "latin1"));
44632
+ if ((0, import_node_fs37.readFileSync)(`${procDir}/${pid}/comm`, "utf-8").trim() !== "mosh-server") continue;
44633
+ const ip = sshClientFromEnviron((0, import_node_fs37.readFileSync)(`${procDir}/${pid}/environ`, "latin1"));
44449
44634
  if (ip) found.add(ip);
44450
44635
  } catch {
44451
44636
  }
@@ -44651,17 +44836,17 @@ async function fetchFeeds(settings, fetchImpl = fetch) {
44651
44836
  }
44652
44837
  function readFeedCache(path2) {
44653
44838
  try {
44654
- const set = JSON.parse((0, import_node_fs37.readFileSync)(path2, "utf-8"));
44839
+ const set = JSON.parse((0, import_node_fs38.readFileSync)(path2, "utf-8"));
44655
44840
  return set && typeof set.ips === "object" && typeof set.domains === "object" ? set : null;
44656
44841
  } catch {
44657
44842
  return null;
44658
44843
  }
44659
44844
  }
44660
44845
  function writeFeedCache(path2, set) {
44661
- (0, import_node_fs37.mkdirSync)((0, import_node_path29.dirname)(path2), { recursive: true });
44846
+ (0, import_node_fs38.mkdirSync)((0, import_node_path30.dirname)(path2), { recursive: true });
44662
44847
  const tmp = `${path2}.tmp`;
44663
- (0, import_node_fs37.writeFileSync)(tmp, JSON.stringify(set));
44664
- (0, import_node_fs37.renameSync)(tmp, path2);
44848
+ (0, import_node_fs38.writeFileSync)(tmp, JSON.stringify(set));
44849
+ (0, import_node_fs38.renameSync)(tmp, path2);
44665
44850
  }
44666
44851
  var RESOLVER_FILES = {
44667
44852
  hosts: "blocked-domains.hosts",
@@ -44786,9 +44971,9 @@ var DnsMonitor = class {
44786
44971
  }
44787
44972
  start() {
44788
44973
  const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
44789
- if (!(0, import_node_fs38.existsSync)(p)) return false;
44974
+ if (!(0, import_node_fs39.existsSync)(p)) return false;
44790
44975
  try {
44791
- (0, import_node_fs38.accessSync)(p, import_node_fs38.constants.R_OK);
44976
+ (0, import_node_fs39.accessSync)(p, import_node_fs39.constants.R_OK);
44792
44977
  return true;
44793
44978
  } catch {
44794
44979
  return false;
@@ -45057,7 +45242,10 @@ var ModuleHost = class {
45057
45242
  async start() {
45058
45243
  this.registerBuiltins();
45059
45244
  await this.discoverAndStartInstalled();
45060
- this.logWatcher = new LogWatcher(this.bus);
45245
+ this.logWatcher = new LogWatcher(this.bus, [
45246
+ ...DEFAULT_SOURCES,
45247
+ ...configuredWebSources(PATHS.configFile, PATHS.confD)
45248
+ ]);
45061
45249
  const watched = this.logWatcher.start();
45062
45250
  for (const modName of this.logWatcher.activeModules()) {
45063
45251
  const mod = this.modules.get(modName);
@@ -45145,15 +45333,15 @@ var ModuleHost = class {
45145
45333
  }
45146
45334
  }
45147
45335
  async discoverAndStartInstalled() {
45148
- if (!(0, import_node_fs39.existsSync)(PATHS.moduleDir)) return;
45336
+ if (!(0, import_node_fs40.existsSync)(PATHS.moduleDir)) return;
45149
45337
  const configs = loadModuleConfigs(PATHS.confD);
45150
- const entries = (0, import_node_fs39.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
45338
+ const entries = (0, import_node_fs40.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
45151
45339
  for (const entry of entries) {
45152
45340
  if (!entry.isDirectory()) continue;
45153
- const manifestPath = (0, import_node_path30.join)(PATHS.moduleDir, entry.name, "mod.toml");
45154
- if (!(0, import_node_fs39.existsSync)(manifestPath)) continue;
45341
+ const manifestPath = (0, import_node_path31.join)(PATHS.moduleDir, entry.name, "mod.toml");
45342
+ if (!(0, import_node_fs40.existsSync)(manifestPath)) continue;
45155
45343
  try {
45156
- const manifest = import_toml4.default.parse((0, import_node_fs39.readFileSync)(manifestPath, "utf-8"));
45344
+ const manifest = import_toml5.default.parse((0, import_node_fs40.readFileSync)(manifestPath, "utf-8"));
45157
45345
  const name = manifest.module?.name || entry.name;
45158
45346
  const defaults = manifest.module?.config?.defaults || {};
45159
45347
  const config = {
@@ -45167,7 +45355,7 @@ var ModuleHost = class {
45167
45355
  source: "installed",
45168
45356
  status: config.enabled === false ? "disabled" : "loaded",
45169
45357
  events: 0,
45170
- path: (0, import_node_path30.join)(PATHS.moduleDir, entry.name),
45358
+ path: (0, import_node_path31.join)(PATHS.moduleDir, entry.name),
45171
45359
  config
45172
45360
  };
45173
45361
  this.modules.set(name, hosted);
@@ -45182,7 +45370,7 @@ var ModuleHost = class {
45182
45370
  status: "error",
45183
45371
  events: 0,
45184
45372
  detail: `manifest load failed: ${String(err.message || err)}`,
45185
- path: (0, import_node_path30.join)(PATHS.moduleDir, entry.name)
45373
+ path: (0, import_node_path31.join)(PATHS.moduleDir, entry.name)
45186
45374
  });
45187
45375
  }
45188
45376
  }
@@ -45221,17 +45409,17 @@ var ModuleHost = class {
45221
45409
  }
45222
45410
  }
45223
45411
  installedEntrypoint(modulePath) {
45224
- const packageJson = (0, import_node_path30.join)(modulePath, "package.json");
45412
+ const packageJson = (0, import_node_path31.join)(modulePath, "package.json");
45225
45413
  const candidates = [];
45226
- if ((0, import_node_fs39.existsSync)(packageJson)) {
45414
+ if ((0, import_node_fs40.existsSync)(packageJson)) {
45227
45415
  try {
45228
- const pkg = JSON.parse((0, import_node_fs39.readFileSync)(packageJson, "utf-8"));
45229
- if (pkg.main) candidates.push((0, import_node_path30.join)(modulePath, pkg.main));
45416
+ const pkg = JSON.parse((0, import_node_fs40.readFileSync)(packageJson, "utf-8"));
45417
+ if (pkg.main) candidates.push((0, import_node_path31.join)(modulePath, pkg.main));
45230
45418
  } catch {
45231
45419
  }
45232
45420
  }
45233
- candidates.push((0, import_node_path30.join)(modulePath, "dist", "index.js"), (0, import_node_path30.join)(modulePath, "index.js"));
45234
- return candidates.find((candidate) => (0, import_node_fs39.existsSync)(candidate)) || null;
45421
+ candidates.push((0, import_node_path31.join)(modulePath, "dist", "index.js"), (0, import_node_path31.join)(modulePath, "index.js"));
45422
+ return candidates.find((candidate) => (0, import_node_fs40.existsSync)(candidate)) || null;
45235
45423
  }
45236
45424
  isThreatCrushModule(value) {
45237
45425
  return Boolean(
@@ -45428,11 +45616,11 @@ function pagerdutyChannel(config) {
45428
45616
  }
45429
45617
 
45430
45618
  // src/daemon/alerts/smshub.ts
45431
- var import_node_os17 = require("os");
45619
+ var import_node_os18 = require("os");
45432
45620
  var SEVERITY_RANK6 = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
45433
45621
  var DEDUPE_MS = 10 * 6e4;
45434
45622
  var MAX_PER_HOUR = 6;
45435
- function smshubText(event, host = (0, import_node_os17.hostname)()) {
45623
+ function smshubText(event, host = (0, import_node_os18.hostname)()) {
45436
45624
  const evidence = event.details?.evidence?.message;
45437
45625
  const ip = event.source_ip && ![event.message, evidence ?? ""].some((t) => t.includes(event.source_ip)) ? ` from ${event.source_ip}` : "";
45438
45626
  const text = `ThreatCrush ${event.severity.toUpperCase()} on ${host}: ${event.message}${evidence && !event.message.includes(evidence) ? ` | ${evidence}` : ""}${ip}`;
@@ -45552,14 +45740,14 @@ function slackChannel(webhookUrl) {
45552
45740
  }
45553
45741
 
45554
45742
  // src/daemon/workers/runs-worker.ts
45555
- var import_promises6 = require("dns/promises");
45556
- var import_node_fs40 = require("fs");
45743
+ var import_promises7 = require("dns/promises");
45744
+ var import_node_fs41 = require("fs");
45557
45745
  var import_node_net9 = require("net");
45558
- var import_node_path31 = require("path");
45746
+ var import_node_path32 = require("path");
45559
45747
  init_cli_config();
45560
45748
 
45561
45749
  // src/core/cloud-events.ts
45562
- var import_node_crypto9 = require("crypto");
45750
+ var import_node_crypto10 = require("crypto");
45563
45751
  var import_node_net8 = require("net");
45564
45752
  init_cli_config();
45565
45753
  function currentLink() {
@@ -45643,7 +45831,7 @@ function remediationEvent(serverId, event) {
45643
45831
  return {
45644
45832
  type: "remediation",
45645
45833
  server_id: serverId,
45646
- event_id: (0, import_node_crypto9.randomUUID)(),
45834
+ event_id: (0, import_node_crypto10.randomUUID)(),
45647
45835
  action_type: d.action,
45648
45836
  target_value: event.source_ip,
45649
45837
  status: d.failed === true ? "failed" : "executed",
@@ -45687,7 +45875,7 @@ var NOT_PUBLIC = [
45687
45875
  function isPublicTarget(ip) {
45688
45876
  return (0, import_node_net9.isIP)(ip) !== 0 && !isProtected(ip, NOT_PUBLIC);
45689
45877
  }
45690
- async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0, import_promises6.lookup)(h, { all: true })).map((a) => a.address)) {
45878
+ async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0, import_promises7.lookup)(h, { all: true })).map((a) => a.address)) {
45691
45879
  let url;
45692
45880
  try {
45693
45881
  url = new URL(rawUrl.startsWith("http") ? rawUrl : `https://${rawUrl}`);
@@ -45706,24 +45894,24 @@ async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0,
45706
45894
  const inside = addresses.find((a) => !isPublicTarget(a));
45707
45895
  return inside ? `${host} resolves to ${inside}, which is not a public address; dashboard runs never reach inside this network` : null;
45708
45896
  }
45709
- function scanTargetError(target, roots, real = import_node_fs40.realpathSync) {
45897
+ function scanTargetError(target, roots, real = import_node_fs41.realpathSync) {
45710
45898
  if (roots.length === 0) {
45711
45899
  return "dashboard scans of this machine are off; list the directories they may read in [cloud] run_scan_paths";
45712
45900
  }
45713
45901
  let path2;
45714
45902
  try {
45715
- path2 = real((0, import_node_path31.resolve)(target));
45903
+ path2 = real((0, import_node_path32.resolve)(target));
45716
45904
  } catch {
45717
45905
  return `no such path: ${target}`;
45718
45906
  }
45719
45907
  for (const root of roots) {
45720
45908
  let base;
45721
45909
  try {
45722
- base = real((0, import_node_path31.resolve)(root));
45910
+ base = real((0, import_node_path32.resolve)(root));
45723
45911
  } catch {
45724
45912
  continue;
45725
45913
  }
45726
- if (path2 === base || path2.startsWith(base.endsWith(import_node_path31.sep) ? base : base + import_node_path31.sep)) return null;
45914
+ if (path2 === base || path2.startsWith(base.endsWith(import_node_path32.sep) ? base : base + import_node_path32.sep)) return null;
45727
45915
  }
45728
45916
  return `${target} is outside [cloud] run_scan_paths`;
45729
45917
  }
@@ -45877,16 +46065,16 @@ var RunsWorker = class {
45877
46065
  init_cli_config();
45878
46066
 
45879
46067
  // src/daemon/workers/cloud-spool.ts
45880
- var import_node_fs41 = require("fs");
45881
- var import_promises7 = require("fs/promises");
45882
- var import_node_path32 = require("path");
46068
+ var import_node_fs42 = require("fs");
46069
+ var import_promises8 = require("fs/promises");
46070
+ var import_node_path33 = require("path");
45883
46071
  var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
45884
46072
  var CloudSpool = class {
45885
46073
  constructor(path2, limits = DEFAULT_SPOOL_LIMITS) {
45886
46074
  this.path = path2;
45887
46075
  this.limits = limits;
45888
46076
  try {
45889
- (0, import_node_fs41.mkdirSync)((0, import_node_path32.dirname)(path2), { recursive: true });
46077
+ (0, import_node_fs42.mkdirSync)((0, import_node_path33.dirname)(path2), { recursive: true });
45890
46078
  } catch {
45891
46079
  }
45892
46080
  this.load();
@@ -45955,7 +46143,7 @@ var CloudSpool = class {
45955
46143
  load() {
45956
46144
  let raw;
45957
46145
  try {
45958
- raw = (0, import_node_fs41.readFileSync)(this.path, "utf-8");
46146
+ raw = (0, import_node_fs42.readFileSync)(this.path, "utf-8");
45959
46147
  } catch {
45960
46148
  return;
45961
46149
  }
@@ -45986,13 +46174,13 @@ var CloudSpool = class {
45986
46174
  const body = this.lines.length > 0 ? `${this.lines.join("\n")}
45987
46175
  ` : "";
45988
46176
  const tmp = `${this.path}.tmp`;
45989
- await (0, import_promises7.writeFile)(tmp, body, { mode: 384 });
45990
- await (0, import_promises7.rename)(tmp, this.path);
46177
+ await (0, import_promises8.writeFile)(tmp, body, { mode: 384 });
46178
+ await (0, import_promises8.rename)(tmp, this.path);
45991
46179
  } else if (this.pendingAppend.length > 0) {
45992
46180
  const chunk2 = `${this.pendingAppend.join("\n")}
45993
46181
  `;
45994
46182
  this.pendingAppend = [];
45995
- await (0, import_promises7.appendFile)(this.path, chunk2, { mode: 384 });
46183
+ await (0, import_promises8.appendFile)(this.path, chunk2, { mode: 384 });
45996
46184
  }
45997
46185
  }).catch(() => {
45998
46186
  this.needsRewrite = true;
@@ -46200,7 +46388,7 @@ var CloudSync = class {
46200
46388
  };
46201
46389
 
46202
46390
  // src/daemon/workers/abuse-reporter.ts
46203
- var import_node_crypto10 = require("crypto");
46391
+ var import_node_crypto11 = require("crypto");
46204
46392
 
46205
46393
  // src/daemon/workers/abuse-evidence.ts
46206
46394
  var import_node_net10 = require("net");
@@ -46429,32 +46617,32 @@ function resolveConfig(section) {
46429
46617
  }
46430
46618
 
46431
46619
  // src/core/abuse-report-log.ts
46432
- var import_node_fs42 = require("fs");
46433
- var import_node_path33 = require("path");
46620
+ var import_node_fs43 = require("fs");
46621
+ var import_node_path34 = require("path");
46434
46622
  init_paths();
46435
46623
  var ABUSE_DIRNAME = "abuse-reports";
46436
46624
  var LOG_FILE2 = "reports.jsonl";
46437
46625
  function resolveAbuseDir(dir) {
46438
46626
  if (dir) return dir;
46439
46627
  if (process.env.THREATCRUSH_ABUSE_DIR) return process.env.THREATCRUSH_ABUSE_DIR;
46440
- const system = (0, import_node_path33.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
46441
- if ((0, import_node_fs42.existsSync)(system)) return system;
46442
- return (0, import_node_path33.join)(PATHS.stateDir, ABUSE_DIRNAME);
46628
+ const system = (0, import_node_path34.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
46629
+ if ((0, import_node_fs43.existsSync)(system)) return system;
46630
+ return (0, import_node_path34.join)(PATHS.stateDir, ABUSE_DIRNAME);
46443
46631
  }
46444
46632
  function logPath(dir) {
46445
- return (0, import_node_path33.join)(resolveAbuseDir(dir), LOG_FILE2);
46633
+ return (0, import_node_path34.join)(resolveAbuseDir(dir), LOG_FILE2);
46446
46634
  }
46447
46635
  function appendReport(record, dir) {
46448
46636
  const path2 = logPath(dir);
46449
- (0, import_node_fs42.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
46450
- (0, import_node_fs42.appendFileSync)(path2, `${JSON.stringify(record)}
46637
+ (0, import_node_fs43.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
46638
+ (0, import_node_fs43.appendFileSync)(path2, `${JSON.stringify(record)}
46451
46639
  `, { mode: 420 });
46452
46640
  }
46453
46641
  function readReports(dir) {
46454
46642
  const path2 = logPath(dir);
46455
46643
  let raw;
46456
46644
  try {
46457
- raw = (0, import_node_fs42.readFileSync)(path2, "utf-8");
46645
+ raw = (0, import_node_fs43.readFileSync)(path2, "utf-8");
46458
46646
  } catch {
46459
46647
  return [];
46460
46648
  }
@@ -46593,7 +46781,7 @@ var AbuseReporter = class {
46593
46781
  const payload = buildPayload(ip, evidence);
46594
46782
  const results = this.cfg.dryRun ? [] : await dispatch(payload, this.cfg.destinations, this.cfg.keys);
46595
46783
  const record = {
46596
- id: (0, import_node_crypto10.randomUUID)().slice(0, 8),
46784
+ id: (0, import_node_crypto11.randomUUID)().slice(0, 8),
46597
46785
  ip,
46598
46786
  reported_at: new Date(now).toISOString(),
46599
46787
  mode: this.cfg.dryRun ? "dry_run" : "live",
@@ -46880,8 +47068,8 @@ var RemediationConsumer = class {
46880
47068
 
46881
47069
  // src/daemon/workers/auto-update.ts
46882
47070
  var import_node_child_process11 = require("child_process");
46883
- var import_node_fs43 = require("fs");
46884
- var import_node_path34 = require("path");
47071
+ var import_node_fs44 = require("fs");
47072
+ var import_node_path35 = require("path");
46885
47073
  init_backoff();
46886
47074
  var PKG_NAME = "@profullstack/threatcrush";
46887
47075
  var REGISTRY = `https://registry.npmjs.org/${PKG_NAME}`;
@@ -46925,12 +47113,12 @@ function pickUpdate(doc, current, opts) {
46925
47113
  return { version: null, reason: `${latest} is younger than min_age, and nothing older is newer than ${current}; waiting` };
46926
47114
  }
46927
47115
  function installPlan(opts) {
46928
- const expected = `${import_node_path34.sep}lib${import_node_path34.sep}node_modules${import_node_path34.sep}@profullstack${import_node_path34.sep}threatcrush`;
47116
+ const expected = `${import_node_path35.sep}lib${import_node_path35.sep}node_modules${import_node_path35.sep}@profullstack${import_node_path35.sep}threatcrush`;
46929
47117
  if (!opts.pkgRoot.endsWith(expected)) {
46930
47118
  return { kind: "unsupported", reason: `not an npm global install (${opts.pkgRoot}); run \`threatcrush update\`` };
46931
47119
  }
46932
- const nodeBin = (0, import_node_path34.dirname)(opts.execPath);
46933
- const npm = (0, import_node_path34.join)(nodeBin, "npm");
47120
+ const nodeBin = (0, import_node_path35.dirname)(opts.execPath);
47121
+ const npm = (0, import_node_path35.join)(nodeBin, "npm");
46934
47122
  if (!opts.npmExists(npm)) return { kind: "unsupported", reason: `no npm beside ${opts.execPath}` };
46935
47123
  if (!opts.owner) return { kind: "unsupported", reason: `cannot tell who owns ${opts.pkgRoot}` };
46936
47124
  const npmArgs = [npm, "i", "-g", `${PKG_NAME}@${opts.version}`, "--no-fund", "--no-audit"];
@@ -46962,10 +47150,10 @@ function installPlan(opts) {
46962
47150
  }
46963
47151
  function ownerOf(path2, passwd = "/etc/passwd") {
46964
47152
  try {
46965
- const st = (0, import_node_fs43.statSync)(path2);
47153
+ const st = (0, import_node_fs44.statSync)(path2);
46966
47154
  let home = st.uid === 0 ? "/root" : "";
46967
47155
  try {
46968
- for (const line2 of (0, import_node_fs43.readFileSync)(passwd, "utf8").split("\n")) {
47156
+ for (const line2 of (0, import_node_fs44.readFileSync)(passwd, "utf8").split("\n")) {
46969
47157
  const f = line2.split(":");
46970
47158
  if (Number(f[2]) === st.uid && f[5]) home = f[5];
46971
47159
  }
@@ -47075,7 +47263,7 @@ var AutoUpdate = class {
47075
47263
  uid: process.getuid?.() ?? -1,
47076
47264
  owner: ownerOf(this.opts.pkgRoot),
47077
47265
  underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
47078
- npmExists: import_node_fs43.existsSync
47266
+ npmExists: import_node_fs44.existsSync
47079
47267
  });
47080
47268
  if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
47081
47269
  this.recordAttempt(target);
@@ -47111,7 +47299,7 @@ var AutoUpdate = class {
47111
47299
  }
47112
47300
  lastAttempt() {
47113
47301
  try {
47114
- const v = JSON.parse((0, import_node_fs43.readFileSync)(this.opts.statePath, "utf8"));
47302
+ const v = JSON.parse((0, import_node_fs44.readFileSync)(this.opts.statePath, "utf8"));
47115
47303
  return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
47116
47304
  } catch {
47117
47305
  return null;
@@ -47119,7 +47307,7 @@ var AutoUpdate = class {
47119
47307
  }
47120
47308
  recordAttempt(version) {
47121
47309
  try {
47122
- (0, import_node_fs43.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
47310
+ (0, import_node_fs44.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
47123
47311
  } catch (err) {
47124
47312
  this.opts.log(`[update] could not record attempt: ${err.message}`);
47125
47313
  }
@@ -47128,8 +47316,8 @@ var AutoUpdate = class {
47128
47316
 
47129
47317
  // src/daemon/workers/threat-feeds.ts
47130
47318
  var import_node_child_process12 = require("child_process");
47131
- var import_node_fs44 = require("fs");
47132
- var import_node_path35 = require("path");
47319
+ var import_node_fs45 = require("fs");
47320
+ var import_node_path36 = require("path");
47133
47321
  var import_node_net13 = require("net");
47134
47322
  init_backoff();
47135
47323
  var EGRESS_TABLE = "threatcrush_egress";
@@ -47301,14 +47489,14 @@ var ThreatFeeds = class {
47301
47489
  */
47302
47490
  writeResolverFiles(set) {
47303
47491
  const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
47304
- const dir = this.opts.resolverDir ?? (0, import_node_path35.dirname)(this.opts.cachePath);
47492
+ const dir = this.opts.resolverDir ?? (0, import_node_path36.dirname)(this.opts.cachePath);
47305
47493
  const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
47306
47494
  const write = (name, content) => {
47307
- const path2 = (0, import_node_path35.join)(dir, name);
47495
+ const path2 = (0, import_node_path36.join)(dir, name);
47308
47496
  if (this.resolverWritten.get(name) === content) return false;
47309
47497
  try {
47310
- (0, import_node_fs44.writeFileSync)(`${path2}.tmp`, content);
47311
- (0, import_node_fs44.renameSync)(`${path2}.tmp`, path2);
47498
+ (0, import_node_fs45.writeFileSync)(`${path2}.tmp`, content);
47499
+ (0, import_node_fs45.renameSync)(`${path2}.tmp`, path2);
47312
47500
  this.resolverWritten.set(name, content);
47313
47501
  return true;
47314
47502
  } catch (err) {
@@ -47319,11 +47507,11 @@ var ThreatFeeds = class {
47319
47507
  const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
47320
47508
  const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
47321
47509
  const via = [];
47322
- if ((0, import_node_fs44.existsSync)(hooks.dnsmasq)) {
47510
+ if ((0, import_node_fs45.existsSync)(hooks.dnsmasq)) {
47323
47511
  via.push("dnsmasq");
47324
47512
  if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
47325
47513
  }
47326
- if ((0, import_node_fs44.existsSync)(hooks.unbound)) {
47514
+ if ((0, import_node_fs45.existsSync)(hooks.unbound)) {
47327
47515
  via.push("unbound");
47328
47516
  if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
47329
47517
  this.run("systemctl", ["reload", "unbound.service"]);
@@ -47384,12 +47572,12 @@ var ThreatFeeds = class {
47384
47572
  };
47385
47573
 
47386
47574
  // src/daemon/workers/privilege-watch.ts
47387
- var import_node_fs45 = require("fs");
47388
- var import_node_path36 = require("path");
47575
+ var import_node_fs46 = require("fs");
47576
+ var import_node_path37 = require("path");
47389
47577
  var import_node_child_process13 = require("child_process");
47390
47578
 
47391
47579
  // src/core/privileges/index.ts
47392
- var import_node_crypto11 = require("crypto");
47580
+ var import_node_crypto12 = require("crypto");
47393
47581
  var ADMIN_GROUPS = ["sudo", "wheel", "admin"];
47394
47582
  function parseUsers(text) {
47395
47583
  const out = [];
@@ -47430,7 +47618,7 @@ function sudoReadsIncluded(name) {
47430
47618
  }
47431
47619
  function keyFingerprint(blobBase64) {
47432
47620
  if (!/^[A-Za-z0-9+/]+=*$/.test(blobBase64)) return null;
47433
- const digest = (0, import_node_crypto11.createHash)("sha256").update(Buffer.from(blobBase64, "base64")).digest("base64");
47621
+ const digest = (0, import_node_crypto12.createHash)("sha256").update(Buffer.from(blobBase64, "base64")).digest("base64");
47434
47622
  return `SHA256:${digest.replace(/=+$/, "")}`;
47435
47623
  }
47436
47624
  function parseAuthorizedKeys(text) {
@@ -47611,31 +47799,31 @@ function countryName(code) {
47611
47799
  var fsIO = {
47612
47800
  readFile: (p) => {
47613
47801
  try {
47614
- return (0, import_node_fs45.readFileSync)(p, "utf-8");
47802
+ return (0, import_node_fs46.readFileSync)(p, "utf-8");
47615
47803
  } catch {
47616
47804
  return null;
47617
47805
  }
47618
47806
  },
47619
47807
  readDir: (p) => {
47620
47808
  try {
47621
- return (0, import_node_fs45.readdirSync)(p);
47809
+ return (0, import_node_fs46.readdirSync)(p);
47622
47810
  } catch {
47623
47811
  return null;
47624
47812
  }
47625
47813
  },
47626
- exists: (p) => (0, import_node_fs45.existsSync)(p)
47814
+ exists: (p) => (0, import_node_fs46.existsSync)(p)
47627
47815
  };
47628
47816
  function readJson(path2) {
47629
47817
  try {
47630
- return JSON.parse((0, import_node_fs45.readFileSync)(path2, "utf-8"));
47818
+ return JSON.parse((0, import_node_fs46.readFileSync)(path2, "utf-8"));
47631
47819
  } catch {
47632
47820
  return null;
47633
47821
  }
47634
47822
  }
47635
47823
  function writeJson(path2, value) {
47636
- (0, import_node_fs45.mkdirSync)((0, import_node_path36.dirname)(path2), { recursive: true });
47637
- (0, import_node_fs45.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
47638
- (0, import_node_fs45.renameSync)(`${path2}.tmp`, path2);
47824
+ (0, import_node_fs46.mkdirSync)((0, import_node_path37.dirname)(path2), { recursive: true });
47825
+ (0, import_node_fs46.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
47826
+ (0, import_node_fs46.renameSync)(`${path2}.tmp`, path2);
47639
47827
  }
47640
47828
  function defaultRun3(cmd, args) {
47641
47829
  const res = (0, import_node_child_process13.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 2e4, maxBuffer: 16 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
@@ -47752,7 +47940,7 @@ var PrivilegeWatch = class {
47752
47940
  for (const dir of dirs) {
47753
47941
  if (this.watchers.has(dir) || !this.io.exists(dir)) continue;
47754
47942
  try {
47755
- const w = (0, import_node_fs45.watch)(dir, { persistent: false }, (_type2, name) => {
47943
+ const w = (0, import_node_fs46.watch)(dir, { persistent: false }, (_type2, name) => {
47756
47944
  if (name && !String(name).startsWith("authorized_keys")) return;
47757
47945
  if (this.debounce) clearTimeout(this.debounce);
47758
47946
  this.debounce = setTimeout(() => {
@@ -47851,7 +48039,7 @@ var PrivilegeWatch = class {
47851
48039
  * raised a "new country" alert on its first run; on dev2 it did, at once.
47852
48040
  */
47853
48041
  async backfillLogins() {
47854
- if ((0, import_node_fs45.existsSync)(this.opts.loginsPath)) return;
48042
+ if ((0, import_node_fs46.existsSync)(this.opts.loginsPath)) return;
47855
48043
  const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
47856
48044
  const byUser = parseAcceptedLogins(out ?? "");
47857
48045
  const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
@@ -47864,7 +48052,7 @@ var PrivilegeWatch = class {
47864
48052
  return;
47865
48053
  }
47866
48054
  }
47867
- if ((0, import_node_fs45.existsSync)(this.opts.loginsPath)) return;
48055
+ if ((0, import_node_fs46.existsSync)(this.opts.loginsPath)) return;
47868
48056
  const at = this.now().toISOString();
47869
48057
  const history = {};
47870
48058
  for (const [user, userIps] of byUser) {
@@ -47916,11 +48104,11 @@ var PrivilegeWatch = class {
47916
48104
  };
47917
48105
 
47918
48106
  // src/daemon/workers/command-history.ts
47919
- var import_node_fs46 = require("fs");
48107
+ var import_node_fs47 = require("fs");
47920
48108
  var import_node_child_process14 = require("child_process");
47921
- var import_node_path37 = require("path");
48109
+ var import_node_path38 = require("path");
47922
48110
  var import_node_zlib2 = require("zlib");
47923
- var import_node_crypto12 = require("crypto");
48111
+ var import_node_crypto13 = require("crypto");
47924
48112
  var POLL_MS3 = 6e4;
47925
48113
  var MAX_HISTORY_BYTES = 4 * 1024 * 1024;
47926
48114
  var MAX_COMPRESSED_HISTORY_BYTES = MAX_HISTORY_BYTES + 65536;
@@ -47941,7 +48129,7 @@ function historyAccounts() {
47941
48129
  passwd = (0, import_node_child_process14.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
47942
48130
  } catch {
47943
48131
  try {
47944
- passwd = (0, import_node_fs46.readFileSync)("/etc/passwd", "utf8");
48132
+ passwd = (0, import_node_fs47.readFileSync)("/etc/passwd", "utf8");
47945
48133
  } catch {
47946
48134
  return [];
47947
48135
  }
@@ -47954,9 +48142,9 @@ function historyAccounts() {
47954
48142
  const name = fields[0] ?? "";
47955
48143
  const home = fields[5] ?? "";
47956
48144
  const shell = fields[6] ?? "";
47957
- if (!Number.isInteger(uid) || !Number.isInteger(gid) || !(0, import_node_path37.isAbsolute)(home) || home === "/" || home.split("/").includes("..")) return [];
48145
+ if (!Number.isInteger(uid) || !Number.isInteger(gid) || !(0, import_node_path38.isAbsolute)(home) || home === "/" || home.split("/").includes("..")) return [];
47958
48146
  if (root ? uid !== 0 && uid < 1e3 : uid !== process.getuid?.()) return [];
47959
- if (!HISTORY_TARGETS[(0, import_node_path37.basename)(shell)]) return [];
48147
+ if (!HISTORY_TARGETS[(0, import_node_path38.basename)(shell)]) return [];
47960
48148
  return [{ uid, gid, name, home, shell }];
47961
48149
  });
47962
48150
  }
@@ -47967,18 +48155,18 @@ function descriptorPath(directoryFd, name) {
47967
48155
  return `/proc/self/fd/${directoryFd}/${name}`;
47968
48156
  }
47969
48157
  function openDirectoryChain(path2) {
47970
- 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");
47971
- const flags = import_node_fs46.constants.O_RDONLY | import_node_fs46.constants.O_DIRECTORY | (import_node_fs46.constants.O_NOFOLLOW ?? 0);
47972
- let fd = (0, import_node_fs46.openSync)("/", flags);
48158
+ if (!(0, import_node_path38.isAbsolute)(path2) || path2.split(import_node_path38.sep).includes("..")) throw new Error("directory path is not a safe absolute path");
48159
+ const flags = import_node_fs47.constants.O_RDONLY | import_node_fs47.constants.O_DIRECTORY | (import_node_fs47.constants.O_NOFOLLOW ?? 0);
48160
+ let fd = (0, import_node_fs47.openSync)("/", flags);
47973
48161
  try {
47974
- for (const part of path2.split(import_node_path37.sep).filter((item) => item && item !== ".")) {
47975
- const next = (0, import_node_fs46.openSync)(descriptorPath(fd, part), flags);
47976
- (0, import_node_fs46.closeSync)(fd);
48162
+ for (const part of path2.split(import_node_path38.sep).filter((item) => item && item !== ".")) {
48163
+ const next = (0, import_node_fs47.openSync)(descriptorPath(fd, part), flags);
48164
+ (0, import_node_fs47.closeSync)(fd);
47977
48165
  fd = next;
47978
48166
  }
47979
48167
  return fd;
47980
48168
  } catch (error2) {
47981
- (0, import_node_fs46.closeSync)(fd);
48169
+ (0, import_node_fs47.closeSync)(fd);
47982
48170
  throw error2;
47983
48171
  }
47984
48172
  }
@@ -47986,89 +48174,89 @@ function readExact(fd, size) {
47986
48174
  const data = Buffer.alloc(size);
47987
48175
  let offset = 0;
47988
48176
  while (offset < data.length) {
47989
- const read = (0, import_node_fs46.readSync)(fd, data, offset, data.length - offset, offset);
48177
+ const read = (0, import_node_fs47.readSync)(fd, data, offset, data.length - offset, offset);
47990
48178
  if (read === 0) break;
47991
48179
  offset += read;
47992
48180
  }
47993
48181
  return offset === data.length ? data : null;
47994
48182
  }
47995
48183
  function privateDirectory(path2) {
47996
- (0, import_node_fs46.mkdirSync)(path2, { recursive: true, mode: 448 });
47997
- const stat = (0, import_node_fs46.lstatSync)(path2);
48184
+ (0, import_node_fs47.mkdirSync)(path2, { recursive: true, mode: 448 });
48185
+ const stat = (0, import_node_fs47.lstatSync)(path2);
47998
48186
  if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error("history storage path is not a directory");
47999
- (0, import_node_fs46.chmodSync)(path2, 448);
48187
+ (0, import_node_fs47.chmodSync)(path2, 448);
48000
48188
  }
48001
48189
  function safeReadHistory(directoryFd, name, uid) {
48002
- const noFollow = import_node_fs46.constants.O_NOFOLLOW ?? 0;
48003
- const fd = (0, import_node_fs46.openSync)(descriptorPath(directoryFd, name), import_node_fs46.constants.O_RDONLY | noFollow);
48190
+ const noFollow = import_node_fs47.constants.O_NOFOLLOW ?? 0;
48191
+ const fd = (0, import_node_fs47.openSync)(descriptorPath(directoryFd, name), import_node_fs47.constants.O_RDONLY | noFollow);
48004
48192
  try {
48005
- const opened = (0, import_node_fs46.fstatSync)(fd);
48193
+ const opened = (0, import_node_fs47.fstatSync)(fd);
48006
48194
  if (!opened.isFile() || opened.nlink !== 1 || opened.uid !== uid) return null;
48007
48195
  if (opened.size > MAX_HISTORY_BYTES) throw new Error(`history file exceeds ${MAX_HISTORY_BYTES} bytes`);
48008
48196
  const data = readExact(fd, opened.size);
48009
48197
  if (data === null) return null;
48010
- const after = (0, import_node_fs46.fstatSync)(fd);
48198
+ const after = (0, import_node_fs47.fstatSync)(fd);
48011
48199
  if (after.size !== opened.size || after.mtimeMs !== opened.mtimeMs) return null;
48012
48200
  return data;
48013
48201
  } finally {
48014
- (0, import_node_fs46.closeSync)(fd);
48202
+ (0, import_node_fs47.closeSync)(fd);
48015
48203
  }
48016
48204
  }
48017
48205
  function atomicWrite(path2, data, mode = 384, owner, parentFd) {
48018
- const dirFd = parentFd ?? openDirectoryChain((0, import_node_path37.dirname)(path2));
48206
+ const dirFd = parentFd ?? openDirectoryChain((0, import_node_path38.dirname)(path2));
48019
48207
  const ownsDirFd = parentFd === void 0;
48020
- const name = (0, import_node_path37.basename)(path2);
48021
- const temp = descriptorPath(dirFd, `${name}.${(0, import_node_crypto12.randomUUID)()}.tmp`);
48208
+ const name = (0, import_node_path38.basename)(path2);
48209
+ const temp = descriptorPath(dirFd, `${name}.${(0, import_node_crypto13.randomUUID)()}.tmp`);
48022
48210
  const destination = descriptorPath(dirFd, name);
48023
- const noFollow = import_node_fs46.constants.O_NOFOLLOW ?? 0;
48211
+ const noFollow = import_node_fs47.constants.O_NOFOLLOW ?? 0;
48024
48212
  let fd;
48025
48213
  try {
48026
- 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);
48214
+ 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);
48027
48215
  let offset = 0;
48028
- while (offset < data.length) offset += (0, import_node_fs46.writeSync)(fd, data, offset, data.length - offset);
48029
- (0, import_node_fs46.fchmodSync)(fd, mode);
48216
+ while (offset < data.length) offset += (0, import_node_fs47.writeSync)(fd, data, offset, data.length - offset);
48217
+ (0, import_node_fs47.fchmodSync)(fd, mode);
48030
48218
  if (owner && typeof process.getuid === "function" && process.getuid() === 0) {
48031
- (0, import_node_fs46.fchownSync)(fd, owner.uid, owner.gid);
48219
+ (0, import_node_fs47.fchownSync)(fd, owner.uid, owner.gid);
48032
48220
  }
48033
- (0, import_node_fs46.fsyncSync)(fd);
48034
- (0, import_node_fs46.closeSync)(fd);
48221
+ (0, import_node_fs47.fsyncSync)(fd);
48222
+ (0, import_node_fs47.closeSync)(fd);
48035
48223
  fd = void 0;
48036
- (0, import_node_fs46.renameSync)(temp, destination);
48224
+ (0, import_node_fs47.renameSync)(temp, destination);
48037
48225
  } catch (error2) {
48038
48226
  if (fd !== void 0) {
48039
48227
  try {
48040
- (0, import_node_fs46.closeSync)(fd);
48228
+ (0, import_node_fs47.closeSync)(fd);
48041
48229
  } catch {
48042
48230
  }
48043
48231
  }
48044
48232
  try {
48045
- (0, import_node_fs46.unlinkSync)(temp);
48233
+ (0, import_node_fs47.unlinkSync)(temp);
48046
48234
  } catch {
48047
48235
  }
48048
48236
  throw error2;
48049
48237
  } finally {
48050
- if (ownsDirFd) (0, import_node_fs46.closeSync)(dirFd);
48238
+ if (ownsDirFd) (0, import_node_fs47.closeSync)(dirFd);
48051
48239
  }
48052
48240
  }
48053
48241
  function readCurrentBackup(path2) {
48054
48242
  let fd;
48055
48243
  try {
48056
- const parentFd = openDirectoryChain((0, import_node_path37.dirname)(path2));
48244
+ const parentFd = openDirectoryChain((0, import_node_path38.dirname)(path2));
48057
48245
  try {
48058
- 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));
48246
+ fd = (0, import_node_fs47.openSync)(descriptorPath(parentFd, (0, import_node_path38.basename)(path2)), import_node_fs47.constants.O_RDONLY | (import_node_fs47.constants.O_NOFOLLOW ?? 0));
48059
48247
  } finally {
48060
- (0, import_node_fs46.closeSync)(parentFd);
48248
+ (0, import_node_fs47.closeSync)(parentFd);
48061
48249
  }
48062
- const stat = (0, import_node_fs46.fstatSync)(fd);
48250
+ const stat = (0, import_node_fs47.fstatSync)(fd);
48063
48251
  if (!stat.isFile() || stat.nlink !== 1 || stat.size > MAX_COMPRESSED_HISTORY_BYTES) return null;
48064
48252
  const compressed = readExact(fd, stat.size);
48065
- const after = (0, import_node_fs46.fstatSync)(fd);
48253
+ const after = (0, import_node_fs47.fstatSync)(fd);
48066
48254
  if (!compressed || after.size !== stat.size || after.mtimeMs !== stat.mtimeMs) return null;
48067
48255
  return (0, import_node_zlib2.gunzipSync)(compressed, { maxOutputLength: MAX_HISTORY_BYTES });
48068
48256
  } catch {
48069
48257
  return null;
48070
48258
  } finally {
48071
- if (fd !== void 0) (0, import_node_fs46.closeSync)(fd);
48259
+ if (fd !== void 0) (0, import_node_fs47.closeSync)(fd);
48072
48260
  }
48073
48261
  }
48074
48262
  function compactTime(date) {
@@ -48080,7 +48268,7 @@ var CommandHistoryWatcher = class {
48080
48268
  this.pollMs = Math.max(1e4, opts.pollMs ?? POLL_MS3);
48081
48269
  this.now = opts.now ?? (() => /* @__PURE__ */ new Date());
48082
48270
  this.listAccounts = opts.listAccounts ?? historyAccounts;
48083
- this.root = (0, import_node_path37.join)(opts.stateDir, "command-history");
48271
+ this.root = (0, import_node_path38.join)(opts.stateDir, "command-history");
48084
48272
  }
48085
48273
  opts;
48086
48274
  timer = null;
@@ -48121,7 +48309,7 @@ var CommandHistoryWatcher = class {
48121
48309
  try {
48122
48310
  privateDirectory(this.root);
48123
48311
  for (const account of this.listAccounts()) {
48124
- if (!Number.isInteger(account.uid) || account.uid < 0 || !(0, import_node_path37.isAbsolute)(account.home)) continue;
48312
+ if (!Number.isInteger(account.uid) || account.uid < 0 || !(0, import_node_path38.isAbsolute)(account.home)) continue;
48125
48313
  const targets = this.targetsFor(account);
48126
48314
  for (const relative4 of targets) this.scanFile(account, relative4);
48127
48315
  }
@@ -48132,39 +48320,39 @@ var CommandHistoryWatcher = class {
48132
48320
  }
48133
48321
  }
48134
48322
  targetsFor(account) {
48135
- const targets = new Set(HISTORY_TARGETS[(0, import_node_path37.basename)(account.shell)] ?? []);
48323
+ const targets = new Set(HISTORY_TARGETS[(0, import_node_path38.basename)(account.shell)] ?? []);
48136
48324
  for (const relative4 of Object.values(HISTORY_TARGETS).flat()) {
48137
48325
  if (targets.has(relative4)) continue;
48138
- const path2 = (0, import_node_path37.join)(account.home, relative4);
48326
+ const path2 = (0, import_node_path38.join)(account.home, relative4);
48139
48327
  try {
48140
- (0, import_node_fs46.lstatSync)(path2);
48328
+ (0, import_node_fs47.lstatSync)(path2);
48141
48329
  targets.add(relative4);
48142
48330
  continue;
48143
48331
  } catch (error2) {
48144
48332
  if (error2.code !== "ENOENT") continue;
48145
48333
  }
48146
- const current = (0, import_node_path37.join)(this.root, String(account.uid), `${(0, import_node_path37.basename)(relative4)}.current.gz`);
48334
+ const current = (0, import_node_path38.join)(this.root, String(account.uid), `${(0, import_node_path38.basename)(relative4)}.current.gz`);
48147
48335
  if (readCurrentBackup(current) !== null) targets.add(relative4);
48148
48336
  }
48149
48337
  return [...targets];
48150
48338
  }
48151
48339
  scanFile(account, relative4) {
48152
- const path2 = (0, import_node_path37.join)(account.home, relative4);
48153
- const store = (0, import_node_path37.join)(this.root, String(account.uid), (0, import_node_path37.basename)(relative4));
48340
+ const path2 = (0, import_node_path38.join)(account.home, relative4);
48341
+ const store = (0, import_node_path38.join)(this.root, String(account.uid), (0, import_node_path38.basename)(relative4));
48154
48342
  const current = `${store}.current.gz`;
48155
48343
  let userParentFd;
48156
48344
  try {
48157
- userParentFd = openDirectoryChain((0, import_node_path37.dirname)(path2));
48345
+ userParentFd = openDirectoryChain((0, import_node_path38.dirname)(path2));
48158
48346
  } catch {
48159
- this.opts.log(`[command-history] skipped uid=${account.uid} ${(0, import_node_path37.basename)(relative4)} because its parent path is missing or not a real directory`);
48347
+ this.opts.log(`[command-history] skipped uid=${account.uid} ${(0, import_node_path38.basename)(relative4)} because its parent path is missing or not a real directory`);
48160
48348
  return;
48161
48349
  }
48162
48350
  try {
48163
- privateDirectory((0, import_node_path37.dirname)(store));
48164
- const userPath = descriptorPath(userParentFd, (0, import_node_path37.basename)(path2));
48351
+ privateDirectory((0, import_node_path38.dirname)(store));
48352
+ const userPath = descriptorPath(userParentFd, (0, import_node_path38.basename)(path2));
48165
48353
  let status;
48166
48354
  try {
48167
- status = (0, import_node_fs46.lstatSync)(userPath);
48355
+ status = (0, import_node_fs47.lstatSync)(userPath);
48168
48356
  } catch (error2) {
48169
48357
  if (error2.code !== "ENOENT") throw error2;
48170
48358
  }
@@ -48179,7 +48367,7 @@ var CommandHistoryWatcher = class {
48179
48367
  } else if (!status) {
48180
48368
  this.restore(path2, Buffer.alloc(0), account, userParentFd);
48181
48369
  }
48182
- const data = safeReadHistory(userParentFd, (0, import_node_path37.basename)(path2), account.uid);
48370
+ const data = safeReadHistory(userParentFd, (0, import_node_path38.basename)(path2), account.uid);
48183
48371
  if (data === null) return;
48184
48372
  const previous = backup;
48185
48373
  if (previous?.equals(data)) {
@@ -48188,13 +48376,13 @@ var CommandHistoryWatcher = class {
48188
48376
  }
48189
48377
  const compressed = (0, import_node_zlib2.gzipSync)(data, { level: 6 });
48190
48378
  const stamp = compactTime(this.now());
48191
- atomicWrite(`${store}.${stamp}-${(0, import_node_crypto12.randomUUID)().slice(0, 8)}.gz`, compressed);
48379
+ atomicWrite(`${store}.${stamp}-${(0, import_node_crypto13.randomUUID)().slice(0, 8)}.gz`, compressed);
48192
48380
  atomicWrite(current, compressed);
48193
48381
  this.pruneSnapshots(store);
48194
48382
  } catch (error2) {
48195
- this.opts.log(`[command-history] could not snapshot uid=${account.uid} ${(0, import_node_path37.basename)(relative4)}: ${error2.message}`);
48383
+ this.opts.log(`[command-history] could not snapshot uid=${account.uid} ${(0, import_node_path38.basename)(relative4)}: ${error2.message}`);
48196
48384
  } finally {
48197
- (0, import_node_fs46.closeSync)(userParentFd);
48385
+ (0, import_node_fs47.closeSync)(userParentFd);
48198
48386
  }
48199
48387
  }
48200
48388
  restore(path2, content, account, parentFd) {
@@ -48207,22 +48395,22 @@ var CommandHistoryWatcher = class {
48207
48395
  module: "command-history",
48208
48396
  category: "system",
48209
48397
  severity: "medium",
48210
- message: `Shell history for ${name} (${(0, import_node_path37.basename)(relative4)}) was ${reason}; restored${hadBackup ? " from the latest backup" : " as an empty file"}`,
48211
- details: { uid: account.uid, account: name, history_file: (0, import_node_path37.basename)(relative4), action: "restored", reason, had_backup: hadBackup }
48398
+ message: `Shell history for ${name} (${(0, import_node_path38.basename)(relative4)}) was ${reason}; restored${hadBackup ? " from the latest backup" : " as an empty file"}`,
48399
+ details: { uid: account.uid, account: name, history_file: (0, import_node_path38.basename)(relative4), action: "restored", reason, had_backup: hadBackup }
48212
48400
  };
48213
48401
  this.opts.bus.publish(event);
48214
48402
  this.opts.log(`[command-history] ${event.message}`);
48215
48403
  }
48216
48404
  pruneSnapshots(current) {
48217
- const dir = (0, import_node_path37.dirname)(current);
48218
- const prefix = `${(0, import_node_path37.basename)(current).replace(/\.current\.gz$/, "")}.`;
48219
- 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);
48405
+ const dir = (0, import_node_path38.dirname)(current);
48406
+ const prefix = `${(0, import_node_path38.basename)(current).replace(/\.current\.gz$/, "")}.`;
48407
+ const snapshots = (0, import_node_fs47.readdirSync)(dir).filter((name) => name !== (0, import_node_path38.basename)(current) && name.startsWith(prefix) && name.endsWith(".gz")).map((name) => ({ path: (0, import_node_path38.join)(dir, name), name, time: (0, import_node_fs47.lstatSync)((0, import_node_path38.join)(dir, name)).mtimeMs })).sort((a, b) => a.time - b.time);
48220
48408
  const cutoff = this.now().getTime() - SNAPSHOT_RETENTION_MS;
48221
48409
  const removeCount = Math.max(0, snapshots.length - MAX_SNAPSHOTS);
48222
48410
  snapshots.forEach((snapshot, index) => {
48223
48411
  if (snapshot.time < cutoff || index < removeCount) {
48224
48412
  try {
48225
- (0, import_node_fs46.unlinkSync)(snapshot.path);
48413
+ (0, import_node_fs47.unlinkSync)(snapshot.path);
48226
48414
  } catch {
48227
48415
  }
48228
48416
  }
@@ -48231,10 +48419,10 @@ var CommandHistoryWatcher = class {
48231
48419
  };
48232
48420
 
48233
48421
  // src/daemon/workers/file-integrity.ts
48234
- var import_node_fs47 = require("fs");
48235
- var import_promises8 = require("fs/promises");
48236
- var import_node_crypto13 = require("crypto");
48237
- var import_node_path38 = require("path");
48422
+ var import_node_fs48 = require("fs");
48423
+ var import_promises9 = require("fs/promises");
48424
+ var import_node_crypto14 = require("crypto");
48425
+ var import_node_path39 = require("path");
48238
48426
  var DEFAULT_POLL_MS = 15 * 6e4;
48239
48427
  var MAX_FILES = 5e4;
48240
48428
  var MAX_FILE_BYTES = 64 * 1024 * 1024;
@@ -48249,8 +48437,8 @@ var READ_CHUNK_BYTES = 64 * 1024;
48249
48437
  var CANARY_CONTENT = "ThreatCrush file integrity canary v1\n";
48250
48438
  function fileIntegritySettings(section) {
48251
48439
  const safePath = (value) => {
48252
- if (typeof value !== "string" || !(0, import_node_path38.isAbsolute)(value) || value.split(import_node_path38.sep).includes("..")) return null;
48253
- const path2 = (0, import_node_path38.normalize)(value);
48440
+ if (typeof value !== "string" || !(0, import_node_path39.isAbsolute)(value) || value.split(import_node_path39.sep).includes("..")) return null;
48441
+ const path2 = (0, import_node_path39.normalize)(value);
48254
48442
  return path2 === "/" ? null : path2;
48255
48443
  };
48256
48444
  const strings = (values) => Array.isArray(values) ? [...new Set(values.map(safePath).filter((path2) => path2 !== null))] : [];
@@ -48271,7 +48459,7 @@ function signature(value) {
48271
48459
  }
48272
48460
  async function readState(path2) {
48273
48461
  try {
48274
- const parsed = JSON.parse(await (0, import_promises8.readFile)(path2, "utf8"));
48462
+ const parsed = JSON.parse(await (0, import_promises9.readFile)(path2, "utf8"));
48275
48463
  if (parsed.schema !== 1 || !Array.isArray(parsed.targets) || !parsed.files || typeof parsed.files !== "object") return null;
48276
48464
  return parsed;
48277
48465
  } catch {
@@ -48279,13 +48467,13 @@ async function readState(path2) {
48279
48467
  }
48280
48468
  }
48281
48469
  async function writeState(path2, state) {
48282
- await (0, import_promises8.mkdir)((0, import_node_path38.dirname)(path2), { recursive: true, mode: 448 });
48283
- const temp = `${path2}.${process.pid}.${(0, import_node_crypto13.randomUUID)()}.tmp`;
48284
- await (0, import_promises8.writeFile)(temp, JSON.stringify(state), { mode: 384 });
48285
- await (0, import_promises8.rename)(temp, path2);
48470
+ await (0, import_promises9.mkdir)((0, import_node_path39.dirname)(path2), { recursive: true, mode: 448 });
48471
+ const temp = `${path2}.${process.pid}.${(0, import_node_crypto14.randomUUID)()}.tmp`;
48472
+ await (0, import_promises9.writeFile)(temp, JSON.stringify(state), { mode: 384 });
48473
+ await (0, import_promises9.rename)(temp, path2);
48286
48474
  }
48287
48475
  async function hashFile(path2, handle, size) {
48288
- const hash = (0, import_node_crypto13.createHash)("sha256");
48476
+ const hash = (0, import_node_crypto14.createHash)("sha256");
48289
48477
  const buffer = Buffer.alloc(READ_CHUNK_BYTES);
48290
48478
  const counts = new Uint32Array(256);
48291
48479
  let position = 0;
@@ -48305,19 +48493,19 @@ async function hashFile(path2, handle, size) {
48305
48493
  }
48306
48494
  return { sha256: hash.digest("hex"), entropy };
48307
48495
  }
48308
- var OPEN_FILE_FLAGS = import_promises8.constants.O_RDONLY | import_promises8.constants.O_NONBLOCK | (import_promises8.constants.O_NOFOLLOW ?? 0);
48309
- var OPEN_DIR_FLAGS = OPEN_FILE_FLAGS | import_promises8.constants.O_DIRECTORY;
48310
- var CREATE_FILE_FLAGS = import_promises8.constants.O_WRONLY | import_promises8.constants.O_CREAT | import_promises8.constants.O_EXCL | import_promises8.constants.O_NOFOLLOW;
48496
+ var OPEN_FILE_FLAGS = import_promises9.constants.O_RDONLY | import_promises9.constants.O_NONBLOCK | (import_promises9.constants.O_NOFOLLOW ?? 0);
48497
+ var OPEN_DIR_FLAGS = OPEN_FILE_FLAGS | import_promises9.constants.O_DIRECTORY;
48498
+ var CREATE_FILE_FLAGS = import_promises9.constants.O_WRONLY | import_promises9.constants.O_CREAT | import_promises9.constants.O_EXCL | import_promises9.constants.O_NOFOLLOW;
48311
48499
  function autoCanaryPath(directory) {
48312
- return (0, import_node_path38.join)(directory, ".threatcrush-canary");
48500
+ return (0, import_node_path39.join)(directory, ".threatcrush-canary");
48313
48501
  }
48314
48502
  async function openAbsoluteDirectory(path2) {
48315
- const parts = path2.split(import_node_path38.sep).filter((part) => part && part !== ".");
48503
+ const parts = path2.split(import_node_path39.sep).filter((part) => part && part !== ".");
48316
48504
  if (parts.includes("..")) throw new Error("invalid canary directory");
48317
- let directory = await (0, import_promises8.open)("/", OPEN_DIR_FLAGS);
48505
+ let directory = await (0, import_promises9.open)("/", OPEN_DIR_FLAGS);
48318
48506
  try {
48319
48507
  for (const part of parts) {
48320
- const next = await (0, import_promises8.open)(`/proc/self/fd/${directory.fd}/${part}`, OPEN_DIR_FLAGS);
48508
+ const next = await (0, import_promises9.open)(`/proc/self/fd/${directory.fd}/${part}`, OPEN_DIR_FLAGS);
48321
48509
  await directory.close();
48322
48510
  directory = next;
48323
48511
  }
@@ -48335,9 +48523,9 @@ async function createAutoCanary(path2) {
48335
48523
  } catch (error2) {
48336
48524
  if (error2.code !== "ENOENT") return false;
48337
48525
  }
48338
- const directory = await openAbsoluteDirectory((0, import_node_path38.dirname)(path2));
48526
+ const directory = await openAbsoluteDirectory((0, import_node_path39.dirname)(path2));
48339
48527
  try {
48340
- const file = await (0, import_promises8.open)(`/proc/self/fd/${directory.fd}/${(0, import_node_path38.basename)(path2)}`, CREATE_FILE_FLAGS, 438);
48528
+ const file = await (0, import_promises9.open)(`/proc/self/fd/${directory.fd}/${(0, import_node_path39.basename)(path2)}`, CREATE_FILE_FLAGS, 438);
48341
48529
  try {
48342
48530
  await file.chmod(438);
48343
48531
  await file.writeFile(CANARY_CONTENT);
@@ -48354,16 +48542,16 @@ async function createAutoCanary(path2) {
48354
48542
  }
48355
48543
  }
48356
48544
  async function openAbsoluteTarget(path2) {
48357
- const parts = path2.split(import_node_path38.sep).filter((part) => part && part !== ".");
48545
+ const parts = path2.split(import_node_path39.sep).filter((part) => part && part !== ".");
48358
48546
  if (parts.length === 0 || parts.includes("..")) throw new Error("invalid file integrity path");
48359
- let directory = await (0, import_promises8.open)("/", OPEN_DIR_FLAGS);
48547
+ let directory = await (0, import_promises9.open)("/", OPEN_DIR_FLAGS);
48360
48548
  try {
48361
48549
  for (const part of parts.slice(0, -1)) {
48362
- const next = await (0, import_promises8.open)(`/proc/self/fd/${directory.fd}/${part}`, OPEN_DIR_FLAGS);
48550
+ const next = await (0, import_promises9.open)(`/proc/self/fd/${directory.fd}/${part}`, OPEN_DIR_FLAGS);
48363
48551
  await directory.close();
48364
48552
  directory = next;
48365
48553
  }
48366
- const target = await (0, import_promises8.open)(`/proc/self/fd/${directory.fd}/${parts.at(-1)}`, OPEN_FILE_FLAGS);
48554
+ const target = await (0, import_promises9.open)(`/proc/self/fd/${directory.fd}/${parts.at(-1)}`, OPEN_FILE_FLAGS);
48367
48555
  await directory.close();
48368
48556
  return target;
48369
48557
  } catch (error2) {
@@ -48389,7 +48577,7 @@ async function scanTargets(targets, canaries) {
48389
48577
  }
48390
48578
  let handle;
48391
48579
  try {
48392
- 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);
48580
+ handle = parent ? await (0, import_promises9.open)(`/proc/self/fd/${parent.fd}/${path2.slice(path2.lastIndexOf(import_node_path39.sep) + 1)}`, OPEN_FILE_FLAGS) : await openAbsoluteTarget(path2);
48393
48581
  const stat = await handle.stat();
48394
48582
  if (stat.isDirectory()) {
48395
48583
  directories.push(path2);
@@ -48400,14 +48588,14 @@ async function scanTargets(targets, canaries) {
48400
48588
  }
48401
48589
  let entries;
48402
48590
  try {
48403
- entries = await (0, import_promises8.readdir)(`/proc/self/fd/${handle.fd}`, { withFileTypes: true });
48591
+ entries = await (0, import_promises9.readdir)(`/proc/self/fd/${handle.fd}`, { withFileTypes: true });
48404
48592
  } catch {
48405
48593
  complete = false;
48406
48594
  errors.add(path2);
48407
48595
  return;
48408
48596
  }
48409
48597
  for (const entry of entries) {
48410
- await walk((0, import_node_path38.join)(path2, entry.name), handle);
48598
+ await walk((0, import_node_path39.join)(path2, entry.name), handle);
48411
48599
  if (!complete) return;
48412
48600
  }
48413
48601
  return;
@@ -48545,7 +48733,7 @@ var FileIntegrityWatch = class {
48545
48733
  for (const path2 of wanted) {
48546
48734
  if (this.watchers.has(path2)) continue;
48547
48735
  try {
48548
- const watcher = (0, import_node_fs47.watch)(path2, { persistent: false }, () => {
48736
+ const watcher = (0, import_node_fs48.watch)(path2, { persistent: false }, () => {
48549
48737
  this.scheduleEventScan();
48550
48738
  });
48551
48739
  watcher.on("error", (error2) => {
@@ -48601,7 +48789,7 @@ var FileIntegrityWatch = class {
48601
48789
  let baselineFilePresent = false;
48602
48790
  if (!baseline) {
48603
48791
  try {
48604
- await (0, import_promises8.lstat)(this.opts.baselinePath);
48792
+ await (0, import_promises9.lstat)(this.opts.baselinePath);
48605
48793
  baselineFilePresent = true;
48606
48794
  } catch (error2) {
48607
48795
  baselineFilePresent = error2.code !== "ENOENT";
@@ -48617,7 +48805,7 @@ var FileIntegrityWatch = class {
48617
48805
  if (current.complete) {
48618
48806
  const directories = new Set(current.directories);
48619
48807
  for (const path2 of Object.keys(current.files)) {
48620
- if (!directories.has(path2)) directories.add((0, import_node_path38.dirname)(path2));
48808
+ if (!directories.has(path2)) directories.add((0, import_node_path39.dirname)(path2));
48621
48809
  }
48622
48810
  this.refreshWatchers([...directories]);
48623
48811
  }
@@ -48726,8 +48914,8 @@ var FileIntegrityWatch = class {
48726
48914
  };
48727
48915
 
48728
48916
  // src/daemon/workers/edr.ts
48729
- var import_node_fs48 = require("fs");
48730
- var import_node_path39 = require("path");
48917
+ var import_node_fs49 = require("fs");
48918
+ var import_node_path40 = require("path");
48731
48919
  var import_node_child_process15 = require("child_process");
48732
48920
  var DEFAULT_AUDIT_LOG = "/var/log/audit/audit.log";
48733
48921
  var DEFAULT_WEB_USERS = ["www-data", "nginx", "apache", "httpd", "caddy", "node"];
@@ -48745,8 +48933,8 @@ var SHELLS = /* @__PURE__ */ new Set(["sh", "bash", "dash", "zsh", "ksh", "fish"
48745
48933
  var DOWNLOADERS = /* @__PURE__ */ new Set(["curl", "wget"]);
48746
48934
  var MINERS = /* @__PURE__ */ new Set(["xmrig", "minerd", "cpuminer", "cpuminer-multi", "kdevtmpfsi", "kinsing", "cryptonight"]);
48747
48935
  function safeAbsolutePath(value) {
48748
- if (typeof value !== "string" || !(0, import_node_path39.isAbsolute)(value) || value.split(import_node_path39.sep).includes("..")) return null;
48749
- const path2 = (0, import_node_path39.normalize)(value);
48936
+ if (typeof value !== "string" || !(0, import_node_path40.isAbsolute)(value) || value.split(import_node_path40.sep).includes("..")) return null;
48937
+ const path2 = (0, import_node_path40.normalize)(value);
48750
48938
  return path2 === "/" ? null : path2;
48751
48939
  }
48752
48940
  function edrSettings(section) {
@@ -48792,7 +48980,7 @@ function parseAuditRecord(line2) {
48792
48980
  serial: header2[2],
48793
48981
  key: fields.key,
48794
48982
  executable,
48795
- comm: fields.comm ?? (0, import_node_path39.basename)(executable),
48983
+ comm: fields.comm ?? (0, import_node_path40.basename)(executable),
48796
48984
  euid,
48797
48985
  ...Number.isInteger(pid) && pid > 0 ? { pid } : {},
48798
48986
  ...Number.isInteger(ppid) && ppid > 0 ? { ppid } : {}
@@ -48804,7 +48992,7 @@ function accountNames2() {
48804
48992
  raw = (0, import_node_child_process15.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
48805
48993
  } catch {
48806
48994
  try {
48807
- raw = (0, import_node_fs48.readFileSync)("/etc/passwd", "utf8");
48995
+ raw = (0, import_node_fs49.readFileSync)("/etc/passwd", "utf8");
48808
48996
  } catch {
48809
48997
  return /* @__PURE__ */ new Map();
48810
48998
  }
@@ -48822,7 +49010,7 @@ function pathWithin(path2, root) {
48822
49010
  }
48823
49011
  function executableInWorldWritableDirectory(executable) {
48824
49012
  try {
48825
- return ((0, import_node_fs48.statSync)((0, import_node_path39.dirname)(executable)).mode & 2) !== 0;
49013
+ return ((0, import_node_fs49.statSync)((0, import_node_path40.dirname)(executable)).mode & 2) !== 0;
48826
49014
  } catch {
48827
49015
  return false;
48828
49016
  }
@@ -48856,11 +49044,11 @@ var EdrWatch = class {
48856
49044
  this.opts.log("[edr] disabled; set [edr] enabled = true after installing the generated audit rules");
48857
49045
  return;
48858
49046
  }
48859
- if (!(0, import_node_fs48.existsSync)(this.opts.settings.auditLogPath)) {
49047
+ if (!(0, import_node_fs49.existsSync)(this.opts.settings.auditLogPath)) {
48860
49048
  this.opts.log(`[edr] audit log not found at ${this.opts.settings.auditLogPath}; auditd detections are unavailable`);
48861
49049
  } else {
48862
49050
  try {
48863
- (0, import_node_fs48.accessSync)(this.opts.settings.auditLogPath, import_node_fs48.constants.R_OK);
49051
+ (0, import_node_fs49.accessSync)(this.opts.settings.auditLogPath, import_node_fs49.constants.R_OK);
48864
49052
  this.tail = new LogTail(this.opts.settings.auditLogPath);
48865
49053
  this.timer = setInterval(() => this.poll(), this.opts.settings.pollMs);
48866
49054
  this.timer.unref?.();
@@ -48908,7 +49096,7 @@ var EdrWatch = class {
48908
49096
  this.opts.bus.publish(event);
48909
49097
  }
48910
49098
  classify(execution) {
48911
- const name = (0, import_node_path39.basename)(execution.executable).toLowerCase();
49099
+ const name = (0, import_node_path40.basename)(execution.executable).toLowerCase();
48912
49100
  const account = this.usersById.get(execution.euid) ?? String(execution.euid);
48913
49101
  let severity;
48914
49102
  let ruleId;
@@ -48971,7 +49159,7 @@ var EdrWatch = class {
48971
49159
  const path2 = this.opts.networkBaselinePath;
48972
49160
  if (!path2) return;
48973
49161
  try {
48974
- const parsed = JSON.parse((0, import_node_fs48.readFileSync)(path2, "utf8"));
49162
+ const parsed = JSON.parse((0, import_node_fs49.readFileSync)(path2, "utf8"));
48975
49163
  if (Array.isArray(parsed)) {
48976
49164
  for (const value of parsed.slice(0, 1e4)) {
48977
49165
  if (typeof value === "string" && value.startsWith("/")) this.outboundExecutables.add(value);
@@ -48988,9 +49176,9 @@ var EdrWatch = class {
48988
49176
  if (!path2) return;
48989
49177
  try {
48990
49178
  const temp = `${path2}.${process.pid}.tmp`;
48991
- (0, import_node_fs48.writeFileSync)(temp, `${JSON.stringify([...this.outboundExecutables])}
49179
+ (0, import_node_fs49.writeFileSync)(temp, `${JSON.stringify([...this.outboundExecutables])}
48992
49180
  `, { mode: 384 });
48993
- (0, import_node_fs48.renameSync)(temp, path2);
49181
+ (0, import_node_fs49.renameSync)(temp, path2);
48994
49182
  this.baselineWriteFailed = false;
48995
49183
  } catch (error2) {
48996
49184
  if (!this.baselineWriteFailed) this.opts.log(`[edr] could not persist outbound executable baseline: ${error2.message.split("\n")[0]}`);
@@ -49011,7 +49199,7 @@ var EdrWatch = class {
49011
49199
  const current = /* @__PURE__ */ new Map();
49012
49200
  let pids;
49013
49201
  try {
49014
- pids = (0, import_node_fs48.readdirSync)("/proc");
49202
+ pids = (0, import_node_fs49.readdirSync)("/proc");
49015
49203
  } catch {
49016
49204
  return;
49017
49205
  }
@@ -49019,7 +49207,7 @@ var EdrWatch = class {
49019
49207
  if (!/^\d+$/.test(pid)) continue;
49020
49208
  const proc = `/proc/${pid}`;
49021
49209
  try {
49022
- const raw = (0, import_node_fs48.readFileSync)(`${proc}/stat`, "utf8");
49210
+ const raw = (0, import_node_fs49.readFileSync)(`${proc}/stat`, "utf8");
49023
49211
  const end = raw.lastIndexOf(")");
49024
49212
  if (end < 0) continue;
49025
49213
  const fields = raw.slice(end + 1).trim().split(/\s+/);
@@ -49027,10 +49215,10 @@ var EdrWatch = class {
49027
49215
  const systemTicks = Number(fields[12]);
49028
49216
  const startTicks = fields[19];
49029
49217
  if (!Number.isFinite(userTicks) || !Number.isFinite(systemTicks) || !startTicks) continue;
49030
- let executable = (0, import_node_fs48.readlinkSync)(`${proc}/exe`);
49218
+ let executable = (0, import_node_fs49.readlinkSync)(`${proc}/exe`);
49031
49219
  executable = executable.replace(/ \(deleted\)$/, "");
49032
49220
  if (!this.opts.settings.tempExecPaths.some((path2) => pathWithin(executable, path2))) continue;
49033
- const name = (0, import_node_path39.basename)(executable).toLowerCase();
49221
+ const name = (0, import_node_path40.basename)(executable).toLowerCase();
49034
49222
  if (MINERS.has(name)) continue;
49035
49223
  const key = `${pid}:${startTicks}`;
49036
49224
  const ticks = userTicks + systemTicks;
@@ -49066,8 +49254,8 @@ var EdrWatch = class {
49066
49254
  };
49067
49255
 
49068
49256
  // src/daemon/workers/ssh-intrusion.ts
49069
- var import_node_fs49 = require("fs");
49070
- var import_node_path40 = require("path");
49257
+ var import_node_fs50 = require("fs");
49258
+ var import_node_path41 = require("path");
49071
49259
  var import_node_child_process16 = require("child_process");
49072
49260
 
49073
49261
  // src/core/asn.ts
@@ -49261,32 +49449,32 @@ function parseKeyLoginsByFingerprint(text) {
49261
49449
  }
49262
49450
  function readJson2(path2) {
49263
49451
  try {
49264
- return JSON.parse((0, import_node_fs49.readFileSync)(path2, "utf-8"));
49452
+ return JSON.parse((0, import_node_fs50.readFileSync)(path2, "utf-8"));
49265
49453
  } catch {
49266
49454
  return null;
49267
49455
  }
49268
49456
  }
49269
49457
  function writeJson2(path2, value) {
49270
- (0, import_node_fs49.mkdirSync)((0, import_node_path40.dirname)(path2), { recursive: true });
49271
- (0, import_node_fs49.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
49272
- (0, import_node_fs49.renameSync)(`${path2}.tmp`, path2);
49458
+ (0, import_node_fs50.mkdirSync)((0, import_node_path41.dirname)(path2), { recursive: true });
49459
+ (0, import_node_fs50.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
49460
+ (0, import_node_fs50.renameSync)(`${path2}.tmp`, path2);
49273
49461
  }
49274
49462
  var fsIO2 = {
49275
49463
  readFile: (p) => {
49276
49464
  try {
49277
- return (0, import_node_fs49.readFileSync)(p, "utf-8");
49465
+ return (0, import_node_fs50.readFileSync)(p, "utf-8");
49278
49466
  } catch {
49279
49467
  return null;
49280
49468
  }
49281
49469
  },
49282
49470
  readDir: (p) => {
49283
49471
  try {
49284
- return (0, import_node_fs49.readdirSync)(p);
49472
+ return (0, import_node_fs50.readdirSync)(p);
49285
49473
  } catch {
49286
49474
  return null;
49287
49475
  }
49288
49476
  },
49289
- exists: (p) => (0, import_node_fs49.existsSync)(p)
49477
+ exists: (p) => (0, import_node_fs50.existsSync)(p)
49290
49478
  };
49291
49479
  function defaultRun4(cmd, args) {
49292
49480
  const res = (0, import_node_child_process16.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 6e4, maxBuffer: 64 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
@@ -49487,23 +49675,23 @@ var SshIntrusionWatch = class {
49487
49675
  };
49488
49676
 
49489
49677
  // src/daemon/key-directory.ts
49490
- var import_node_fs50 = require("fs");
49678
+ var import_node_fs51 = require("fs");
49491
49679
  var fsIO3 = {
49492
49680
  readFile: (p) => {
49493
49681
  try {
49494
- return (0, import_node_fs50.readFileSync)(p, "utf-8");
49682
+ return (0, import_node_fs51.readFileSync)(p, "utf-8");
49495
49683
  } catch {
49496
49684
  return null;
49497
49685
  }
49498
49686
  },
49499
49687
  readDir: (p) => {
49500
49688
  try {
49501
- return (0, import_node_fs50.readdirSync)(p);
49689
+ return (0, import_node_fs51.readdirSync)(p);
49502
49690
  } catch {
49503
49691
  return null;
49504
49692
  }
49505
49693
  },
49506
- exists: (p) => (0, import_node_fs50.existsSync)(p)
49694
+ exists: (p) => (0, import_node_fs51.existsSync)(p)
49507
49695
  };
49508
49696
  var KeyDirectory = class {
49509
49697
  constructor(io = fsIO3, now = Date.now, ttlMs = 3e5) {
@@ -49547,7 +49735,7 @@ function enrichLoginEvent(event, keys) {
49547
49735
  }
49548
49736
 
49549
49737
  // src/daemon/workers/lightning-watch.ts
49550
- var import_node_fs51 = require("fs");
49738
+ var import_node_fs52 = require("fs");
49551
49739
  var DEFAULT_CLN_LOGS = [
49552
49740
  "/home/lightning/.lightning/cln.log",
49553
49741
  "/root/.lightning/cln.log",
@@ -49603,9 +49791,9 @@ var LightningWatch = class {
49603
49791
  if (this.opts.enabled === false) return [];
49604
49792
  const found = [];
49605
49793
  for (const path2 of this.opts.paths?.length ? this.opts.paths : DEFAULT_CLN_LOGS) {
49606
- if (!(0, import_node_fs51.existsSync)(path2)) continue;
49794
+ if (!(0, import_node_fs52.existsSync)(path2)) continue;
49607
49795
  try {
49608
- (0, import_node_fs51.accessSync)(path2, import_node_fs51.constants.R_OK);
49796
+ (0, import_node_fs52.accessSync)(path2, import_node_fs52.constants.R_OK);
49609
49797
  } catch {
49610
49798
  continue;
49611
49799
  }
@@ -49640,8 +49828,8 @@ var LightningWatch = class {
49640
49828
  };
49641
49829
 
49642
49830
  // src/core/tor-exits.ts
49643
- var import_node_fs52 = require("fs");
49644
- var import_node_path41 = require("path");
49831
+ var import_node_fs53 = require("fs");
49832
+ var import_node_path42 = require("path");
49645
49833
  var import_node_net15 = require("net");
49646
49834
  var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
49647
49835
  function parseTorExitList(text) {
@@ -49709,10 +49897,10 @@ var TorExitList = class _TorExitList {
49709
49897
  }
49710
49898
  loadCache() {
49711
49899
  try {
49712
- if (!(0, import_node_fs52.existsSync)(this.opts.cachePath)) return false;
49713
- const parsed = parseTorExitList((0, import_node_fs52.readFileSync)(this.opts.cachePath, "utf-8"));
49900
+ if (!(0, import_node_fs53.existsSync)(this.opts.cachePath)) return false;
49901
+ const parsed = parseTorExitList((0, import_node_fs53.readFileSync)(this.opts.cachePath, "utf-8"));
49714
49902
  if (parsed.size === 0) return false;
49715
- this.load(parsed, (0, import_node_fs52.statSync)(this.opts.cachePath).mtimeMs);
49903
+ this.load(parsed, (0, import_node_fs53.statSync)(this.opts.cachePath).mtimeMs);
49716
49904
  this.log(`[tor] loaded ${parsed.size} Tor exit addresses from cache (${new Date(this.updatedAt).toISOString()})`);
49717
49905
  return true;
49718
49906
  } catch (err) {
@@ -49744,9 +49932,9 @@ var TorExitList = class _TorExitList {
49744
49932
  const before2 = this.exits.size;
49745
49933
  this.load(parsed);
49746
49934
  try {
49747
- (0, import_node_fs52.mkdirSync)((0, import_node_path41.dirname)(this.opts.cachePath), { recursive: true });
49748
- (0, import_node_fs52.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
49749
- (0, import_node_fs52.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
49935
+ (0, import_node_fs53.mkdirSync)((0, import_node_path42.dirname)(this.opts.cachePath), { recursive: true });
49936
+ (0, import_node_fs53.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
49937
+ (0, import_node_fs53.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
49750
49938
  } catch (err) {
49751
49939
  this.log(`[tor] could not save the exit list cache: ${err.message}`);
49752
49940
  }
@@ -49967,8 +50155,8 @@ var RuleEngine = class {
49967
50155
  };
49968
50156
 
49969
50157
  // src/daemon/rules/loader.ts
49970
- var import_node_fs53 = require("fs");
49971
- var import_node_path42 = require("path");
50158
+ var import_node_fs54 = require("fs");
50159
+ var import_node_path43 = require("path");
49972
50160
 
49973
50161
  // src/daemon/rules/default-rules.ts
49974
50162
  var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
@@ -50613,11 +50801,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
50613
50801
  function loadAllRules(customDir) {
50614
50802
  const rules = [...DEFAULT_RULES];
50615
50803
  const dir = customDir || RULES_DIR;
50616
- if ((0, import_node_fs53.existsSync)(dir)) {
50617
- const files = (0, import_node_fs53.readdirSync)(dir).filter((f) => f.endsWith(".json"));
50804
+ if ((0, import_node_fs54.existsSync)(dir)) {
50805
+ const files = (0, import_node_fs54.readdirSync)(dir).filter((f) => f.endsWith(".json"));
50618
50806
  for (const file of files) {
50619
50807
  try {
50620
- const raw = (0, import_node_fs53.readFileSync)((0, import_node_path42.join)(dir, file), "utf-8");
50808
+ const raw = (0, import_node_fs54.readFileSync)((0, import_node_path43.join)(dir, file), "utf-8");
50621
50809
  const parsed = JSON.parse(raw);
50622
50810
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
50623
50811
  for (const rule of customRules) {
@@ -50649,8 +50837,8 @@ function loadAllRules(customDir) {
50649
50837
 
50650
50838
  // src/daemon/firewall/adapters.ts
50651
50839
  var import_node_child_process17 = require("child_process");
50652
- var import_node_fs54 = require("fs");
50653
- var import_node_path43 = require("path");
50840
+ var import_node_fs55 = require("fs");
50841
+ var import_node_path44 = require("path");
50654
50842
  var import_node_net16 = require("net");
50655
50843
  function assertValidFirewallIp(ip) {
50656
50844
  if ((0, import_node_net16.isIP)(ip) !== 4) {
@@ -50663,9 +50851,9 @@ function assertBannableIp(ip) {
50663
50851
  }
50664
50852
  }
50665
50853
  function writeIfAbsent(path2, contents) {
50666
- (0, import_node_fs54.mkdirSync)((0, import_node_path43.dirname)(path2), { recursive: true });
50854
+ (0, import_node_fs55.mkdirSync)((0, import_node_path44.dirname)(path2), { recursive: true });
50667
50855
  try {
50668
- (0, import_node_fs54.writeFileSync)(path2, contents, { flag: "wx" });
50856
+ (0, import_node_fs55.writeFileSync)(path2, contents, { flag: "wx" });
50669
50857
  } catch (err) {
50670
50858
  if (err.code !== "EEXIST") throw err;
50671
50859
  }
@@ -50924,7 +51112,7 @@ function detectFirewallAdapter(backend = "auto") {
50924
51112
  }
50925
51113
 
50926
51114
  // src/daemon/firewall/remediation.ts
50927
- var import_node_fs55 = require("fs");
51115
+ var import_node_fs56 = require("fs");
50928
51116
  var import_node_child_process18 = require("child_process");
50929
51117
  var import_node_net17 = require("net");
50930
51118
  init_paths();
@@ -50996,19 +51184,19 @@ var defaultDiscovery = {
50996
51184
  const snapshot = takeSnapshot({
50997
51185
  readFile: (p) => {
50998
51186
  try {
50999
- return (0, import_node_fs55.readFileSync)(p, "utf-8");
51187
+ return (0, import_node_fs56.readFileSync)(p, "utf-8");
51000
51188
  } catch {
51001
51189
  return null;
51002
51190
  }
51003
51191
  },
51004
51192
  readDir: (p) => {
51005
51193
  try {
51006
- return (0, import_node_fs55.readdirSync)(p);
51194
+ return (0, import_node_fs56.readdirSync)(p);
51007
51195
  } catch {
51008
51196
  return null;
51009
51197
  }
51010
51198
  },
51011
- exists: (p) => (0, import_node_fs55.existsSync)(p)
51199
+ exists: (p) => (0, import_node_fs56.existsSync)(p)
51012
51200
  });
51013
51201
  const out = /* @__PURE__ */ new Set();
51014
51202
  for (const keys of Object.values(snapshot.keys)) {
@@ -51521,7 +51709,7 @@ var RemediationManager = class {
51521
51709
  }
51522
51710
  logLine(line2) {
51523
51711
  try {
51524
- (0, import_node_fs55.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
51712
+ (0, import_node_fs56.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
51525
51713
  `);
51526
51714
  } catch {
51527
51715
  }
@@ -51565,19 +51753,19 @@ function remediationSettings(section) {
51565
51753
  init_backoff();
51566
51754
 
51567
51755
  // src/daemon/watchdog-service.ts
51568
- var import_node_fs56 = require("fs");
51569
- var import_node_path44 = require("path");
51756
+ var import_node_fs57 = require("fs");
51757
+ var import_node_path45 = require("path");
51570
51758
  function defaultShareGid() {
51571
51759
  const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
51572
51760
  if (!isRoot4) return void 0;
51573
51761
  try {
51574
- return (0, import_node_fs56.statSync)("/var/log/auth.log").gid;
51762
+ return (0, import_node_fs57.statSync)("/var/log/auth.log").gid;
51575
51763
  } catch {
51576
51764
  return void 0;
51577
51765
  }
51578
51766
  }
51579
51767
  function startWatchdog(opts) {
51580
- const dir = opts.config?.dir ?? (0, import_node_path44.join)(opts.stateDir, WATCHDOG_DIRNAME);
51768
+ const dir = opts.config?.dir ?? (0, import_node_path45.join)(opts.stateDir, WATCHDOG_DIRNAME);
51581
51769
  const base = { dir, logged: 0, answered: 0, errored: 0 };
51582
51770
  if (opts.config?.enabled === false) {
51583
51771
  opts.log("[watchdog] off ([watchdog] enabled = false)");
@@ -51692,7 +51880,7 @@ function versionOfNode(path2) {
51692
51880
  // src/daemon/index.ts
51693
51881
  function readVersion2() {
51694
51882
  try {
51695
- const pkg = JSON.parse((0, import_node_fs57.readFileSync)((0, import_node_path45.join)(__dirname, "..", "package.json"), "utf-8"));
51883
+ const pkg = JSON.parse((0, import_node_fs58.readFileSync)((0, import_node_path46.join)(__dirname, "..", "package.json"), "utf-8"));
51696
51884
  return pkg.version || "0.0.0";
51697
51885
  } catch {
51698
51886
  return "0.0.0";
@@ -51701,7 +51889,7 @@ function readVersion2() {
51701
51889
  async function runHardeningChecks() {
51702
51890
  const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process20.execFile)(
51703
51891
  process.execPath,
51704
- [(0, import_node_path45.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
51892
+ [(0, import_node_path46.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
51705
51893
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
51706
51894
  );
51707
51895
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -51715,7 +51903,7 @@ async function runHardeningChecks() {
51715
51903
  async function runPatchCheck() {
51716
51904
  const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process20.execFile)(
51717
51905
  process.execPath,
51718
- [(0, import_node_path45.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
51906
+ [(0, import_node_path46.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
51719
51907
  { timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
51720
51908
  );
51721
51909
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -51723,7 +51911,7 @@ async function runPatchCheck() {
51723
51911
  }
51724
51912
  function logLine(line2) {
51725
51913
  try {
51726
- (0, import_node_fs57.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
51914
+ (0, import_node_fs58.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
51727
51915
  `);
51728
51916
  } catch {
51729
51917
  }
@@ -51765,7 +51953,7 @@ async function runDaemon() {
51765
51953
  } catch (err) {
51766
51954
  logLine(`[daemon] state db unavailable: ${err.message}`);
51767
51955
  }
51768
- const loaded = loadDaemonConfig(PATHS.configFile, (0, import_node_path45.join)(PATHS.stateDir, "threatcrushd.conf.last-good"));
51956
+ const loaded = loadDaemonConfig(PATHS.configFile, (0, import_node_path46.join)(PATHS.stateDir, "threatcrushd.conf.last-good"));
51769
51957
  const config = loaded.config;
51770
51958
  if (loaded.error) {
51771
51959
  logLine(`[daemon] CONFIG ERROR: ${loaded.error}; ${loaded.usedLastGood ? "running on the last config that parsed" : "no earlier good copy, running on DEFAULTS (no protected list)"}`);
@@ -51836,7 +52024,7 @@ async function runDaemon() {
51836
52024
  const threatFeeds = new ThreatFeeds({
51837
52025
  settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
51838
52026
  enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
51839
- cachePath: (0, import_node_path45.join)(PATHS.stateDir, "threat-feeds.json"),
52027
+ cachePath: (0, import_node_path46.join)(PATHS.stateDir, "threat-feeds.json"),
51840
52028
  bus,
51841
52029
  log: logLine
51842
52030
  });
@@ -51844,9 +52032,9 @@ async function runDaemon() {
51844
52032
  const privilegeWatch = new PrivilegeWatch({
51845
52033
  settings: privilegeSettings(config.privileged),
51846
52034
  bus,
51847
- snapshotPath: (0, import_node_path45.join)(PATHS.stateDir, "privileges.json"),
51848
- loginsPath: (0, import_node_path45.join)(PATHS.stateDir, "login-countries.json"),
51849
- cursorPath: (0, import_node_path45.join)(PATHS.stateDir, "sudo-cursor.json"),
52035
+ snapshotPath: (0, import_node_path46.join)(PATHS.stateDir, "privileges.json"),
52036
+ loginsPath: (0, import_node_path46.join)(PATHS.stateDir, "login-countries.json"),
52037
+ cursorPath: (0, import_node_path46.join)(PATHS.stateDir, "sudo-cursor.json"),
51850
52038
  log: logLine
51851
52039
  });
51852
52040
  privilegeWatch.start();
@@ -51860,20 +52048,20 @@ async function runDaemon() {
51860
52048
  const fileIntegrity = new FileIntegrityWatch({
51861
52049
  bus,
51862
52050
  settings: fileIntegritySettings(config.file_integrity),
51863
- baselinePath: (0, import_node_path45.join)(PATHS.stateDir, "file-integrity-baseline.json"),
51864
- observedPath: (0, import_node_path45.join)(PATHS.stateDir, "file-integrity-observed.json"),
52051
+ baselinePath: (0, import_node_path46.join)(PATHS.stateDir, "file-integrity-baseline.json"),
52052
+ observedPath: (0, import_node_path46.join)(PATHS.stateDir, "file-integrity-observed.json"),
51865
52053
  log: logLine
51866
52054
  });
51867
52055
  fileIntegrity.start();
51868
52056
  const edr = new EdrWatch({
51869
52057
  bus,
51870
52058
  settings: edrSettings(config.edr),
51871
- networkBaselinePath: (0, import_node_path45.join)(PATHS.stateDir, "edr-outbound-executables.json"),
52059
+ networkBaselinePath: (0, import_node_path46.join)(PATHS.stateDir, "edr-outbound-executables.json"),
51872
52060
  log: logLine
51873
52061
  });
51874
52062
  edr.start();
51875
52063
  const torExits = new TorExitList({
51876
- cachePath: (0, import_node_path45.join)(PATHS.stateDir, "tor-exits.txt"),
52064
+ cachePath: (0, import_node_path46.join)(PATHS.stateDir, "tor-exits.txt"),
51877
52065
  url: config.remediation?.tor_exit_list_url,
51878
52066
  log: logLine
51879
52067
  });
@@ -51881,7 +52069,7 @@ async function runDaemon() {
51881
52069
  bus,
51882
52070
  manager: remediation,
51883
52071
  tor: torExits,
51884
- historyPath: (0, import_node_path45.join)(PATHS.stateDir, "key-logins.json"),
52072
+ historyPath: (0, import_node_path46.join)(PATHS.stateDir, "key-logins.json"),
51885
52073
  keyLoginWatch: config.privileged?.key_login_watch !== false,
51886
52074
  log: logLine
51887
52075
  });
@@ -51926,9 +52114,9 @@ async function runDaemon() {
51926
52114
  cloudSync = new CloudSync({
51927
52115
  bus,
51928
52116
  version,
51929
- hostname: (0, import_node_os18.hostname)(),
52117
+ hostname: (0, import_node_os19.hostname)(),
51930
52118
  minSeverity,
51931
- spoolPath: (0, import_node_path45.join)(PATHS.stateDir, "cloud-spool.jsonl"),
52119
+ spoolPath: (0, import_node_path46.join)(PATHS.stateDir, "cloud-spool.jsonl"),
51932
52120
  log: logLine,
51933
52121
  ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
51934
52122
  runHardening: runHardeningChecks
@@ -51961,8 +52149,8 @@ async function runDaemon() {
51961
52149
  const autoUpdate = autoUpdateRef = new AutoUpdate({
51962
52150
  version,
51963
52151
  settings: updateSettings(config.update),
51964
- pkgRoot: (0, import_node_path45.join)(__dirname, ".."),
51965
- statePath: (0, import_node_path45.join)(PATHS.stateDir, "auto-update.json"),
52152
+ pkgRoot: (0, import_node_path46.join)(__dirname, ".."),
52153
+ statePath: (0, import_node_path46.join)(PATHS.stateDir, "auto-update.json"),
51966
52154
  bus,
51967
52155
  log: logLine,
51968
52156
  restartDaemon
@@ -52072,7 +52260,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
52072
52260
  function isRoot2() {
52073
52261
  return typeof process.getuid === "function" && process.getuid() === 0;
52074
52262
  }
52075
- var DAEMON_ENTRY = (0, import_node_path46.join)(__dirname, "daemon.js");
52263
+ var DAEMON_ENTRY = (0, import_node_path47.join)(__dirname, "daemon.js");
52076
52264
  async function daemonForeground() {
52077
52265
  await runDaemon();
52078
52266
  }
@@ -52093,7 +52281,7 @@ async function daemonStart() {
52093
52281
  return;
52094
52282
  }
52095
52283
  ensureRuntimeDirs();
52096
- if (!(0, import_node_fs58.existsSync)(DAEMON_ENTRY)) {
52284
+ if (!(0, import_node_fs59.existsSync)(DAEMON_ENTRY)) {
52097
52285
  console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
52098
52286
  console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
52099
52287
  return;
@@ -52101,8 +52289,8 @@ async function daemonStart() {
52101
52289
  let out;
52102
52290
  let err;
52103
52291
  try {
52104
- out = (0, import_node_fs59.openSync)(PATHS.logFile, "a");
52105
- err = (0, import_node_fs59.openSync)(PATHS.logFile, "a");
52292
+ out = (0, import_node_fs60.openSync)(PATHS.logFile, "a");
52293
+ err = (0, import_node_fs60.openSync)(PATHS.logFile, "a");
52106
52294
  } catch (e) {
52107
52295
  const code = e.code;
52108
52296
  console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
@@ -52190,12 +52378,12 @@ async function waitForExit(pid, timeoutMs) {
52190
52378
  }
52191
52379
  async function releaseStaleSocket() {
52192
52380
  const deadline = Date.now() + 2e3;
52193
- while ((0, import_node_fs58.existsSync)(PATHS.socket) && Date.now() < deadline) {
52381
+ while ((0, import_node_fs59.existsSync)(PATHS.socket) && Date.now() < deadline) {
52194
52382
  await new Promise((r) => setTimeout(r, 50));
52195
52383
  }
52196
- if ((0, import_node_fs58.existsSync)(PATHS.socket)) {
52384
+ if ((0, import_node_fs59.existsSync)(PATHS.socket)) {
52197
52385
  try {
52198
- (0, import_node_fs58.unlinkSync)(PATHS.socket);
52386
+ (0, import_node_fs59.unlinkSync)(PATHS.socket);
52199
52387
  } catch {
52200
52388
  }
52201
52389
  }
@@ -52203,26 +52391,26 @@ async function releaseStaleSocket() {
52203
52391
 
52204
52392
  // src/commands/service.ts
52205
52393
  var import_node_child_process22 = require("child_process");
52206
- var import_node_fs60 = require("fs");
52207
- var import_node_path47 = require("path");
52208
- var import_node_os19 = require("os");
52394
+ var import_node_fs61 = require("fs");
52395
+ var import_node_path48 = require("path");
52396
+ var import_node_os20 = require("os");
52209
52397
  var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
52210
52398
  var DAEMON_UNIT_NAME = "threatcrushd.service";
52211
52399
  function resolveTemplate() {
52212
- const templatePath = (0, import_node_path47.join)(__dirname, "systemd", "threatcrushd.service");
52213
- if (!(0, import_node_fs60.existsSync)(templatePath)) {
52400
+ const templatePath = (0, import_node_path48.join)(__dirname, "systemd", "threatcrushd.service");
52401
+ if (!(0, import_node_fs61.existsSync)(templatePath)) {
52214
52402
  throw new Error(`systemd unit template not found at ${templatePath}`);
52215
52403
  }
52216
- return (0, import_node_fs60.readFileSync)(templatePath, "utf-8");
52404
+ return (0, import_node_fs61.readFileSync)(templatePath, "utf-8");
52217
52405
  }
52218
52406
  function stableBinPath(binPath) {
52219
52407
  const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
52220
52408
  if (stable === binPath) return binPath;
52221
- return (0, import_node_fs60.existsSync)(stable) ? stable : binPath;
52409
+ return (0, import_node_fs61.existsSync)(stable) ? stable : binPath;
52222
52410
  }
52223
52411
  function resolveBinPath() {
52224
52412
  const arg = process.argv[1];
52225
- if (arg && (0, import_node_fs60.existsSync)(arg)) return stableBinPath(arg);
52413
+ if (arg && (0, import_node_fs61.existsSync)(arg)) return stableBinPath(arg);
52226
52414
  try {
52227
52415
  return (0, import_node_child_process22.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
52228
52416
  } catch {
@@ -52232,12 +52420,12 @@ function resolveBinPath() {
52232
52420
  function stableNodePath(execPath) {
52233
52421
  const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
52234
52422
  if (stable === execPath) return execPath;
52235
- return (0, import_node_fs60.existsSync)(stable) ? stable : execPath;
52423
+ return (0, import_node_fs61.existsSync)(stable) ? stable : execPath;
52236
52424
  }
52237
52425
  function looksLikeNodeScript(path2) {
52238
52426
  try {
52239
- const head = (0, import_node_fs60.readFileSync)(path2, "utf-8").slice(0, 120);
52240
- return /^#!.*\bnode\b/.test(head);
52427
+ const head2 = (0, import_node_fs61.readFileSync)(path2, "utf-8").slice(0, 120);
52428
+ return /^#!.*\bnode\b/.test(head2);
52241
52429
  } catch {
52242
52430
  return false;
52243
52431
  }
@@ -52276,7 +52464,7 @@ function callerHome() {
52276
52464
  try {
52277
52465
  const line2 = (0, import_node_child_process22.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
52278
52466
  const home = line2.split(":")[5];
52279
- return home && (0, import_node_fs60.existsSync)(home) ? home : null;
52467
+ return home && (0, import_node_fs61.existsSync)(home) ? home : null;
52280
52468
  } catch {
52281
52469
  return null;
52282
52470
  }
@@ -52284,13 +52472,13 @@ function callerHome() {
52284
52472
  function stopUserModeDaemon() {
52285
52473
  const home = callerHome();
52286
52474
  if (!home) return;
52287
- const runDir = (0, import_node_path47.join)(home, ".threatcrush", "run");
52288
- const pidFile = (0, import_node_path47.join)(runDir, "threatcrushd.pid");
52289
- const socket = (0, import_node_path47.join)(runDir, "threatcrushd.sock");
52290
- if (!(0, import_node_fs60.existsSync)(pidFile) && !(0, import_node_fs60.existsSync)(socket)) return;
52475
+ const runDir = (0, import_node_path48.join)(home, ".threatcrush", "run");
52476
+ const pidFile = (0, import_node_path48.join)(runDir, "threatcrushd.pid");
52477
+ const socket = (0, import_node_path48.join)(runDir, "threatcrushd.sock");
52478
+ if (!(0, import_node_fs61.existsSync)(pidFile) && !(0, import_node_fs61.existsSync)(socket)) return;
52291
52479
  let pid = null;
52292
52480
  try {
52293
- pid = Number.parseInt((0, import_node_fs60.readFileSync)(pidFile, "utf-8").trim(), 10);
52481
+ pid = Number.parseInt((0, import_node_fs61.readFileSync)(pidFile, "utf-8").trim(), 10);
52294
52482
  } catch {
52295
52483
  pid = null;
52296
52484
  }
@@ -52303,7 +52491,7 @@ function stopUserModeDaemon() {
52303
52491
  }
52304
52492
  for (const path2 of [socket, pidFile]) {
52305
52493
  try {
52306
- if ((0, import_node_fs60.existsSync)(path2)) (0, import_node_fs60.rmSync)(path2);
52494
+ if ((0, import_node_fs61.existsSync)(path2)) (0, import_node_fs61.rmSync)(path2);
52307
52495
  } catch {
52308
52496
  }
52309
52497
  }
@@ -52321,7 +52509,7 @@ async function installServiceCommand() {
52321
52509
  }
52322
52510
  const noSystemd = systemdUnavailableReason({
52323
52511
  hasSystemctl: (0, import_node_child_process22.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
52324
- booted: (0, import_node_fs60.existsSync)("/run/systemd/system")
52512
+ booted: (0, import_node_fs61.existsSync)("/run/systemd/system")
52325
52513
  });
52326
52514
  if (noSystemd) {
52327
52515
  console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
@@ -52343,7 +52531,7 @@ async function installServiceCommand() {
52343
52531
  const isNodeScript = looksLikeNodeScript(binPath);
52344
52532
  let nodePath = stableNodePath(process.execPath);
52345
52533
  if (isNodeScript && nodeVersionDir(binPath)) {
52346
- binPath = (0, import_node_fs60.realpathSync)(binPath);
52534
+ binPath = (0, import_node_fs61.realpathSync)(binPath);
52347
52535
  nodePath = process.execPath;
52348
52536
  }
52349
52537
  if (isNodeScript) {
@@ -52356,11 +52544,11 @@ async function installServiceCommand() {
52356
52544
  }
52357
52545
  }
52358
52546
  const exec = execStartCommand(binPath, nodePath, isNodeScript);
52359
- const configDir = (0, import_node_path47.join)((0, import_node_os19.homedir)(), ".threatcrush");
52547
+ const configDir = (0, import_node_path48.join)((0, import_node_os20.homedir)(), ".threatcrush");
52360
52548
  const commandHistoryEnabled = commandHistorySettings(loadConfig().command_history).enabled;
52361
52549
  const historyPaths = commandHistoryEnabled ? historyWritableHomes() : [];
52362
52550
  const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir, historyPaths });
52363
- (0, import_node_fs60.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
52551
+ (0, import_node_fs61.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
52364
52552
  console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
52365
52553
  console.log(source_default.dim(` ExecStart=${exec}`));
52366
52554
  const nodeDir = nodeVersionDir(nodePath);
@@ -52413,9 +52601,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
52413
52601
  ].join("\n");
52414
52602
  }
52415
52603
  function installLogrotate() {
52416
- if (!(0, import_node_fs60.existsSync)((0, import_node_path47.dirname)(LOGROTATE_PATH))) return;
52604
+ if (!(0, import_node_fs61.existsSync)((0, import_node_path48.dirname)(LOGROTATE_PATH))) return;
52417
52605
  try {
52418
- (0, import_node_fs60.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
52606
+ (0, import_node_fs61.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
52419
52607
  console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
52420
52608
  } catch (err) {
52421
52609
  console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
@@ -52437,20 +52625,20 @@ function ensureSystemDirs(configDir) {
52437
52625
  ];
52438
52626
  let admGid2 = null;
52439
52627
  try {
52440
- admGid2 = (0, import_node_fs60.statSync)("/var/log/auth.log").gid;
52628
+ admGid2 = (0, import_node_fs61.statSync)("/var/log/auth.log").gid;
52441
52629
  } catch {
52442
52630
  }
52443
52631
  for (const { path: path2, groupWritable, sticky } of dirs) {
52444
52632
  try {
52445
- (0, import_node_fs60.mkdirSync)(path2, { recursive: true });
52633
+ (0, import_node_fs61.mkdirSync)(path2, { recursive: true });
52446
52634
  } catch {
52447
52635
  }
52448
52636
  try {
52449
52637
  if (groupWritable && admGid2 !== null) {
52450
- (0, import_node_fs60.chmodSync)(path2, sticky ? 1533 : 509);
52638
+ (0, import_node_fs61.chmodSync)(path2, sticky ? 1533 : 509);
52451
52639
  (0, import_node_child_process22.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
52452
52640
  } else {
52453
- (0, import_node_fs60.chmodSync)(path2, 493);
52641
+ (0, import_node_fs61.chmodSync)(path2, 493);
52454
52642
  }
52455
52643
  } catch {
52456
52644
  }
@@ -52478,7 +52666,7 @@ async function uninstallServiceCommand() {
52478
52666
  } catch {
52479
52667
  }
52480
52668
  try {
52481
- if ((0, import_node_fs60.existsSync)(UNIT_PATH)) {
52669
+ if ((0, import_node_fs61.existsSync)(UNIT_PATH)) {
52482
52670
  (0, import_node_child_process22.execSync)(`rm -f ${UNIT_PATH}`);
52483
52671
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
52484
52672
  }
@@ -52492,8 +52680,8 @@ async function uninstallServiceCommand() {
52492
52680
  }
52493
52681
 
52494
52682
  // src/commands/save.ts
52495
- var import_node_fs61 = require("fs");
52496
- var import_toml5 = __toESM(require_toml());
52683
+ var import_node_fs62 = require("fs");
52684
+ var import_toml6 = __toESM(require_toml());
52497
52685
  init_cli_config();
52498
52686
  init_paths();
52499
52687
  var SECRET_KEY = /pass(word)?|secret|token|api_?key|private|webhook|dsn|url|routing_key|auth/i;
@@ -52531,9 +52719,9 @@ async function saveCommand(opts = {}) {
52531
52719
  }
52532
52720
  const path2 = opts.config ?? PATHS.configFile;
52533
52721
  let config = {};
52534
- if ((0, import_node_fs61.existsSync)(path2)) {
52722
+ if ((0, import_node_fs62.existsSync)(path2)) {
52535
52723
  try {
52536
- config = import_toml5.default.parse((0, import_node_fs61.readFileSync)(path2, "utf-8"));
52724
+ config = import_toml6.default.parse((0, import_node_fs62.readFileSync)(path2, "utf-8"));
52537
52725
  } catch (err) {
52538
52726
  console.log(source_default.red(` \u2717 ${path2} is not valid TOML: ${err.message}
52539
52727
  `));
@@ -52646,8 +52834,8 @@ function welcomeCommand() {
52646
52834
  }
52647
52835
 
52648
52836
  // src/commands/properties.ts
52649
- var import_node_fs62 = require("fs");
52650
- var import_node_path48 = require("path");
52837
+ var import_node_fs63 = require("fs");
52838
+ var import_node_path49 = require("path");
52651
52839
  var import_node_readline4 = __toESM(require("readline"));
52652
52840
  init_cli_config();
52653
52841
  var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
@@ -52977,8 +53165,8 @@ async function propertiesRunsCommand(opts) {
52977
53165
  }
52978
53166
  }
52979
53167
  function parseImportFile(path2) {
52980
- const ext = (0, import_node_path48.extname)(path2).toLowerCase();
52981
- const raw = (0, import_node_fs62.readFileSync)(path2, "utf-8");
53168
+ const ext = (0, import_node_path49.extname)(path2).toLowerCase();
53169
+ const raw = (0, import_node_fs63.readFileSync)(path2, "utf-8");
52982
53170
  if (ext === ".json") {
52983
53171
  const parsed = JSON.parse(raw);
52984
53172
  if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
@@ -53173,13 +53361,13 @@ async function rulesCommand(opts) {
53173
53361
  }
53174
53362
 
53175
53363
  // src/commands/harden.ts
53176
- var import_node_fs64 = require("fs");
53364
+ var import_node_fs65 = require("fs");
53177
53365
  var import_node_child_process23 = require("child_process");
53178
53366
  init_cli_config();
53179
53367
 
53180
53368
  // src/commands/cis-report.ts
53181
- var import_node_os20 = require("os");
53182
- var import_node_fs63 = require("fs");
53369
+ var import_node_os21 = require("os");
53370
+ var import_node_fs64 = require("fs");
53183
53371
  var CIS_UBUNTU_URL = "https://www.cisecurity.org/benchmark/ubuntu_linux";
53184
53372
  var CIS_DEBIAN_URL = "https://www.cisecurity.org/benchmark/debian_linux";
53185
53373
  var UBUNTU_2404_CIS_CONTROL_SOURCE = "https://github.com/ComplianceAsCode/content/blob/v0.1.78/controls/cis_ubuntu2404.yml";
@@ -53199,7 +53387,7 @@ var EDITIONS = {
53199
53387
  function osRelease() {
53200
53388
  let raw = "";
53201
53389
  try {
53202
- raw = (0, import_node_fs63.readFileSync)("/etc/os-release", "utf8");
53390
+ raw = (0, import_node_fs64.readFileSync)("/etc/os-release", "utf8");
53203
53391
  } catch {
53204
53392
  return {};
53205
53393
  }
@@ -53272,7 +53460,7 @@ function buildCisEvidenceReport(findings2, score, now = /* @__PURE__ */ new Date
53272
53460
  schema_version: 1,
53273
53461
  generated_at: now.toISOString(),
53274
53462
  benchmark_catalog_checked_at: "2026-11-01",
53275
- host: { hostname: (0, import_node_os20.hostname)(), os_id: id, os_version: version, pretty_name: os4.PRETTY_NAME ?? null },
53463
+ host: { hostname: (0, import_node_os21.hostname)(), os_id: id, os_version: version, pretty_name: os4.PRETTY_NAME ?? null },
53276
53464
  benchmark: edition ? { name: edition.name, version: edition.version, source: edition.source } : null,
53277
53465
  assessment: "partial",
53278
53466
  mapped_controls: mappedControls.size,
@@ -53379,7 +53567,7 @@ function writeCisReport(path2, format2, report) {
53379
53567
  const markdown = renderCisMarkdown(report);
53380
53568
  const content = format2 === "json" ? `${JSON.stringify(report, null, 2)}
53381
53569
  ` : format2 === "pdf" ? renderCisPdf(markdown) : markdown;
53382
- (0, import_node_fs63.writeFileSync)(path2, content);
53570
+ (0, import_node_fs64.writeFileSync)(path2, content);
53383
53571
  }
53384
53572
 
53385
53573
  // src/commands/harden.ts
@@ -53392,7 +53580,7 @@ function tryExec(cmd) {
53392
53580
  }
53393
53581
  function tryRead(path2) {
53394
53582
  try {
53395
- return (0, import_node_fs64.readFileSync)(path2, "utf-8");
53583
+ return (0, import_node_fs65.readFileSync)(path2, "utf-8");
53396
53584
  } catch {
53397
53585
  return null;
53398
53586
  }
@@ -53506,8 +53694,8 @@ function checkSshWeakConfig() {
53506
53694
  };
53507
53695
  }
53508
53696
  function checkAutoUpdates() {
53509
- 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");
53510
- const dnfAuto = (0, import_node_fs64.existsSync)("/etc/dnf/automatic.conf");
53697
+ 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");
53698
+ const dnfAuto = (0, import_node_fs65.existsSync)("/etc/dnf/automatic.conf");
53511
53699
  if (unattended || dnfAuto) {
53512
53700
  return {
53513
53701
  key: "auto-updates",
@@ -53633,7 +53821,7 @@ function checkFail2ban() {
53633
53821
  explanation: "fail2ban is installed and running."
53634
53822
  };
53635
53823
  }
53636
- if ((0, import_node_fs64.existsSync)("/etc/fail2ban/fail2ban.conf")) {
53824
+ if ((0, import_node_fs65.existsSync)("/etc/fail2ban/fail2ban.conf")) {
53637
53825
  return {
53638
53826
  key: checkKey,
53639
53827
  status: "warn",
@@ -53853,8 +54041,8 @@ async function hardenCommand(opts) {
53853
54041
  }
53854
54042
 
53855
54043
  // src/core/patches/index.ts
53856
- var import_node_fs65 = require("fs");
53857
- var import_node_path49 = require("path");
54044
+ var import_node_fs66 = require("fs");
54045
+ var import_node_path50 = require("path");
53858
54046
  var import_node_child_process24 = require("child_process");
53859
54047
  var import_node_util5 = require("util");
53860
54048
 
@@ -54014,9 +54202,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
54014
54202
  function newestReleaseMtime(dir) {
54015
54203
  try {
54016
54204
  let newest = 0;
54017
- for (const name of (0, import_node_fs65.readdirSync)(dir)) {
54205
+ for (const name of (0, import_node_fs66.readdirSync)(dir)) {
54018
54206
  if (!/Release$/.test(name)) continue;
54019
- newest = Math.max(newest, (0, import_node_fs65.statSync)((0, import_node_path49.join)(dir, name)).mtimeMs);
54207
+ newest = Math.max(newest, (0, import_node_fs66.statSync)((0, import_node_path50.join)(dir, name)).mtimeMs);
54020
54208
  }
54021
54209
  return newest > 0 ? new Date(newest) : null;
54022
54210
  } catch {
@@ -54033,7 +54221,7 @@ async function checkPatches(opts = {}) {
54033
54221
  let osText = opts.osRelease;
54034
54222
  if (osText === void 0) {
54035
54223
  try {
54036
- osText = (0, import_node_fs65.readFileSync)("/etc/os-release", "utf-8");
54224
+ osText = (0, import_node_fs66.readFileSync)("/etc/os-release", "utf-8");
54037
54225
  } catch {
54038
54226
  osText = "";
54039
54227
  }
@@ -54260,24 +54448,24 @@ async function patchesCommand(opts) {
54260
54448
 
54261
54449
  // src/commands/feeds.ts
54262
54450
  var import_node_net18 = require("net");
54263
- var import_node_path51 = require("path");
54451
+ var import_node_path52 = require("path");
54264
54452
  init_paths();
54265
54453
 
54266
54454
  // src/commands/feeds-resolver.ts
54267
54455
  var import_node_child_process25 = require("child_process");
54268
- var import_node_fs66 = require("fs");
54269
- var import_node_path50 = require("path");
54456
+ var import_node_fs67 = require("fs");
54457
+ var import_node_path51 = require("path");
54270
54458
  var realIO = {
54271
- exists: (p) => (0, import_node_fs66.existsSync)(p),
54459
+ exists: (p) => (0, import_node_fs67.existsSync)(p),
54272
54460
  read: (p) => {
54273
54461
  try {
54274
- return (0, import_node_fs66.readFileSync)(p, "utf-8");
54462
+ return (0, import_node_fs67.readFileSync)(p, "utf-8");
54275
54463
  } catch {
54276
54464
  return null;
54277
54465
  }
54278
54466
  },
54279
- write: (p, c) => (0, import_node_fs66.writeFileSync)(p, c),
54280
- remove: (p) => (0, import_node_fs66.rmSync)(p, { force: true }),
54467
+ write: (p, c) => (0, import_node_fs67.writeFileSync)(p, c),
54468
+ remove: (p) => (0, import_node_fs67.rmSync)(p, { force: true }),
54281
54469
  run: (cmd, args) => {
54282
54470
  const r = (0, import_node_child_process25.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
54283
54471
  return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
@@ -54286,18 +54474,18 @@ var realIO = {
54286
54474
  var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
54287
54475
  var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
54288
54476
  function hookContent(resolver, stateDir) {
54289
- const head = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
54290
- return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path50.join)(stateDir, RESOLVER_FILES.hosts)}
54291
- ` : `${head}include: "${(0, import_node_path50.join)(stateDir, RESOLVER_FILES.unbound)}"
54477
+ const head2 = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
54478
+ return resolver === "dnsmasq" ? `${head2}addn-hosts=${(0, import_node_path51.join)(stateDir, RESOLVER_FILES.hosts)}
54479
+ ` : `${head2}include: "${(0, import_node_path51.join)(stateDir, RESOLVER_FILES.unbound)}"
54292
54480
  `;
54293
54481
  }
54294
54482
  function apparmorRule(stateDir) {
54295
- return ` ${(0, import_node_path50.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
54483
+ return ` ${(0, import_node_path51.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
54296
54484
  }
54297
54485
  function detectResolvers(io = realIO) {
54298
54486
  const found = [];
54299
- if (io.exists((0, import_node_path50.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
54300
- if (io.exists((0, import_node_path50.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
54487
+ if (io.exists((0, import_node_path51.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
54488
+ if (io.exists((0, import_node_path51.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
54301
54489
  return found;
54302
54490
  }
54303
54491
  function check(resolver, io) {
@@ -54310,7 +54498,7 @@ function restartIfActive(resolver, io) {
54310
54498
  }
54311
54499
  function installHook(resolver, stateDir, io = realIO) {
54312
54500
  const hook = RESOLVER_HOOKS[resolver];
54313
- const file = (0, import_node_path50.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
54501
+ const file = (0, import_node_path51.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
54314
54502
  if (!io.exists(file)) io.write(file, resolver === "dnsmasq" ? hostsBlocklist([]) : unboundBlocklist([]));
54315
54503
  io.write(hook, hookContent(resolver, stateDir));
54316
54504
  if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
@@ -54371,8 +54559,8 @@ function resolverCommand(sub, stateDir, io = realIO) {
54371
54559
  }
54372
54560
  return failed ? 1 : 0;
54373
54561
  }
54374
- const hosts = io.read((0, import_node_path50.join)(stateDir, RESOLVER_FILES.hosts));
54375
- const unbound = io.read((0, import_node_path50.join)(stateDir, RESOLVER_FILES.unbound));
54562
+ const hosts = io.read((0, import_node_path51.join)(stateDir, RESOLVER_FILES.hosts));
54563
+ const unbound = io.read((0, import_node_path51.join)(stateDir, RESOLVER_FILES.unbound));
54376
54564
  console.log(` resolvers here: ${found.join(", ") || "none that can block (systemd-resolved only?)"}`);
54377
54565
  for (const r of ["dnsmasq", "unbound"]) {
54378
54566
  console.log(` ${r.padEnd(8)} hook ${io.exists(RESOLVER_HOOKS[r]) ? source_default.green("installed") : source_default.gray("not installed")}`);
@@ -54384,11 +54572,11 @@ function resolverCommand(sub, stateDir, io = realIO) {
54384
54572
  // src/commands/feeds.ts
54385
54573
  async function loadSet() {
54386
54574
  for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
54387
- const path2 = (0, import_node_path51.join)(dir, "threat-feeds.json");
54575
+ const path2 = (0, import_node_path52.join)(dir, "threat-feeds.json");
54388
54576
  const set = readFeedCache(path2);
54389
54577
  if (set) return { set, from: path2 };
54390
54578
  }
54391
- const settings = threatFeedSettings(loadConfig((0, import_node_path51.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
54579
+ const settings = threatFeedSettings(loadConfig((0, import_node_path52.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
54392
54580
  return { set: await fetchFeeds(settings), from: "abuse.ch (live; no daemon cache readable)" };
54393
54581
  }
54394
54582
  async function feedsCommand(action, value, opts) {
@@ -54432,21 +54620,21 @@ async function feedsCommand(action, value, opts) {
54432
54620
  }
54433
54621
 
54434
54622
  // src/commands/tor.ts
54435
- var import_node_fs67 = require("fs");
54623
+ var import_node_fs68 = require("fs");
54436
54624
  var import_node_net19 = require("net");
54437
- var import_node_path52 = require("path");
54625
+ var import_node_path53 = require("path");
54438
54626
  init_paths();
54439
54627
  async function torCommand(action, value, opts) {
54440
54628
  let exits = /* @__PURE__ */ new Set();
54441
54629
  let from = "";
54442
54630
  let updated = null;
54443
54631
  for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
54444
- const path2 = (0, import_node_path52.join)(dir, "tor-exits.txt");
54632
+ const path2 = (0, import_node_path53.join)(dir, "tor-exits.txt");
54445
54633
  try {
54446
- if (!(0, import_node_fs67.existsSync)(path2)) continue;
54447
- exits = parseTorExitList((0, import_node_fs67.readFileSync)(path2, "utf-8"));
54634
+ if (!(0, import_node_fs68.existsSync)(path2)) continue;
54635
+ exits = parseTorExitList((0, import_node_fs68.readFileSync)(path2, "utf-8"));
54448
54636
  from = path2;
54449
- updated = (0, import_node_fs67.statSync)(path2).mtime;
54637
+ updated = (0, import_node_fs68.statSync)(path2).mtime;
54450
54638
  break;
54451
54639
  } catch {
54452
54640
  }
@@ -54462,7 +54650,7 @@ async function torCommand(action, value, opts) {
54462
54650
  } catch {
54463
54651
  }
54464
54652
  }
54465
- const remediation = loadConfig((0, import_node_path52.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).remediation;
54653
+ const remediation = loadConfig((0, import_node_path53.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).remediation;
54466
54654
  const ban = remediation?.block_tor_ssh !== false && remediation?.enabled !== false;
54467
54655
  if (action === "check") {
54468
54656
  if (!value || !(0, import_node_net19.isIP)(value)) {
@@ -54493,14 +54681,14 @@ async function torCommand(action, value, opts) {
54493
54681
  }
54494
54682
 
54495
54683
  // src/commands/reputation.ts
54496
- var import_node_os21 = require("os");
54497
- var import_node_fs68 = require("fs");
54498
- var import_node_path53 = require("path");
54684
+ var import_node_os22 = require("os");
54685
+ var import_node_fs69 = require("fs");
54686
+ var import_node_path54 = require("path");
54499
54687
  var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
54500
- var CONFIG_PATH4 = (0, import_node_path53.join)((0, import_node_os21.homedir)(), ".threatcrush", "config.json");
54688
+ var CONFIG_PATH4 = (0, import_node_path54.join)((0, import_node_os22.homedir)(), ".threatcrush", "config.json");
54501
54689
  function readConfig3() {
54502
54690
  try {
54503
- return JSON.parse((0, import_node_fs68.readFileSync)(CONFIG_PATH4, "utf-8"));
54691
+ return JSON.parse((0, import_node_fs69.readFileSync)(CONFIG_PATH4, "utf-8"));
54504
54692
  } catch {
54505
54693
  return {};
54506
54694
  }
@@ -54513,8 +54701,8 @@ function authFor(env3 = process.env, config = readConfig3()) {
54513
54701
  }
54514
54702
  function formatReport(r) {
54515
54703
  const lines = [];
54516
- const head = r.listed ? source_default.red(`LISTED score ${r.score}/100`) : source_default.green("not listed");
54517
- lines.push(` ${source_default.bold(r.ip)} ${head} ${source_default.dim(`(${r.tier})`)}`);
54704
+ const head2 = r.listed ? source_default.red(`LISTED score ${r.score}/100`) : source_default.green("not listed");
54705
+ lines.push(` ${source_default.bold(r.ip)} ${head2} ${source_default.dim(`(${r.tier})`)}`);
54518
54706
  if (r.reports) {
54519
54707
  lines.push(
54520
54708
  ` ${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}` : ""}`
@@ -54535,8 +54723,8 @@ function formatReport(r) {
54535
54723
  }
54536
54724
  function formatAny(r) {
54537
54725
  if (r.type !== "domain") return formatReport(r);
54538
- const head = r.listed ? source_default.red(`LISTED score ${r.score}/100`) : source_default.green("not listed");
54539
- const lines = [` ${source_default.bold(r.domain)} ${head} ${source_default.dim(`(${r.tier})`)}`];
54726
+ const head2 = r.listed ? source_default.red(`LISTED score ${r.score}/100`) : source_default.green("not listed");
54727
+ const lines = [` ${source_default.bold(r.domain)} ${head2} ${source_default.dim(`(${r.tier})`)}`];
54540
54728
  for (const reason of r.reasons) lines.push(` \xB7 ${reason}`);
54541
54729
  for (const a of r.addresses) lines.push(` ${a.ip}: ${a.listed ? source_default.red(`listed, ${a.score}/100`) : "not listed"}`);
54542
54730
  lines.push(source_default.dim(` public record: ${r.public_record}`));
@@ -54688,7 +54876,7 @@ async function reputationSubscribeCommand(opts) {
54688
54876
  }
54689
54877
 
54690
54878
  // src/commands/privileged.ts
54691
- var import_node_fs69 = require("fs");
54879
+ var import_node_fs70 = require("fs");
54692
54880
  init_paths();
54693
54881
  var SEV2 = {
54694
54882
  critical: source_default.red.bold,
@@ -54701,19 +54889,19 @@ async function privilegedCommand(opts) {
54701
54889
  const snapshot = takeSnapshot({
54702
54890
  readFile: (p) => {
54703
54891
  try {
54704
- return (0, import_node_fs69.readFileSync)(p, "utf-8");
54892
+ return (0, import_node_fs70.readFileSync)(p, "utf-8");
54705
54893
  } catch {
54706
54894
  return null;
54707
54895
  }
54708
54896
  },
54709
54897
  readDir: (p) => {
54710
54898
  try {
54711
- return (0, import_node_fs69.readdirSync)(p);
54899
+ return (0, import_node_fs70.readdirSync)(p);
54712
54900
  } catch {
54713
54901
  return null;
54714
54902
  }
54715
54903
  },
54716
- exists: (p) => (0, import_node_fs69.existsSync)(p)
54904
+ exists: (p) => (0, import_node_fs70.existsSync)(p)
54717
54905
  });
54718
54906
  let events = [];
54719
54907
  let ledgerNote = "";
@@ -54755,12 +54943,12 @@ async function privilegedCommand(opts) {
54755
54943
  }
54756
54944
 
54757
54945
  // src/commands/integrity.ts
54758
- var import_node_fs70 = require("fs");
54759
- var import_node_path54 = require("path");
54946
+ var import_node_fs71 = require("fs");
54947
+ var import_node_path55 = require("path");
54760
54948
  init_paths();
54761
54949
  function readState2(path2) {
54762
54950
  try {
54763
- return JSON.parse((0, import_node_fs70.readFileSync)(path2, "utf8"));
54951
+ return JSON.parse((0, import_node_fs71.readFileSync)(path2, "utf8"));
54764
54952
  } catch {
54765
54953
  return null;
54766
54954
  }
@@ -54780,11 +54968,11 @@ function changedCount(baseline, observed) {
54780
54968
  async function integrityCommand(action = "status", opts = {}) {
54781
54969
  const config = loadConfig();
54782
54970
  const settings = fileIntegritySettings(config.file_integrity);
54783
- const systemBaseline = (0, import_node_path54.join)(SYSTEM_PATHS.stateDir, "file-integrity-baseline.json");
54784
- const useSystemState = PATHS.mode === "system" || systemDaemonPresent() || (0, import_node_fs70.existsSync)(systemBaseline);
54971
+ const systemBaseline = (0, import_node_path55.join)(SYSTEM_PATHS.stateDir, "file-integrity-baseline.json");
54972
+ const useSystemState = PATHS.mode === "system" || systemDaemonPresent() || (0, import_node_fs71.existsSync)(systemBaseline);
54785
54973
  const stateDir = useSystemState ? SYSTEM_PATHS.stateDir : PATHS.stateDir;
54786
- const baselinePath = (0, import_node_path54.join)(stateDir, "file-integrity-baseline.json");
54787
- const observedPath = (0, import_node_path54.join)(stateDir, "file-integrity-observed.json");
54974
+ const baselinePath = (0, import_node_path55.join)(stateDir, "file-integrity-baseline.json");
54975
+ const observedPath = (0, import_node_path55.join)(stateDir, "file-integrity-observed.json");
54788
54976
  if (action === "rebaseline") {
54789
54977
  const watch4 = new FileIntegrityWatch({
54790
54978
  bus: { publish: () => void 0 },
@@ -54852,13 +55040,13 @@ async function integrityCommand(action = "status", opts = {}) {
54852
55040
  }
54853
55041
 
54854
55042
  // src/commands/edr.ts
54855
- var import_node_fs72 = require("fs");
55043
+ var import_node_fs73 = require("fs");
54856
55044
  init_paths();
54857
55045
 
54858
55046
  // src/daemon/auditd/rules.ts
54859
- var import_node_fs71 = require("fs");
55047
+ var import_node_fs72 = require("fs");
54860
55048
  var import_node_child_process26 = require("child_process");
54861
- var import_node_path55 = require("path");
55049
+ var import_node_path56 = require("path");
54862
55050
  var WEB_TOOLS = ["sh", "bash", "dash", "zsh", "curl", "wget"];
54863
55051
  var MINER_NAMES = ["xmrig", "minerd", "cpuminer", "cpuminer-multi", "kdevtmpfsi", "kinsing", "cryptonight"];
54864
55052
  var CONNECT_KEY2 = "threatcrush_edr_connect";
@@ -54869,7 +55057,7 @@ function passwdByName() {
54869
55057
  raw = (0, import_node_child_process26.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
54870
55058
  } catch {
54871
55059
  try {
54872
- raw = (0, import_node_fs71.readFileSync)("/etc/passwd", "utf8");
55060
+ raw = (0, import_node_fs72.readFileSync)("/etc/passwd", "utf8");
54873
55061
  } catch {
54874
55062
  return /* @__PURE__ */ new Map();
54875
55063
  }
@@ -54888,8 +55076,8 @@ function existingExecutables(names) {
54888
55076
  for (const prefix of ["/bin", "/usr/bin", "/usr/local/bin"]) {
54889
55077
  const candidate = `${prefix}/${name}`;
54890
55078
  try {
54891
- if (!(0, import_node_fs71.existsSync)(candidate) || !(0, import_node_fs71.statSync)(candidate).isFile()) continue;
54892
- paths.add((0, import_node_fs71.realpathSync)(candidate));
55079
+ if (!(0, import_node_fs72.existsSync)(candidate) || !(0, import_node_fs72.statSync)(candidate).isFile()) continue;
55080
+ paths.add((0, import_node_fs72.realpathSync)(candidate));
54893
55081
  } catch {
54894
55082
  }
54895
55083
  }
@@ -54898,9 +55086,9 @@ function existingExecutables(names) {
54898
55086
  }
54899
55087
  function existingDirectories(paths) {
54900
55088
  return [...new Set(paths)].filter((path2) => {
54901
- if (!(0, import_node_path55.isAbsolute)(path2) || /[\s\r\n]/.test(path2)) return false;
55089
+ if (!(0, import_node_path56.isAbsolute)(path2) || /[\s\r\n]/.test(path2)) return false;
54902
55090
  try {
54903
- return (0, import_node_fs71.statSync)(path2).isDirectory();
55091
+ return (0, import_node_fs72.statSync)(path2).isDirectory();
54904
55092
  } catch {
54905
55093
  return false;
54906
55094
  }
@@ -54961,8 +55149,8 @@ async function edrCommand(action = "status", opts = {}) {
54961
55149
  }
54962
55150
  let readable = false;
54963
55151
  try {
54964
- if ((0, import_node_fs72.existsSync)(settings.auditLogPath)) (0, import_node_fs72.accessSync)(settings.auditLogPath, import_node_fs72.constants.R_OK);
54965
- readable = (0, import_node_fs72.existsSync)(settings.auditLogPath);
55152
+ if ((0, import_node_fs73.existsSync)(settings.auditLogPath)) (0, import_node_fs73.accessSync)(settings.auditLogPath, import_node_fs73.constants.R_OK);
55153
+ readable = (0, import_node_fs73.existsSync)(settings.auditLogPath);
54966
55154
  } catch {
54967
55155
  }
54968
55156
  let events = [];
@@ -55148,7 +55336,7 @@ async function allowlistCommand(opts) {
55148
55336
  }
55149
55337
 
55150
55338
  // src/commands/abuse.ts
55151
- var import_node_fs73 = require("fs");
55339
+ var import_node_fs74 = require("fs");
55152
55340
  init_paths();
55153
55341
  function rows(records) {
55154
55342
  if (records.length === 0) {
@@ -55208,7 +55396,7 @@ function abuseRetractCommand(id, opts = {}) {
55208
55396
  );
55209
55397
  }
55210
55398
  function abuseStatusCommand(opts = {}) {
55211
- const config = loadConfig((0, import_node_fs73.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
55399
+ const config = loadConfig((0, import_node_fs74.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
55212
55400
  const cfg = resolveConfig(config.abuse_reporter);
55213
55401
  const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
55214
55402
  const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
@@ -55377,8 +55565,8 @@ function installUserAgent(target = globalThis) {
55377
55565
 
55378
55566
  // src/core/cloud-upload.ts
55379
55567
  var import_node_child_process28 = require("child_process");
55380
- var import_node_os22 = require("os");
55381
- var import_node_path56 = require("path");
55568
+ var import_node_os23 = require("os");
55569
+ var import_node_path57 = require("path");
55382
55570
  init_cli_config();
55383
55571
  function uploadDisabled(upload, env3 = process.env) {
55384
55572
  if (upload === false) return true;
@@ -55397,8 +55585,8 @@ function cleanUrl(raw) {
55397
55585
  return raw.split(/[?#]/)[0];
55398
55586
  }
55399
55587
  }
55400
- function repoTarget(path2, run2 = (args) => (0, import_node_child_process28.execFileSync)("git", args, { cwd: (0, import_node_path56.resolve)(path2), encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }).trim()) {
55401
- const abs = (0, import_node_path56.resolve)(path2);
55588
+ function repoTarget(path2, run2 = (args) => (0, import_node_child_process28.execFileSync)("git", args, { cwd: (0, import_node_path57.resolve)(path2), encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }).trim()) {
55589
+ const abs = (0, import_node_path57.resolve)(path2);
55402
55590
  try {
55403
55591
  const root = run2(["rev-parse", "--show-toplevel"]);
55404
55592
  const sub = abs === root ? "." : abs.slice(root.length + 1);
@@ -55411,9 +55599,9 @@ function repoTarget(path2, run2 = (args) => (0, import_node_child_process28.exec
55411
55599
  const m = /^(?:[a-z+]+:\/\/)?(?:[^@/]+@)?([^/:]+)[:/](.+?)(?:\.git)?\/?$/i.exec(remote);
55412
55600
  if (m) return { target: `${m[1]}/${m[2]}`, root, sub };
55413
55601
  }
55414
- return { target: `${(0, import_node_os22.hostname)()}:${root}`, root, sub };
55602
+ return { target: `${(0, import_node_os23.hostname)()}:${root}`, root, sub };
55415
55603
  } catch {
55416
- return { target: `${(0, import_node_os22.hostname)()}:${abs}`, root: abs, sub: "." };
55604
+ return { target: `${(0, import_node_os23.hostname)()}:${abs}`, root: abs, sub: "." };
55417
55605
  }
55418
55606
  }
55419
55607
  async function uploadResult(result, opts) {
@@ -55770,7 +55958,7 @@ ${source_default.dim(" C R U S H")}
55770
55958
  var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
55771
55959
  var PKG_NAME2 = "@profullstack/threatcrush";
55772
55960
  var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
55773
- var INSTALL_CONFIG_PATH = (0, import_node_path57.join)((0, import_node_os23.homedir)(), ".threatcrush", "install.json");
55961
+ var INSTALL_CONFIG_PATH = (0, import_node_path58.join)((0, import_node_os24.homedir)(), ".threatcrush", "install.json");
55774
55962
  function detectPackageManager() {
55775
55963
  try {
55776
55964
  const npmGlobal = (0, import_node_child_process29.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
@@ -55796,7 +55984,7 @@ function detectPackageManager() {
55796
55984
  }
55797
55985
  function readInstallConfig() {
55798
55986
  try {
55799
- return JSON.parse((0, import_node_fs74.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
55987
+ return JSON.parse((0, import_node_fs75.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
55800
55988
  } catch {
55801
55989
  return {};
55802
55990
  }
@@ -56075,7 +56263,7 @@ program2.command("scan").description("Scan codebase for vulnerabilities and secr
56075
56263
  }
56076
56264
  });
56077
56265
  var av = program2.command("av").alias("antivirus").description("CrushAV: free open-source antivirus (heuristics + ClamAV + hash reputation), Windows/macOS/Linux");
56078
- 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) => {
56266
+ 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) => {
56079
56267
  await avScanCommand(paths, opts);
56080
56268
  });
56081
56269
  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));
@@ -56227,7 +56415,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
56227
56415
  program2.command("logs").description("Tail daemon logs").action(async () => {
56228
56416
  console.log(LOGO2);
56229
56417
  const logPath2 = PATHS.logFile;
56230
- if (!(0, import_node_fs74.existsSync)(logPath2)) {
56418
+ if (!(0, import_node_fs75.existsSync)(logPath2)) {
56231
56419
  console.log(source_default.yellow(` No log file found at ${logPath2}`));
56232
56420
  console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
56233
56421
  return;
@@ -56400,10 +56588,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
56400
56588
  });
56401
56589
  storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
56402
56590
  console.log(LOGO2);
56403
- const configPath = (0, import_node_path57.join)((0, import_node_os23.homedir)(), ".threatcrush", "config.json");
56591
+ const configPath = (0, import_node_path58.join)((0, import_node_os24.homedir)(), ".threatcrush", "config.json");
56404
56592
  let email = "";
56405
56593
  try {
56406
- const config = JSON.parse((0, import_node_fs74.readFileSync)(configPath, "utf-8"));
56594
+ const config = JSON.parse((0, import_node_fs75.readFileSync)(configPath, "utf-8"));
56407
56595
  email = config.email || "";
56408
56596
  } catch {
56409
56597
  }
@@ -56420,9 +56608,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
56420
56608
  return;
56421
56609
  }
56422
56610
  try {
56423
- const dir = (0, import_node_path57.join)((0, import_node_os23.homedir)(), ".threatcrush");
56424
- if (!(0, import_node_fs74.existsSync)(dir)) (0, import_node_fs74.mkdirSync)(dir, { recursive: true });
56425
- (0, import_node_fs74.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
56611
+ const dir = (0, import_node_path58.join)((0, import_node_os24.homedir)(), ".threatcrush");
56612
+ if (!(0, import_node_fs75.existsSync)(dir)) (0, import_node_fs75.mkdirSync)(dir, { recursive: true });
56613
+ (0, import_node_fs75.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
56426
56614
  console.log(source_default.dim(` Saved email to ${configPath}`));
56427
56615
  } catch {
56428
56616
  }