@profullstack/threatcrush 0.13.74 → 0.13.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -17944,9 +17944,9 @@ function renderCells(data, cols, rows2, opts = {}) {
17944
17944
  const s = targetServer(o, data.servers);
17945
17945
  if (!s) continue;
17946
17946
  const pts = arcSegments(o, s, 64).flat();
17947
- const head = Math.floor(cometPhase(o.ip, now) * pts.length);
17947
+ const head2 = Math.floor(cometPhase(o.ip, now) * pts.length);
17948
17948
  const color = severityColor2(o.severity);
17949
- for (let i = Math.max(0, head - 10); i <= head && i < pts.length; i++) {
17949
+ for (let i = Math.max(0, head2 - 10); i <= head2 && i < pts.length; i++) {
17950
17950
  dot(pts[i].x * W, pts[i].y * H, color, SEVERITY_RANK[o.severity]);
17951
17951
  }
17952
17952
  }
@@ -18041,8 +18041,8 @@ function renderPng(data, width, height, opts = {}) {
18041
18041
  for (let i = 1; i < seg.length; i++) line(r, seg[i - 1], seg[i], width, height, c, 0.18);
18042
18042
  }
18043
18043
  const pts = segs.flat();
18044
- const head = cometPhase(o.ip, now) * (pts.length - 1);
18045
- const h = Math.floor(head);
18044
+ const head2 = cometPhase(o.ip, now) * (pts.length - 1);
18045
+ const h = Math.floor(head2);
18046
18046
  for (let i = Math.max(0, h - 18); i <= h; i++) {
18047
18047
  const t = 1 - (h - i) / 18;
18048
18048
  r.disc(pts[i].x * width, pts[i].y * height, 1 + t * 1.4, c, t * 0.9);
@@ -23787,9 +23787,9 @@ var source_default = chalk;
23787
23787
  // src/index.ts
23788
23788
  var import_readline = __toESM(require("readline"));
23789
23789
  var import_node_child_process29 = require("child_process");
23790
- var import_node_fs74 = require("fs");
23790
+ var import_node_fs75 = require("fs");
23791
23791
  var import_node_path57 = require("path");
23792
- var import_node_os23 = require("os");
23792
+ var import_node_os24 = require("os");
23793
23793
 
23794
23794
  // src/commands/monitor.ts
23795
23795
  var import_node_fs11 = require("fs");
@@ -37030,7 +37030,7 @@ var DISPLAY_STRING = /(\b(?:echo|printf|say|info|warn|error)\s+(?:-[A-Za-z]+\s+)
37030
37030
  function stripDisplayedStrings(line2) {
37031
37031
  return line2.replace(
37032
37032
  DISPLAY_STRING,
37033
- (whole, head, quoted) => /"(?:[^"\\\n]|\\.)*(?:\$\(|`)(?:[^"\\\n]|\\.)*"/.test(quoted) ? whole : `${head}""`
37033
+ (whole, head2, quoted) => /"(?:[^"\\\n]|\\.)*(?:\$\(|`)(?:[^"\\\n]|\\.)*"/.test(quoted) ? whole : `${head2}""`
37034
37034
  );
37035
37035
  }
37036
37036
  var MINIFIED_LINE = 1e3;
@@ -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_path46 = 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");
43441
+ var import_node_os19 = require("os");
43292
43442
  var import_node_path45 = 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,14 @@ 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");
43749
+ var import_node_fs40 = require("fs");
43600
43750
  var import_node_path30 = require("path");
43601
43751
  var import_node_url = require("url");
43602
43752
  var import_toml4 = __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");
43607
43757
  var DEFAULT_SOURCES = [
43608
43758
  { path: "/var/log/auth.log", module: "ssh-guard", category: "auth" },
43609
43759
  { path: "/var/log/secure", module: "ssh-guard", category: "auth" },
@@ -43626,9 +43776,9 @@ var LogWatcher = class {
43626
43776
  start() {
43627
43777
  const started = [];
43628
43778
  for (const src of this.sources) {
43629
- if (!(0, import_node_fs34.existsSync)(src.path)) continue;
43779
+ if (!(0, import_node_fs35.existsSync)(src.path)) continue;
43630
43780
  try {
43631
- (0, import_node_fs34.accessSync)(src.path, import_node_fs34.constants.R_OK);
43781
+ (0, import_node_fs35.accessSync)(src.path, import_node_fs35.constants.R_OK);
43632
43782
  } catch {
43633
43783
  continue;
43634
43784
  }
@@ -44014,7 +44164,7 @@ function realtimeToDate(rt) {
44014
44164
 
44015
44165
  // src/modules/network-monitor/index.ts
44016
44166
  var import_node_child_process8 = require("child_process");
44017
- var import_node_fs35 = require("fs");
44167
+ var import_node_fs36 = require("fs");
44018
44168
  var NetworkMonitor = class {
44019
44169
  constructor(bus2) {
44020
44170
  this.bus = bus2;
@@ -44078,7 +44228,7 @@ var NetworkMonitor = class {
44078
44228
  hasConntrackOrSs() {
44079
44229
  const ss = (0, import_node_child_process8.spawnSync)("ss", ["--version"], { stdio: "pipe" });
44080
44230
  if (ss.status === 0) return true;
44081
- return (0, import_node_fs35.existsSync)("/proc/net/tcp");
44231
+ return (0, import_node_fs36.existsSync)("/proc/net/tcp");
44082
44232
  }
44083
44233
  /**
44084
44234
  * The TCP ports this host actually listens on.
@@ -44265,18 +44415,18 @@ var NetworkMonitor = class {
44265
44415
  };
44266
44416
 
44267
44417
  // src/modules/dns-monitor/index.ts
44268
- var import_node_fs38 = require("fs");
44418
+ var import_node_fs39 = require("fs");
44269
44419
  var import_node_child_process10 = require("child_process");
44270
44420
  var import_node_readline3 = require("readline");
44271
44421
 
44272
44422
  // src/core/threat-feeds/index.ts
44273
- var import_node_fs37 = require("fs");
44423
+ var import_node_fs38 = require("fs");
44274
44424
  var import_node_path29 = require("path");
44275
44425
  var import_node_net7 = require("net");
44276
44426
 
44277
44427
  // src/daemon/firewall/protected.ts
44278
44428
  var import_node_child_process9 = require("child_process");
44279
- var import_node_fs36 = require("fs");
44429
+ var import_node_fs37 = require("fs");
44280
44430
  var import_node_net6 = require("net");
44281
44431
  var DEFAULT_PROTECTED = [
44282
44432
  "127.0.0.0/8",
@@ -44346,7 +44496,7 @@ function v4ToBytes(ip) {
44346
44496
  function v6ToBytes(ip) {
44347
44497
  const bare = ip.split("%")[0];
44348
44498
  const [headText, tailText] = bare.split("::", 2);
44349
- const head = headText ? headText.split(":") : [];
44499
+ const head2 = headText ? headText.split(":") : [];
44350
44500
  const tail = tailText !== void 0 ? tailText ? tailText.split(":") : [] : null;
44351
44501
  const groups = [];
44352
44502
  const pushGroup = (group) => {
@@ -44360,7 +44510,7 @@ function v6ToBytes(ip) {
44360
44510
  groups.push(parseInt(group, 16));
44361
44511
  return true;
44362
44512
  };
44363
- for (const group of head) if (!pushGroup(group)) return null;
44513
+ for (const group of head2) if (!pushGroup(group)) return null;
44364
44514
  const headCount = groups.length;
44365
44515
  if (tail === null) {
44366
44516
  if (headCount !== 8) return null;
@@ -44438,14 +44588,14 @@ function moshClients(procDir = "/proc") {
44438
44588
  const found = /* @__PURE__ */ new Set();
44439
44589
  let pids = [];
44440
44590
  try {
44441
- pids = (0, import_node_fs36.readdirSync)(procDir).filter((p) => /^\d+$/.test(p));
44591
+ pids = (0, import_node_fs37.readdirSync)(procDir).filter((p) => /^\d+$/.test(p));
44442
44592
  } catch {
44443
44593
  return [];
44444
44594
  }
44445
44595
  for (const pid of pids) {
44446
44596
  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"));
44597
+ if ((0, import_node_fs37.readFileSync)(`${procDir}/${pid}/comm`, "utf-8").trim() !== "mosh-server") continue;
44598
+ const ip = sshClientFromEnviron((0, import_node_fs37.readFileSync)(`${procDir}/${pid}/environ`, "latin1"));
44449
44599
  if (ip) found.add(ip);
44450
44600
  } catch {
44451
44601
  }
@@ -44651,17 +44801,17 @@ async function fetchFeeds(settings, fetchImpl = fetch) {
44651
44801
  }
44652
44802
  function readFeedCache(path2) {
44653
44803
  try {
44654
- const set = JSON.parse((0, import_node_fs37.readFileSync)(path2, "utf-8"));
44804
+ const set = JSON.parse((0, import_node_fs38.readFileSync)(path2, "utf-8"));
44655
44805
  return set && typeof set.ips === "object" && typeof set.domains === "object" ? set : null;
44656
44806
  } catch {
44657
44807
  return null;
44658
44808
  }
44659
44809
  }
44660
44810
  function writeFeedCache(path2, set) {
44661
- (0, import_node_fs37.mkdirSync)((0, import_node_path29.dirname)(path2), { recursive: true });
44811
+ (0, import_node_fs38.mkdirSync)((0, import_node_path29.dirname)(path2), { recursive: true });
44662
44812
  const tmp = `${path2}.tmp`;
44663
- (0, import_node_fs37.writeFileSync)(tmp, JSON.stringify(set));
44664
- (0, import_node_fs37.renameSync)(tmp, path2);
44813
+ (0, import_node_fs38.writeFileSync)(tmp, JSON.stringify(set));
44814
+ (0, import_node_fs38.renameSync)(tmp, path2);
44665
44815
  }
44666
44816
  var RESOLVER_FILES = {
44667
44817
  hosts: "blocked-domains.hosts",
@@ -44786,9 +44936,9 @@ var DnsMonitor = class {
44786
44936
  }
44787
44937
  start() {
44788
44938
  const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
44789
- if (!(0, import_node_fs38.existsSync)(p)) return false;
44939
+ if (!(0, import_node_fs39.existsSync)(p)) return false;
44790
44940
  try {
44791
- (0, import_node_fs38.accessSync)(p, import_node_fs38.constants.R_OK);
44941
+ (0, import_node_fs39.accessSync)(p, import_node_fs39.constants.R_OK);
44792
44942
  return true;
44793
44943
  } catch {
44794
44944
  return false;
@@ -45145,15 +45295,15 @@ var ModuleHost = class {
45145
45295
  }
45146
45296
  }
45147
45297
  async discoverAndStartInstalled() {
45148
- if (!(0, import_node_fs39.existsSync)(PATHS.moduleDir)) return;
45298
+ if (!(0, import_node_fs40.existsSync)(PATHS.moduleDir)) return;
45149
45299
  const configs = loadModuleConfigs(PATHS.confD);
45150
- const entries = (0, import_node_fs39.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
45300
+ const entries = (0, import_node_fs40.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
45151
45301
  for (const entry of entries) {
45152
45302
  if (!entry.isDirectory()) continue;
45153
45303
  const manifestPath = (0, import_node_path30.join)(PATHS.moduleDir, entry.name, "mod.toml");
45154
- if (!(0, import_node_fs39.existsSync)(manifestPath)) continue;
45304
+ if (!(0, import_node_fs40.existsSync)(manifestPath)) continue;
45155
45305
  try {
45156
- const manifest = import_toml4.default.parse((0, import_node_fs39.readFileSync)(manifestPath, "utf-8"));
45306
+ const manifest = import_toml4.default.parse((0, import_node_fs40.readFileSync)(manifestPath, "utf-8"));
45157
45307
  const name = manifest.module?.name || entry.name;
45158
45308
  const defaults = manifest.module?.config?.defaults || {};
45159
45309
  const config = {
@@ -45223,15 +45373,15 @@ var ModuleHost = class {
45223
45373
  installedEntrypoint(modulePath) {
45224
45374
  const packageJson = (0, import_node_path30.join)(modulePath, "package.json");
45225
45375
  const candidates = [];
45226
- if ((0, import_node_fs39.existsSync)(packageJson)) {
45376
+ if ((0, import_node_fs40.existsSync)(packageJson)) {
45227
45377
  try {
45228
- const pkg = JSON.parse((0, import_node_fs39.readFileSync)(packageJson, "utf-8"));
45378
+ const pkg = JSON.parse((0, import_node_fs40.readFileSync)(packageJson, "utf-8"));
45229
45379
  if (pkg.main) candidates.push((0, import_node_path30.join)(modulePath, pkg.main));
45230
45380
  } catch {
45231
45381
  }
45232
45382
  }
45233
45383
  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;
45384
+ return candidates.find((candidate) => (0, import_node_fs40.existsSync)(candidate)) || null;
45235
45385
  }
45236
45386
  isThreatCrushModule(value) {
45237
45387
  return Boolean(
@@ -45428,11 +45578,11 @@ function pagerdutyChannel(config) {
45428
45578
  }
45429
45579
 
45430
45580
  // src/daemon/alerts/smshub.ts
45431
- var import_node_os17 = require("os");
45581
+ var import_node_os18 = require("os");
45432
45582
  var SEVERITY_RANK6 = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
45433
45583
  var DEDUPE_MS = 10 * 6e4;
45434
45584
  var MAX_PER_HOUR = 6;
45435
- function smshubText(event, host = (0, import_node_os17.hostname)()) {
45585
+ function smshubText(event, host = (0, import_node_os18.hostname)()) {
45436
45586
  const evidence = event.details?.evidence?.message;
45437
45587
  const ip = event.source_ip && ![event.message, evidence ?? ""].some((t) => t.includes(event.source_ip)) ? ` from ${event.source_ip}` : "";
45438
45588
  const text = `ThreatCrush ${event.severity.toUpperCase()} on ${host}: ${event.message}${evidence && !event.message.includes(evidence) ? ` | ${evidence}` : ""}${ip}`;
@@ -45552,14 +45702,14 @@ function slackChannel(webhookUrl) {
45552
45702
  }
45553
45703
 
45554
45704
  // src/daemon/workers/runs-worker.ts
45555
- var import_promises6 = require("dns/promises");
45556
- var import_node_fs40 = require("fs");
45705
+ var import_promises7 = require("dns/promises");
45706
+ var import_node_fs41 = require("fs");
45557
45707
  var import_node_net9 = require("net");
45558
45708
  var import_node_path31 = require("path");
45559
45709
  init_cli_config();
45560
45710
 
45561
45711
  // src/core/cloud-events.ts
45562
- var import_node_crypto9 = require("crypto");
45712
+ var import_node_crypto10 = require("crypto");
45563
45713
  var import_node_net8 = require("net");
45564
45714
  init_cli_config();
45565
45715
  function currentLink() {
@@ -45643,7 +45793,7 @@ function remediationEvent(serverId, event) {
45643
45793
  return {
45644
45794
  type: "remediation",
45645
45795
  server_id: serverId,
45646
- event_id: (0, import_node_crypto9.randomUUID)(),
45796
+ event_id: (0, import_node_crypto10.randomUUID)(),
45647
45797
  action_type: d.action,
45648
45798
  target_value: event.source_ip,
45649
45799
  status: d.failed === true ? "failed" : "executed",
@@ -45687,7 +45837,7 @@ var NOT_PUBLIC = [
45687
45837
  function isPublicTarget(ip) {
45688
45838
  return (0, import_node_net9.isIP)(ip) !== 0 && !isProtected(ip, NOT_PUBLIC);
45689
45839
  }
45690
- async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0, import_promises6.lookup)(h, { all: true })).map((a) => a.address)) {
45840
+ async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0, import_promises7.lookup)(h, { all: true })).map((a) => a.address)) {
45691
45841
  let url;
45692
45842
  try {
45693
45843
  url = new URL(rawUrl.startsWith("http") ? rawUrl : `https://${rawUrl}`);
@@ -45706,7 +45856,7 @@ async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0,
45706
45856
  const inside = addresses.find((a) => !isPublicTarget(a));
45707
45857
  return inside ? `${host} resolves to ${inside}, which is not a public address; dashboard runs never reach inside this network` : null;
45708
45858
  }
45709
- function scanTargetError(target, roots, real = import_node_fs40.realpathSync) {
45859
+ function scanTargetError(target, roots, real = import_node_fs41.realpathSync) {
45710
45860
  if (roots.length === 0) {
45711
45861
  return "dashboard scans of this machine are off; list the directories they may read in [cloud] run_scan_paths";
45712
45862
  }
@@ -45877,8 +46027,8 @@ var RunsWorker = class {
45877
46027
  init_cli_config();
45878
46028
 
45879
46029
  // src/daemon/workers/cloud-spool.ts
45880
- var import_node_fs41 = require("fs");
45881
- var import_promises7 = require("fs/promises");
46030
+ var import_node_fs42 = require("fs");
46031
+ var import_promises8 = require("fs/promises");
45882
46032
  var import_node_path32 = require("path");
45883
46033
  var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
45884
46034
  var CloudSpool = class {
@@ -45886,7 +46036,7 @@ var CloudSpool = class {
45886
46036
  this.path = path2;
45887
46037
  this.limits = limits;
45888
46038
  try {
45889
- (0, import_node_fs41.mkdirSync)((0, import_node_path32.dirname)(path2), { recursive: true });
46039
+ (0, import_node_fs42.mkdirSync)((0, import_node_path32.dirname)(path2), { recursive: true });
45890
46040
  } catch {
45891
46041
  }
45892
46042
  this.load();
@@ -45955,7 +46105,7 @@ var CloudSpool = class {
45955
46105
  load() {
45956
46106
  let raw;
45957
46107
  try {
45958
- raw = (0, import_node_fs41.readFileSync)(this.path, "utf-8");
46108
+ raw = (0, import_node_fs42.readFileSync)(this.path, "utf-8");
45959
46109
  } catch {
45960
46110
  return;
45961
46111
  }
@@ -45986,13 +46136,13 @@ var CloudSpool = class {
45986
46136
  const body = this.lines.length > 0 ? `${this.lines.join("\n")}
45987
46137
  ` : "";
45988
46138
  const tmp = `${this.path}.tmp`;
45989
- await (0, import_promises7.writeFile)(tmp, body, { mode: 384 });
45990
- await (0, import_promises7.rename)(tmp, this.path);
46139
+ await (0, import_promises8.writeFile)(tmp, body, { mode: 384 });
46140
+ await (0, import_promises8.rename)(tmp, this.path);
45991
46141
  } else if (this.pendingAppend.length > 0) {
45992
46142
  const chunk2 = `${this.pendingAppend.join("\n")}
45993
46143
  `;
45994
46144
  this.pendingAppend = [];
45995
- await (0, import_promises7.appendFile)(this.path, chunk2, { mode: 384 });
46145
+ await (0, import_promises8.appendFile)(this.path, chunk2, { mode: 384 });
45996
46146
  }
45997
46147
  }).catch(() => {
45998
46148
  this.needsRewrite = true;
@@ -46200,7 +46350,7 @@ var CloudSync = class {
46200
46350
  };
46201
46351
 
46202
46352
  // src/daemon/workers/abuse-reporter.ts
46203
- var import_node_crypto10 = require("crypto");
46353
+ var import_node_crypto11 = require("crypto");
46204
46354
 
46205
46355
  // src/daemon/workers/abuse-evidence.ts
46206
46356
  var import_node_net10 = require("net");
@@ -46429,7 +46579,7 @@ function resolveConfig(section) {
46429
46579
  }
46430
46580
 
46431
46581
  // src/core/abuse-report-log.ts
46432
- var import_node_fs42 = require("fs");
46582
+ var import_node_fs43 = require("fs");
46433
46583
  var import_node_path33 = require("path");
46434
46584
  init_paths();
46435
46585
  var ABUSE_DIRNAME = "abuse-reports";
@@ -46438,7 +46588,7 @@ function resolveAbuseDir(dir) {
46438
46588
  if (dir) return dir;
46439
46589
  if (process.env.THREATCRUSH_ABUSE_DIR) return process.env.THREATCRUSH_ABUSE_DIR;
46440
46590
  const system = (0, import_node_path33.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
46441
- if ((0, import_node_fs42.existsSync)(system)) return system;
46591
+ if ((0, import_node_fs43.existsSync)(system)) return system;
46442
46592
  return (0, import_node_path33.join)(PATHS.stateDir, ABUSE_DIRNAME);
46443
46593
  }
46444
46594
  function logPath(dir) {
@@ -46446,15 +46596,15 @@ function logPath(dir) {
46446
46596
  }
46447
46597
  function appendReport(record, dir) {
46448
46598
  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)}
46599
+ (0, import_node_fs43.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
46600
+ (0, import_node_fs43.appendFileSync)(path2, `${JSON.stringify(record)}
46451
46601
  `, { mode: 420 });
46452
46602
  }
46453
46603
  function readReports(dir) {
46454
46604
  const path2 = logPath(dir);
46455
46605
  let raw;
46456
46606
  try {
46457
- raw = (0, import_node_fs42.readFileSync)(path2, "utf-8");
46607
+ raw = (0, import_node_fs43.readFileSync)(path2, "utf-8");
46458
46608
  } catch {
46459
46609
  return [];
46460
46610
  }
@@ -46593,7 +46743,7 @@ var AbuseReporter = class {
46593
46743
  const payload = buildPayload(ip, evidence);
46594
46744
  const results = this.cfg.dryRun ? [] : await dispatch(payload, this.cfg.destinations, this.cfg.keys);
46595
46745
  const record = {
46596
- id: (0, import_node_crypto10.randomUUID)().slice(0, 8),
46746
+ id: (0, import_node_crypto11.randomUUID)().slice(0, 8),
46597
46747
  ip,
46598
46748
  reported_at: new Date(now).toISOString(),
46599
46749
  mode: this.cfg.dryRun ? "dry_run" : "live",
@@ -46880,7 +47030,7 @@ var RemediationConsumer = class {
46880
47030
 
46881
47031
  // src/daemon/workers/auto-update.ts
46882
47032
  var import_node_child_process11 = require("child_process");
46883
- var import_node_fs43 = require("fs");
47033
+ var import_node_fs44 = require("fs");
46884
47034
  var import_node_path34 = require("path");
46885
47035
  init_backoff();
46886
47036
  var PKG_NAME = "@profullstack/threatcrush";
@@ -46962,10 +47112,10 @@ function installPlan(opts) {
46962
47112
  }
46963
47113
  function ownerOf(path2, passwd = "/etc/passwd") {
46964
47114
  try {
46965
- const st = (0, import_node_fs43.statSync)(path2);
47115
+ const st = (0, import_node_fs44.statSync)(path2);
46966
47116
  let home = st.uid === 0 ? "/root" : "";
46967
47117
  try {
46968
- for (const line2 of (0, import_node_fs43.readFileSync)(passwd, "utf8").split("\n")) {
47118
+ for (const line2 of (0, import_node_fs44.readFileSync)(passwd, "utf8").split("\n")) {
46969
47119
  const f = line2.split(":");
46970
47120
  if (Number(f[2]) === st.uid && f[5]) home = f[5];
46971
47121
  }
@@ -47075,7 +47225,7 @@ var AutoUpdate = class {
47075
47225
  uid: process.getuid?.() ?? -1,
47076
47226
  owner: ownerOf(this.opts.pkgRoot),
47077
47227
  underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
47078
- npmExists: import_node_fs43.existsSync
47228
+ npmExists: import_node_fs44.existsSync
47079
47229
  });
47080
47230
  if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
47081
47231
  this.recordAttempt(target);
@@ -47111,7 +47261,7 @@ var AutoUpdate = class {
47111
47261
  }
47112
47262
  lastAttempt() {
47113
47263
  try {
47114
- const v = JSON.parse((0, import_node_fs43.readFileSync)(this.opts.statePath, "utf8"));
47264
+ const v = JSON.parse((0, import_node_fs44.readFileSync)(this.opts.statePath, "utf8"));
47115
47265
  return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
47116
47266
  } catch {
47117
47267
  return null;
@@ -47119,7 +47269,7 @@ var AutoUpdate = class {
47119
47269
  }
47120
47270
  recordAttempt(version) {
47121
47271
  try {
47122
- (0, import_node_fs43.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
47272
+ (0, import_node_fs44.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
47123
47273
  } catch (err) {
47124
47274
  this.opts.log(`[update] could not record attempt: ${err.message}`);
47125
47275
  }
@@ -47128,7 +47278,7 @@ var AutoUpdate = class {
47128
47278
 
47129
47279
  // src/daemon/workers/threat-feeds.ts
47130
47280
  var import_node_child_process12 = require("child_process");
47131
- var import_node_fs44 = require("fs");
47281
+ var import_node_fs45 = require("fs");
47132
47282
  var import_node_path35 = require("path");
47133
47283
  var import_node_net13 = require("net");
47134
47284
  init_backoff();
@@ -47307,8 +47457,8 @@ var ThreatFeeds = class {
47307
47457
  const path2 = (0, import_node_path35.join)(dir, name);
47308
47458
  if (this.resolverWritten.get(name) === content) return false;
47309
47459
  try {
47310
- (0, import_node_fs44.writeFileSync)(`${path2}.tmp`, content);
47311
- (0, import_node_fs44.renameSync)(`${path2}.tmp`, path2);
47460
+ (0, import_node_fs45.writeFileSync)(`${path2}.tmp`, content);
47461
+ (0, import_node_fs45.renameSync)(`${path2}.tmp`, path2);
47312
47462
  this.resolverWritten.set(name, content);
47313
47463
  return true;
47314
47464
  } catch (err) {
@@ -47319,11 +47469,11 @@ var ThreatFeeds = class {
47319
47469
  const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
47320
47470
  const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
47321
47471
  const via = [];
47322
- if ((0, import_node_fs44.existsSync)(hooks.dnsmasq)) {
47472
+ if ((0, import_node_fs45.existsSync)(hooks.dnsmasq)) {
47323
47473
  via.push("dnsmasq");
47324
47474
  if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
47325
47475
  }
47326
- if ((0, import_node_fs44.existsSync)(hooks.unbound)) {
47476
+ if ((0, import_node_fs45.existsSync)(hooks.unbound)) {
47327
47477
  via.push("unbound");
47328
47478
  if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
47329
47479
  this.run("systemctl", ["reload", "unbound.service"]);
@@ -47384,12 +47534,12 @@ var ThreatFeeds = class {
47384
47534
  };
47385
47535
 
47386
47536
  // src/daemon/workers/privilege-watch.ts
47387
- var import_node_fs45 = require("fs");
47537
+ var import_node_fs46 = require("fs");
47388
47538
  var import_node_path36 = require("path");
47389
47539
  var import_node_child_process13 = require("child_process");
47390
47540
 
47391
47541
  // src/core/privileges/index.ts
47392
- var import_node_crypto11 = require("crypto");
47542
+ var import_node_crypto12 = require("crypto");
47393
47543
  var ADMIN_GROUPS = ["sudo", "wheel", "admin"];
47394
47544
  function parseUsers(text) {
47395
47545
  const out = [];
@@ -47430,7 +47580,7 @@ function sudoReadsIncluded(name) {
47430
47580
  }
47431
47581
  function keyFingerprint(blobBase64) {
47432
47582
  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");
47583
+ const digest = (0, import_node_crypto12.createHash)("sha256").update(Buffer.from(blobBase64, "base64")).digest("base64");
47434
47584
  return `SHA256:${digest.replace(/=+$/, "")}`;
47435
47585
  }
47436
47586
  function parseAuthorizedKeys(text) {
@@ -47611,31 +47761,31 @@ function countryName(code) {
47611
47761
  var fsIO = {
47612
47762
  readFile: (p) => {
47613
47763
  try {
47614
- return (0, import_node_fs45.readFileSync)(p, "utf-8");
47764
+ return (0, import_node_fs46.readFileSync)(p, "utf-8");
47615
47765
  } catch {
47616
47766
  return null;
47617
47767
  }
47618
47768
  },
47619
47769
  readDir: (p) => {
47620
47770
  try {
47621
- return (0, import_node_fs45.readdirSync)(p);
47771
+ return (0, import_node_fs46.readdirSync)(p);
47622
47772
  } catch {
47623
47773
  return null;
47624
47774
  }
47625
47775
  },
47626
- exists: (p) => (0, import_node_fs45.existsSync)(p)
47776
+ exists: (p) => (0, import_node_fs46.existsSync)(p)
47627
47777
  };
47628
47778
  function readJson(path2) {
47629
47779
  try {
47630
- return JSON.parse((0, import_node_fs45.readFileSync)(path2, "utf-8"));
47780
+ return JSON.parse((0, import_node_fs46.readFileSync)(path2, "utf-8"));
47631
47781
  } catch {
47632
47782
  return null;
47633
47783
  }
47634
47784
  }
47635
47785
  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);
47786
+ (0, import_node_fs46.mkdirSync)((0, import_node_path36.dirname)(path2), { recursive: true });
47787
+ (0, import_node_fs46.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
47788
+ (0, import_node_fs46.renameSync)(`${path2}.tmp`, path2);
47639
47789
  }
47640
47790
  function defaultRun3(cmd, args) {
47641
47791
  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 +47902,7 @@ var PrivilegeWatch = class {
47752
47902
  for (const dir of dirs) {
47753
47903
  if (this.watchers.has(dir) || !this.io.exists(dir)) continue;
47754
47904
  try {
47755
- const w = (0, import_node_fs45.watch)(dir, { persistent: false }, (_type2, name) => {
47905
+ const w = (0, import_node_fs46.watch)(dir, { persistent: false }, (_type2, name) => {
47756
47906
  if (name && !String(name).startsWith("authorized_keys")) return;
47757
47907
  if (this.debounce) clearTimeout(this.debounce);
47758
47908
  this.debounce = setTimeout(() => {
@@ -47851,7 +48001,7 @@ var PrivilegeWatch = class {
47851
48001
  * raised a "new country" alert on its first run; on dev2 it did, at once.
47852
48002
  */
47853
48003
  async backfillLogins() {
47854
- if ((0, import_node_fs45.existsSync)(this.opts.loginsPath)) return;
48004
+ if ((0, import_node_fs46.existsSync)(this.opts.loginsPath)) return;
47855
48005
  const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
47856
48006
  const byUser = parseAcceptedLogins(out ?? "");
47857
48007
  const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
@@ -47864,7 +48014,7 @@ var PrivilegeWatch = class {
47864
48014
  return;
47865
48015
  }
47866
48016
  }
47867
- if ((0, import_node_fs45.existsSync)(this.opts.loginsPath)) return;
48017
+ if ((0, import_node_fs46.existsSync)(this.opts.loginsPath)) return;
47868
48018
  const at = this.now().toISOString();
47869
48019
  const history = {};
47870
48020
  for (const [user, userIps] of byUser) {
@@ -47916,11 +48066,11 @@ var PrivilegeWatch = class {
47916
48066
  };
47917
48067
 
47918
48068
  // src/daemon/workers/command-history.ts
47919
- var import_node_fs46 = require("fs");
48069
+ var import_node_fs47 = require("fs");
47920
48070
  var import_node_child_process14 = require("child_process");
47921
48071
  var import_node_path37 = require("path");
47922
48072
  var import_node_zlib2 = require("zlib");
47923
- var import_node_crypto12 = require("crypto");
48073
+ var import_node_crypto13 = require("crypto");
47924
48074
  var POLL_MS3 = 6e4;
47925
48075
  var MAX_HISTORY_BYTES = 4 * 1024 * 1024;
47926
48076
  var MAX_COMPRESSED_HISTORY_BYTES = MAX_HISTORY_BYTES + 65536;
@@ -47941,7 +48091,7 @@ function historyAccounts() {
47941
48091
  passwd = (0, import_node_child_process14.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
47942
48092
  } catch {
47943
48093
  try {
47944
- passwd = (0, import_node_fs46.readFileSync)("/etc/passwd", "utf8");
48094
+ passwd = (0, import_node_fs47.readFileSync)("/etc/passwd", "utf8");
47945
48095
  } catch {
47946
48096
  return [];
47947
48097
  }
@@ -47968,17 +48118,17 @@ function descriptorPath(directoryFd, name) {
47968
48118
  }
47969
48119
  function openDirectoryChain(path2) {
47970
48120
  if (!(0, import_node_path37.isAbsolute)(path2) || path2.split(import_node_path37.sep).includes("..")) throw new Error("directory path is not a safe absolute path");
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);
48121
+ const flags = import_node_fs47.constants.O_RDONLY | import_node_fs47.constants.O_DIRECTORY | (import_node_fs47.constants.O_NOFOLLOW ?? 0);
48122
+ let fd = (0, import_node_fs47.openSync)("/", flags);
47973
48123
  try {
47974
48124
  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);
48125
+ const next = (0, import_node_fs47.openSync)(descriptorPath(fd, part), flags);
48126
+ (0, import_node_fs47.closeSync)(fd);
47977
48127
  fd = next;
47978
48128
  }
47979
48129
  return fd;
47980
48130
  } catch (error2) {
47981
- (0, import_node_fs46.closeSync)(fd);
48131
+ (0, import_node_fs47.closeSync)(fd);
47982
48132
  throw error2;
47983
48133
  }
47984
48134
  }
@@ -47986,68 +48136,68 @@ function readExact(fd, size) {
47986
48136
  const data = Buffer.alloc(size);
47987
48137
  let offset = 0;
47988
48138
  while (offset < data.length) {
47989
- const read = (0, import_node_fs46.readSync)(fd, data, offset, data.length - offset, offset);
48139
+ const read = (0, import_node_fs47.readSync)(fd, data, offset, data.length - offset, offset);
47990
48140
  if (read === 0) break;
47991
48141
  offset += read;
47992
48142
  }
47993
48143
  return offset === data.length ? data : null;
47994
48144
  }
47995
48145
  function privateDirectory(path2) {
47996
- (0, import_node_fs46.mkdirSync)(path2, { recursive: true, mode: 448 });
47997
- const stat = (0, import_node_fs46.lstatSync)(path2);
48146
+ (0, import_node_fs47.mkdirSync)(path2, { recursive: true, mode: 448 });
48147
+ const stat = (0, import_node_fs47.lstatSync)(path2);
47998
48148
  if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error("history storage path is not a directory");
47999
- (0, import_node_fs46.chmodSync)(path2, 448);
48149
+ (0, import_node_fs47.chmodSync)(path2, 448);
48000
48150
  }
48001
48151
  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);
48152
+ const noFollow = import_node_fs47.constants.O_NOFOLLOW ?? 0;
48153
+ const fd = (0, import_node_fs47.openSync)(descriptorPath(directoryFd, name), import_node_fs47.constants.O_RDONLY | noFollow);
48004
48154
  try {
48005
- const opened = (0, import_node_fs46.fstatSync)(fd);
48155
+ const opened = (0, import_node_fs47.fstatSync)(fd);
48006
48156
  if (!opened.isFile() || opened.nlink !== 1 || opened.uid !== uid) return null;
48007
48157
  if (opened.size > MAX_HISTORY_BYTES) throw new Error(`history file exceeds ${MAX_HISTORY_BYTES} bytes`);
48008
48158
  const data = readExact(fd, opened.size);
48009
48159
  if (data === null) return null;
48010
- const after = (0, import_node_fs46.fstatSync)(fd);
48160
+ const after = (0, import_node_fs47.fstatSync)(fd);
48011
48161
  if (after.size !== opened.size || after.mtimeMs !== opened.mtimeMs) return null;
48012
48162
  return data;
48013
48163
  } finally {
48014
- (0, import_node_fs46.closeSync)(fd);
48164
+ (0, import_node_fs47.closeSync)(fd);
48015
48165
  }
48016
48166
  }
48017
48167
  function atomicWrite(path2, data, mode = 384, owner, parentFd) {
48018
48168
  const dirFd = parentFd ?? openDirectoryChain((0, import_node_path37.dirname)(path2));
48019
48169
  const ownsDirFd = parentFd === void 0;
48020
48170
  const name = (0, import_node_path37.basename)(path2);
48021
- const temp = descriptorPath(dirFd, `${name}.${(0, import_node_crypto12.randomUUID)()}.tmp`);
48171
+ const temp = descriptorPath(dirFd, `${name}.${(0, import_node_crypto13.randomUUID)()}.tmp`);
48022
48172
  const destination = descriptorPath(dirFd, name);
48023
- const noFollow = import_node_fs46.constants.O_NOFOLLOW ?? 0;
48173
+ const noFollow = import_node_fs47.constants.O_NOFOLLOW ?? 0;
48024
48174
  let fd;
48025
48175
  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);
48176
+ fd = (0, import_node_fs47.openSync)(temp, import_node_fs47.constants.O_WRONLY | import_node_fs47.constants.O_CREAT | import_node_fs47.constants.O_EXCL | noFollow, mode);
48027
48177
  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);
48178
+ while (offset < data.length) offset += (0, import_node_fs47.writeSync)(fd, data, offset, data.length - offset);
48179
+ (0, import_node_fs47.fchmodSync)(fd, mode);
48030
48180
  if (owner && typeof process.getuid === "function" && process.getuid() === 0) {
48031
- (0, import_node_fs46.fchownSync)(fd, owner.uid, owner.gid);
48181
+ (0, import_node_fs47.fchownSync)(fd, owner.uid, owner.gid);
48032
48182
  }
48033
- (0, import_node_fs46.fsyncSync)(fd);
48034
- (0, import_node_fs46.closeSync)(fd);
48183
+ (0, import_node_fs47.fsyncSync)(fd);
48184
+ (0, import_node_fs47.closeSync)(fd);
48035
48185
  fd = void 0;
48036
- (0, import_node_fs46.renameSync)(temp, destination);
48186
+ (0, import_node_fs47.renameSync)(temp, destination);
48037
48187
  } catch (error2) {
48038
48188
  if (fd !== void 0) {
48039
48189
  try {
48040
- (0, import_node_fs46.closeSync)(fd);
48190
+ (0, import_node_fs47.closeSync)(fd);
48041
48191
  } catch {
48042
48192
  }
48043
48193
  }
48044
48194
  try {
48045
- (0, import_node_fs46.unlinkSync)(temp);
48195
+ (0, import_node_fs47.unlinkSync)(temp);
48046
48196
  } catch {
48047
48197
  }
48048
48198
  throw error2;
48049
48199
  } finally {
48050
- if (ownsDirFd) (0, import_node_fs46.closeSync)(dirFd);
48200
+ if (ownsDirFd) (0, import_node_fs47.closeSync)(dirFd);
48051
48201
  }
48052
48202
  }
48053
48203
  function readCurrentBackup(path2) {
@@ -48055,20 +48205,20 @@ function readCurrentBackup(path2) {
48055
48205
  try {
48056
48206
  const parentFd = openDirectoryChain((0, import_node_path37.dirname)(path2));
48057
48207
  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));
48208
+ fd = (0, import_node_fs47.openSync)(descriptorPath(parentFd, (0, import_node_path37.basename)(path2)), import_node_fs47.constants.O_RDONLY | (import_node_fs47.constants.O_NOFOLLOW ?? 0));
48059
48209
  } finally {
48060
- (0, import_node_fs46.closeSync)(parentFd);
48210
+ (0, import_node_fs47.closeSync)(parentFd);
48061
48211
  }
48062
- const stat = (0, import_node_fs46.fstatSync)(fd);
48212
+ const stat = (0, import_node_fs47.fstatSync)(fd);
48063
48213
  if (!stat.isFile() || stat.nlink !== 1 || stat.size > MAX_COMPRESSED_HISTORY_BYTES) return null;
48064
48214
  const compressed = readExact(fd, stat.size);
48065
- const after = (0, import_node_fs46.fstatSync)(fd);
48215
+ const after = (0, import_node_fs47.fstatSync)(fd);
48066
48216
  if (!compressed || after.size !== stat.size || after.mtimeMs !== stat.mtimeMs) return null;
48067
48217
  return (0, import_node_zlib2.gunzipSync)(compressed, { maxOutputLength: MAX_HISTORY_BYTES });
48068
48218
  } catch {
48069
48219
  return null;
48070
48220
  } finally {
48071
- if (fd !== void 0) (0, import_node_fs46.closeSync)(fd);
48221
+ if (fd !== void 0) (0, import_node_fs47.closeSync)(fd);
48072
48222
  }
48073
48223
  }
48074
48224
  function compactTime(date) {
@@ -48137,7 +48287,7 @@ var CommandHistoryWatcher = class {
48137
48287
  if (targets.has(relative4)) continue;
48138
48288
  const path2 = (0, import_node_path37.join)(account.home, relative4);
48139
48289
  try {
48140
- (0, import_node_fs46.lstatSync)(path2);
48290
+ (0, import_node_fs47.lstatSync)(path2);
48141
48291
  targets.add(relative4);
48142
48292
  continue;
48143
48293
  } catch (error2) {
@@ -48164,7 +48314,7 @@ var CommandHistoryWatcher = class {
48164
48314
  const userPath = descriptorPath(userParentFd, (0, import_node_path37.basename)(path2));
48165
48315
  let status;
48166
48316
  try {
48167
- status = (0, import_node_fs46.lstatSync)(userPath);
48317
+ status = (0, import_node_fs47.lstatSync)(userPath);
48168
48318
  } catch (error2) {
48169
48319
  if (error2.code !== "ENOENT") throw error2;
48170
48320
  }
@@ -48188,13 +48338,13 @@ var CommandHistoryWatcher = class {
48188
48338
  }
48189
48339
  const compressed = (0, import_node_zlib2.gzipSync)(data, { level: 6 });
48190
48340
  const stamp = compactTime(this.now());
48191
- atomicWrite(`${store}.${stamp}-${(0, import_node_crypto12.randomUUID)().slice(0, 8)}.gz`, compressed);
48341
+ atomicWrite(`${store}.${stamp}-${(0, import_node_crypto13.randomUUID)().slice(0, 8)}.gz`, compressed);
48192
48342
  atomicWrite(current, compressed);
48193
48343
  this.pruneSnapshots(store);
48194
48344
  } catch (error2) {
48195
48345
  this.opts.log(`[command-history] could not snapshot uid=${account.uid} ${(0, import_node_path37.basename)(relative4)}: ${error2.message}`);
48196
48346
  } finally {
48197
- (0, import_node_fs46.closeSync)(userParentFd);
48347
+ (0, import_node_fs47.closeSync)(userParentFd);
48198
48348
  }
48199
48349
  }
48200
48350
  restore(path2, content, account, parentFd) {
@@ -48216,13 +48366,13 @@ var CommandHistoryWatcher = class {
48216
48366
  pruneSnapshots(current) {
48217
48367
  const dir = (0, import_node_path37.dirname)(current);
48218
48368
  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);
48369
+ const snapshots = (0, import_node_fs47.readdirSync)(dir).filter((name) => name !== (0, import_node_path37.basename)(current) && name.startsWith(prefix) && name.endsWith(".gz")).map((name) => ({ path: (0, import_node_path37.join)(dir, name), name, time: (0, import_node_fs47.lstatSync)((0, import_node_path37.join)(dir, name)).mtimeMs })).sort((a, b) => a.time - b.time);
48220
48370
  const cutoff = this.now().getTime() - SNAPSHOT_RETENTION_MS;
48221
48371
  const removeCount = Math.max(0, snapshots.length - MAX_SNAPSHOTS);
48222
48372
  snapshots.forEach((snapshot, index) => {
48223
48373
  if (snapshot.time < cutoff || index < removeCount) {
48224
48374
  try {
48225
- (0, import_node_fs46.unlinkSync)(snapshot.path);
48375
+ (0, import_node_fs47.unlinkSync)(snapshot.path);
48226
48376
  } catch {
48227
48377
  }
48228
48378
  }
@@ -48231,9 +48381,9 @@ var CommandHistoryWatcher = class {
48231
48381
  };
48232
48382
 
48233
48383
  // 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");
48384
+ var import_node_fs48 = require("fs");
48385
+ var import_promises9 = require("fs/promises");
48386
+ var import_node_crypto14 = require("crypto");
48237
48387
  var import_node_path38 = require("path");
48238
48388
  var DEFAULT_POLL_MS = 15 * 6e4;
48239
48389
  var MAX_FILES = 5e4;
@@ -48271,7 +48421,7 @@ function signature(value) {
48271
48421
  }
48272
48422
  async function readState(path2) {
48273
48423
  try {
48274
- const parsed = JSON.parse(await (0, import_promises8.readFile)(path2, "utf8"));
48424
+ const parsed = JSON.parse(await (0, import_promises9.readFile)(path2, "utf8"));
48275
48425
  if (parsed.schema !== 1 || !Array.isArray(parsed.targets) || !parsed.files || typeof parsed.files !== "object") return null;
48276
48426
  return parsed;
48277
48427
  } catch {
@@ -48279,13 +48429,13 @@ async function readState(path2) {
48279
48429
  }
48280
48430
  }
48281
48431
  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);
48432
+ await (0, import_promises9.mkdir)((0, import_node_path38.dirname)(path2), { recursive: true, mode: 448 });
48433
+ const temp = `${path2}.${process.pid}.${(0, import_node_crypto14.randomUUID)()}.tmp`;
48434
+ await (0, import_promises9.writeFile)(temp, JSON.stringify(state), { mode: 384 });
48435
+ await (0, import_promises9.rename)(temp, path2);
48286
48436
  }
48287
48437
  async function hashFile(path2, handle, size) {
48288
- const hash = (0, import_node_crypto13.createHash)("sha256");
48438
+ const hash = (0, import_node_crypto14.createHash)("sha256");
48289
48439
  const buffer = Buffer.alloc(READ_CHUNK_BYTES);
48290
48440
  const counts = new Uint32Array(256);
48291
48441
  let position = 0;
@@ -48305,19 +48455,19 @@ async function hashFile(path2, handle, size) {
48305
48455
  }
48306
48456
  return { sha256: hash.digest("hex"), entropy };
48307
48457
  }
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;
48458
+ var OPEN_FILE_FLAGS = import_promises9.constants.O_RDONLY | import_promises9.constants.O_NONBLOCK | (import_promises9.constants.O_NOFOLLOW ?? 0);
48459
+ var OPEN_DIR_FLAGS = OPEN_FILE_FLAGS | import_promises9.constants.O_DIRECTORY;
48460
+ var CREATE_FILE_FLAGS = import_promises9.constants.O_WRONLY | import_promises9.constants.O_CREAT | import_promises9.constants.O_EXCL | import_promises9.constants.O_NOFOLLOW;
48311
48461
  function autoCanaryPath(directory) {
48312
48462
  return (0, import_node_path38.join)(directory, ".threatcrush-canary");
48313
48463
  }
48314
48464
  async function openAbsoluteDirectory(path2) {
48315
48465
  const parts = path2.split(import_node_path38.sep).filter((part) => part && part !== ".");
48316
48466
  if (parts.includes("..")) throw new Error("invalid canary directory");
48317
- let directory = await (0, import_promises8.open)("/", OPEN_DIR_FLAGS);
48467
+ let directory = await (0, import_promises9.open)("/", OPEN_DIR_FLAGS);
48318
48468
  try {
48319
48469
  for (const part of parts) {
48320
- const next = await (0, import_promises8.open)(`/proc/self/fd/${directory.fd}/${part}`, OPEN_DIR_FLAGS);
48470
+ const next = await (0, import_promises9.open)(`/proc/self/fd/${directory.fd}/${part}`, OPEN_DIR_FLAGS);
48321
48471
  await directory.close();
48322
48472
  directory = next;
48323
48473
  }
@@ -48337,7 +48487,7 @@ async function createAutoCanary(path2) {
48337
48487
  }
48338
48488
  const directory = await openAbsoluteDirectory((0, import_node_path38.dirname)(path2));
48339
48489
  try {
48340
- const file = await (0, import_promises8.open)(`/proc/self/fd/${directory.fd}/${(0, import_node_path38.basename)(path2)}`, CREATE_FILE_FLAGS, 438);
48490
+ const file = await (0, import_promises9.open)(`/proc/self/fd/${directory.fd}/${(0, import_node_path38.basename)(path2)}`, CREATE_FILE_FLAGS, 438);
48341
48491
  try {
48342
48492
  await file.chmod(438);
48343
48493
  await file.writeFile(CANARY_CONTENT);
@@ -48356,14 +48506,14 @@ async function createAutoCanary(path2) {
48356
48506
  async function openAbsoluteTarget(path2) {
48357
48507
  const parts = path2.split(import_node_path38.sep).filter((part) => part && part !== ".");
48358
48508
  if (parts.length === 0 || parts.includes("..")) throw new Error("invalid file integrity path");
48359
- let directory = await (0, import_promises8.open)("/", OPEN_DIR_FLAGS);
48509
+ let directory = await (0, import_promises9.open)("/", OPEN_DIR_FLAGS);
48360
48510
  try {
48361
48511
  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);
48512
+ const next = await (0, import_promises9.open)(`/proc/self/fd/${directory.fd}/${part}`, OPEN_DIR_FLAGS);
48363
48513
  await directory.close();
48364
48514
  directory = next;
48365
48515
  }
48366
- const target = await (0, import_promises8.open)(`/proc/self/fd/${directory.fd}/${parts.at(-1)}`, OPEN_FILE_FLAGS);
48516
+ const target = await (0, import_promises9.open)(`/proc/self/fd/${directory.fd}/${parts.at(-1)}`, OPEN_FILE_FLAGS);
48367
48517
  await directory.close();
48368
48518
  return target;
48369
48519
  } catch (error2) {
@@ -48389,7 +48539,7 @@ async function scanTargets(targets, canaries) {
48389
48539
  }
48390
48540
  let handle;
48391
48541
  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);
48542
+ handle = parent ? await (0, import_promises9.open)(`/proc/self/fd/${parent.fd}/${path2.slice(path2.lastIndexOf(import_node_path38.sep) + 1)}`, OPEN_FILE_FLAGS) : await openAbsoluteTarget(path2);
48393
48543
  const stat = await handle.stat();
48394
48544
  if (stat.isDirectory()) {
48395
48545
  directories.push(path2);
@@ -48400,7 +48550,7 @@ async function scanTargets(targets, canaries) {
48400
48550
  }
48401
48551
  let entries;
48402
48552
  try {
48403
- entries = await (0, import_promises8.readdir)(`/proc/self/fd/${handle.fd}`, { withFileTypes: true });
48553
+ entries = await (0, import_promises9.readdir)(`/proc/self/fd/${handle.fd}`, { withFileTypes: true });
48404
48554
  } catch {
48405
48555
  complete = false;
48406
48556
  errors.add(path2);
@@ -48545,7 +48695,7 @@ var FileIntegrityWatch = class {
48545
48695
  for (const path2 of wanted) {
48546
48696
  if (this.watchers.has(path2)) continue;
48547
48697
  try {
48548
- const watcher = (0, import_node_fs47.watch)(path2, { persistent: false }, () => {
48698
+ const watcher = (0, import_node_fs48.watch)(path2, { persistent: false }, () => {
48549
48699
  this.scheduleEventScan();
48550
48700
  });
48551
48701
  watcher.on("error", (error2) => {
@@ -48601,7 +48751,7 @@ var FileIntegrityWatch = class {
48601
48751
  let baselineFilePresent = false;
48602
48752
  if (!baseline) {
48603
48753
  try {
48604
- await (0, import_promises8.lstat)(this.opts.baselinePath);
48754
+ await (0, import_promises9.lstat)(this.opts.baselinePath);
48605
48755
  baselineFilePresent = true;
48606
48756
  } catch (error2) {
48607
48757
  baselineFilePresent = error2.code !== "ENOENT";
@@ -48726,7 +48876,7 @@ var FileIntegrityWatch = class {
48726
48876
  };
48727
48877
 
48728
48878
  // src/daemon/workers/edr.ts
48729
- var import_node_fs48 = require("fs");
48879
+ var import_node_fs49 = require("fs");
48730
48880
  var import_node_path39 = require("path");
48731
48881
  var import_node_child_process15 = require("child_process");
48732
48882
  var DEFAULT_AUDIT_LOG = "/var/log/audit/audit.log";
@@ -48804,7 +48954,7 @@ function accountNames2() {
48804
48954
  raw = (0, import_node_child_process15.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
48805
48955
  } catch {
48806
48956
  try {
48807
- raw = (0, import_node_fs48.readFileSync)("/etc/passwd", "utf8");
48957
+ raw = (0, import_node_fs49.readFileSync)("/etc/passwd", "utf8");
48808
48958
  } catch {
48809
48959
  return /* @__PURE__ */ new Map();
48810
48960
  }
@@ -48822,7 +48972,7 @@ function pathWithin(path2, root) {
48822
48972
  }
48823
48973
  function executableInWorldWritableDirectory(executable) {
48824
48974
  try {
48825
- return ((0, import_node_fs48.statSync)((0, import_node_path39.dirname)(executable)).mode & 2) !== 0;
48975
+ return ((0, import_node_fs49.statSync)((0, import_node_path39.dirname)(executable)).mode & 2) !== 0;
48826
48976
  } catch {
48827
48977
  return false;
48828
48978
  }
@@ -48856,11 +49006,11 @@ var EdrWatch = class {
48856
49006
  this.opts.log("[edr] disabled; set [edr] enabled = true after installing the generated audit rules");
48857
49007
  return;
48858
49008
  }
48859
- if (!(0, import_node_fs48.existsSync)(this.opts.settings.auditLogPath)) {
49009
+ if (!(0, import_node_fs49.existsSync)(this.opts.settings.auditLogPath)) {
48860
49010
  this.opts.log(`[edr] audit log not found at ${this.opts.settings.auditLogPath}; auditd detections are unavailable`);
48861
49011
  } else {
48862
49012
  try {
48863
- (0, import_node_fs48.accessSync)(this.opts.settings.auditLogPath, import_node_fs48.constants.R_OK);
49013
+ (0, import_node_fs49.accessSync)(this.opts.settings.auditLogPath, import_node_fs49.constants.R_OK);
48864
49014
  this.tail = new LogTail(this.opts.settings.auditLogPath);
48865
49015
  this.timer = setInterval(() => this.poll(), this.opts.settings.pollMs);
48866
49016
  this.timer.unref?.();
@@ -48971,7 +49121,7 @@ var EdrWatch = class {
48971
49121
  const path2 = this.opts.networkBaselinePath;
48972
49122
  if (!path2) return;
48973
49123
  try {
48974
- const parsed = JSON.parse((0, import_node_fs48.readFileSync)(path2, "utf8"));
49124
+ const parsed = JSON.parse((0, import_node_fs49.readFileSync)(path2, "utf8"));
48975
49125
  if (Array.isArray(parsed)) {
48976
49126
  for (const value of parsed.slice(0, 1e4)) {
48977
49127
  if (typeof value === "string" && value.startsWith("/")) this.outboundExecutables.add(value);
@@ -48988,9 +49138,9 @@ var EdrWatch = class {
48988
49138
  if (!path2) return;
48989
49139
  try {
48990
49140
  const temp = `${path2}.${process.pid}.tmp`;
48991
- (0, import_node_fs48.writeFileSync)(temp, `${JSON.stringify([...this.outboundExecutables])}
49141
+ (0, import_node_fs49.writeFileSync)(temp, `${JSON.stringify([...this.outboundExecutables])}
48992
49142
  `, { mode: 384 });
48993
- (0, import_node_fs48.renameSync)(temp, path2);
49143
+ (0, import_node_fs49.renameSync)(temp, path2);
48994
49144
  this.baselineWriteFailed = false;
48995
49145
  } catch (error2) {
48996
49146
  if (!this.baselineWriteFailed) this.opts.log(`[edr] could not persist outbound executable baseline: ${error2.message.split("\n")[0]}`);
@@ -49011,7 +49161,7 @@ var EdrWatch = class {
49011
49161
  const current = /* @__PURE__ */ new Map();
49012
49162
  let pids;
49013
49163
  try {
49014
- pids = (0, import_node_fs48.readdirSync)("/proc");
49164
+ pids = (0, import_node_fs49.readdirSync)("/proc");
49015
49165
  } catch {
49016
49166
  return;
49017
49167
  }
@@ -49019,7 +49169,7 @@ var EdrWatch = class {
49019
49169
  if (!/^\d+$/.test(pid)) continue;
49020
49170
  const proc = `/proc/${pid}`;
49021
49171
  try {
49022
- const raw = (0, import_node_fs48.readFileSync)(`${proc}/stat`, "utf8");
49172
+ const raw = (0, import_node_fs49.readFileSync)(`${proc}/stat`, "utf8");
49023
49173
  const end = raw.lastIndexOf(")");
49024
49174
  if (end < 0) continue;
49025
49175
  const fields = raw.slice(end + 1).trim().split(/\s+/);
@@ -49027,7 +49177,7 @@ var EdrWatch = class {
49027
49177
  const systemTicks = Number(fields[12]);
49028
49178
  const startTicks = fields[19];
49029
49179
  if (!Number.isFinite(userTicks) || !Number.isFinite(systemTicks) || !startTicks) continue;
49030
- let executable = (0, import_node_fs48.readlinkSync)(`${proc}/exe`);
49180
+ let executable = (0, import_node_fs49.readlinkSync)(`${proc}/exe`);
49031
49181
  executable = executable.replace(/ \(deleted\)$/, "");
49032
49182
  if (!this.opts.settings.tempExecPaths.some((path2) => pathWithin(executable, path2))) continue;
49033
49183
  const name = (0, import_node_path39.basename)(executable).toLowerCase();
@@ -49066,7 +49216,7 @@ var EdrWatch = class {
49066
49216
  };
49067
49217
 
49068
49218
  // src/daemon/workers/ssh-intrusion.ts
49069
- var import_node_fs49 = require("fs");
49219
+ var import_node_fs50 = require("fs");
49070
49220
  var import_node_path40 = require("path");
49071
49221
  var import_node_child_process16 = require("child_process");
49072
49222
 
@@ -49261,32 +49411,32 @@ function parseKeyLoginsByFingerprint(text) {
49261
49411
  }
49262
49412
  function readJson2(path2) {
49263
49413
  try {
49264
- return JSON.parse((0, import_node_fs49.readFileSync)(path2, "utf-8"));
49414
+ return JSON.parse((0, import_node_fs50.readFileSync)(path2, "utf-8"));
49265
49415
  } catch {
49266
49416
  return null;
49267
49417
  }
49268
49418
  }
49269
49419
  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);
49420
+ (0, import_node_fs50.mkdirSync)((0, import_node_path40.dirname)(path2), { recursive: true });
49421
+ (0, import_node_fs50.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
49422
+ (0, import_node_fs50.renameSync)(`${path2}.tmp`, path2);
49273
49423
  }
49274
49424
  var fsIO2 = {
49275
49425
  readFile: (p) => {
49276
49426
  try {
49277
- return (0, import_node_fs49.readFileSync)(p, "utf-8");
49427
+ return (0, import_node_fs50.readFileSync)(p, "utf-8");
49278
49428
  } catch {
49279
49429
  return null;
49280
49430
  }
49281
49431
  },
49282
49432
  readDir: (p) => {
49283
49433
  try {
49284
- return (0, import_node_fs49.readdirSync)(p);
49434
+ return (0, import_node_fs50.readdirSync)(p);
49285
49435
  } catch {
49286
49436
  return null;
49287
49437
  }
49288
49438
  },
49289
- exists: (p) => (0, import_node_fs49.existsSync)(p)
49439
+ exists: (p) => (0, import_node_fs50.existsSync)(p)
49290
49440
  };
49291
49441
  function defaultRun4(cmd, args) {
49292
49442
  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 +49637,23 @@ var SshIntrusionWatch = class {
49487
49637
  };
49488
49638
 
49489
49639
  // src/daemon/key-directory.ts
49490
- var import_node_fs50 = require("fs");
49640
+ var import_node_fs51 = require("fs");
49491
49641
  var fsIO3 = {
49492
49642
  readFile: (p) => {
49493
49643
  try {
49494
- return (0, import_node_fs50.readFileSync)(p, "utf-8");
49644
+ return (0, import_node_fs51.readFileSync)(p, "utf-8");
49495
49645
  } catch {
49496
49646
  return null;
49497
49647
  }
49498
49648
  },
49499
49649
  readDir: (p) => {
49500
49650
  try {
49501
- return (0, import_node_fs50.readdirSync)(p);
49651
+ return (0, import_node_fs51.readdirSync)(p);
49502
49652
  } catch {
49503
49653
  return null;
49504
49654
  }
49505
49655
  },
49506
- exists: (p) => (0, import_node_fs50.existsSync)(p)
49656
+ exists: (p) => (0, import_node_fs51.existsSync)(p)
49507
49657
  };
49508
49658
  var KeyDirectory = class {
49509
49659
  constructor(io = fsIO3, now = Date.now, ttlMs = 3e5) {
@@ -49547,7 +49697,7 @@ function enrichLoginEvent(event, keys) {
49547
49697
  }
49548
49698
 
49549
49699
  // src/daemon/workers/lightning-watch.ts
49550
- var import_node_fs51 = require("fs");
49700
+ var import_node_fs52 = require("fs");
49551
49701
  var DEFAULT_CLN_LOGS = [
49552
49702
  "/home/lightning/.lightning/cln.log",
49553
49703
  "/root/.lightning/cln.log",
@@ -49603,9 +49753,9 @@ var LightningWatch = class {
49603
49753
  if (this.opts.enabled === false) return [];
49604
49754
  const found = [];
49605
49755
  for (const path2 of this.opts.paths?.length ? this.opts.paths : DEFAULT_CLN_LOGS) {
49606
- if (!(0, import_node_fs51.existsSync)(path2)) continue;
49756
+ if (!(0, import_node_fs52.existsSync)(path2)) continue;
49607
49757
  try {
49608
- (0, import_node_fs51.accessSync)(path2, import_node_fs51.constants.R_OK);
49758
+ (0, import_node_fs52.accessSync)(path2, import_node_fs52.constants.R_OK);
49609
49759
  } catch {
49610
49760
  continue;
49611
49761
  }
@@ -49640,7 +49790,7 @@ var LightningWatch = class {
49640
49790
  };
49641
49791
 
49642
49792
  // src/core/tor-exits.ts
49643
- var import_node_fs52 = require("fs");
49793
+ var import_node_fs53 = require("fs");
49644
49794
  var import_node_path41 = require("path");
49645
49795
  var import_node_net15 = require("net");
49646
49796
  var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
@@ -49709,10 +49859,10 @@ var TorExitList = class _TorExitList {
49709
49859
  }
49710
49860
  loadCache() {
49711
49861
  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"));
49862
+ if (!(0, import_node_fs53.existsSync)(this.opts.cachePath)) return false;
49863
+ const parsed = parseTorExitList((0, import_node_fs53.readFileSync)(this.opts.cachePath, "utf-8"));
49714
49864
  if (parsed.size === 0) return false;
49715
- this.load(parsed, (0, import_node_fs52.statSync)(this.opts.cachePath).mtimeMs);
49865
+ this.load(parsed, (0, import_node_fs53.statSync)(this.opts.cachePath).mtimeMs);
49716
49866
  this.log(`[tor] loaded ${parsed.size} Tor exit addresses from cache (${new Date(this.updatedAt).toISOString()})`);
49717
49867
  return true;
49718
49868
  } catch (err) {
@@ -49744,9 +49894,9 @@ var TorExitList = class _TorExitList {
49744
49894
  const before2 = this.exits.size;
49745
49895
  this.load(parsed);
49746
49896
  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);
49897
+ (0, import_node_fs53.mkdirSync)((0, import_node_path41.dirname)(this.opts.cachePath), { recursive: true });
49898
+ (0, import_node_fs53.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
49899
+ (0, import_node_fs53.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
49750
49900
  } catch (err) {
49751
49901
  this.log(`[tor] could not save the exit list cache: ${err.message}`);
49752
49902
  }
@@ -49967,7 +50117,7 @@ var RuleEngine = class {
49967
50117
  };
49968
50118
 
49969
50119
  // src/daemon/rules/loader.ts
49970
- var import_node_fs53 = require("fs");
50120
+ var import_node_fs54 = require("fs");
49971
50121
  var import_node_path42 = require("path");
49972
50122
 
49973
50123
  // src/daemon/rules/default-rules.ts
@@ -50613,11 +50763,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
50613
50763
  function loadAllRules(customDir) {
50614
50764
  const rules = [...DEFAULT_RULES];
50615
50765
  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"));
50766
+ if ((0, import_node_fs54.existsSync)(dir)) {
50767
+ const files = (0, import_node_fs54.readdirSync)(dir).filter((f) => f.endsWith(".json"));
50618
50768
  for (const file of files) {
50619
50769
  try {
50620
- const raw = (0, import_node_fs53.readFileSync)((0, import_node_path42.join)(dir, file), "utf-8");
50770
+ const raw = (0, import_node_fs54.readFileSync)((0, import_node_path42.join)(dir, file), "utf-8");
50621
50771
  const parsed = JSON.parse(raw);
50622
50772
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
50623
50773
  for (const rule of customRules) {
@@ -50649,7 +50799,7 @@ function loadAllRules(customDir) {
50649
50799
 
50650
50800
  // src/daemon/firewall/adapters.ts
50651
50801
  var import_node_child_process17 = require("child_process");
50652
- var import_node_fs54 = require("fs");
50802
+ var import_node_fs55 = require("fs");
50653
50803
  var import_node_path43 = require("path");
50654
50804
  var import_node_net16 = require("net");
50655
50805
  function assertValidFirewallIp(ip) {
@@ -50663,9 +50813,9 @@ function assertBannableIp(ip) {
50663
50813
  }
50664
50814
  }
50665
50815
  function writeIfAbsent(path2, contents) {
50666
- (0, import_node_fs54.mkdirSync)((0, import_node_path43.dirname)(path2), { recursive: true });
50816
+ (0, import_node_fs55.mkdirSync)((0, import_node_path43.dirname)(path2), { recursive: true });
50667
50817
  try {
50668
- (0, import_node_fs54.writeFileSync)(path2, contents, { flag: "wx" });
50818
+ (0, import_node_fs55.writeFileSync)(path2, contents, { flag: "wx" });
50669
50819
  } catch (err) {
50670
50820
  if (err.code !== "EEXIST") throw err;
50671
50821
  }
@@ -50924,7 +51074,7 @@ function detectFirewallAdapter(backend = "auto") {
50924
51074
  }
50925
51075
 
50926
51076
  // src/daemon/firewall/remediation.ts
50927
- var import_node_fs55 = require("fs");
51077
+ var import_node_fs56 = require("fs");
50928
51078
  var import_node_child_process18 = require("child_process");
50929
51079
  var import_node_net17 = require("net");
50930
51080
  init_paths();
@@ -50996,19 +51146,19 @@ var defaultDiscovery = {
50996
51146
  const snapshot = takeSnapshot({
50997
51147
  readFile: (p) => {
50998
51148
  try {
50999
- return (0, import_node_fs55.readFileSync)(p, "utf-8");
51149
+ return (0, import_node_fs56.readFileSync)(p, "utf-8");
51000
51150
  } catch {
51001
51151
  return null;
51002
51152
  }
51003
51153
  },
51004
51154
  readDir: (p) => {
51005
51155
  try {
51006
- return (0, import_node_fs55.readdirSync)(p);
51156
+ return (0, import_node_fs56.readdirSync)(p);
51007
51157
  } catch {
51008
51158
  return null;
51009
51159
  }
51010
51160
  },
51011
- exists: (p) => (0, import_node_fs55.existsSync)(p)
51161
+ exists: (p) => (0, import_node_fs56.existsSync)(p)
51012
51162
  });
51013
51163
  const out = /* @__PURE__ */ new Set();
51014
51164
  for (const keys of Object.values(snapshot.keys)) {
@@ -51521,7 +51671,7 @@ var RemediationManager = class {
51521
51671
  }
51522
51672
  logLine(line2) {
51523
51673
  try {
51524
- (0, import_node_fs55.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
51674
+ (0, import_node_fs56.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
51525
51675
  `);
51526
51676
  } catch {
51527
51677
  }
@@ -51565,13 +51715,13 @@ function remediationSettings(section) {
51565
51715
  init_backoff();
51566
51716
 
51567
51717
  // src/daemon/watchdog-service.ts
51568
- var import_node_fs56 = require("fs");
51718
+ var import_node_fs57 = require("fs");
51569
51719
  var import_node_path44 = require("path");
51570
51720
  function defaultShareGid() {
51571
51721
  const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
51572
51722
  if (!isRoot4) return void 0;
51573
51723
  try {
51574
- return (0, import_node_fs56.statSync)("/var/log/auth.log").gid;
51724
+ return (0, import_node_fs57.statSync)("/var/log/auth.log").gid;
51575
51725
  } catch {
51576
51726
  return void 0;
51577
51727
  }
@@ -51692,7 +51842,7 @@ function versionOfNode(path2) {
51692
51842
  // src/daemon/index.ts
51693
51843
  function readVersion2() {
51694
51844
  try {
51695
- const pkg = JSON.parse((0, import_node_fs57.readFileSync)((0, import_node_path45.join)(__dirname, "..", "package.json"), "utf-8"));
51845
+ const pkg = JSON.parse((0, import_node_fs58.readFileSync)((0, import_node_path45.join)(__dirname, "..", "package.json"), "utf-8"));
51696
51846
  return pkg.version || "0.0.0";
51697
51847
  } catch {
51698
51848
  return "0.0.0";
@@ -51723,7 +51873,7 @@ async function runPatchCheck() {
51723
51873
  }
51724
51874
  function logLine(line2) {
51725
51875
  try {
51726
- (0, import_node_fs57.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
51876
+ (0, import_node_fs58.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
51727
51877
  `);
51728
51878
  } catch {
51729
51879
  }
@@ -51926,7 +52076,7 @@ async function runDaemon() {
51926
52076
  cloudSync = new CloudSync({
51927
52077
  bus,
51928
52078
  version,
51929
- hostname: (0, import_node_os18.hostname)(),
52079
+ hostname: (0, import_node_os19.hostname)(),
51930
52080
  minSeverity,
51931
52081
  spoolPath: (0, import_node_path45.join)(PATHS.stateDir, "cloud-spool.jsonl"),
51932
52082
  log: logLine,
@@ -52093,7 +52243,7 @@ async function daemonStart() {
52093
52243
  return;
52094
52244
  }
52095
52245
  ensureRuntimeDirs();
52096
- if (!(0, import_node_fs58.existsSync)(DAEMON_ENTRY)) {
52246
+ if (!(0, import_node_fs59.existsSync)(DAEMON_ENTRY)) {
52097
52247
  console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
52098
52248
  console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
52099
52249
  return;
@@ -52101,8 +52251,8 @@ async function daemonStart() {
52101
52251
  let out;
52102
52252
  let err;
52103
52253
  try {
52104
- out = (0, import_node_fs59.openSync)(PATHS.logFile, "a");
52105
- err = (0, import_node_fs59.openSync)(PATHS.logFile, "a");
52254
+ out = (0, import_node_fs60.openSync)(PATHS.logFile, "a");
52255
+ err = (0, import_node_fs60.openSync)(PATHS.logFile, "a");
52106
52256
  } catch (e) {
52107
52257
  const code = e.code;
52108
52258
  console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
@@ -52190,12 +52340,12 @@ async function waitForExit(pid, timeoutMs) {
52190
52340
  }
52191
52341
  async function releaseStaleSocket() {
52192
52342
  const deadline = Date.now() + 2e3;
52193
- while ((0, import_node_fs58.existsSync)(PATHS.socket) && Date.now() < deadline) {
52343
+ while ((0, import_node_fs59.existsSync)(PATHS.socket) && Date.now() < deadline) {
52194
52344
  await new Promise((r) => setTimeout(r, 50));
52195
52345
  }
52196
- if ((0, import_node_fs58.existsSync)(PATHS.socket)) {
52346
+ if ((0, import_node_fs59.existsSync)(PATHS.socket)) {
52197
52347
  try {
52198
- (0, import_node_fs58.unlinkSync)(PATHS.socket);
52348
+ (0, import_node_fs59.unlinkSync)(PATHS.socket);
52199
52349
  } catch {
52200
52350
  }
52201
52351
  }
@@ -52203,26 +52353,26 @@ async function releaseStaleSocket() {
52203
52353
 
52204
52354
  // src/commands/service.ts
52205
52355
  var import_node_child_process22 = require("child_process");
52206
- var import_node_fs60 = require("fs");
52356
+ var import_node_fs61 = require("fs");
52207
52357
  var import_node_path47 = require("path");
52208
- var import_node_os19 = require("os");
52358
+ var import_node_os20 = require("os");
52209
52359
  var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
52210
52360
  var DAEMON_UNIT_NAME = "threatcrushd.service";
52211
52361
  function resolveTemplate() {
52212
52362
  const templatePath = (0, import_node_path47.join)(__dirname, "systemd", "threatcrushd.service");
52213
- if (!(0, import_node_fs60.existsSync)(templatePath)) {
52363
+ if (!(0, import_node_fs61.existsSync)(templatePath)) {
52214
52364
  throw new Error(`systemd unit template not found at ${templatePath}`);
52215
52365
  }
52216
- return (0, import_node_fs60.readFileSync)(templatePath, "utf-8");
52366
+ return (0, import_node_fs61.readFileSync)(templatePath, "utf-8");
52217
52367
  }
52218
52368
  function stableBinPath(binPath) {
52219
52369
  const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
52220
52370
  if (stable === binPath) return binPath;
52221
- return (0, import_node_fs60.existsSync)(stable) ? stable : binPath;
52371
+ return (0, import_node_fs61.existsSync)(stable) ? stable : binPath;
52222
52372
  }
52223
52373
  function resolveBinPath() {
52224
52374
  const arg = process.argv[1];
52225
- if (arg && (0, import_node_fs60.existsSync)(arg)) return stableBinPath(arg);
52375
+ if (arg && (0, import_node_fs61.existsSync)(arg)) return stableBinPath(arg);
52226
52376
  try {
52227
52377
  return (0, import_node_child_process22.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
52228
52378
  } catch {
@@ -52232,12 +52382,12 @@ function resolveBinPath() {
52232
52382
  function stableNodePath(execPath) {
52233
52383
  const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
52234
52384
  if (stable === execPath) return execPath;
52235
- return (0, import_node_fs60.existsSync)(stable) ? stable : execPath;
52385
+ return (0, import_node_fs61.existsSync)(stable) ? stable : execPath;
52236
52386
  }
52237
52387
  function looksLikeNodeScript(path2) {
52238
52388
  try {
52239
- const head = (0, import_node_fs60.readFileSync)(path2, "utf-8").slice(0, 120);
52240
- return /^#!.*\bnode\b/.test(head);
52389
+ const head2 = (0, import_node_fs61.readFileSync)(path2, "utf-8").slice(0, 120);
52390
+ return /^#!.*\bnode\b/.test(head2);
52241
52391
  } catch {
52242
52392
  return false;
52243
52393
  }
@@ -52276,7 +52426,7 @@ function callerHome() {
52276
52426
  try {
52277
52427
  const line2 = (0, import_node_child_process22.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
52278
52428
  const home = line2.split(":")[5];
52279
- return home && (0, import_node_fs60.existsSync)(home) ? home : null;
52429
+ return home && (0, import_node_fs61.existsSync)(home) ? home : null;
52280
52430
  } catch {
52281
52431
  return null;
52282
52432
  }
@@ -52287,10 +52437,10 @@ function stopUserModeDaemon() {
52287
52437
  const runDir = (0, import_node_path47.join)(home, ".threatcrush", "run");
52288
52438
  const pidFile = (0, import_node_path47.join)(runDir, "threatcrushd.pid");
52289
52439
  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;
52440
+ if (!(0, import_node_fs61.existsSync)(pidFile) && !(0, import_node_fs61.existsSync)(socket)) return;
52291
52441
  let pid = null;
52292
52442
  try {
52293
- pid = Number.parseInt((0, import_node_fs60.readFileSync)(pidFile, "utf-8").trim(), 10);
52443
+ pid = Number.parseInt((0, import_node_fs61.readFileSync)(pidFile, "utf-8").trim(), 10);
52294
52444
  } catch {
52295
52445
  pid = null;
52296
52446
  }
@@ -52303,7 +52453,7 @@ function stopUserModeDaemon() {
52303
52453
  }
52304
52454
  for (const path2 of [socket, pidFile]) {
52305
52455
  try {
52306
- if ((0, import_node_fs60.existsSync)(path2)) (0, import_node_fs60.rmSync)(path2);
52456
+ if ((0, import_node_fs61.existsSync)(path2)) (0, import_node_fs61.rmSync)(path2);
52307
52457
  } catch {
52308
52458
  }
52309
52459
  }
@@ -52321,7 +52471,7 @@ async function installServiceCommand() {
52321
52471
  }
52322
52472
  const noSystemd = systemdUnavailableReason({
52323
52473
  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")
52474
+ booted: (0, import_node_fs61.existsSync)("/run/systemd/system")
52325
52475
  });
52326
52476
  if (noSystemd) {
52327
52477
  console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
@@ -52343,7 +52493,7 @@ async function installServiceCommand() {
52343
52493
  const isNodeScript = looksLikeNodeScript(binPath);
52344
52494
  let nodePath = stableNodePath(process.execPath);
52345
52495
  if (isNodeScript && nodeVersionDir(binPath)) {
52346
- binPath = (0, import_node_fs60.realpathSync)(binPath);
52496
+ binPath = (0, import_node_fs61.realpathSync)(binPath);
52347
52497
  nodePath = process.execPath;
52348
52498
  }
52349
52499
  if (isNodeScript) {
@@ -52356,11 +52506,11 @@ async function installServiceCommand() {
52356
52506
  }
52357
52507
  }
52358
52508
  const exec = execStartCommand(binPath, nodePath, isNodeScript);
52359
- const configDir = (0, import_node_path47.join)((0, import_node_os19.homedir)(), ".threatcrush");
52509
+ const configDir = (0, import_node_path47.join)((0, import_node_os20.homedir)(), ".threatcrush");
52360
52510
  const commandHistoryEnabled = commandHistorySettings(loadConfig().command_history).enabled;
52361
52511
  const historyPaths = commandHistoryEnabled ? historyWritableHomes() : [];
52362
52512
  const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir, historyPaths });
52363
- (0, import_node_fs60.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
52513
+ (0, import_node_fs61.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
52364
52514
  console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
52365
52515
  console.log(source_default.dim(` ExecStart=${exec}`));
52366
52516
  const nodeDir = nodeVersionDir(nodePath);
@@ -52413,9 +52563,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
52413
52563
  ].join("\n");
52414
52564
  }
52415
52565
  function installLogrotate() {
52416
- if (!(0, import_node_fs60.existsSync)((0, import_node_path47.dirname)(LOGROTATE_PATH))) return;
52566
+ if (!(0, import_node_fs61.existsSync)((0, import_node_path47.dirname)(LOGROTATE_PATH))) return;
52417
52567
  try {
52418
- (0, import_node_fs60.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
52568
+ (0, import_node_fs61.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
52419
52569
  console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
52420
52570
  } catch (err) {
52421
52571
  console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
@@ -52437,20 +52587,20 @@ function ensureSystemDirs(configDir) {
52437
52587
  ];
52438
52588
  let admGid2 = null;
52439
52589
  try {
52440
- admGid2 = (0, import_node_fs60.statSync)("/var/log/auth.log").gid;
52590
+ admGid2 = (0, import_node_fs61.statSync)("/var/log/auth.log").gid;
52441
52591
  } catch {
52442
52592
  }
52443
52593
  for (const { path: path2, groupWritable, sticky } of dirs) {
52444
52594
  try {
52445
- (0, import_node_fs60.mkdirSync)(path2, { recursive: true });
52595
+ (0, import_node_fs61.mkdirSync)(path2, { recursive: true });
52446
52596
  } catch {
52447
52597
  }
52448
52598
  try {
52449
52599
  if (groupWritable && admGid2 !== null) {
52450
- (0, import_node_fs60.chmodSync)(path2, sticky ? 1533 : 509);
52600
+ (0, import_node_fs61.chmodSync)(path2, sticky ? 1533 : 509);
52451
52601
  (0, import_node_child_process22.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
52452
52602
  } else {
52453
- (0, import_node_fs60.chmodSync)(path2, 493);
52603
+ (0, import_node_fs61.chmodSync)(path2, 493);
52454
52604
  }
52455
52605
  } catch {
52456
52606
  }
@@ -52478,7 +52628,7 @@ async function uninstallServiceCommand() {
52478
52628
  } catch {
52479
52629
  }
52480
52630
  try {
52481
- if ((0, import_node_fs60.existsSync)(UNIT_PATH)) {
52631
+ if ((0, import_node_fs61.existsSync)(UNIT_PATH)) {
52482
52632
  (0, import_node_child_process22.execSync)(`rm -f ${UNIT_PATH}`);
52483
52633
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
52484
52634
  }
@@ -52492,7 +52642,7 @@ async function uninstallServiceCommand() {
52492
52642
  }
52493
52643
 
52494
52644
  // src/commands/save.ts
52495
- var import_node_fs61 = require("fs");
52645
+ var import_node_fs62 = require("fs");
52496
52646
  var import_toml5 = __toESM(require_toml());
52497
52647
  init_cli_config();
52498
52648
  init_paths();
@@ -52531,9 +52681,9 @@ async function saveCommand(opts = {}) {
52531
52681
  }
52532
52682
  const path2 = opts.config ?? PATHS.configFile;
52533
52683
  let config = {};
52534
- if ((0, import_node_fs61.existsSync)(path2)) {
52684
+ if ((0, import_node_fs62.existsSync)(path2)) {
52535
52685
  try {
52536
- config = import_toml5.default.parse((0, import_node_fs61.readFileSync)(path2, "utf-8"));
52686
+ config = import_toml5.default.parse((0, import_node_fs62.readFileSync)(path2, "utf-8"));
52537
52687
  } catch (err) {
52538
52688
  console.log(source_default.red(` \u2717 ${path2} is not valid TOML: ${err.message}
52539
52689
  `));
@@ -52646,7 +52796,7 @@ function welcomeCommand() {
52646
52796
  }
52647
52797
 
52648
52798
  // src/commands/properties.ts
52649
- var import_node_fs62 = require("fs");
52799
+ var import_node_fs63 = require("fs");
52650
52800
  var import_node_path48 = require("path");
52651
52801
  var import_node_readline4 = __toESM(require("readline"));
52652
52802
  init_cli_config();
@@ -52978,7 +53128,7 @@ async function propertiesRunsCommand(opts) {
52978
53128
  }
52979
53129
  function parseImportFile(path2) {
52980
53130
  const ext = (0, import_node_path48.extname)(path2).toLowerCase();
52981
- const raw = (0, import_node_fs62.readFileSync)(path2, "utf-8");
53131
+ const raw = (0, import_node_fs63.readFileSync)(path2, "utf-8");
52982
53132
  if (ext === ".json") {
52983
53133
  const parsed = JSON.parse(raw);
52984
53134
  if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
@@ -53173,13 +53323,13 @@ async function rulesCommand(opts) {
53173
53323
  }
53174
53324
 
53175
53325
  // src/commands/harden.ts
53176
- var import_node_fs64 = require("fs");
53326
+ var import_node_fs65 = require("fs");
53177
53327
  var import_node_child_process23 = require("child_process");
53178
53328
  init_cli_config();
53179
53329
 
53180
53330
  // src/commands/cis-report.ts
53181
- var import_node_os20 = require("os");
53182
- var import_node_fs63 = require("fs");
53331
+ var import_node_os21 = require("os");
53332
+ var import_node_fs64 = require("fs");
53183
53333
  var CIS_UBUNTU_URL = "https://www.cisecurity.org/benchmark/ubuntu_linux";
53184
53334
  var CIS_DEBIAN_URL = "https://www.cisecurity.org/benchmark/debian_linux";
53185
53335
  var UBUNTU_2404_CIS_CONTROL_SOURCE = "https://github.com/ComplianceAsCode/content/blob/v0.1.78/controls/cis_ubuntu2404.yml";
@@ -53199,7 +53349,7 @@ var EDITIONS = {
53199
53349
  function osRelease() {
53200
53350
  let raw = "";
53201
53351
  try {
53202
- raw = (0, import_node_fs63.readFileSync)("/etc/os-release", "utf8");
53352
+ raw = (0, import_node_fs64.readFileSync)("/etc/os-release", "utf8");
53203
53353
  } catch {
53204
53354
  return {};
53205
53355
  }
@@ -53272,7 +53422,7 @@ function buildCisEvidenceReport(findings2, score, now = /* @__PURE__ */ new Date
53272
53422
  schema_version: 1,
53273
53423
  generated_at: now.toISOString(),
53274
53424
  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 },
53425
+ host: { hostname: (0, import_node_os21.hostname)(), os_id: id, os_version: version, pretty_name: os4.PRETTY_NAME ?? null },
53276
53426
  benchmark: edition ? { name: edition.name, version: edition.version, source: edition.source } : null,
53277
53427
  assessment: "partial",
53278
53428
  mapped_controls: mappedControls.size,
@@ -53379,7 +53529,7 @@ function writeCisReport(path2, format2, report) {
53379
53529
  const markdown = renderCisMarkdown(report);
53380
53530
  const content = format2 === "json" ? `${JSON.stringify(report, null, 2)}
53381
53531
  ` : format2 === "pdf" ? renderCisPdf(markdown) : markdown;
53382
- (0, import_node_fs63.writeFileSync)(path2, content);
53532
+ (0, import_node_fs64.writeFileSync)(path2, content);
53383
53533
  }
53384
53534
 
53385
53535
  // src/commands/harden.ts
@@ -53392,7 +53542,7 @@ function tryExec(cmd) {
53392
53542
  }
53393
53543
  function tryRead(path2) {
53394
53544
  try {
53395
- return (0, import_node_fs64.readFileSync)(path2, "utf-8");
53545
+ return (0, import_node_fs65.readFileSync)(path2, "utf-8");
53396
53546
  } catch {
53397
53547
  return null;
53398
53548
  }
@@ -53506,8 +53656,8 @@ function checkSshWeakConfig() {
53506
53656
  };
53507
53657
  }
53508
53658
  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");
53659
+ const unattended = (0, import_node_fs65.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs65.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
53660
+ const dnfAuto = (0, import_node_fs65.existsSync)("/etc/dnf/automatic.conf");
53511
53661
  if (unattended || dnfAuto) {
53512
53662
  return {
53513
53663
  key: "auto-updates",
@@ -53633,7 +53783,7 @@ function checkFail2ban() {
53633
53783
  explanation: "fail2ban is installed and running."
53634
53784
  };
53635
53785
  }
53636
- if ((0, import_node_fs64.existsSync)("/etc/fail2ban/fail2ban.conf")) {
53786
+ if ((0, import_node_fs65.existsSync)("/etc/fail2ban/fail2ban.conf")) {
53637
53787
  return {
53638
53788
  key: checkKey,
53639
53789
  status: "warn",
@@ -53853,7 +54003,7 @@ async function hardenCommand(opts) {
53853
54003
  }
53854
54004
 
53855
54005
  // src/core/patches/index.ts
53856
- var import_node_fs65 = require("fs");
54006
+ var import_node_fs66 = require("fs");
53857
54007
  var import_node_path49 = require("path");
53858
54008
  var import_node_child_process24 = require("child_process");
53859
54009
  var import_node_util5 = require("util");
@@ -54014,9 +54164,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
54014
54164
  function newestReleaseMtime(dir) {
54015
54165
  try {
54016
54166
  let newest = 0;
54017
- for (const name of (0, import_node_fs65.readdirSync)(dir)) {
54167
+ for (const name of (0, import_node_fs66.readdirSync)(dir)) {
54018
54168
  if (!/Release$/.test(name)) continue;
54019
- newest = Math.max(newest, (0, import_node_fs65.statSync)((0, import_node_path49.join)(dir, name)).mtimeMs);
54169
+ newest = Math.max(newest, (0, import_node_fs66.statSync)((0, import_node_path49.join)(dir, name)).mtimeMs);
54020
54170
  }
54021
54171
  return newest > 0 ? new Date(newest) : null;
54022
54172
  } catch {
@@ -54033,7 +54183,7 @@ async function checkPatches(opts = {}) {
54033
54183
  let osText = opts.osRelease;
54034
54184
  if (osText === void 0) {
54035
54185
  try {
54036
- osText = (0, import_node_fs65.readFileSync)("/etc/os-release", "utf-8");
54186
+ osText = (0, import_node_fs66.readFileSync)("/etc/os-release", "utf-8");
54037
54187
  } catch {
54038
54188
  osText = "";
54039
54189
  }
@@ -54265,19 +54415,19 @@ init_paths();
54265
54415
 
54266
54416
  // src/commands/feeds-resolver.ts
54267
54417
  var import_node_child_process25 = require("child_process");
54268
- var import_node_fs66 = require("fs");
54418
+ var import_node_fs67 = require("fs");
54269
54419
  var import_node_path50 = require("path");
54270
54420
  var realIO = {
54271
- exists: (p) => (0, import_node_fs66.existsSync)(p),
54421
+ exists: (p) => (0, import_node_fs67.existsSync)(p),
54272
54422
  read: (p) => {
54273
54423
  try {
54274
- return (0, import_node_fs66.readFileSync)(p, "utf-8");
54424
+ return (0, import_node_fs67.readFileSync)(p, "utf-8");
54275
54425
  } catch {
54276
54426
  return null;
54277
54427
  }
54278
54428
  },
54279
- write: (p, c) => (0, import_node_fs66.writeFileSync)(p, c),
54280
- remove: (p) => (0, import_node_fs66.rmSync)(p, { force: true }),
54429
+ write: (p, c) => (0, import_node_fs67.writeFileSync)(p, c),
54430
+ remove: (p) => (0, import_node_fs67.rmSync)(p, { force: true }),
54281
54431
  run: (cmd, args) => {
54282
54432
  const r = (0, import_node_child_process25.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
54283
54433
  return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
@@ -54286,9 +54436,9 @@ var realIO = {
54286
54436
  var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
54287
54437
  var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
54288
54438
  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)}"
54439
+ const head2 = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
54440
+ return resolver === "dnsmasq" ? `${head2}addn-hosts=${(0, import_node_path50.join)(stateDir, RESOLVER_FILES.hosts)}
54441
+ ` : `${head2}include: "${(0, import_node_path50.join)(stateDir, RESOLVER_FILES.unbound)}"
54292
54442
  `;
54293
54443
  }
54294
54444
  function apparmorRule(stateDir) {
@@ -54432,7 +54582,7 @@ async function feedsCommand(action, value, opts) {
54432
54582
  }
54433
54583
 
54434
54584
  // src/commands/tor.ts
54435
- var import_node_fs67 = require("fs");
54585
+ var import_node_fs68 = require("fs");
54436
54586
  var import_node_net19 = require("net");
54437
54587
  var import_node_path52 = require("path");
54438
54588
  init_paths();
@@ -54443,10 +54593,10 @@ async function torCommand(action, value, opts) {
54443
54593
  for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
54444
54594
  const path2 = (0, import_node_path52.join)(dir, "tor-exits.txt");
54445
54595
  try {
54446
- if (!(0, import_node_fs67.existsSync)(path2)) continue;
54447
- exits = parseTorExitList((0, import_node_fs67.readFileSync)(path2, "utf-8"));
54596
+ if (!(0, import_node_fs68.existsSync)(path2)) continue;
54597
+ exits = parseTorExitList((0, import_node_fs68.readFileSync)(path2, "utf-8"));
54448
54598
  from = path2;
54449
- updated = (0, import_node_fs67.statSync)(path2).mtime;
54599
+ updated = (0, import_node_fs68.statSync)(path2).mtime;
54450
54600
  break;
54451
54601
  } catch {
54452
54602
  }
@@ -54493,14 +54643,14 @@ async function torCommand(action, value, opts) {
54493
54643
  }
54494
54644
 
54495
54645
  // src/commands/reputation.ts
54496
- var import_node_os21 = require("os");
54497
- var import_node_fs68 = require("fs");
54646
+ var import_node_os22 = require("os");
54647
+ var import_node_fs69 = require("fs");
54498
54648
  var import_node_path53 = require("path");
54499
54649
  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");
54650
+ var CONFIG_PATH4 = (0, import_node_path53.join)((0, import_node_os22.homedir)(), ".threatcrush", "config.json");
54501
54651
  function readConfig3() {
54502
54652
  try {
54503
- return JSON.parse((0, import_node_fs68.readFileSync)(CONFIG_PATH4, "utf-8"));
54653
+ return JSON.parse((0, import_node_fs69.readFileSync)(CONFIG_PATH4, "utf-8"));
54504
54654
  } catch {
54505
54655
  return {};
54506
54656
  }
@@ -54513,8 +54663,8 @@ function authFor(env3 = process.env, config = readConfig3()) {
54513
54663
  }
54514
54664
  function formatReport(r) {
54515
54665
  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})`)}`);
54666
+ const head2 = r.listed ? source_default.red(`LISTED score ${r.score}/100`) : source_default.green("not listed");
54667
+ lines.push(` ${source_default.bold(r.ip)} ${head2} ${source_default.dim(`(${r.tier})`)}`);
54518
54668
  if (r.reports) {
54519
54669
  lines.push(
54520
54670
  ` ${r.severity} \xB7 ${r.reports} reports from ${r.reporters} reporter${r.reporters === 1 ? "" : "s"} \xB7 last seen ${String(r.last_seen ?? "").slice(0, 10)}${r.country ? ` \xB7 ${r.country}` : ""}`
@@ -54535,8 +54685,8 @@ function formatReport(r) {
54535
54685
  }
54536
54686
  function formatAny(r) {
54537
54687
  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})`)}`];
54688
+ const head2 = r.listed ? source_default.red(`LISTED score ${r.score}/100`) : source_default.green("not listed");
54689
+ const lines = [` ${source_default.bold(r.domain)} ${head2} ${source_default.dim(`(${r.tier})`)}`];
54540
54690
  for (const reason of r.reasons) lines.push(` \xB7 ${reason}`);
54541
54691
  for (const a of r.addresses) lines.push(` ${a.ip}: ${a.listed ? source_default.red(`listed, ${a.score}/100`) : "not listed"}`);
54542
54692
  lines.push(source_default.dim(` public record: ${r.public_record}`));
@@ -54688,7 +54838,7 @@ async function reputationSubscribeCommand(opts) {
54688
54838
  }
54689
54839
 
54690
54840
  // src/commands/privileged.ts
54691
- var import_node_fs69 = require("fs");
54841
+ var import_node_fs70 = require("fs");
54692
54842
  init_paths();
54693
54843
  var SEV2 = {
54694
54844
  critical: source_default.red.bold,
@@ -54701,19 +54851,19 @@ async function privilegedCommand(opts) {
54701
54851
  const snapshot = takeSnapshot({
54702
54852
  readFile: (p) => {
54703
54853
  try {
54704
- return (0, import_node_fs69.readFileSync)(p, "utf-8");
54854
+ return (0, import_node_fs70.readFileSync)(p, "utf-8");
54705
54855
  } catch {
54706
54856
  return null;
54707
54857
  }
54708
54858
  },
54709
54859
  readDir: (p) => {
54710
54860
  try {
54711
- return (0, import_node_fs69.readdirSync)(p);
54861
+ return (0, import_node_fs70.readdirSync)(p);
54712
54862
  } catch {
54713
54863
  return null;
54714
54864
  }
54715
54865
  },
54716
- exists: (p) => (0, import_node_fs69.existsSync)(p)
54866
+ exists: (p) => (0, import_node_fs70.existsSync)(p)
54717
54867
  });
54718
54868
  let events = [];
54719
54869
  let ledgerNote = "";
@@ -54755,12 +54905,12 @@ async function privilegedCommand(opts) {
54755
54905
  }
54756
54906
 
54757
54907
  // src/commands/integrity.ts
54758
- var import_node_fs70 = require("fs");
54908
+ var import_node_fs71 = require("fs");
54759
54909
  var import_node_path54 = require("path");
54760
54910
  init_paths();
54761
54911
  function readState2(path2) {
54762
54912
  try {
54763
- return JSON.parse((0, import_node_fs70.readFileSync)(path2, "utf8"));
54913
+ return JSON.parse((0, import_node_fs71.readFileSync)(path2, "utf8"));
54764
54914
  } catch {
54765
54915
  return null;
54766
54916
  }
@@ -54781,7 +54931,7 @@ async function integrityCommand(action = "status", opts = {}) {
54781
54931
  const config = loadConfig();
54782
54932
  const settings = fileIntegritySettings(config.file_integrity);
54783
54933
  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);
54934
+ const useSystemState = PATHS.mode === "system" || systemDaemonPresent() || (0, import_node_fs71.existsSync)(systemBaseline);
54785
54935
  const stateDir = useSystemState ? SYSTEM_PATHS.stateDir : PATHS.stateDir;
54786
54936
  const baselinePath = (0, import_node_path54.join)(stateDir, "file-integrity-baseline.json");
54787
54937
  const observedPath = (0, import_node_path54.join)(stateDir, "file-integrity-observed.json");
@@ -54852,11 +55002,11 @@ async function integrityCommand(action = "status", opts = {}) {
54852
55002
  }
54853
55003
 
54854
55004
  // src/commands/edr.ts
54855
- var import_node_fs72 = require("fs");
55005
+ var import_node_fs73 = require("fs");
54856
55006
  init_paths();
54857
55007
 
54858
55008
  // src/daemon/auditd/rules.ts
54859
- var import_node_fs71 = require("fs");
55009
+ var import_node_fs72 = require("fs");
54860
55010
  var import_node_child_process26 = require("child_process");
54861
55011
  var import_node_path55 = require("path");
54862
55012
  var WEB_TOOLS = ["sh", "bash", "dash", "zsh", "curl", "wget"];
@@ -54869,7 +55019,7 @@ function passwdByName() {
54869
55019
  raw = (0, import_node_child_process26.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
54870
55020
  } catch {
54871
55021
  try {
54872
- raw = (0, import_node_fs71.readFileSync)("/etc/passwd", "utf8");
55022
+ raw = (0, import_node_fs72.readFileSync)("/etc/passwd", "utf8");
54873
55023
  } catch {
54874
55024
  return /* @__PURE__ */ new Map();
54875
55025
  }
@@ -54888,8 +55038,8 @@ function existingExecutables(names) {
54888
55038
  for (const prefix of ["/bin", "/usr/bin", "/usr/local/bin"]) {
54889
55039
  const candidate = `${prefix}/${name}`;
54890
55040
  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));
55041
+ if (!(0, import_node_fs72.existsSync)(candidate) || !(0, import_node_fs72.statSync)(candidate).isFile()) continue;
55042
+ paths.add((0, import_node_fs72.realpathSync)(candidate));
54893
55043
  } catch {
54894
55044
  }
54895
55045
  }
@@ -54900,7 +55050,7 @@ function existingDirectories(paths) {
54900
55050
  return [...new Set(paths)].filter((path2) => {
54901
55051
  if (!(0, import_node_path55.isAbsolute)(path2) || /[\s\r\n]/.test(path2)) return false;
54902
55052
  try {
54903
- return (0, import_node_fs71.statSync)(path2).isDirectory();
55053
+ return (0, import_node_fs72.statSync)(path2).isDirectory();
54904
55054
  } catch {
54905
55055
  return false;
54906
55056
  }
@@ -54961,8 +55111,8 @@ async function edrCommand(action = "status", opts = {}) {
54961
55111
  }
54962
55112
  let readable = false;
54963
55113
  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);
55114
+ if ((0, import_node_fs73.existsSync)(settings.auditLogPath)) (0, import_node_fs73.accessSync)(settings.auditLogPath, import_node_fs73.constants.R_OK);
55115
+ readable = (0, import_node_fs73.existsSync)(settings.auditLogPath);
54966
55116
  } catch {
54967
55117
  }
54968
55118
  let events = [];
@@ -55148,7 +55298,7 @@ async function allowlistCommand(opts) {
55148
55298
  }
55149
55299
 
55150
55300
  // src/commands/abuse.ts
55151
- var import_node_fs73 = require("fs");
55301
+ var import_node_fs74 = require("fs");
55152
55302
  init_paths();
55153
55303
  function rows(records) {
55154
55304
  if (records.length === 0) {
@@ -55208,7 +55358,7 @@ function abuseRetractCommand(id, opts = {}) {
55208
55358
  );
55209
55359
  }
55210
55360
  function abuseStatusCommand(opts = {}) {
55211
- const config = loadConfig((0, import_node_fs73.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
55361
+ const config = loadConfig((0, import_node_fs74.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
55212
55362
  const cfg = resolveConfig(config.abuse_reporter);
55213
55363
  const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
55214
55364
  const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
@@ -55377,7 +55527,7 @@ function installUserAgent(target = globalThis) {
55377
55527
 
55378
55528
  // src/core/cloud-upload.ts
55379
55529
  var import_node_child_process28 = require("child_process");
55380
- var import_node_os22 = require("os");
55530
+ var import_node_os23 = require("os");
55381
55531
  var import_node_path56 = require("path");
55382
55532
  init_cli_config();
55383
55533
  function uploadDisabled(upload, env3 = process.env) {
@@ -55411,9 +55561,9 @@ function repoTarget(path2, run2 = (args) => (0, import_node_child_process28.exec
55411
55561
  const m = /^(?:[a-z+]+:\/\/)?(?:[^@/]+@)?([^/:]+)[:/](.+?)(?:\.git)?\/?$/i.exec(remote);
55412
55562
  if (m) return { target: `${m[1]}/${m[2]}`, root, sub };
55413
55563
  }
55414
- return { target: `${(0, import_node_os22.hostname)()}:${root}`, root, sub };
55564
+ return { target: `${(0, import_node_os23.hostname)()}:${root}`, root, sub };
55415
55565
  } catch {
55416
- return { target: `${(0, import_node_os22.hostname)()}:${abs}`, root: abs, sub: "." };
55566
+ return { target: `${(0, import_node_os23.hostname)()}:${abs}`, root: abs, sub: "." };
55417
55567
  }
55418
55568
  }
55419
55569
  async function uploadResult(result, opts) {
@@ -55770,7 +55920,7 @@ ${source_default.dim(" C R U S H")}
55770
55920
  var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
55771
55921
  var PKG_NAME2 = "@profullstack/threatcrush";
55772
55922
  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");
55923
+ var INSTALL_CONFIG_PATH = (0, import_node_path57.join)((0, import_node_os24.homedir)(), ".threatcrush", "install.json");
55774
55924
  function detectPackageManager() {
55775
55925
  try {
55776
55926
  const npmGlobal = (0, import_node_child_process29.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
@@ -55796,7 +55946,7 @@ function detectPackageManager() {
55796
55946
  }
55797
55947
  function readInstallConfig() {
55798
55948
  try {
55799
- return JSON.parse((0, import_node_fs74.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
55949
+ return JSON.parse((0, import_node_fs75.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
55800
55950
  } catch {
55801
55951
  return {};
55802
55952
  }
@@ -56075,7 +56225,7 @@ program2.command("scan").description("Scan codebase for vulnerabilities and secr
56075
56225
  }
56076
56226
  });
56077
56227
  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) => {
56228
+ av.command("scan").description("Scan files or folders for malware; no paths = quick scan of downloads, desktop, temp and startup items").argument("[paths...]", "files or folders to scan").option("--full", "scan the whole home folder plus system startup and temp locations").option("--no-clamav", "do not use ClamAV even when it is installed").option("--require-clamav", "fail if ClamAV is not installed").option("--offline", "do not send file hashes to threatcrush.com for reputation lookups").option("--quarantine", "move malware into quarantine (reversible with `av quarantine restore`)").option("--max-size <mb>", "skip files larger than this many MB (default 1024)").option("-j, --jobs <n>", "files scanned in parallel worker threads (default: one per CPU core)").option("--json", "emit JSON").action(async (paths, opts) => {
56079
56229
  await avScanCommand(paths, opts);
56080
56230
  });
56081
56231
  av.command("watch").description("Real-time protection: scan new and changed files as they land (default: downloads, desktop, temp, startup)").argument("[paths...]", "folders to watch instead of the defaults").option("--quarantine", "quarantine malware the moment it is detected").option("--offline", "do not send file hashes to threatcrush.com").option("--json", "one JSON line per scanned file").action(async (paths, opts) => avWatchCommand(paths, opts));
@@ -56227,7 +56377,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
56227
56377
  program2.command("logs").description("Tail daemon logs").action(async () => {
56228
56378
  console.log(LOGO2);
56229
56379
  const logPath2 = PATHS.logFile;
56230
- if (!(0, import_node_fs74.existsSync)(logPath2)) {
56380
+ if (!(0, import_node_fs75.existsSync)(logPath2)) {
56231
56381
  console.log(source_default.yellow(` No log file found at ${logPath2}`));
56232
56382
  console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
56233
56383
  return;
@@ -56400,10 +56550,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
56400
56550
  });
56401
56551
  storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
56402
56552
  console.log(LOGO2);
56403
- const configPath = (0, import_node_path57.join)((0, import_node_os23.homedir)(), ".threatcrush", "config.json");
56553
+ const configPath = (0, import_node_path57.join)((0, import_node_os24.homedir)(), ".threatcrush", "config.json");
56404
56554
  let email = "";
56405
56555
  try {
56406
- const config = JSON.parse((0, import_node_fs74.readFileSync)(configPath, "utf-8"));
56556
+ const config = JSON.parse((0, import_node_fs75.readFileSync)(configPath, "utf-8"));
56407
56557
  email = config.email || "";
56408
56558
  } catch {
56409
56559
  }
@@ -56420,9 +56570,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
56420
56570
  return;
56421
56571
  }
56422
56572
  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));
56573
+ const dir = (0, import_node_path57.join)((0, import_node_os24.homedir)(), ".threatcrush");
56574
+ if (!(0, import_node_fs75.existsSync)(dir)) (0, import_node_fs75.mkdirSync)(dir, { recursive: true });
56575
+ (0, import_node_fs75.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
56426
56576
  console.log(source_default.dim(` Saved email to ${configPath}`));
56427
56577
  } catch {
56428
56578
  }