@profullstack/threatcrush 0.13.36 → 0.13.37

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
@@ -24745,9 +24745,9 @@ var source_default = chalk;
24745
24745
 
24746
24746
  // src/index.ts
24747
24747
  var import_readline = __toESM(require("readline"));
24748
- var import_node_child_process20 = require("child_process");
24749
- var import_node_fs46 = require("fs");
24750
- var import_node_path34 = require("path");
24748
+ var import_node_child_process22 = require("child_process");
24749
+ var import_node_fs49 = require("fs");
24750
+ var import_node_path36 = require("path");
24751
24751
  var import_node_os13 = require("os");
24752
24752
 
24753
24753
  // src/commands/monitor.ts
@@ -38315,35 +38315,35 @@ async function modulesInstallCommand(source) {
38315
38315
  `));
38316
38316
  return;
38317
38317
  }
38318
- const check = validateManifest(absPath);
38319
- if (!check.ok) {
38320
- console.log(source_default.red(` \u2717 ${check.error}
38318
+ const check2 = validateManifest(absPath);
38319
+ if (!check2.ok) {
38320
+ console.log(source_default.red(` \u2717 ${check2.error}
38321
38321
  `));
38322
38322
  return;
38323
38323
  }
38324
38324
  let dest2;
38325
38325
  try {
38326
- dest2 = moduleDestination(dir, check.name);
38326
+ dest2 = moduleDestination(dir, check2.name);
38327
38327
  } catch (err) {
38328
38328
  console.log(source_default.red(` x ${err.message}
38329
38329
  `));
38330
38330
  return;
38331
38331
  }
38332
38332
  if ((0, import_node_fs20.existsSync)(dest2)) {
38333
- console.log(source_default.yellow(` ! ${check.name} is already installed at ${dest2}`));
38334
- console.log(source_default.dim(` Run ${source_default.white(`threatcrush modules remove ${check.name}`)} first.
38333
+ console.log(source_default.yellow(` ! ${check2.name} is already installed at ${dest2}`));
38334
+ console.log(source_default.dim(` Run ${source_default.white(`threatcrush modules remove ${check2.name}`)} first.
38335
38335
  `));
38336
38336
  return;
38337
38337
  }
38338
38338
  const spinner2 = ora({ text: `Copying module files...`, color: "green" }).start();
38339
38339
  try {
38340
38340
  (0, import_node_fs20.cpSync)(absPath, dest2, { recursive: true, dereference: true });
38341
- spinner2.succeed(`Installed ${source_default.white(check.name)} v${check.version} \u2192 ${dest2}`);
38341
+ spinner2.succeed(`Installed ${source_default.white(check2.name)} v${check2.version} \u2192 ${dest2}`);
38342
38342
  } catch (err) {
38343
38343
  spinner2.fail(`Copy failed: ${err.message}`);
38344
38344
  return;
38345
38345
  }
38346
- printTrustRequired(check.name);
38346
+ printTrustRequired(check2.name);
38347
38347
  notifyDaemonIfRunning();
38348
38348
  console.log();
38349
38349
  return;
@@ -38373,17 +38373,17 @@ async function modulesInstallCommand(source) {
38373
38373
  spinner2.fail(`Clone failed: ${err.message}`);
38374
38374
  return;
38375
38375
  }
38376
- const check = validateManifest(dest2);
38377
- if (!check.ok) {
38378
- spinner2.fail(check.error);
38376
+ const check2 = validateManifest(dest2);
38377
+ if (!check2.ok) {
38378
+ spinner2.fail(check2.error);
38379
38379
  try {
38380
38380
  (0, import_node_fs20.rmSync)(dest2, { recursive: true, force: true });
38381
38381
  } catch {
38382
38382
  }
38383
38383
  return;
38384
38384
  }
38385
- spinner2.succeed(`Installed ${source_default.white(check.name)} v${check.version} \u2192 ${dest2}`);
38386
- printTrustRequired(check.name);
38385
+ spinner2.succeed(`Installed ${source_default.white(check2.name)} v${check2.version} \u2192 ${dest2}`);
38386
+ printTrustRequired(check2.name);
38387
38387
  notifyDaemonIfRunning();
38388
38388
  console.log();
38389
38389
  return;
@@ -38446,9 +38446,9 @@ async function modulesInstallCommand(source) {
38446
38446
  cloneSpinner.fail(`Clone failed: ${err.message}`);
38447
38447
  return;
38448
38448
  }
38449
- const check = validateManifest(dest);
38450
- if (!check.ok) {
38451
- cloneSpinner.fail(check.error);
38449
+ const check2 = validateManifest(dest);
38450
+ if (!check2.ok) {
38451
+ cloneSpinner.fail(check2.error);
38452
38452
  try {
38453
38453
  (0, import_node_fs20.rmSync)(dest, { recursive: true, force: true });
38454
38454
  } catch {
@@ -38469,9 +38469,9 @@ async function modulesInstallCommand(source) {
38469
38469
  assertSafeTarballEntries(tar);
38470
38470
  (0, import_node_child_process3.execFileSync)("tar", ["-xzf", tar, "-C", dir], { stdio: "pipe" });
38471
38471
  (0, import_node_fs20.rmSync)(tar, { force: true });
38472
- const check = validateManifest(dest);
38473
- if (!check.ok) {
38474
- dlSpinner.fail(check.error);
38472
+ const check2 = validateManifest(dest);
38473
+ if (!check2.ok) {
38474
+ dlSpinner.fail(check2.error);
38475
38475
  return;
38476
38476
  }
38477
38477
  dlSpinner.succeed(`Installed ${mod.name} v${mod.version} \u2192 ${dest}`);
@@ -38505,9 +38505,9 @@ async function modulesRemoveCommand(name) {
38505
38505
  `));
38506
38506
  return;
38507
38507
  }
38508
- const check = validateManifest(target);
38509
- if (check.ok && check.name !== name) {
38510
- console.log(source_default.yellow(` ! Directory name "${name}" does not match manifest name "${check.name}"`));
38508
+ const check2 = validateManifest(target);
38509
+ if (check2.ok && check2.name !== name) {
38510
+ console.log(source_default.yellow(` ! Directory name "${name}" does not match manifest name "${check2.name}"`));
38511
38511
  }
38512
38512
  try {
38513
38513
  (0, import_node_fs20.rmSync)(target, { recursive: true, force: true });
@@ -38540,14 +38540,14 @@ async function modulesTrustCommand(name) {
38540
38540
  `));
38541
38541
  return;
38542
38542
  }
38543
- const check = validateManifest(target);
38544
- if (!check.ok) {
38545
- console.log(source_default.red(` \u2717 ${check.error}
38543
+ const check2 = validateManifest(target);
38544
+ if (!check2.ok) {
38545
+ console.log(source_default.red(` \u2717 ${check2.error}
38546
38546
  `));
38547
38547
  return;
38548
38548
  }
38549
38549
  const record = trustModule(name, target, target);
38550
- console.log(source_default.green(` \u2713 Trusted ${source_default.white(name)} v${check.version}`));
38550
+ console.log(source_default.green(` \u2713 Trusted ${source_default.white(name)} v${check2.version}`));
38551
38551
  console.log(source_default.dim(` digest ${record.digest.slice(0, 16)}\u2026`));
38552
38552
  console.log(
38553
38553
  source_default.dim(" threatcrushd will refuse to load it again if its contents change.\n")
@@ -38756,10 +38756,10 @@ async function collectPentestResults(targetUrl) {
38756
38756
  headers[k] = v;
38757
38757
  });
38758
38758
  const body = await resp.text();
38759
- for (const check of PENTEST_CHECKS) {
38759
+ for (const check2 of PENTEST_CHECKS) {
38760
38760
  try {
38761
- if (check.test(body, body, headers)) {
38762
- results.push({ url: targetUrl, type: check.name, severity: check.severity, message: check.message });
38761
+ if (check2.test(body, body, headers)) {
38762
+ results.push({ url: targetUrl, type: check2.name, severity: check2.severity, message: check2.message });
38763
38763
  }
38764
38764
  } catch {
38765
38765
  }
@@ -38827,14 +38827,14 @@ async function pentestCommand(targetUrl) {
38827
38827
  const body = await resp.text();
38828
38828
  spinner.succeed(`Got ${resp.status} response
38829
38829
  `);
38830
- for (const check of PENTEST_CHECKS) {
38830
+ for (const check2 of PENTEST_CHECKS) {
38831
38831
  try {
38832
- if (check.test(body, body, headers)) {
38832
+ if (check2.test(body, body, headers)) {
38833
38833
  results.push({
38834
38834
  url: targetUrl,
38835
- type: check.name,
38836
- severity: check.severity,
38837
- message: check.message
38835
+ type: check2.name,
38836
+ severity: check2.severity,
38837
+ message: check2.message
38838
38838
  });
38839
38839
  }
38840
38840
  } catch {
@@ -39789,16 +39789,16 @@ async function sshConnect(options) {
39789
39789
  }
39790
39790
 
39791
39791
  // src/commands/daemon.ts
39792
- var import_node_child_process15 = require("child_process");
39793
- var import_node_fs38 = require("fs");
39794
- var import_node_path29 = require("path");
39795
- var import_node_fs39 = require("fs");
39792
+ var import_node_child_process16 = require("child_process");
39793
+ var import_node_fs40 = require("fs");
39794
+ var import_node_path30 = require("path");
39795
+ var import_node_fs41 = require("fs");
39796
39796
 
39797
39797
  // src/daemon/index.ts
39798
- var import_node_fs37 = require("fs");
39799
- var import_node_child_process14 = require("child_process");
39798
+ var import_node_fs39 = require("fs");
39799
+ var import_node_child_process15 = require("child_process");
39800
39800
  var import_node_os11 = require("os");
39801
- var import_node_path28 = require("path");
39801
+ var import_node_path29 = require("path");
39802
39802
  var import_node_util = require("util");
39803
39803
  init_paths();
39804
39804
 
@@ -40101,7 +40101,7 @@ function admGid(readGroup = () => (0, import_node_fs24.readFileSync)("/etc/group
40101
40101
  }
40102
40102
 
40103
40103
  // src/daemon/module-host.ts
40104
- var import_node_fs29 = require("fs");
40104
+ var import_node_fs30 = require("fs");
40105
40105
  var import_node_path21 = require("path");
40106
40106
  var import_node_url = require("url");
40107
40107
  var import_toml4 = __toESM(require_toml());
@@ -40678,17 +40678,18 @@ var NetworkMonitor = class {
40678
40678
  };
40679
40679
 
40680
40680
  // src/modules/dns-monitor/index.ts
40681
- var import_node_fs28 = require("fs");
40681
+ var import_node_fs29 = require("fs");
40682
40682
  var import_node_child_process8 = require("child_process");
40683
40683
  var import_node_readline3 = require("readline");
40684
40684
 
40685
40685
  // src/core/threat-feeds/index.ts
40686
- var import_node_fs27 = require("fs");
40686
+ var import_node_fs28 = require("fs");
40687
40687
  var import_node_path20 = require("path");
40688
40688
  var import_node_net5 = require("net");
40689
40689
 
40690
40690
  // src/daemon/firewall/protected.ts
40691
40691
  var import_node_child_process7 = require("child_process");
40692
+ var import_node_fs27 = require("fs");
40692
40693
  var import_node_net4 = require("net");
40693
40694
  var DEFAULT_PROTECTED = [
40694
40695
  "127.0.0.0/8",
@@ -40801,6 +40802,45 @@ function establishedSshPeers() {
40801
40802
  }
40802
40803
  return [...peers];
40803
40804
  }
40805
+ function sshClientFromEnviron(environ) {
40806
+ for (const entry of environ.split("\0")) {
40807
+ const m = /^SSH_(?:CONNECTION|CLIENT)=(\S+)/.exec(entry);
40808
+ if (m && (0, import_node_net4.isIP)(m[1])) return m[1];
40809
+ }
40810
+ return null;
40811
+ }
40812
+ function moshClients(procDir = "/proc") {
40813
+ const found = /* @__PURE__ */ new Set();
40814
+ let pids = [];
40815
+ try {
40816
+ pids = (0, import_node_fs27.readdirSync)(procDir).filter((p) => /^\d+$/.test(p));
40817
+ } catch {
40818
+ return [];
40819
+ }
40820
+ for (const pid of pids) {
40821
+ try {
40822
+ if ((0, import_node_fs27.readFileSync)(`${procDir}/${pid}/comm`, "utf-8").trim() !== "mosh-server") continue;
40823
+ const ip = sshClientFromEnviron((0, import_node_fs27.readFileSync)(`${procDir}/${pid}/environ`, "latin1"));
40824
+ if (ip) found.add(ip);
40825
+ } catch {
40826
+ }
40827
+ }
40828
+ return [...found];
40829
+ }
40830
+ function parseKeyLogins(text, skip = () => false) {
40831
+ const out = /* @__PURE__ */ new Map();
40832
+ for (const line2 of text.split("\n")) {
40833
+ const m = /^(\d+(?:\.\d+)?)\s.*Accepted publickey for \S+ from (\S+) port \d+ [^\s:]+(?:: \S+ (SHA256:\S+))?/.exec(line2);
40834
+ if (!m || !(0, import_node_net4.isIP)(m[2])) continue;
40835
+ if (m[3] && skip(m[3])) continue;
40836
+ const at = Math.round(Number(m[1]) * 1e3);
40837
+ if (at > (out.get(m[2]) ?? 0)) out.set(m[2], at);
40838
+ }
40839
+ return out;
40840
+ }
40841
+ function isAutomationKeyComment(comment) {
40842
+ return /github-actions|gitlab|jenkins|buildkite|circleci|drone|\bci\b|runner|deploy|backup|automation|\bbot\b/i.test(comment);
40843
+ }
40804
40844
  function defaultGateways() {
40805
40845
  const found = /* @__PURE__ */ new Set();
40806
40846
  for (const args of [["-4", "route", "show", "default"], ["-6", "route", "show", "default"]]) {
@@ -40986,17 +41026,38 @@ async function fetchFeeds(settings, fetchImpl = fetch) {
40986
41026
  }
40987
41027
  function readFeedCache(path) {
40988
41028
  try {
40989
- const set = JSON.parse((0, import_node_fs27.readFileSync)(path, "utf-8"));
41029
+ const set = JSON.parse((0, import_node_fs28.readFileSync)(path, "utf-8"));
40990
41030
  return set && typeof set.ips === "object" && typeof set.domains === "object" ? set : null;
40991
41031
  } catch {
40992
41032
  return null;
40993
41033
  }
40994
41034
  }
40995
41035
  function writeFeedCache(path, set) {
40996
- (0, import_node_fs27.mkdirSync)((0, import_node_path20.dirname)(path), { recursive: true });
41036
+ (0, import_node_fs28.mkdirSync)((0, import_node_path20.dirname)(path), { recursive: true });
40997
41037
  const tmp = `${path}.tmp`;
40998
- (0, import_node_fs27.writeFileSync)(tmp, JSON.stringify(set));
40999
- (0, import_node_fs27.renameSync)(tmp, path);
41038
+ (0, import_node_fs28.writeFileSync)(tmp, JSON.stringify(set));
41039
+ (0, import_node_fs28.renameSync)(tmp, path);
41040
+ }
41041
+ var RESOLVER_FILES = {
41042
+ hosts: "blocked-domains.hosts",
41043
+ unbound: "blocked-domains.unbound.conf"
41044
+ };
41045
+ var RESOLVER_HOOKS = {
41046
+ dnsmasq: "/etc/dnsmasq.d/threatcrush.conf",
41047
+ unbound: "/etc/unbound/unbound.conf.d/threatcrush.conf"
41048
+ };
41049
+ var GENERATED = "# Written by threatcrushd from abuse.ch feeds; rewritten every refresh. Do not edit.";
41050
+ function hostsBlocklist(domains) {
41051
+ const lines = [GENERATED];
41052
+ for (const d of domains) lines.push(`0.0.0.0 ${d}`, `:: ${d}`);
41053
+ return `${lines.join("\n")}
41054
+ `;
41055
+ }
41056
+ function unboundBlocklist(domains) {
41057
+ const lines = [GENERATED, "server:"];
41058
+ for (const d of domains) lines.push(` local-zone: "${d}." always_nxdomain`);
41059
+ return `${lines.join("\n")}
41060
+ `;
41000
41061
  }
41001
41062
  var active = null;
41002
41063
  function setActiveFeeds(set) {
@@ -41100,9 +41161,9 @@ var DnsMonitor = class {
41100
41161
  }
41101
41162
  start() {
41102
41163
  const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
41103
- if (!(0, import_node_fs28.existsSync)(p)) return false;
41164
+ if (!(0, import_node_fs29.existsSync)(p)) return false;
41104
41165
  try {
41105
- (0, import_node_fs28.accessSync)(p, import_node_fs28.constants.R_OK);
41166
+ (0, import_node_fs29.accessSync)(p, import_node_fs29.constants.R_OK);
41106
41167
  return true;
41107
41168
  } catch {
41108
41169
  return false;
@@ -41459,15 +41520,15 @@ var ModuleHost = class {
41459
41520
  }
41460
41521
  }
41461
41522
  async discoverAndStartInstalled() {
41462
- if (!(0, import_node_fs29.existsSync)(PATHS.moduleDir)) return;
41523
+ if (!(0, import_node_fs30.existsSync)(PATHS.moduleDir)) return;
41463
41524
  const configs = loadModuleConfigs(PATHS.confD);
41464
- const entries = (0, import_node_fs29.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
41525
+ const entries = (0, import_node_fs30.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
41465
41526
  for (const entry of entries) {
41466
41527
  if (!entry.isDirectory()) continue;
41467
41528
  const manifestPath = (0, import_node_path21.join)(PATHS.moduleDir, entry.name, "mod.toml");
41468
- if (!(0, import_node_fs29.existsSync)(manifestPath)) continue;
41529
+ if (!(0, import_node_fs30.existsSync)(manifestPath)) continue;
41469
41530
  try {
41470
- const manifest = import_toml4.default.parse((0, import_node_fs29.readFileSync)(manifestPath, "utf-8"));
41531
+ const manifest = import_toml4.default.parse((0, import_node_fs30.readFileSync)(manifestPath, "utf-8"));
41471
41532
  const name = manifest.module?.name || entry.name;
41472
41533
  const defaults = manifest.module?.config?.defaults || {};
41473
41534
  const config = {
@@ -41537,15 +41598,15 @@ var ModuleHost = class {
41537
41598
  installedEntrypoint(modulePath) {
41538
41599
  const packageJson = (0, import_node_path21.join)(modulePath, "package.json");
41539
41600
  const candidates = [];
41540
- if ((0, import_node_fs29.existsSync)(packageJson)) {
41601
+ if ((0, import_node_fs30.existsSync)(packageJson)) {
41541
41602
  try {
41542
- const pkg = JSON.parse((0, import_node_fs29.readFileSync)(packageJson, "utf-8"));
41603
+ const pkg = JSON.parse((0, import_node_fs30.readFileSync)(packageJson, "utf-8"));
41543
41604
  if (pkg.main) candidates.push((0, import_node_path21.join)(modulePath, pkg.main));
41544
41605
  } catch {
41545
41606
  }
41546
41607
  }
41547
41608
  candidates.push((0, import_node_path21.join)(modulePath, "dist", "index.js"), (0, import_node_path21.join)(modulePath, "index.js"));
41548
- return candidates.find((candidate) => (0, import_node_fs29.existsSync)(candidate)) || null;
41609
+ return candidates.find((candidate) => (0, import_node_fs30.existsSync)(candidate)) || null;
41549
41610
  }
41550
41611
  isThreatCrushModule(value) {
41551
41612
  return Boolean(
@@ -42054,7 +42115,7 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
42054
42115
  }
42055
42116
 
42056
42117
  // src/daemon/workers/cloud-spool.ts
42057
- var import_node_fs30 = require("fs");
42118
+ var import_node_fs31 = require("fs");
42058
42119
  var import_promises = require("fs/promises");
42059
42120
  var import_node_path22 = require("path");
42060
42121
  var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
@@ -42063,7 +42124,7 @@ var CloudSpool = class {
42063
42124
  this.path = path;
42064
42125
  this.limits = limits;
42065
42126
  try {
42066
- (0, import_node_fs30.mkdirSync)((0, import_node_path22.dirname)(path), { recursive: true });
42127
+ (0, import_node_fs31.mkdirSync)((0, import_node_path22.dirname)(path), { recursive: true });
42067
42128
  } catch {
42068
42129
  }
42069
42130
  this.load();
@@ -42132,7 +42193,7 @@ var CloudSpool = class {
42132
42193
  load() {
42133
42194
  let raw;
42134
42195
  try {
42135
- raw = (0, import_node_fs30.readFileSync)(this.path, "utf-8");
42196
+ raw = (0, import_node_fs31.readFileSync)(this.path, "utf-8");
42136
42197
  } catch {
42137
42198
  return;
42138
42199
  }
@@ -42591,7 +42652,7 @@ var RemediationConsumer = class {
42591
42652
 
42592
42653
  // src/daemon/workers/auto-update.ts
42593
42654
  var import_node_child_process9 = require("child_process");
42594
- var import_node_fs31 = require("fs");
42655
+ var import_node_fs32 = require("fs");
42595
42656
  var import_node_path23 = require("path");
42596
42657
  init_backoff();
42597
42658
  var PKG_NAME = "@profullstack/threatcrush";
@@ -42667,10 +42728,10 @@ function installPlan(opts) {
42667
42728
  }
42668
42729
  function ownerOf(path, passwd = "/etc/passwd") {
42669
42730
  try {
42670
- const st = (0, import_node_fs31.statSync)(path);
42731
+ const st = (0, import_node_fs32.statSync)(path);
42671
42732
  let home = st.uid === 0 ? "/root" : "";
42672
42733
  try {
42673
- for (const line2 of (0, import_node_fs31.readFileSync)(passwd, "utf8").split("\n")) {
42734
+ for (const line2 of (0, import_node_fs32.readFileSync)(passwd, "utf8").split("\n")) {
42674
42735
  const f = line2.split(":");
42675
42736
  if (Number(f[2]) === st.uid && f[5]) home = f[5];
42676
42737
  }
@@ -42775,7 +42836,7 @@ var AutoUpdate = class {
42775
42836
  uid: process.getuid?.() ?? -1,
42776
42837
  owner: ownerOf(this.opts.pkgRoot),
42777
42838
  underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
42778
- npmExists: import_node_fs31.existsSync
42839
+ npmExists: import_node_fs32.existsSync
42779
42840
  });
42780
42841
  if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
42781
42842
  this.recordAttempt(target);
@@ -42810,7 +42871,7 @@ var AutoUpdate = class {
42810
42871
  }
42811
42872
  lastAttempt() {
42812
42873
  try {
42813
- const v = JSON.parse((0, import_node_fs31.readFileSync)(this.opts.statePath, "utf8"));
42874
+ const v = JSON.parse((0, import_node_fs32.readFileSync)(this.opts.statePath, "utf8"));
42814
42875
  return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
42815
42876
  } catch {
42816
42877
  return null;
@@ -42818,7 +42879,7 @@ var AutoUpdate = class {
42818
42879
  }
42819
42880
  recordAttempt(version) {
42820
42881
  try {
42821
- (0, import_node_fs31.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
42882
+ (0, import_node_fs32.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
42822
42883
  } catch (err) {
42823
42884
  this.opts.log(`[update] could not record attempt: ${err.message}`);
42824
42885
  }
@@ -42827,6 +42888,8 @@ var AutoUpdate = class {
42827
42888
 
42828
42889
  // src/daemon/workers/threat-feeds.ts
42829
42890
  var import_node_child_process10 = require("child_process");
42891
+ var import_node_fs33 = require("fs");
42892
+ var import_node_path24 = require("path");
42830
42893
  var import_node_net9 = require("net");
42831
42894
  init_backoff();
42832
42895
  var EGRESS_TABLE = "threatcrush_egress";
@@ -42838,6 +42901,7 @@ function threatFeedSettings(section) {
42838
42901
  return {
42839
42902
  enabled: section?.enabled !== false,
42840
42903
  block: section?.block === true,
42904
+ blockDomains: section?.block_domains === true,
42841
42905
  // abuse.ch asks for no more than one fetch per 5 minutes; hourly is plenty.
42842
42906
  refreshMs: refresh ? Math.max(900, refresh) * 1e3 : DEFAULT_REFRESH_MS,
42843
42907
  minConfidence: typeof section?.min_confidence === "number" ? section.min_confidence : 75,
@@ -42917,6 +42981,8 @@ var ThreatFeeds = class {
42917
42981
  set = null;
42918
42982
  alerted = /* @__PURE__ */ new Map();
42919
42983
  blocking = false;
42984
+ /** Resolver blocklist content last written, by file name (see writeResolverFiles). */
42985
+ resolverWritten = /* @__PURE__ */ new Map();
42920
42986
  run;
42921
42987
  now;
42922
42988
  get wantsBlock() {
@@ -42978,10 +43044,55 @@ var ThreatFeeds = class {
42978
43044
  this.blocking = ok;
42979
43045
  mode = ok ? "blocking egress" : "detecting (nft load failed)";
42980
43046
  }
42981
- const detail = `${ips.length} IPs, ${domains} domains, ${mode}`;
43047
+ const detail = `${ips.length} IPs, ${domains} domains, ${mode}${this.writeResolverFiles(set)}`;
42982
43048
  this.opts.log(`[threat-feeds] ${from === "cache" ? "loaded cached" : "refreshed"} list: ${detail} (${set.skipped_shared} shared/protected entries skipped)`);
42983
43049
  this.opts.bus.announceModule("threat-feeds", "running", detail);
42984
43050
  }
43051
+ /** Whether listed domains are refused at the resolver: opted in and enforcing. */
43052
+ get wantsDomainBlock() {
43053
+ return this.opts.settings.blockDomains && this.opts.enforcing;
43054
+ }
43055
+ /**
43056
+ * Rewrite the resolver blocklists in the state dir and reload any resolver
43057
+ * whose hook is installed — only when the content changed, so an hourly
43058
+ * refresh with nothing new costs no reload. With domain blocking off the
43059
+ * files are emptied, so an installed hook blocks nothing and the config
43060
+ * stays the one switch. Returns a status suffix for the log line.
43061
+ */
43062
+ writeResolverFiles(set) {
43063
+ const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
43064
+ const dir = this.opts.resolverDir ?? (0, import_node_path24.dirname)(this.opts.cachePath);
43065
+ const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
43066
+ const write = (name, content) => {
43067
+ const path = (0, import_node_path24.join)(dir, name);
43068
+ if (this.resolverWritten.get(name) === content) return false;
43069
+ try {
43070
+ (0, import_node_fs33.writeFileSync)(`${path}.tmp`, content);
43071
+ (0, import_node_fs33.renameSync)(`${path}.tmp`, path);
43072
+ this.resolverWritten.set(name, content);
43073
+ return true;
43074
+ } catch (err) {
43075
+ this.opts.log(`[threat-feeds] could not write ${path}: ${err.message}`);
43076
+ return false;
43077
+ }
43078
+ };
43079
+ const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
43080
+ const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
43081
+ const via = [];
43082
+ if ((0, import_node_fs33.existsSync)(hooks.dnsmasq)) {
43083
+ via.push("dnsmasq");
43084
+ if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
43085
+ }
43086
+ if ((0, import_node_fs33.existsSync)(hooks.unbound)) {
43087
+ via.push("unbound");
43088
+ if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
43089
+ this.run("systemctl", ["reload", "unbound.service"]);
43090
+ }
43091
+ }
43092
+ if (!this.opts.settings.blockDomains) return "";
43093
+ if (!this.opts.enforcing) return "; domain blocking set but remediation is dry_run";
43094
+ return via.length ? `; ${domains.length} domains refused via ${via.join(" + ")}` : "; domain blocking set but no resolver hook (run `threatcrush feeds resolver install`)";
43095
+ }
42985
43096
  removeBlocking() {
42986
43097
  if (this.run("nft", ["list", "table", "inet", EGRESS_TABLE]) !== null) {
42987
43098
  this.run("nft", ["delete", "table", "inet", EGRESS_TABLE]);
@@ -43033,8 +43144,8 @@ var ThreatFeeds = class {
43033
43144
  };
43034
43145
 
43035
43146
  // src/daemon/workers/privilege-watch.ts
43036
- var import_node_fs32 = require("fs");
43037
- var import_node_path24 = require("path");
43147
+ var import_node_fs34 = require("fs");
43148
+ var import_node_path25 = require("path");
43038
43149
  var import_node_child_process11 = require("child_process");
43039
43150
 
43040
43151
  // src/core/privileges/index.ts
@@ -43225,31 +43336,31 @@ function countryName(code) {
43225
43336
  var fsIO = {
43226
43337
  readFile: (p) => {
43227
43338
  try {
43228
- return (0, import_node_fs32.readFileSync)(p, "utf-8");
43339
+ return (0, import_node_fs34.readFileSync)(p, "utf-8");
43229
43340
  } catch {
43230
43341
  return null;
43231
43342
  }
43232
43343
  },
43233
43344
  readDir: (p) => {
43234
43345
  try {
43235
- return (0, import_node_fs32.readdirSync)(p);
43346
+ return (0, import_node_fs34.readdirSync)(p);
43236
43347
  } catch {
43237
43348
  return null;
43238
43349
  }
43239
43350
  },
43240
- exists: (p) => (0, import_node_fs32.existsSync)(p)
43351
+ exists: (p) => (0, import_node_fs34.existsSync)(p)
43241
43352
  };
43242
43353
  function readJson(path) {
43243
43354
  try {
43244
- return JSON.parse((0, import_node_fs32.readFileSync)(path, "utf-8"));
43355
+ return JSON.parse((0, import_node_fs34.readFileSync)(path, "utf-8"));
43245
43356
  } catch {
43246
43357
  return null;
43247
43358
  }
43248
43359
  }
43249
43360
  function writeJson(path, value) {
43250
- (0, import_node_fs32.mkdirSync)((0, import_node_path24.dirname)(path), { recursive: true });
43251
- (0, import_node_fs32.writeFileSync)(`${path}.tmp`, JSON.stringify(value));
43252
- (0, import_node_fs32.renameSync)(`${path}.tmp`, path);
43361
+ (0, import_node_fs34.mkdirSync)((0, import_node_path25.dirname)(path), { recursive: true });
43362
+ (0, import_node_fs34.writeFileSync)(`${path}.tmp`, JSON.stringify(value));
43363
+ (0, import_node_fs34.renameSync)(`${path}.tmp`, path);
43253
43364
  }
43254
43365
  function defaultRun3(cmd, args) {
43255
43366
  const res = (0, import_node_child_process11.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 2e4, maxBuffer: 16 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
@@ -43405,7 +43516,7 @@ var PrivilegeWatch = class {
43405
43516
  * raised a "new country" alert on its first run; on dev2 it did, at once.
43406
43517
  */
43407
43518
  async backfillLogins() {
43408
- if ((0, import_node_fs32.existsSync)(this.opts.loginsPath)) return;
43519
+ if ((0, import_node_fs34.existsSync)(this.opts.loginsPath)) return;
43409
43520
  const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
43410
43521
  const byUser = parseAcceptedLogins(out ?? "");
43411
43522
  const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
@@ -43418,7 +43529,7 @@ var PrivilegeWatch = class {
43418
43529
  return;
43419
43530
  }
43420
43531
  }
43421
- if ((0, import_node_fs32.existsSync)(this.opts.loginsPath)) return;
43532
+ if ((0, import_node_fs34.existsSync)(this.opts.loginsPath)) return;
43422
43533
  const at = this.now().toISOString();
43423
43534
  const history = {};
43424
43535
  for (const [user, userIps] of byUser) {
@@ -43630,8 +43741,8 @@ var RuleEngine = class {
43630
43741
  };
43631
43742
 
43632
43743
  // src/daemon/rules/loader.ts
43633
- var import_node_fs33 = require("fs");
43634
- var import_node_path25 = require("path");
43744
+ var import_node_fs35 = require("fs");
43745
+ var import_node_path26 = require("path");
43635
43746
 
43636
43747
  // src/daemon/rules/default-rules.ts
43637
43748
  var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
@@ -44032,11 +44143,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
44032
44143
  function loadAllRules(customDir) {
44033
44144
  const rules = [...DEFAULT_RULES];
44034
44145
  const dir = customDir || RULES_DIR;
44035
- if ((0, import_node_fs33.existsSync)(dir)) {
44036
- const files = (0, import_node_fs33.readdirSync)(dir).filter((f) => f.endsWith(".json"));
44146
+ if ((0, import_node_fs35.existsSync)(dir)) {
44147
+ const files = (0, import_node_fs35.readdirSync)(dir).filter((f) => f.endsWith(".json"));
44037
44148
  for (const file of files) {
44038
44149
  try {
44039
- const raw = (0, import_node_fs33.readFileSync)((0, import_node_path25.join)(dir, file), "utf-8");
44150
+ const raw = (0, import_node_fs35.readFileSync)((0, import_node_path26.join)(dir, file), "utf-8");
44040
44151
  const parsed = JSON.parse(raw);
44041
44152
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
44042
44153
  for (const rule of customRules) {
@@ -44068,8 +44179,8 @@ function loadAllRules(customDir) {
44068
44179
 
44069
44180
  // src/daemon/firewall/adapters.ts
44070
44181
  var import_node_child_process12 = require("child_process");
44071
- var import_node_fs34 = require("fs");
44072
- var import_node_path26 = require("path");
44182
+ var import_node_fs36 = require("fs");
44183
+ var import_node_path27 = require("path");
44073
44184
  var import_node_net10 = require("net");
44074
44185
  function assertValidFirewallIp(ip) {
44075
44186
  if ((0, import_node_net10.isIP)(ip) !== 4) {
@@ -44082,9 +44193,9 @@ function assertBannableIp(ip) {
44082
44193
  }
44083
44194
  }
44084
44195
  function writeIfAbsent(path, contents) {
44085
- (0, import_node_fs34.mkdirSync)((0, import_node_path26.dirname)(path), { recursive: true });
44196
+ (0, import_node_fs36.mkdirSync)((0, import_node_path27.dirname)(path), { recursive: true });
44086
44197
  try {
44087
- (0, import_node_fs34.writeFileSync)(path, contents, { flag: "wx" });
44198
+ (0, import_node_fs36.writeFileSync)(path, contents, { flag: "wx" });
44088
44199
  } catch (err) {
44089
44200
  if (err.code !== "EEXIST") throw err;
44090
44201
  }
@@ -44343,7 +44454,8 @@ function detectFirewallAdapter(backend = "auto") {
44343
44454
  }
44344
44455
 
44345
44456
  // src/daemon/firewall/remediation.ts
44346
- var import_node_fs35 = require("fs");
44457
+ var import_node_fs37 = require("fs");
44458
+ var import_node_child_process13 = require("child_process");
44347
44459
  var import_node_net11 = require("net");
44348
44460
  init_paths();
44349
44461
  init_backoff();
@@ -44402,8 +44514,46 @@ var DEFAULT_CONFIG2 = {
44402
44514
  strike_memory_seconds: 30 * 86400,
44403
44515
  allowlist: [],
44404
44516
  protect_current_ssh_client: true,
44517
+ protect_recent_operators: true,
44518
+ operator_memory_seconds: 30 * 86400,
44405
44519
  spare_verified_crawlers: true
44406
44520
  };
44521
+ var defaultDiscovery = {
44522
+ sshPeers: () => [currentSshClient(), ...establishedSshPeers()].filter((ip) => Boolean(ip)),
44523
+ moshClients: () => moshClients(),
44524
+ automationKeys: () => {
44525
+ const snapshot = takeSnapshot({
44526
+ readFile: (p) => {
44527
+ try {
44528
+ return (0, import_node_fs37.readFileSync)(p, "utf-8");
44529
+ } catch {
44530
+ return null;
44531
+ }
44532
+ },
44533
+ readDir: (p) => {
44534
+ try {
44535
+ return (0, import_node_fs37.readdirSync)(p);
44536
+ } catch {
44537
+ return null;
44538
+ }
44539
+ },
44540
+ exists: (p) => (0, import_node_fs37.existsSync)(p)
44541
+ });
44542
+ const out = /* @__PURE__ */ new Set();
44543
+ for (const keys of Object.values(snapshot.keys)) {
44544
+ for (const [fp, k] of Object.entries(keys)) if (isAutomationKeyComment(k.comment)) out.add(fp);
44545
+ }
44546
+ return out;
44547
+ },
44548
+ keyLoginJournal: (sinceSeconds) => new Promise((resolve6) => {
44549
+ (0, import_node_child_process13.execFile)(
44550
+ "journalctl",
44551
+ ["_COMM=sshd", "_COMM=sshd-session", `--since=-${Math.ceil(sinceSeconds / 86400)}d`, "-o", "short-unix", "--no-pager", "--grep", "Accepted publickey"],
44552
+ { maxBuffer: 32 * 1024 * 1024, timeout: 6e4 },
44553
+ (_err, stdout) => resolve6(stdout ?? "")
44554
+ );
44555
+ })
44556
+ };
44407
44557
  var SEVERITY_RANK7 = {
44408
44558
  info: 0,
44409
44559
  low: 1,
@@ -44426,28 +44576,70 @@ function explainBlockFailure(err, backend) {
44426
44576
  return `threatcrushd is running ${who} and cannot manage ${backend}. A ban is written by the daemon, not by whoever asked for it. Fix it with one command, which asks for root itself: threatcrush install-service`;
44427
44577
  }
44428
44578
  var RemediationManager = class {
44429
- constructor(adapter, bus2, config, verifyCrawler = crawlerVerifier()) {
44579
+ constructor(adapter, bus2, config, verifyCrawler = crawlerVerifier(), discovery = defaultDiscovery) {
44430
44580
  this.adapter = adapter;
44431
44581
  this.bus = bus2;
44432
44582
  this.verifyCrawler = verifyCrawler;
44583
+ this.discovery = discovery;
44433
44584
  this.config = { ...DEFAULT_CONFIG2, ...config };
44434
44585
  this.config.allowlist = [...this.config.allowlist];
44435
44586
  this.protectedList = [...DEFAULT_PROTECTED, ...this.config.allowlist];
44436
44587
  for (const gateway of defaultGateways()) this.protectedList.push(gateway);
44437
- this.refreshSshProtection();
44438
44588
  if (this.adapter.enforces === false) this.config.dry_run = true;
44439
44589
  this.loadState();
44590
+ this.refreshSshProtection();
44440
44591
  void this.reconcile();
44441
44592
  this.startExpiryWorker();
44593
+ if (this.config.protect_recent_operators) void this.seedOperatorsFromJournal();
44442
44594
  }
44443
44595
  adapter;
44444
44596
  bus;
44445
44597
  verifyCrawler;
44598
+ discovery;
44446
44599
  config;
44447
44600
  blocklist = [];
44448
44601
  strikes = {};
44449
44602
  protectedList = [];
44603
+ /** Operator address → last time seen (ms), persisted. */
44604
+ operators = {};
44450
44605
  expiryTimer = null;
44606
+ operatorTimer = null;
44607
+ /** Remembered operator addresses and when each was last seen. */
44608
+ getOperators() {
44609
+ return { ...this.operators };
44610
+ }
44611
+ /**
44612
+ * An address an operator really came from: never ban it, remember it, and
44613
+ * lift a ban that is already on it — the operator is the one who needs in.
44614
+ */
44615
+ noteOperator(ip, at, remember = true) {
44616
+ if (Date.now() - at > this.config.operator_memory_seconds * 1e3) return;
44617
+ if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
44618
+ if (!remember || !this.config.protect_recent_operators || isProtected(ip, DEFAULT_PROTECTED)) return;
44619
+ const known = this.operators[ip] ?? 0;
44620
+ if (at > known) {
44621
+ this.operators[ip] = at;
44622
+ if (!known) this.logLine(`[firewall] operator address remembered: ${ip}`);
44623
+ this.saveState();
44624
+ }
44625
+ if (this.blocklist.some((b) => b.ip === ip)) {
44626
+ void this.unban(ip, { forget: true, reason: "operator address (key login or live session)" });
44627
+ }
44628
+ }
44629
+ /**
44630
+ * Key-based SSH logins in the memory window, by keys that belong to people:
44631
+ * a key whose comment marks automation (a CI deploy key) logs in from
44632
+ * shared cloud runners, and remembering those would allowlist hundreds of
44633
+ * strangers' addresses — dev2 saw 308 distinct key-login IPs in 30 days.
44634
+ */
44635
+ async seedOperatorsFromJournal() {
44636
+ try {
44637
+ const automation = this.discovery.automationKeys();
44638
+ const journal = await this.discovery.keyLoginJournal(this.config.operator_memory_seconds);
44639
+ for (const [ip, at] of parseKeyLogins(journal, (fp) => automation.has(fp))) this.noteOperator(ip, at);
44640
+ } catch {
44641
+ }
44642
+ }
44451
44643
  /** Every address that can never be blocked, built-ins included. */
44452
44644
  getProtected() {
44453
44645
  return [...this.protectedList];
@@ -44462,10 +44654,9 @@ var RemediationManager = class {
44462
44654
  */
44463
44655
  refreshSshProtection() {
44464
44656
  if (!this.config.protect_current_ssh_client) return;
44465
- const candidates = [currentSshClient(), ...establishedSshPeers()];
44466
- for (const ip of candidates) {
44467
- if (ip && !this.protectedList.includes(ip)) this.protectedList.push(ip);
44468
- }
44657
+ const now = Date.now();
44658
+ for (const ip of this.discovery.sshPeers()) this.noteOperator(ip, now, false);
44659
+ for (const ip of this.discovery.moshClients()) this.noteOperator(ip, now);
44469
44660
  }
44470
44661
  isAllowlisted(ip) {
44471
44662
  return isProtected(ip, this.protectedList);
@@ -44664,7 +44855,9 @@ var RemediationManager = class {
44664
44855
  }
44665
44856
  stop() {
44666
44857
  if (this.expiryTimer) clearInterval(this.expiryTimer);
44858
+ if (this.operatorTimer) clearInterval(this.operatorTimer);
44667
44859
  this.expiryTimer = null;
44860
+ this.operatorTimer = null;
44668
44861
  }
44669
44862
  /**
44670
44863
  * R5: bans survive a restart, their TTLs do not. Anything that expired while
@@ -44713,6 +44906,10 @@ var RemediationManager = class {
44713
44906
  startExpiryWorker() {
44714
44907
  this.expiryTimer = setInterval(() => void this.processExpiries(), 1e4);
44715
44908
  this.expiryTimer.unref?.();
44909
+ if (this.config.protect_recent_operators) {
44910
+ this.operatorTimer = setInterval(() => void this.seedOperatorsFromJournal(), 36e5);
44911
+ this.operatorTimer.unref?.();
44912
+ }
44716
44913
  }
44717
44914
  async processExpiries() {
44718
44915
  const now = Date.now();
@@ -44725,6 +44922,12 @@ var RemediationManager = class {
44725
44922
  this.strikes = pruned;
44726
44923
  this.saveState();
44727
44924
  }
44925
+ const cutoff = now - this.config.operator_memory_seconds * 1e3;
44926
+ const stale = Object.keys(this.operators).filter((ip) => this.operators[ip] < cutoff);
44927
+ if (stale.length > 0) {
44928
+ for (const ip of stale) delete this.operators[ip];
44929
+ this.saveState();
44930
+ }
44728
44931
  }
44729
44932
  loadState() {
44730
44933
  try {
@@ -44744,6 +44947,18 @@ var RemediationManager = class {
44744
44947
  if (saved && typeof saved === "object") this.strikes = saved;
44745
44948
  } catch {
44746
44949
  }
44950
+ try {
44951
+ const saved = getModuleState("firewall-rules", "operators");
44952
+ if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
44953
+ const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
44954
+ for (const [ip, at] of Object.entries(saved)) {
44955
+ if (typeof at !== "number" || at < cutoff || !(0, import_node_net11.isIP)(ip)) continue;
44956
+ this.operators[ip] = at;
44957
+ if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
44958
+ }
44959
+ }
44960
+ } catch {
44961
+ }
44747
44962
  }
44748
44963
  saveState() {
44749
44964
  try {
@@ -44754,10 +44969,14 @@ var RemediationManager = class {
44754
44969
  setModuleState("firewall-rules", "strikes", this.strikes);
44755
44970
  } catch {
44756
44971
  }
44972
+ try {
44973
+ setModuleState("firewall-rules", "operators", this.operators);
44974
+ } catch {
44975
+ }
44757
44976
  }
44758
44977
  logLine(line2) {
44759
44978
  try {
44760
- (0, import_node_fs35.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
44979
+ (0, import_node_fs37.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
44761
44980
  `);
44762
44981
  } catch {
44763
44982
  }
@@ -44785,6 +45004,11 @@ function remediationSettings(section) {
44785
45004
  if (typeof section.protect_current_ssh_client === "boolean") {
44786
45005
  settings.protect_current_ssh_client = section.protect_current_ssh_client;
44787
45006
  }
45007
+ if (typeof section.protect_recent_operators === "boolean") {
45008
+ settings.protect_recent_operators = section.protect_recent_operators;
45009
+ }
45010
+ const operatorMemory = parseDuration(section.operator_memory);
45011
+ if (operatorMemory) settings.operator_memory_seconds = operatorMemory;
44788
45012
  if (typeof section.spare_verified_crawlers === "boolean") {
44789
45013
  settings.spare_verified_crawlers = section.spare_verified_crawlers;
44790
45014
  }
@@ -44795,19 +45019,19 @@ function remediationSettings(section) {
44795
45019
  init_backoff();
44796
45020
 
44797
45021
  // src/daemon/watchdog-service.ts
44798
- var import_node_fs36 = require("fs");
44799
- var import_node_path27 = require("path");
45022
+ var import_node_fs38 = require("fs");
45023
+ var import_node_path28 = require("path");
44800
45024
  function defaultShareGid() {
44801
45025
  const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
44802
45026
  if (!isRoot4) return void 0;
44803
45027
  try {
44804
- return (0, import_node_fs36.statSync)("/var/log/auth.log").gid;
45028
+ return (0, import_node_fs38.statSync)("/var/log/auth.log").gid;
44805
45029
  } catch {
44806
45030
  return void 0;
44807
45031
  }
44808
45032
  }
44809
45033
  function startWatchdog(opts) {
44810
- const dir = opts.config?.dir ?? (0, import_node_path27.join)(opts.stateDir, WATCHDOG_DIRNAME);
45034
+ const dir = opts.config?.dir ?? (0, import_node_path28.join)(opts.stateDir, WATCHDOG_DIRNAME);
44811
45035
  const base = { dir, logged: 0, answered: 0, errored: 0 };
44812
45036
  if (opts.config?.enabled === false) {
44813
45037
  opts.log("[watchdog] off ([watchdog] enabled = false)");
@@ -44901,7 +45125,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
44901
45125
  }
44902
45126
 
44903
45127
  // src/core/node-runtime.ts
44904
- var import_node_child_process13 = require("child_process");
45128
+ var import_node_child_process14 = require("child_process");
44905
45129
  var MIN_DAEMON_NODE_MAJOR = 22;
44906
45130
  function nodeMajor(version) {
44907
45131
  const m = String(version ?? "").trim().replace(/^v/, "").match(/^(\d+)\./);
@@ -44915,23 +45139,23 @@ function daemonNodeProblem(version) {
44915
45139
  }
44916
45140
  function versionOfNode(path) {
44917
45141
  if (path === process.execPath) return process.versions.node;
44918
- const res = (0, import_node_child_process13.spawnSync)(path, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
45142
+ const res = (0, import_node_child_process14.spawnSync)(path, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
44919
45143
  return res.status === 0 ? res.stdout.trim() : null;
44920
45144
  }
44921
45145
 
44922
45146
  // src/daemon/index.ts
44923
45147
  function readVersion2() {
44924
45148
  try {
44925
- const pkg = JSON.parse((0, import_node_fs37.readFileSync)((0, import_node_path28.join)(__dirname, "..", "package.json"), "utf-8"));
45149
+ const pkg = JSON.parse((0, import_node_fs39.readFileSync)((0, import_node_path29.join)(__dirname, "..", "package.json"), "utf-8"));
44926
45150
  return pkg.version || "0.0.0";
44927
45151
  } catch {
44928
45152
  return "0.0.0";
44929
45153
  }
44930
45154
  }
44931
45155
  async function runHardeningChecks() {
44932
- const { stdout } = await (0, import_node_util.promisify)(import_node_child_process14.execFile)(
45156
+ const { stdout } = await (0, import_node_util.promisify)(import_node_child_process15.execFile)(
44933
45157
  process.execPath,
44934
- [(0, import_node_path28.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
45158
+ [(0, import_node_path29.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
44935
45159
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
44936
45160
  );
44937
45161
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -44943,9 +45167,9 @@ async function runHardeningChecks() {
44943
45167
  return patches ? [...findings, patches] : findings;
44944
45168
  }
44945
45169
  async function runPatchCheck() {
44946
- const { stdout } = await (0, import_node_util.promisify)(import_node_child_process14.execFile)(
45170
+ const { stdout } = await (0, import_node_util.promisify)(import_node_child_process15.execFile)(
44947
45171
  process.execPath,
44948
- [(0, import_node_path28.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
45172
+ [(0, import_node_path29.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
44949
45173
  { timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
44950
45174
  );
44951
45175
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -44953,7 +45177,7 @@ async function runPatchCheck() {
44953
45177
  }
44954
45178
  function logLine(line2) {
44955
45179
  try {
44956
- (0, import_node_fs37.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
45180
+ (0, import_node_fs39.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
44957
45181
  `);
44958
45182
  } catch {
44959
45183
  }
@@ -44978,9 +45202,9 @@ async function runDaemon() {
44978
45202
  logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
44979
45203
  const restartDaemon = () => {
44980
45204
  if (PATHS.mode === "system") {
44981
- (0, import_node_child_process14.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
45205
+ (0, import_node_child_process15.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
44982
45206
  } else {
44983
- (0, import_node_child_process14.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
45207
+ (0, import_node_child_process15.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
44984
45208
  setTimeout(() => process.exit(0), 500).unref();
44985
45209
  }
44986
45210
  };
@@ -44995,7 +45219,7 @@ async function runDaemon() {
44995
45219
  } catch (err) {
44996
45220
  logLine(`[daemon] state db unavailable: ${err.message}`);
44997
45221
  }
44998
- const config = loadConfig((0, import_node_fs37.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
45222
+ const config = loadConfig((0, import_node_fs39.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
44999
45223
  configureAttackDetection(config.detection);
45000
45224
  const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
45001
45225
  const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
@@ -45059,7 +45283,7 @@ async function runDaemon() {
45059
45283
  const threatFeeds = new ThreatFeeds({
45060
45284
  settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
45061
45285
  enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
45062
- cachePath: (0, import_node_path28.join)(PATHS.stateDir, "threat-feeds.json"),
45286
+ cachePath: (0, import_node_path29.join)(PATHS.stateDir, "threat-feeds.json"),
45063
45287
  bus,
45064
45288
  log: logLine
45065
45289
  });
@@ -45067,9 +45291,9 @@ async function runDaemon() {
45067
45291
  const privilegeWatch = new PrivilegeWatch({
45068
45292
  settings: privilegeSettings(config.privileged),
45069
45293
  bus,
45070
- snapshotPath: (0, import_node_path28.join)(PATHS.stateDir, "privileges.json"),
45071
- loginsPath: (0, import_node_path28.join)(PATHS.stateDir, "login-countries.json"),
45072
- cursorPath: (0, import_node_path28.join)(PATHS.stateDir, "sudo-cursor.json"),
45294
+ snapshotPath: (0, import_node_path29.join)(PATHS.stateDir, "privileges.json"),
45295
+ loginsPath: (0, import_node_path29.join)(PATHS.stateDir, "login-countries.json"),
45296
+ cursorPath: (0, import_node_path29.join)(PATHS.stateDir, "sudo-cursor.json"),
45073
45297
  log: logLine
45074
45298
  });
45075
45299
  privilegeWatch.start();
@@ -45092,7 +45316,7 @@ async function runDaemon() {
45092
45316
  version,
45093
45317
  hostname: (0, import_node_os11.hostname)(),
45094
45318
  minSeverity,
45095
- spoolPath: (0, import_node_path28.join)(PATHS.stateDir, "cloud-spool.jsonl"),
45319
+ spoolPath: (0, import_node_path29.join)(PATHS.stateDir, "cloud-spool.jsonl"),
45096
45320
  log: logLine,
45097
45321
  ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
45098
45322
  runHardening: runHardeningChecks
@@ -45109,8 +45333,8 @@ async function runDaemon() {
45109
45333
  const autoUpdate = new AutoUpdate({
45110
45334
  version,
45111
45335
  settings: updateSettings(config.update),
45112
- pkgRoot: (0, import_node_path28.join)(__dirname, ".."),
45113
- statePath: (0, import_node_path28.join)(PATHS.stateDir, "auto-update.json"),
45336
+ pkgRoot: (0, import_node_path29.join)(__dirname, ".."),
45337
+ statePath: (0, import_node_path29.join)(PATHS.stateDir, "auto-update.json"),
45114
45338
  bus,
45115
45339
  log: logLine,
45116
45340
  restartDaemon
@@ -45196,7 +45420,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
45196
45420
  function isRoot2() {
45197
45421
  return typeof process.getuid === "function" && process.getuid() === 0;
45198
45422
  }
45199
- var DAEMON_ENTRY = (0, import_node_path29.join)(__dirname, "daemon.js");
45423
+ var DAEMON_ENTRY = (0, import_node_path30.join)(__dirname, "daemon.js");
45200
45424
  async function daemonForeground() {
45201
45425
  await runDaemon();
45202
45426
  }
@@ -45217,7 +45441,7 @@ async function daemonStart() {
45217
45441
  return;
45218
45442
  }
45219
45443
  ensureRuntimeDirs();
45220
- if (!(0, import_node_fs38.existsSync)(DAEMON_ENTRY)) {
45444
+ if (!(0, import_node_fs40.existsSync)(DAEMON_ENTRY)) {
45221
45445
  console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
45222
45446
  console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
45223
45447
  return;
@@ -45225,8 +45449,8 @@ async function daemonStart() {
45225
45449
  let out;
45226
45450
  let err;
45227
45451
  try {
45228
- out = (0, import_node_fs39.openSync)(PATHS.logFile, "a");
45229
- err = (0, import_node_fs39.openSync)(PATHS.logFile, "a");
45452
+ out = (0, import_node_fs41.openSync)(PATHS.logFile, "a");
45453
+ err = (0, import_node_fs41.openSync)(PATHS.logFile, "a");
45230
45454
  } catch (e) {
45231
45455
  const code = e.code;
45232
45456
  console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
@@ -45239,7 +45463,7 @@ async function daemonStart() {
45239
45463
  }
45240
45464
  return;
45241
45465
  }
45242
- const child = (0, import_node_child_process15.spawn)(process.execPath, [DAEMON_ENTRY], {
45466
+ const child = (0, import_node_child_process16.spawn)(process.execPath, [DAEMON_ENTRY], {
45243
45467
  detached: true,
45244
45468
  stdio: ["ignore", out, err],
45245
45469
  env: { ...process.env, THREATCRUSH_DAEMON: "1" }
@@ -45314,41 +45538,41 @@ async function waitForExit(pid, timeoutMs) {
45314
45538
  }
45315
45539
  async function releaseStaleSocket() {
45316
45540
  const deadline = Date.now() + 2e3;
45317
- while ((0, import_node_fs38.existsSync)(PATHS.socket) && Date.now() < deadline) {
45541
+ while ((0, import_node_fs40.existsSync)(PATHS.socket) && Date.now() < deadline) {
45318
45542
  await new Promise((r) => setTimeout(r, 50));
45319
45543
  }
45320
- if ((0, import_node_fs38.existsSync)(PATHS.socket)) {
45544
+ if ((0, import_node_fs40.existsSync)(PATHS.socket)) {
45321
45545
  try {
45322
- (0, import_node_fs38.unlinkSync)(PATHS.socket);
45546
+ (0, import_node_fs40.unlinkSync)(PATHS.socket);
45323
45547
  } catch {
45324
45548
  }
45325
45549
  }
45326
45550
  }
45327
45551
 
45328
45552
  // src/commands/service.ts
45329
- var import_node_child_process16 = require("child_process");
45330
- var import_node_fs40 = require("fs");
45331
- var import_node_path30 = require("path");
45553
+ var import_node_child_process17 = require("child_process");
45554
+ var import_node_fs42 = require("fs");
45555
+ var import_node_path31 = require("path");
45332
45556
  var import_node_os12 = require("os");
45333
45557
  var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
45334
45558
  var DAEMON_UNIT_NAME = "threatcrushd.service";
45335
45559
  function resolveTemplate() {
45336
- const templatePath = (0, import_node_path30.join)(__dirname, "systemd", "threatcrushd.service");
45337
- if (!(0, import_node_fs40.existsSync)(templatePath)) {
45560
+ const templatePath = (0, import_node_path31.join)(__dirname, "systemd", "threatcrushd.service");
45561
+ if (!(0, import_node_fs42.existsSync)(templatePath)) {
45338
45562
  throw new Error(`systemd unit template not found at ${templatePath}`);
45339
45563
  }
45340
- return (0, import_node_fs40.readFileSync)(templatePath, "utf-8");
45564
+ return (0, import_node_fs42.readFileSync)(templatePath, "utf-8");
45341
45565
  }
45342
45566
  function stableBinPath(binPath) {
45343
45567
  const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
45344
45568
  if (stable === binPath) return binPath;
45345
- return (0, import_node_fs40.existsSync)(stable) ? stable : binPath;
45569
+ return (0, import_node_fs42.existsSync)(stable) ? stable : binPath;
45346
45570
  }
45347
45571
  function resolveBinPath() {
45348
45572
  const arg = process.argv[1];
45349
- if (arg && (0, import_node_fs40.existsSync)(arg)) return stableBinPath(arg);
45573
+ if (arg && (0, import_node_fs42.existsSync)(arg)) return stableBinPath(arg);
45350
45574
  try {
45351
- return (0, import_node_child_process16.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
45575
+ return (0, import_node_child_process17.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
45352
45576
  } catch {
45353
45577
  return "threatcrush";
45354
45578
  }
@@ -45356,11 +45580,11 @@ function resolveBinPath() {
45356
45580
  function stableNodePath(execPath) {
45357
45581
  const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
45358
45582
  if (stable === execPath) return execPath;
45359
- return (0, import_node_fs40.existsSync)(stable) ? stable : execPath;
45583
+ return (0, import_node_fs42.existsSync)(stable) ? stable : execPath;
45360
45584
  }
45361
45585
  function looksLikeNodeScript(path) {
45362
45586
  try {
45363
- const head = (0, import_node_fs40.readFileSync)(path, "utf-8").slice(0, 120);
45587
+ const head = (0, import_node_fs42.readFileSync)(path, "utf-8").slice(0, 120);
45364
45588
  return /^#!.*\bnode\b/.test(head);
45365
45589
  } catch {
45366
45590
  return false;
@@ -45387,20 +45611,20 @@ function isRoot3() {
45387
45611
  return typeof process.getuid === "function" && process.getuid() === 0;
45388
45612
  }
45389
45613
  function reexecWithSudo(args) {
45390
- if ((0, import_node_child_process16.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
45614
+ if ((0, import_node_child_process17.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
45391
45615
  console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
45392
45616
  const bin = resolveBinPath();
45393
45617
  const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
45394
- const result = (0, import_node_child_process16.spawnSync)("sudo", argv, { stdio: "inherit" });
45618
+ const result = (0, import_node_child_process17.spawnSync)("sudo", argv, { stdio: "inherit" });
45395
45619
  return result.status === 0;
45396
45620
  }
45397
45621
  function callerHome() {
45398
45622
  const user = process.env.SUDO_USER;
45399
45623
  if (!user) return null;
45400
45624
  try {
45401
- const line2 = (0, import_node_child_process16.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
45625
+ const line2 = (0, import_node_child_process17.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
45402
45626
  const home = line2.split(":")[5];
45403
- return home && (0, import_node_fs40.existsSync)(home) ? home : null;
45627
+ return home && (0, import_node_fs42.existsSync)(home) ? home : null;
45404
45628
  } catch {
45405
45629
  return null;
45406
45630
  }
@@ -45408,13 +45632,13 @@ function callerHome() {
45408
45632
  function stopUserModeDaemon() {
45409
45633
  const home = callerHome();
45410
45634
  if (!home) return;
45411
- const runDir = (0, import_node_path30.join)(home, ".threatcrush", "run");
45412
- const pidFile = (0, import_node_path30.join)(runDir, "threatcrushd.pid");
45413
- const socket = (0, import_node_path30.join)(runDir, "threatcrushd.sock");
45414
- if (!(0, import_node_fs40.existsSync)(pidFile) && !(0, import_node_fs40.existsSync)(socket)) return;
45635
+ const runDir = (0, import_node_path31.join)(home, ".threatcrush", "run");
45636
+ const pidFile = (0, import_node_path31.join)(runDir, "threatcrushd.pid");
45637
+ const socket = (0, import_node_path31.join)(runDir, "threatcrushd.sock");
45638
+ if (!(0, import_node_fs42.existsSync)(pidFile) && !(0, import_node_fs42.existsSync)(socket)) return;
45415
45639
  let pid = null;
45416
45640
  try {
45417
- pid = Number.parseInt((0, import_node_fs40.readFileSync)(pidFile, "utf-8").trim(), 10);
45641
+ pid = Number.parseInt((0, import_node_fs42.readFileSync)(pidFile, "utf-8").trim(), 10);
45418
45642
  } catch {
45419
45643
  pid = null;
45420
45644
  }
@@ -45427,13 +45651,13 @@ function stopUserModeDaemon() {
45427
45651
  }
45428
45652
  for (const path of [socket, pidFile]) {
45429
45653
  try {
45430
- if ((0, import_node_fs40.existsSync)(path)) (0, import_node_fs40.rmSync)(path);
45654
+ if ((0, import_node_fs42.existsSync)(path)) (0, import_node_fs42.rmSync)(path);
45431
45655
  } catch {
45432
45656
  }
45433
45657
  }
45434
45658
  }
45435
45659
  function unitIsActive() {
45436
- const result = (0, import_node_child_process16.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
45660
+ const result = (0, import_node_child_process17.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
45437
45661
  return result.status === 0;
45438
45662
  }
45439
45663
  async function installServiceCommand() {
@@ -45444,8 +45668,8 @@ async function installServiceCommand() {
45444
45668
  return;
45445
45669
  }
45446
45670
  const noSystemd = systemdUnavailableReason({
45447
- hasSystemctl: (0, import_node_child_process16.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
45448
- booted: (0, import_node_fs40.existsSync)("/run/systemd/system")
45671
+ hasSystemctl: (0, import_node_child_process17.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
45672
+ booted: (0, import_node_fs42.existsSync)("/run/systemd/system")
45449
45673
  });
45450
45674
  if (noSystemd) {
45451
45675
  console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
@@ -45467,7 +45691,7 @@ async function installServiceCommand() {
45467
45691
  const isNodeScript = looksLikeNodeScript(binPath);
45468
45692
  let nodePath = stableNodePath(process.execPath);
45469
45693
  if (isNodeScript && nodeVersionDir(binPath)) {
45470
- binPath = (0, import_node_fs40.realpathSync)(binPath);
45694
+ binPath = (0, import_node_fs42.realpathSync)(binPath);
45471
45695
  nodePath = process.execPath;
45472
45696
  }
45473
45697
  if (isNodeScript) {
@@ -45480,9 +45704,9 @@ async function installServiceCommand() {
45480
45704
  }
45481
45705
  }
45482
45706
  const exec = execStartCommand(binPath, nodePath, isNodeScript);
45483
- const configDir = (0, import_node_path30.join)((0, import_node_os12.homedir)(), ".threatcrush");
45707
+ const configDir = (0, import_node_path31.join)((0, import_node_os12.homedir)(), ".threatcrush");
45484
45708
  const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
45485
- (0, import_node_fs40.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
45709
+ (0, import_node_fs42.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
45486
45710
  console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
45487
45711
  console.log(source_default.dim(` ExecStart=${exec}`));
45488
45712
  const nodeDir = nodeVersionDir(nodePath);
@@ -45497,8 +45721,8 @@ async function installServiceCommand() {
45497
45721
  installLogrotate();
45498
45722
  stopUserModeDaemon();
45499
45723
  try {
45500
- (0, import_node_child_process16.execSync)("systemctl daemon-reload", { stdio: "inherit" });
45501
- (0, import_node_child_process16.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
45724
+ (0, import_node_child_process17.execSync)("systemctl daemon-reload", { stdio: "inherit" });
45725
+ (0, import_node_child_process17.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
45502
45726
  } catch (err) {
45503
45727
  console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
45504
45728
  console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
@@ -45535,9 +45759,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
45535
45759
  ].join("\n");
45536
45760
  }
45537
45761
  function installLogrotate() {
45538
- if (!(0, import_node_fs40.existsSync)((0, import_node_path30.dirname)(LOGROTATE_PATH))) return;
45762
+ if (!(0, import_node_fs42.existsSync)((0, import_node_path31.dirname)(LOGROTATE_PATH))) return;
45539
45763
  try {
45540
- (0, import_node_fs40.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
45764
+ (0, import_node_fs42.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
45541
45765
  console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
45542
45766
  } catch (err) {
45543
45767
  console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
@@ -45559,20 +45783,20 @@ function ensureSystemDirs(configDir) {
45559
45783
  ];
45560
45784
  let admGid2 = null;
45561
45785
  try {
45562
- admGid2 = (0, import_node_fs40.statSync)("/var/log/auth.log").gid;
45786
+ admGid2 = (0, import_node_fs42.statSync)("/var/log/auth.log").gid;
45563
45787
  } catch {
45564
45788
  }
45565
45789
  for (const { path, groupWritable, sticky } of dirs) {
45566
45790
  try {
45567
- (0, import_node_fs40.mkdirSync)(path, { recursive: true });
45791
+ (0, import_node_fs42.mkdirSync)(path, { recursive: true });
45568
45792
  } catch {
45569
45793
  }
45570
45794
  try {
45571
45795
  if (groupWritable && admGid2 !== null) {
45572
- (0, import_node_fs40.chmodSync)(path, sticky ? 1533 : 509);
45573
- (0, import_node_child_process16.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
45796
+ (0, import_node_fs42.chmodSync)(path, sticky ? 1533 : 509);
45797
+ (0, import_node_child_process17.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
45574
45798
  } else {
45575
- (0, import_node_fs40.chmodSync)(path, 493);
45799
+ (0, import_node_fs42.chmodSync)(path, 493);
45576
45800
  }
45577
45801
  } catch {
45578
45802
  }
@@ -45592,29 +45816,29 @@ async function uninstallServiceCommand() {
45592
45816
  return;
45593
45817
  }
45594
45818
  try {
45595
- (0, import_node_child_process16.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
45819
+ (0, import_node_child_process17.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
45596
45820
  } catch {
45597
45821
  }
45598
45822
  try {
45599
- (0, import_node_child_process16.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
45823
+ (0, import_node_child_process17.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
45600
45824
  } catch {
45601
45825
  }
45602
45826
  try {
45603
- if ((0, import_node_fs40.existsSync)(UNIT_PATH)) {
45604
- (0, import_node_child_process16.execSync)(`rm -f ${UNIT_PATH}`);
45827
+ if ((0, import_node_fs42.existsSync)(UNIT_PATH)) {
45828
+ (0, import_node_child_process17.execSync)(`rm -f ${UNIT_PATH}`);
45605
45829
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
45606
45830
  }
45607
45831
  } catch {
45608
45832
  }
45609
45833
  try {
45610
- (0, import_node_child_process16.execSync)("systemctl daemon-reload", { stdio: "inherit" });
45834
+ (0, import_node_child_process17.execSync)("systemctl daemon-reload", { stdio: "inherit" });
45611
45835
  } catch {
45612
45836
  }
45613
45837
  console.log(source_default.green(" \u2713 threatcrushd service removed."));
45614
45838
  }
45615
45839
 
45616
45840
  // src/commands/save.ts
45617
- var import_node_fs41 = require("fs");
45841
+ var import_node_fs43 = require("fs");
45618
45842
  var import_toml5 = __toESM(require_toml());
45619
45843
  init_cli_config();
45620
45844
  init_paths();
@@ -45653,9 +45877,9 @@ async function saveCommand(opts = {}) {
45653
45877
  }
45654
45878
  const path = opts.config ?? PATHS.configFile;
45655
45879
  let config = {};
45656
- if ((0, import_node_fs41.existsSync)(path)) {
45880
+ if ((0, import_node_fs43.existsSync)(path)) {
45657
45881
  try {
45658
- config = import_toml5.default.parse((0, import_node_fs41.readFileSync)(path, "utf-8"));
45882
+ config = import_toml5.default.parse((0, import_node_fs43.readFileSync)(path, "utf-8"));
45659
45883
  } catch (err) {
45660
45884
  console.log(source_default.red(` \u2717 ${path} is not valid TOML: ${err.message}
45661
45885
  `));
@@ -45768,8 +45992,8 @@ function welcomeCommand() {
45768
45992
  }
45769
45993
 
45770
45994
  // src/commands/properties.ts
45771
- var import_node_fs42 = require("fs");
45772
- var import_node_path31 = require("path");
45995
+ var import_node_fs44 = require("fs");
45996
+ var import_node_path32 = require("path");
45773
45997
  var import_node_readline4 = __toESM(require("readline"));
45774
45998
  init_cli_config();
45775
45999
  var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
@@ -46099,8 +46323,8 @@ async function propertiesRunsCommand(opts) {
46099
46323
  }
46100
46324
  }
46101
46325
  function parseImportFile(path) {
46102
- const ext = (0, import_node_path31.extname)(path).toLowerCase();
46103
- const raw = (0, import_node_fs42.readFileSync)(path, "utf-8");
46326
+ const ext = (0, import_node_path32.extname)(path).toLowerCase();
46327
+ const raw = (0, import_node_fs44.readFileSync)(path, "utf-8");
46104
46328
  if (ext === ".json") {
46105
46329
  const parsed = JSON.parse(raw);
46106
46330
  if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
@@ -46295,19 +46519,19 @@ async function rulesCommand(opts) {
46295
46519
  }
46296
46520
 
46297
46521
  // src/commands/harden.ts
46298
- var import_node_fs43 = require("fs");
46299
- var import_node_child_process17 = require("child_process");
46522
+ var import_node_fs45 = require("fs");
46523
+ var import_node_child_process18 = require("child_process");
46300
46524
  init_cli_config();
46301
46525
  function tryExec(cmd) {
46302
46526
  try {
46303
- return (0, import_node_child_process17.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
46527
+ return (0, import_node_child_process18.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
46304
46528
  } catch {
46305
46529
  return null;
46306
46530
  }
46307
46531
  }
46308
46532
  function tryRead(path) {
46309
46533
  try {
46310
- return (0, import_node_fs43.readFileSync)(path, "utf-8");
46534
+ return (0, import_node_fs45.readFileSync)(path, "utf-8");
46311
46535
  } catch {
46312
46536
  return null;
46313
46537
  }
@@ -46411,8 +46635,8 @@ function checkSshWeakConfig() {
46411
46635
  };
46412
46636
  }
46413
46637
  function checkAutoUpdates() {
46414
- const unattended = (0, import_node_fs43.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs43.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
46415
- const dnfAuto = (0, import_node_fs43.existsSync)("/etc/dnf/automatic.conf");
46638
+ const unattended = (0, import_node_fs45.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs45.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
46639
+ const dnfAuto = (0, import_node_fs45.existsSync)("/etc/dnf/automatic.conf");
46416
46640
  if (unattended || dnfAuto) {
46417
46641
  return {
46418
46642
  key: "auto-updates",
@@ -46538,7 +46762,7 @@ function checkFail2ban() {
46538
46762
  explanation: "fail2ban is installed and running."
46539
46763
  };
46540
46764
  }
46541
- if ((0, import_node_fs43.existsSync)("/etc/fail2ban/fail2ban.conf")) {
46765
+ if ((0, import_node_fs45.existsSync)("/etc/fail2ban/fail2ban.conf")) {
46542
46766
  return {
46543
46767
  key: checkKey,
46544
46768
  status: "warn",
@@ -46724,9 +46948,9 @@ async function hardenCommand(opts) {
46724
46948
  }
46725
46949
 
46726
46950
  // src/core/patches/index.ts
46727
- var import_node_fs44 = require("fs");
46728
- var import_node_path32 = require("path");
46729
- var import_node_child_process18 = require("child_process");
46951
+ var import_node_fs46 = require("fs");
46952
+ var import_node_path33 = require("path");
46953
+ var import_node_child_process19 = require("child_process");
46730
46954
  var import_node_util2 = require("util");
46731
46955
 
46732
46956
  // src/core/patches/dpkg-version.ts
@@ -46786,7 +47010,7 @@ var STALE_AFTER_MS = 2 * 864e5;
46786
47010
  var SEVERITIES2 = ["info", "low", "medium", "high", "critical"];
46787
47011
  var RANK = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
46788
47012
  var defaultExec = async (file, args) => {
46789
- const { stdout } = await (0, import_node_util2.promisify)(import_node_child_process18.execFile)(file, args, {
47013
+ const { stdout } = await (0, import_node_util2.promisify)(import_node_child_process19.execFile)(file, args, {
46790
47014
  timeout: 12e4,
46791
47015
  maxBuffer: 32 * 1024 * 1024,
46792
47016
  env: { ...process.env, LC_ALL: "C" }
@@ -46885,9 +47109,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
46885
47109
  function newestReleaseMtime(dir) {
46886
47110
  try {
46887
47111
  let newest = 0;
46888
- for (const name of (0, import_node_fs44.readdirSync)(dir)) {
47112
+ for (const name of (0, import_node_fs46.readdirSync)(dir)) {
46889
47113
  if (!/Release$/.test(name)) continue;
46890
- newest = Math.max(newest, (0, import_node_fs44.statSync)((0, import_node_path32.join)(dir, name)).mtimeMs);
47114
+ newest = Math.max(newest, (0, import_node_fs46.statSync)((0, import_node_path33.join)(dir, name)).mtimeMs);
46891
47115
  }
46892
47116
  return newest > 0 ? new Date(newest) : null;
46893
47117
  } catch {
@@ -46904,7 +47128,7 @@ async function checkPatches(opts = {}) {
46904
47128
  let osText = opts.osRelease;
46905
47129
  if (osText === void 0) {
46906
47130
  try {
46907
- osText = (0, import_node_fs44.readFileSync)("/etc/os-release", "utf-8");
47131
+ osText = (0, import_node_fs46.readFileSync)("/etc/os-release", "utf-8");
46908
47132
  } catch {
46909
47133
  osText = "";
46910
47134
  }
@@ -47131,18 +47355,142 @@ async function patchesCommand(opts) {
47131
47355
 
47132
47356
  // src/commands/feeds.ts
47133
47357
  var import_node_net12 = require("net");
47134
- var import_node_path33 = require("path");
47358
+ var import_node_path35 = require("path");
47135
47359
  init_paths();
47360
+
47361
+ // src/commands/feeds-resolver.ts
47362
+ var import_node_child_process20 = require("child_process");
47363
+ var import_node_fs47 = require("fs");
47364
+ var import_node_path34 = require("path");
47365
+ var realIO = {
47366
+ exists: (p) => (0, import_node_fs47.existsSync)(p),
47367
+ read: (p) => {
47368
+ try {
47369
+ return (0, import_node_fs47.readFileSync)(p, "utf-8");
47370
+ } catch {
47371
+ return null;
47372
+ }
47373
+ },
47374
+ write: (p, c) => (0, import_node_fs47.writeFileSync)(p, c),
47375
+ remove: (p) => (0, import_node_fs47.rmSync)(p, { force: true }),
47376
+ run: (cmd, args) => {
47377
+ const r = (0, import_node_child_process20.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
47378
+ return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
47379
+ }
47380
+ };
47381
+ var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
47382
+ var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
47383
+ function hookContent(resolver, stateDir) {
47384
+ const head = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
47385
+ return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path34.join)(stateDir, RESOLVER_FILES.hosts)}
47386
+ ` : `${head}include: "${(0, import_node_path34.join)(stateDir, RESOLVER_FILES.unbound)}"
47387
+ `;
47388
+ }
47389
+ function apparmorRule(stateDir) {
47390
+ return ` ${(0, import_node_path34.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
47391
+ }
47392
+ function detectResolvers(io = realIO) {
47393
+ const found = [];
47394
+ if (io.exists((0, import_node_path34.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
47395
+ if (io.exists((0, import_node_path34.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
47396
+ return found;
47397
+ }
47398
+ function check(resolver, io) {
47399
+ return resolver === "dnsmasq" ? io.run("dnsmasq", ["--test"]) : io.run("unbound-checkconf", []);
47400
+ }
47401
+ function restartIfActive(resolver, io) {
47402
+ if (io.run("systemctl", ["is-active", "--quiet", `${resolver}.service`]).code !== 0) return "not running; takes effect when it starts";
47403
+ const r = io.run("systemctl", ["restart", `${resolver}.service`]);
47404
+ return r.code === 0 ? "restarted" : `restart failed: ${r.out.split("\n")[0]}`;
47405
+ }
47406
+ function installHook(resolver, stateDir, io = realIO) {
47407
+ const hook = RESOLVER_HOOKS[resolver];
47408
+ const file = (0, import_node_path34.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
47409
+ if (!io.exists(file)) io.write(file, resolver === "dnsmasq" ? hostsBlocklist([]) : unboundBlocklist([]));
47410
+ io.write(hook, hookContent(resolver, stateDir));
47411
+ if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
47412
+ const local = io.read(APPARMOR_LOCAL) ?? "";
47413
+ if (!local.includes(apparmorRule(stateDir))) io.write(APPARMOR_LOCAL, `${local.replace(/\n?$/, "\n")}${apparmorRule(stateDir)}
47414
+ `);
47415
+ if (io.exists(APPARMOR_PROFILE)) io.run("apparmor_parser", ["-r", APPARMOR_PROFILE]);
47416
+ }
47417
+ const checked = check(resolver, io);
47418
+ if (checked.code !== 0) {
47419
+ removeHook(resolver, stateDir, io, { restart: false });
47420
+ return { ok: false, message: `${resolver} rejected the config, so nothing was changed: ${checked.out.split("\n").slice(-2).join(" ")}` };
47421
+ }
47422
+ return { ok: true, message: `${hook} installed; ${resolver} ${restartIfActive(resolver, io)}` };
47423
+ }
47424
+ function removeHook(resolver, stateDir, io = realIO, opts = { restart: true }) {
47425
+ const hook = RESOLVER_HOOKS[resolver];
47426
+ const had = io.exists(hook);
47427
+ io.remove(hook);
47428
+ if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
47429
+ const local = io.read(APPARMOR_LOCAL) ?? "";
47430
+ const kept = local.split("\n").filter((l) => l !== apparmorRule(stateDir)).join("\n");
47431
+ if (kept !== local) {
47432
+ io.write(APPARMOR_LOCAL, kept);
47433
+ if (io.exists(APPARMOR_PROFILE)) io.run("apparmor_parser", ["-r", APPARMOR_PROFILE]);
47434
+ }
47435
+ }
47436
+ if (!had) return `${resolver}: no hook installed`;
47437
+ return `${hook} removed${opts.restart ? `; ${resolver} ${restartIfActive(resolver, io)}` : ""}`;
47438
+ }
47439
+ function countListed(text, pattern) {
47440
+ return text ? (text.match(pattern) ?? []).length : 0;
47441
+ }
47442
+ function resolverCommand(sub, stateDir, io = realIO) {
47443
+ const found = detectResolvers(io);
47444
+ const root = typeof process.getuid !== "function" || process.getuid() === 0;
47445
+ if (sub === "install" || sub === "remove") {
47446
+ if (!root) {
47447
+ console.error(`Run as root: sudo $(which threatcrush) feeds resolver ${sub}`);
47448
+ return 1;
47449
+ }
47450
+ if (sub === "install" && found.length === 0) {
47451
+ console.error("No dnsmasq or unbound here. systemd-resolved cannot refuse names from a list; listed domains stay detection-only (dns-monitor), and listed IPs can still be blocked with [threat_feeds] block = true.");
47452
+ return 1;
47453
+ }
47454
+ let failed = false;
47455
+ for (const resolver of sub === "install" ? found : ["dnsmasq", "unbound"]) {
47456
+ if (sub === "install") {
47457
+ const r = installHook(resolver, stateDir, io);
47458
+ failed ||= !r.ok;
47459
+ console.log(`${r.ok ? source_default.green("\u2713") : source_default.red("\u2717")} ${r.message}`);
47460
+ } else {
47461
+ console.log(` ${removeHook(resolver, stateDir, io)}`);
47462
+ }
47463
+ }
47464
+ if (sub === "install" && !failed) {
47465
+ console.log(source_default.gray(" Now set [threat_feeds] block_domains = true (with [remediation] in enforce mode) and restart threatcrushd; until then the lists stay empty."));
47466
+ }
47467
+ return failed ? 1 : 0;
47468
+ }
47469
+ const hosts = io.read((0, import_node_path34.join)(stateDir, RESOLVER_FILES.hosts));
47470
+ const unbound = io.read((0, import_node_path34.join)(stateDir, RESOLVER_FILES.unbound));
47471
+ console.log(` resolvers here: ${found.join(", ") || "none that can block (systemd-resolved only?)"}`);
47472
+ for (const r of ["dnsmasq", "unbound"]) {
47473
+ console.log(` ${r.padEnd(8)} hook ${io.exists(RESOLVER_HOOKS[r]) ? source_default.green("installed") : source_default.gray("not installed")}`);
47474
+ }
47475
+ console.log(` listed now: ${countListed(hosts, /^0\.0\.0\.0 /gm)} names in ${RESOLVER_FILES.hosts}, ${countListed(unbound, /local-zone:/g)} zones in ${RESOLVER_FILES.unbound}`);
47476
+ return 0;
47477
+ }
47478
+
47479
+ // src/commands/feeds.ts
47136
47480
  async function loadSet() {
47137
47481
  for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
47138
- const path = (0, import_node_path33.join)(dir, "threat-feeds.json");
47482
+ const path = (0, import_node_path35.join)(dir, "threat-feeds.json");
47139
47483
  const set = readFeedCache(path);
47140
47484
  if (set) return { set, from: path };
47141
47485
  }
47142
- const settings = threatFeedSettings(loadConfig((0, import_node_path33.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
47486
+ const settings = threatFeedSettings(loadConfig((0, import_node_path35.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
47143
47487
  return { set: await fetchFeeds(settings), from: "abuse.ch (live; no daemon cache readable)" };
47144
47488
  }
47145
47489
  async function feedsCommand(action, value, opts) {
47490
+ if (action === "resolver") {
47491
+ process.exitCode = resolverCommand(value, SYSTEM_PATHS.stateDir);
47492
+ return;
47493
+ }
47146
47494
  const { set, from } = await loadSet();
47147
47495
  if (action === "check") {
47148
47496
  if (!value) {
@@ -47179,7 +47527,7 @@ async function feedsCommand(action, value, opts) {
47179
47527
  }
47180
47528
 
47181
47529
  // src/commands/privileged.ts
47182
- var import_node_fs45 = require("fs");
47530
+ var import_node_fs48 = require("fs");
47183
47531
  init_paths();
47184
47532
  var SEV2 = {
47185
47533
  critical: source_default.red.bold,
@@ -47192,19 +47540,19 @@ async function privilegedCommand(opts) {
47192
47540
  const snapshot = takeSnapshot({
47193
47541
  readFile: (p) => {
47194
47542
  try {
47195
- return (0, import_node_fs45.readFileSync)(p, "utf-8");
47543
+ return (0, import_node_fs48.readFileSync)(p, "utf-8");
47196
47544
  } catch {
47197
47545
  return null;
47198
47546
  }
47199
47547
  },
47200
47548
  readDir: (p) => {
47201
47549
  try {
47202
- return (0, import_node_fs45.readdirSync)(p);
47550
+ return (0, import_node_fs48.readdirSync)(p);
47203
47551
  } catch {
47204
47552
  return null;
47205
47553
  }
47206
47554
  },
47207
- exists: (p) => (0, import_node_fs45.existsSync)(p)
47555
+ exists: (p) => (0, import_node_fs48.existsSync)(p)
47208
47556
  });
47209
47557
  let events = [];
47210
47558
  let ledgerNote = "";
@@ -47389,11 +47737,11 @@ async function allowlistCommand(opts) {
47389
47737
  init_paths();
47390
47738
 
47391
47739
  // src/upgrade.ts
47392
- var import_node_child_process19 = require("child_process");
47740
+ var import_node_child_process21 = require("child_process");
47393
47741
  var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
47394
47742
  var defaultRunner = (cmd) => {
47395
47743
  try {
47396
- return (0, import_node_child_process19.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
47744
+ return (0, import_node_child_process21.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
47397
47745
  } catch {
47398
47746
  return null;
47399
47747
  }
@@ -47508,25 +47856,25 @@ ${source_default.dim(" C R U S H")}
47508
47856
  var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
47509
47857
  var PKG_NAME2 = "@profullstack/threatcrush";
47510
47858
  var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
47511
- var INSTALL_CONFIG_PATH = (0, import_node_path34.join)((0, import_node_os13.homedir)(), ".threatcrush", "install.json");
47859
+ var INSTALL_CONFIG_PATH = (0, import_node_path36.join)((0, import_node_os13.homedir)(), ".threatcrush", "install.json");
47512
47860
  function detectPackageManager() {
47513
47861
  try {
47514
- const npmGlobal = (0, import_node_child_process20.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
47862
+ const npmGlobal = (0, import_node_child_process22.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
47515
47863
  if (npmGlobal.includes(PKG_NAME2)) return "npm";
47516
47864
  } catch {
47517
47865
  }
47518
47866
  try {
47519
- (0, import_node_child_process20.execSync)("pnpm --version", { stdio: "pipe" });
47867
+ (0, import_node_child_process22.execSync)("pnpm --version", { stdio: "pipe" });
47520
47868
  return "pnpm";
47521
47869
  } catch {
47522
47870
  }
47523
47871
  try {
47524
- (0, import_node_child_process20.execSync)("yarn --version", { stdio: "pipe" });
47872
+ (0, import_node_child_process22.execSync)("yarn --version", { stdio: "pipe" });
47525
47873
  return "yarn";
47526
47874
  } catch {
47527
47875
  }
47528
47876
  try {
47529
- (0, import_node_child_process20.execSync)("bun --version", { stdio: "pipe" });
47877
+ (0, import_node_child_process22.execSync)("bun --version", { stdio: "pipe" });
47530
47878
  return "bun";
47531
47879
  } catch {
47532
47880
  }
@@ -47534,14 +47882,14 @@ function detectPackageManager() {
47534
47882
  }
47535
47883
  function readInstallConfig() {
47536
47884
  try {
47537
- return JSON.parse((0, import_node_fs46.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
47885
+ return JSON.parse((0, import_node_fs49.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
47538
47886
  } catch {
47539
47887
  return {};
47540
47888
  }
47541
47889
  }
47542
47890
  function packageLooksInstalled(pm, pkgName) {
47543
47891
  try {
47544
- const output = (0, import_node_child_process20.execSync)(globalListCommand(pm, pkgName), {
47892
+ const output = (0, import_node_child_process22.execSync)(globalListCommand(pm, pkgName), {
47545
47893
  encoding: "utf-8",
47546
47894
  stdio: ["pipe", "pipe", "pipe"]
47547
47895
  });
@@ -47644,14 +47992,14 @@ async function promoteUnprivilegedDaemon() {
47644
47992
  function restartSystemdDaemon() {
47645
47993
  const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
47646
47994
  const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
47647
- if (!asRoot && (0, import_node_child_process20.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
47995
+ if (!asRoot && (0, import_node_child_process22.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
47648
47996
  const [cmd, ...args] = argv;
47649
- if ((0, import_node_child_process20.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
47650
- return (0, import_node_child_process20.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
47997
+ if ((0, import_node_child_process22.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
47998
+ return (0, import_node_child_process22.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
47651
47999
  }
47652
48000
  function execQuiet(cmd) {
47653
48001
  try {
47654
- return (0, import_node_child_process20.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
48002
+ return (0, import_node_child_process22.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
47655
48003
  } catch {
47656
48004
  return null;
47657
48005
  }
@@ -47804,7 +48152,7 @@ program2.command("harden").description("Run hardening security scan").option("--
47804
48152
  program2.command("patches").description("List OS packages with a security update waiting, and the CVEs it fixes (Debian/Ubuntu)").option("--json", "Output the report as JSON").option("--no-upload", "Do not upload the result to the dashboard (uploaded when this machine is linked)").action(async (opts) => {
47805
48153
  await patchesCommand(opts);
47806
48154
  });
47807
- program2.command("feeds [action] [value]").description("Show the abuse.ch C2/malware list the daemon matches; `feeds check <ip|domain>` looks one up (exit 1 when listed)").option("--json", "Output as JSON").action(async (action, value, opts) => {
48155
+ program2.command("feeds [action] [value]").description("Show the abuse.ch C2/malware list the daemon matches; `feeds check <ip|domain>` looks one up (exit 1 when listed); `feeds resolver install|remove|status` lets dnsmasq/unbound refuse the listed domains").option("--json", "Output as JSON").action(async (action, value, opts) => {
47808
48156
  await feedsCommand(action, value, opts);
47809
48157
  });
47810
48158
  program2.command("privileged").description("Who can become root here (uid 0, sudo groups, sudoers, SSH keys) and the daemon's record of changes and sudo commands").option("--json", "Output as JSON").option("--limit <n>", "How many recent events to show", "25").action(async (opts) => {
@@ -47846,7 +48194,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
47846
48194
  program2.command("logs").description("Tail daemon logs").action(async () => {
47847
48195
  console.log(LOGO2);
47848
48196
  const logPath = PATHS.logFile;
47849
- if (!(0, import_node_fs46.existsSync)(logPath)) {
48197
+ if (!(0, import_node_fs49.existsSync)(logPath)) {
47850
48198
  console.log(source_default.yellow(` No log file found at ${logPath}`));
47851
48199
  console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
47852
48200
  return;
@@ -47854,7 +48202,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
47854
48202
  console.log(source_default.green(` Tailing ${logPath}...
47855
48203
  `));
47856
48204
  console.log(source_default.gray(" Press Ctrl+C to stop\n"));
47857
- (0, import_node_child_process20.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
48205
+ (0, import_node_child_process22.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
47858
48206
  });
47859
48207
  program2.command("update").description("Update ThreatCrush CLI and installed bundle").option("--cli", "Update CLI only").option("--modules", "Update modules only").option("--desktop", "Update desktop app too").action(async (opts) => {
47860
48208
  console.log(LOGO2);
@@ -47866,7 +48214,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
47866
48214
  for (const cmd of commands2) {
47867
48215
  console.log(source_default.green(` \u2192 ${cmd}
47868
48216
  `));
47869
- (0, import_node_child_process20.execSync)(cmd, { stdio: "inherit" });
48217
+ (0, import_node_child_process22.execSync)(cmd, { stdio: "inherit" });
47870
48218
  }
47871
48219
  console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
47872
48220
  await reportIfStillStale();
@@ -47891,7 +48239,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
47891
48239
  for (const cmd of commands) {
47892
48240
  console.log(source_default.green(` \u2192 ${cmd}
47893
48241
  `));
47894
- (0, import_node_child_process20.execSync)(cmd, { stdio: "inherit" });
48242
+ (0, import_node_child_process22.execSync)(cmd, { stdio: "inherit" });
47895
48243
  }
47896
48244
  console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
47897
48245
  if (installMode === "desktop") {
@@ -47942,7 +48290,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
47942
48290
  for (const cmd of commands) {
47943
48291
  console.log(source_default.green(` \u2192 ${cmd}
47944
48292
  `));
47945
- (0, import_node_child_process20.execSync)(cmd, { stdio: "inherit" });
48293
+ (0, import_node_child_process22.execSync)(cmd, { stdio: "inherit" });
47946
48294
  }
47947
48295
  console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
47948
48296
  console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
@@ -48019,10 +48367,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
48019
48367
  });
48020
48368
  storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
48021
48369
  console.log(LOGO2);
48022
- const configPath = (0, import_node_path34.join)((0, import_node_os13.homedir)(), ".threatcrush", "config.json");
48370
+ const configPath = (0, import_node_path36.join)((0, import_node_os13.homedir)(), ".threatcrush", "config.json");
48023
48371
  let email = "";
48024
48372
  try {
48025
- const config = JSON.parse((0, import_node_fs46.readFileSync)(configPath, "utf-8"));
48373
+ const config = JSON.parse((0, import_node_fs49.readFileSync)(configPath, "utf-8"));
48026
48374
  email = config.email || "";
48027
48375
  } catch {
48028
48376
  }
@@ -48039,9 +48387,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
48039
48387
  return;
48040
48388
  }
48041
48389
  try {
48042
- const dir = (0, import_node_path34.join)((0, import_node_os13.homedir)(), ".threatcrush");
48043
- if (!(0, import_node_fs46.existsSync)(dir)) (0, import_node_fs46.mkdirSync)(dir, { recursive: true });
48044
- (0, import_node_fs46.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
48390
+ const dir = (0, import_node_path36.join)((0, import_node_os13.homedir)(), ".threatcrush");
48391
+ if (!(0, import_node_fs49.existsSync)(dir)) (0, import_node_fs49.mkdirSync)(dir, { recursive: true });
48392
+ (0, import_node_fs49.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
48045
48393
  console.log(source_default.dim(` Saved email to ${configPath}`));
48046
48394
  } catch {
48047
48395
  }