@profullstack/threatcrush 0.13.76 → 0.13.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/daemon.js CHANGED
@@ -2029,7 +2029,7 @@ var require_toml = __commonJS({
2029
2029
  var import_node_fs38 = require("fs");
2030
2030
  var import_node_child_process14 = require("child_process");
2031
2031
  var import_node_os6 = require("os");
2032
- var import_node_path29 = require("path");
2032
+ var import_node_path30 = require("path");
2033
2033
  var import_node_util = require("util");
2034
2034
 
2035
2035
  // src/daemon/paths.ts
@@ -2693,9 +2693,9 @@ function admGid(readGroup = () => (0, import_node_fs4.readFileSync)("/etc/group"
2693
2693
 
2694
2694
  // src/daemon/module-host.ts
2695
2695
  var import_node_fs14 = require("fs");
2696
- var import_node_path7 = require("path");
2696
+ var import_node_path8 = require("path");
2697
2697
  var import_node_url = require("url");
2698
- var import_toml2 = __toESM(require_toml());
2698
+ var import_toml3 = __toESM(require_toml());
2699
2699
 
2700
2700
  // src/daemon/module-trust.ts
2701
2701
  var import_node_crypto2 = require("crypto");
@@ -2820,6 +2820,8 @@ function verifyModuleTrust(name, modulePath) {
2820
2820
 
2821
2821
  // src/daemon/watchers/log-watcher.ts
2822
2822
  var import_node_fs8 = require("fs");
2823
+ var import_node_path5 = require("path");
2824
+ var import_toml = __toESM(require_toml());
2823
2825
 
2824
2826
  // src/core/log-tail.ts
2825
2827
  var import_node_fs6 = require("fs");
@@ -9758,6 +9760,39 @@ var DEFAULT_SOURCES = [
9758
9760
  { path: "/var/log/caddy/agent.database.pit.world.access.log", module: "log-watcher", category: "web" },
9759
9761
  { path: "/var/log/syslog", module: "log-watcher", category: "system" }
9760
9762
  ];
9763
+ function configuredWebSources(configFile, confD) {
9764
+ const paths = [];
9765
+ const take = (v) => {
9766
+ if (!Array.isArray(v)) return;
9767
+ for (const p of v) if (typeof p === "string" && p.startsWith("/")) paths.push(p);
9768
+ };
9769
+ const read = (file) => {
9770
+ try {
9771
+ return import_toml.default.parse((0, import_node_fs8.readFileSync)(file, "utf-8"));
9772
+ } catch {
9773
+ return null;
9774
+ }
9775
+ };
9776
+ const main = (0, import_node_fs8.existsSync)(configFile) ? read(configFile) : null;
9777
+ take(main?.modules?.["log-watcher"]?.paths);
9778
+ take(main?.["log-watcher"]?.paths);
9779
+ if ((0, import_node_fs8.existsSync)(confD)) {
9780
+ let files = [];
9781
+ try {
9782
+ files = (0, import_node_fs8.readdirSync)(confD).filter((f) => f.endsWith(".conf")).sort();
9783
+ } catch {
9784
+ }
9785
+ for (const f of files) take(read((0, import_node_path5.join)(confD, f))?.["log-watcher"]?.paths);
9786
+ }
9787
+ const known = new Set(DEFAULT_SOURCES.map((s) => s.path));
9788
+ const out = [];
9789
+ for (const path of paths) {
9790
+ if (known.has(path)) continue;
9791
+ known.add(path);
9792
+ out.push({ path, module: "log-watcher", category: "web" });
9793
+ }
9794
+ return out;
9795
+ }
9761
9796
  var AGENTDB_API_PATH = /^\/v1\/(?:list_databases|inspect_schema|query_readonly|explain_query|cluster_health|backup_status|audit\/events|backup\/(?:create|verify)|tokens(?:\/revoke)?)$/;
9762
9797
  var AGENTDB_HOST = "agent.database.pit.world";
9763
9798
  var LogWatcher = class {
@@ -10418,7 +10453,7 @@ var import_node_readline = require("readline");
10418
10453
 
10419
10454
  // src/core/threat-feeds/index.ts
10420
10455
  var import_node_fs11 = require("fs");
10421
- var import_node_path5 = require("path");
10456
+ var import_node_path6 = require("path");
10422
10457
  var import_node_net4 = require("net");
10423
10458
 
10424
10459
  // src/daemon/firewall/protected.ts
@@ -10805,7 +10840,7 @@ function readFeedCache(path) {
10805
10840
  }
10806
10841
  }
10807
10842
  function writeFeedCache(path, set) {
10808
- (0, import_node_fs11.mkdirSync)((0, import_node_path5.dirname)(path), { recursive: true });
10843
+ (0, import_node_fs11.mkdirSync)((0, import_node_path6.dirname)(path), { recursive: true });
10809
10844
  const tmp = `${path}.tmp`;
10810
10845
  (0, import_node_fs11.writeFileSync)(tmp, JSON.stringify(set));
10811
10846
  (0, import_node_fs11.renameSync)(tmp, path);
@@ -11180,8 +11215,8 @@ var DnsMonitor = class {
11180
11215
 
11181
11216
  // src/core/config.ts
11182
11217
  var import_node_fs13 = require("fs");
11183
- var import_node_path6 = require("path");
11184
- var import_toml = __toESM(require_toml());
11218
+ var import_node_path7 = require("path");
11219
+ var import_toml2 = __toESM(require_toml());
11185
11220
  var DEFAULT_CONFDIR = "/etc/threatcrush/threatcrushd.conf.d";
11186
11221
  var DEFAULT_CONFIG = {
11187
11222
  daemon: {
@@ -11204,7 +11239,7 @@ var DEFAULT_CONFIG = {
11204
11239
  }
11205
11240
  };
11206
11241
  function parseConfigText(raw) {
11207
- const parsed = import_toml.default.parse(raw);
11242
+ const parsed = import_toml2.default.parse(raw);
11208
11243
  return {
11209
11244
  daemon: { ...DEFAULT_CONFIG.daemon, ...parsed.daemon },
11210
11245
  api: { ...DEFAULT_CONFIG.api, ...parsed.api },
@@ -11235,7 +11270,7 @@ function loadDaemonConfig(configPath, lastGoodPath) {
11235
11270
  raw = (0, import_node_fs13.readFileSync)(configPath, "utf-8");
11236
11271
  const config = parseConfigText(raw);
11237
11272
  try {
11238
- (0, import_node_fs13.mkdirSync)((0, import_node_path6.dirname)(lastGoodPath), { recursive: true });
11273
+ (0, import_node_fs13.mkdirSync)((0, import_node_path7.dirname)(lastGoodPath), { recursive: true });
11239
11274
  (0, import_node_fs13.writeFileSync)(lastGoodPath, raw, { mode: 384 });
11240
11275
  } catch {
11241
11276
  }
@@ -11260,8 +11295,8 @@ function loadModuleConfigs(confDir) {
11260
11295
  const files = (0, import_node_fs13.readdirSync)(dir).filter((f) => f.endsWith(".conf"));
11261
11296
  for (const file of files) {
11262
11297
  try {
11263
- const raw = (0, import_node_fs13.readFileSync)((0, import_node_path6.join)(dir, file), "utf-8");
11264
- const parsed = import_toml.default.parse(raw);
11298
+ const raw = (0, import_node_fs13.readFileSync)((0, import_node_path7.join)(dir, file), "utf-8");
11299
+ const parsed = import_toml2.default.parse(raw);
11265
11300
  for (const [name, config] of Object.entries(parsed)) {
11266
11301
  configs.set(name, config);
11267
11302
  }
@@ -11306,7 +11341,10 @@ var ModuleHost = class {
11306
11341
  async start() {
11307
11342
  this.registerBuiltins();
11308
11343
  await this.discoverAndStartInstalled();
11309
- this.logWatcher = new LogWatcher(this.bus);
11344
+ this.logWatcher = new LogWatcher(this.bus, [
11345
+ ...DEFAULT_SOURCES,
11346
+ ...configuredWebSources(PATHS.configFile, PATHS.confD)
11347
+ ]);
11310
11348
  const watched = this.logWatcher.start();
11311
11349
  for (const modName of this.logWatcher.activeModules()) {
11312
11350
  const mod = this.modules.get(modName);
@@ -11399,10 +11437,10 @@ var ModuleHost = class {
11399
11437
  const entries = (0, import_node_fs14.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
11400
11438
  for (const entry of entries) {
11401
11439
  if (!entry.isDirectory()) continue;
11402
- const manifestPath = (0, import_node_path7.join)(PATHS.moduleDir, entry.name, "mod.toml");
11440
+ const manifestPath = (0, import_node_path8.join)(PATHS.moduleDir, entry.name, "mod.toml");
11403
11441
  if (!(0, import_node_fs14.existsSync)(manifestPath)) continue;
11404
11442
  try {
11405
- const manifest = import_toml2.default.parse((0, import_node_fs14.readFileSync)(manifestPath, "utf-8"));
11443
+ const manifest = import_toml3.default.parse((0, import_node_fs14.readFileSync)(manifestPath, "utf-8"));
11406
11444
  const name = manifest.module?.name || entry.name;
11407
11445
  const defaults = manifest.module?.config?.defaults || {};
11408
11446
  const config = {
@@ -11416,7 +11454,7 @@ var ModuleHost = class {
11416
11454
  source: "installed",
11417
11455
  status: config.enabled === false ? "disabled" : "loaded",
11418
11456
  events: 0,
11419
- path: (0, import_node_path7.join)(PATHS.moduleDir, entry.name),
11457
+ path: (0, import_node_path8.join)(PATHS.moduleDir, entry.name),
11420
11458
  config
11421
11459
  };
11422
11460
  this.modules.set(name, hosted);
@@ -11431,7 +11469,7 @@ var ModuleHost = class {
11431
11469
  status: "error",
11432
11470
  events: 0,
11433
11471
  detail: `manifest load failed: ${String(err.message || err)}`,
11434
- path: (0, import_node_path7.join)(PATHS.moduleDir, entry.name)
11472
+ path: (0, import_node_path8.join)(PATHS.moduleDir, entry.name)
11435
11473
  });
11436
11474
  }
11437
11475
  }
@@ -11470,16 +11508,16 @@ var ModuleHost = class {
11470
11508
  }
11471
11509
  }
11472
11510
  installedEntrypoint(modulePath) {
11473
- const packageJson = (0, import_node_path7.join)(modulePath, "package.json");
11511
+ const packageJson = (0, import_node_path8.join)(modulePath, "package.json");
11474
11512
  const candidates = [];
11475
11513
  if ((0, import_node_fs14.existsSync)(packageJson)) {
11476
11514
  try {
11477
11515
  const pkg = JSON.parse((0, import_node_fs14.readFileSync)(packageJson, "utf-8"));
11478
- if (pkg.main) candidates.push((0, import_node_path7.join)(modulePath, pkg.main));
11516
+ if (pkg.main) candidates.push((0, import_node_path8.join)(modulePath, pkg.main));
11479
11517
  } catch {
11480
11518
  }
11481
11519
  }
11482
- candidates.push((0, import_node_path7.join)(modulePath, "dist", "index.js"), (0, import_node_path7.join)(modulePath, "index.js"));
11520
+ candidates.push((0, import_node_path8.join)(modulePath, "dist", "index.js"), (0, import_node_path8.join)(modulePath, "index.js"));
11483
11521
  return candidates.find((candidate) => (0, import_node_fs14.existsSync)(candidate)) || null;
11484
11522
  }
11485
11523
  isThreatCrushModule(value) {
@@ -11804,14 +11842,14 @@ function slackChannel(webhookUrl) {
11804
11842
  var import_promises = require("dns/promises");
11805
11843
  var import_node_fs20 = require("fs");
11806
11844
  var import_node_net6 = require("net");
11807
- var import_node_path14 = require("path");
11845
+ var import_node_path15 = require("path");
11808
11846
 
11809
11847
  // src/core/cli-config.ts
11810
11848
  var import_node_fs15 = require("fs");
11811
- var import_node_path8 = require("path");
11849
+ var import_node_path9 = require("path");
11812
11850
  var import_node_os3 = require("os");
11813
- var CLI_CONFIG_DIR = (0, import_node_path8.join)((0, import_node_os3.homedir)(), ".threatcrush");
11814
- var CLI_CONFIG_PATH = (0, import_node_path8.join)(CLI_CONFIG_DIR, "config.json");
11851
+ var CLI_CONFIG_DIR = (0, import_node_path9.join)((0, import_node_os3.homedir)(), ".threatcrush");
11852
+ var CLI_CONFIG_PATH = (0, import_node_path9.join)(CLI_CONFIG_DIR, "config.json");
11815
11853
  function apiUrl() {
11816
11854
  return process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
11817
11855
  }
@@ -12013,7 +12051,7 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
12013
12051
 
12014
12052
  // src/commands/scan.ts
12015
12053
  var import_node_fs19 = require("fs");
12016
- var import_node_path13 = require("path");
12054
+ var import_node_path14 = require("path");
12017
12055
 
12018
12056
  // ../../node_modules/.pnpm/chalk@6.0.1/node_modules/chalk/source/utilities.js
12019
12057
  function stringReplaceAll(string, substring, postfix) {
@@ -12579,12 +12617,12 @@ var source_default = chalk;
12579
12617
 
12580
12618
  // src/core/version.ts
12581
12619
  var import_node_fs16 = require("fs");
12582
- var import_node_path9 = require("path");
12620
+ var import_node_path10 = require("path");
12583
12621
  var FALLBACK_VERSION = "0.0.0";
12584
12622
  function readPackageVersion() {
12585
12623
  try {
12586
12624
  const pkg = JSON.parse(
12587
- (0, import_node_fs16.readFileSync)((0, import_node_path9.join)(__dirname, "..", "package.json"), "utf-8")
12625
+ (0, import_node_fs16.readFileSync)((0, import_node_path10.join)(__dirname, "..", "package.json"), "utf-8")
12588
12626
  );
12589
12627
  return pkg.version || FALLBACK_VERSION;
12590
12628
  } catch {
@@ -15668,7 +15706,7 @@ function scanManifest(relativePath, filename, text) {
15668
15706
 
15669
15707
  // ../../packages/scan/src/node/walk.ts
15670
15708
  var import_node_fs17 = require("fs");
15671
- var import_node_path10 = require("path");
15709
+ var import_node_path11 = require("path");
15672
15710
  function compileExcludes(patterns) {
15673
15711
  const matchers = patterns.map((p) => p.trim()).filter((p) => p.length > 0 && !p.startsWith("#")).map(compilePattern);
15674
15712
  if (matchers.length === 0) return () => false;
@@ -15739,7 +15777,7 @@ function matchPrefix(parts, segs) {
15739
15777
  }
15740
15778
  function readIgnoreFile(root) {
15741
15779
  try {
15742
- return (0, import_node_fs17.readFileSync)((0, import_node_path10.join)(root, ".threatcrushignore"), "utf-8").split("\n");
15780
+ return (0, import_node_fs17.readFileSync)((0, import_node_path11.join)(root, ".threatcrushignore"), "utf-8").split("\n");
15743
15781
  } catch {
15744
15782
  return [];
15745
15783
  }
@@ -15760,11 +15798,11 @@ function scanPath(targetPath, options = {}) {
15760
15798
  return true;
15761
15799
  }
15762
15800
  })();
15763
- const walkRoot = rootIsDirectory ? targetPath : (0, import_node_path10.dirname)(targetPath);
15801
+ const walkRoot = rootIsDirectory ? targetPath : (0, import_node_path11.dirname)(targetPath);
15764
15802
  const isExcluded = compileExcludes([...options.exclude ?? [], ...readIgnoreFile(walkRoot)]);
15765
15803
  const scanFile = (fullPath, filename) => {
15766
15804
  const relativePath = toRelative(walkRoot, fullPath);
15767
- const extension = (0, import_node_path10.extname)(filename).toLowerCase();
15805
+ const extension = (0, import_node_path11.extname)(filename).toLowerCase();
15768
15806
  const isManifest = filename === "package.json" || filename === "requirements.txt";
15769
15807
  const scannable = SCAN_EXTENSIONS.has(extension) || filename.startsWith(".env");
15770
15808
  const mayDeclareInterpreter = !scannable && !isManifest && extension === "";
@@ -15819,7 +15857,7 @@ function scanPath(targetPath, options = {}) {
15819
15857
  return;
15820
15858
  }
15821
15859
  for (const entry of entries) {
15822
- const fullPath = (0, import_node_path10.join)(currentPath, entry.name);
15860
+ const fullPath = (0, import_node_path11.join)(currentPath, entry.name);
15823
15861
  const relativePath = toRelative(walkRoot, fullPath);
15824
15862
  if (entry.isDirectory()) {
15825
15863
  if (SKIP_DIRS.has(entry.name)) continue;
@@ -15843,7 +15881,7 @@ function scanPath(targetPath, options = {}) {
15843
15881
  } else if (isExcluded(toRelative(walkRoot, targetPath))) {
15844
15882
  excluded += 1;
15845
15883
  } else {
15846
- scanFile(targetPath, (0, import_node_path10.basename)(targetPath));
15884
+ scanFile(targetPath, (0, import_node_path11.basename)(targetPath));
15847
15885
  }
15848
15886
  if (options.missingControls) findings.push(...controls.findings());
15849
15887
  const filtered = allowed ? findings.filter((f) => allowed.has(f.category)) : findings;
@@ -15875,18 +15913,18 @@ function recordSensitiveFile(filename, relativePath, sink, fileFindings) {
15875
15913
  }
15876
15914
  }
15877
15915
  function toRelative(base, target) {
15878
- const rel = (0, import_node_path10.relative)(base, target);
15879
- return (rel === "" ? target : rel).split(import_node_path10.sep).join("/");
15916
+ const rel = (0, import_node_path11.relative)(base, target);
15917
+ return (rel === "" ? target : rel).split(import_node_path11.sep).join("/");
15880
15918
  }
15881
15919
 
15882
15920
  // ../../packages/scan/src/node/dependencies.ts
15883
15921
  var import_node_fs18 = require("fs");
15884
- var import_node_path11 = require("path");
15922
+ var import_node_path12 = require("path");
15885
15923
  var MAX_DEPS_PER_LOCKFILE = 50;
15886
15924
  async function scanDependencies(targetPath) {
15887
15925
  const findings = [];
15888
15926
  for (const { file, ecosystem, parse } of LOCKFILES) {
15889
- const lockPath = (0, import_node_path11.join)(targetPath, file);
15927
+ const lockPath = (0, import_node_path12.join)(targetPath, file);
15890
15928
  if (!(0, import_node_fs18.existsSync)(lockPath)) continue;
15891
15929
  let deps;
15892
15930
  try {
@@ -16105,13 +16143,13 @@ async function queryOsv(name, version, ecosystem) {
16105
16143
 
16106
16144
  // ../../packages/scan/src/node/sarif.ts
16107
16145
  var import_node_crypto4 = require("crypto");
16108
- var import_node_path12 = require("path");
16146
+ var import_node_path13 = require("path");
16109
16147
 
16110
16148
  // src/commands/scan.ts
16111
16149
  function readVersion() {
16112
16150
  for (const candidate of [
16113
- (0, import_node_path13.join)(__dirname, "..", "package.json"),
16114
- (0, import_node_path13.join)(__dirname, "..", "..", "package.json")
16151
+ (0, import_node_path14.join)(__dirname, "..", "package.json"),
16152
+ (0, import_node_path14.join)(__dirname, "..", "..", "package.json")
16115
16153
  ]) {
16116
16154
  try {
16117
16155
  return JSON.parse((0, import_node_fs19.readFileSync)(candidate, "utf-8")).version ?? "0.0.0";
@@ -16368,18 +16406,18 @@ function scanTargetError(target, roots, real = import_node_fs20.realpathSync) {
16368
16406
  }
16369
16407
  let path;
16370
16408
  try {
16371
- path = real((0, import_node_path14.resolve)(target));
16409
+ path = real((0, import_node_path15.resolve)(target));
16372
16410
  } catch {
16373
16411
  return `no such path: ${target}`;
16374
16412
  }
16375
16413
  for (const root of roots) {
16376
16414
  let base;
16377
16415
  try {
16378
- base = real((0, import_node_path14.resolve)(root));
16416
+ base = real((0, import_node_path15.resolve)(root));
16379
16417
  } catch {
16380
16418
  continue;
16381
16419
  }
16382
- if (path === base || path.startsWith(base.endsWith(import_node_path14.sep) ? base : base + import_node_path14.sep)) return null;
16420
+ if (path === base || path.startsWith(base.endsWith(import_node_path15.sep) ? base : base + import_node_path15.sep)) return null;
16383
16421
  }
16384
16422
  return `${target} is outside [cloud] run_scan_paths`;
16385
16423
  }
@@ -16532,14 +16570,14 @@ var RunsWorker = class {
16532
16570
  // src/daemon/workers/cloud-spool.ts
16533
16571
  var import_node_fs21 = require("fs");
16534
16572
  var import_promises2 = require("fs/promises");
16535
- var import_node_path15 = require("path");
16573
+ var import_node_path16 = require("path");
16536
16574
  var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
16537
16575
  var CloudSpool = class {
16538
16576
  constructor(path, limits = DEFAULT_SPOOL_LIMITS) {
16539
16577
  this.path = path;
16540
16578
  this.limits = limits;
16541
16579
  try {
16542
- (0, import_node_fs21.mkdirSync)((0, import_node_path15.dirname)(path), { recursive: true });
16580
+ (0, import_node_fs21.mkdirSync)((0, import_node_path16.dirname)(path), { recursive: true });
16543
16581
  } catch {
16544
16582
  }
16545
16583
  this.load();
@@ -17082,18 +17120,18 @@ function resolveConfig(section) {
17082
17120
 
17083
17121
  // src/core/abuse-report-log.ts
17084
17122
  var import_node_fs22 = require("fs");
17085
- var import_node_path16 = require("path");
17123
+ var import_node_path17 = require("path");
17086
17124
  var ABUSE_DIRNAME = "abuse-reports";
17087
17125
  var LOG_FILE = "reports.jsonl";
17088
17126
  function resolveAbuseDir(dir) {
17089
17127
  if (dir) return dir;
17090
17128
  if (process.env.THREATCRUSH_ABUSE_DIR) return process.env.THREATCRUSH_ABUSE_DIR;
17091
- const system = (0, import_node_path16.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
17129
+ const system = (0, import_node_path17.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
17092
17130
  if ((0, import_node_fs22.existsSync)(system)) return system;
17093
- return (0, import_node_path16.join)(PATHS.stateDir, ABUSE_DIRNAME);
17131
+ return (0, import_node_path17.join)(PATHS.stateDir, ABUSE_DIRNAME);
17094
17132
  }
17095
17133
  function logPath(dir) {
17096
- return (0, import_node_path16.join)(resolveAbuseDir(dir), LOG_FILE);
17134
+ return (0, import_node_path17.join)(resolveAbuseDir(dir), LOG_FILE);
17097
17135
  }
17098
17136
  function appendReport(record, dir) {
17099
17137
  const path = logPath(dir);
@@ -17512,7 +17550,7 @@ var RemediationConsumer = class {
17512
17550
  // src/daemon/workers/auto-update.ts
17513
17551
  var import_node_child_process5 = require("child_process");
17514
17552
  var import_node_fs23 = require("fs");
17515
- var import_node_path17 = require("path");
17553
+ var import_node_path18 = require("path");
17516
17554
  var PKG_NAME = "@profullstack/threatcrush";
17517
17555
  var REGISTRY = `https://registry.npmjs.org/${PKG_NAME}`;
17518
17556
  var DEFAULT_INTERVAL_MS = 6 * 36e5;
@@ -17555,12 +17593,12 @@ function pickUpdate(doc, current, opts) {
17555
17593
  return { version: null, reason: `${latest} is younger than min_age, and nothing older is newer than ${current}; waiting` };
17556
17594
  }
17557
17595
  function installPlan(opts) {
17558
- const expected = `${import_node_path17.sep}lib${import_node_path17.sep}node_modules${import_node_path17.sep}@profullstack${import_node_path17.sep}threatcrush`;
17596
+ const expected = `${import_node_path18.sep}lib${import_node_path18.sep}node_modules${import_node_path18.sep}@profullstack${import_node_path18.sep}threatcrush`;
17559
17597
  if (!opts.pkgRoot.endsWith(expected)) {
17560
17598
  return { kind: "unsupported", reason: `not an npm global install (${opts.pkgRoot}); run \`threatcrush update\`` };
17561
17599
  }
17562
- const nodeBin = (0, import_node_path17.dirname)(opts.execPath);
17563
- const npm = (0, import_node_path17.join)(nodeBin, "npm");
17600
+ const nodeBin = (0, import_node_path18.dirname)(opts.execPath);
17601
+ const npm = (0, import_node_path18.join)(nodeBin, "npm");
17564
17602
  if (!opts.npmExists(npm)) return { kind: "unsupported", reason: `no npm beside ${opts.execPath}` };
17565
17603
  if (!opts.owner) return { kind: "unsupported", reason: `cannot tell who owns ${opts.pkgRoot}` };
17566
17604
  const npmArgs = [npm, "i", "-g", `${PKG_NAME}@${opts.version}`, "--no-fund", "--no-audit"];
@@ -17759,7 +17797,7 @@ var AutoUpdate = class {
17759
17797
  // src/daemon/workers/threat-feeds.ts
17760
17798
  var import_node_child_process6 = require("child_process");
17761
17799
  var import_node_fs24 = require("fs");
17762
- var import_node_path18 = require("path");
17800
+ var import_node_path19 = require("path");
17763
17801
  var import_node_net10 = require("net");
17764
17802
  var EGRESS_TABLE = "threatcrush_egress";
17765
17803
  var DEFAULT_REFRESH_MS = 36e5;
@@ -17930,10 +17968,10 @@ var ThreatFeeds = class {
17930
17968
  */
17931
17969
  writeResolverFiles(set) {
17932
17970
  const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
17933
- const dir = this.opts.resolverDir ?? (0, import_node_path18.dirname)(this.opts.cachePath);
17971
+ const dir = this.opts.resolverDir ?? (0, import_node_path19.dirname)(this.opts.cachePath);
17934
17972
  const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
17935
17973
  const write = (name, content) => {
17936
- const path = (0, import_node_path18.join)(dir, name);
17974
+ const path = (0, import_node_path19.join)(dir, name);
17937
17975
  if (this.resolverWritten.get(name) === content) return false;
17938
17976
  try {
17939
17977
  (0, import_node_fs24.writeFileSync)(`${path}.tmp`, content);
@@ -18014,7 +18052,7 @@ var ThreatFeeds = class {
18014
18052
 
18015
18053
  // src/daemon/workers/privilege-watch.ts
18016
18054
  var import_node_fs25 = require("fs");
18017
- var import_node_path19 = require("path");
18055
+ var import_node_path20 = require("path");
18018
18056
  var import_node_child_process7 = require("child_process");
18019
18057
 
18020
18058
  // src/core/privileges/index.ts
@@ -18262,7 +18300,7 @@ function readJson(path) {
18262
18300
  }
18263
18301
  }
18264
18302
  function writeJson(path, value) {
18265
- (0, import_node_fs25.mkdirSync)((0, import_node_path19.dirname)(path), { recursive: true });
18303
+ (0, import_node_fs25.mkdirSync)((0, import_node_path20.dirname)(path), { recursive: true });
18266
18304
  (0, import_node_fs25.writeFileSync)(`${path}.tmp`, JSON.stringify(value));
18267
18305
  (0, import_node_fs25.renameSync)(`${path}.tmp`, path);
18268
18306
  }
@@ -18547,7 +18585,7 @@ var PrivilegeWatch = class {
18547
18585
  // src/daemon/workers/command-history.ts
18548
18586
  var import_node_fs26 = require("fs");
18549
18587
  var import_node_child_process8 = require("child_process");
18550
- var import_node_path20 = require("path");
18588
+ var import_node_path21 = require("path");
18551
18589
  var import_node_zlib = require("zlib");
18552
18590
  var import_node_crypto7 = require("crypto");
18553
18591
  var POLL_MS2 = 6e4;
@@ -18583,9 +18621,9 @@ function historyAccounts() {
18583
18621
  const name = fields[0] ?? "";
18584
18622
  const home = fields[5] ?? "";
18585
18623
  const shell = fields[6] ?? "";
18586
- if (!Number.isInteger(uid) || !Number.isInteger(gid) || !(0, import_node_path20.isAbsolute)(home) || home === "/" || home.split("/").includes("..")) return [];
18624
+ if (!Number.isInteger(uid) || !Number.isInteger(gid) || !(0, import_node_path21.isAbsolute)(home) || home === "/" || home.split("/").includes("..")) return [];
18587
18625
  if (root ? uid !== 0 && uid < 1e3 : uid !== process.getuid?.()) return [];
18588
- if (!HISTORY_TARGETS[(0, import_node_path20.basename)(shell)]) return [];
18626
+ if (!HISTORY_TARGETS[(0, import_node_path21.basename)(shell)]) return [];
18589
18627
  return [{ uid, gid, name, home, shell }];
18590
18628
  });
18591
18629
  }
@@ -18593,11 +18631,11 @@ function descriptorPath(directoryFd, name) {
18593
18631
  return `/proc/self/fd/${directoryFd}/${name}`;
18594
18632
  }
18595
18633
  function openDirectoryChain(path) {
18596
- if (!(0, import_node_path20.isAbsolute)(path) || path.split(import_node_path20.sep).includes("..")) throw new Error("directory path is not a safe absolute path");
18634
+ if (!(0, import_node_path21.isAbsolute)(path) || path.split(import_node_path21.sep).includes("..")) throw new Error("directory path is not a safe absolute path");
18597
18635
  const flags = import_node_fs26.constants.O_RDONLY | import_node_fs26.constants.O_DIRECTORY | (import_node_fs26.constants.O_NOFOLLOW ?? 0);
18598
18636
  let fd = (0, import_node_fs26.openSync)("/", flags);
18599
18637
  try {
18600
- for (const part of path.split(import_node_path20.sep).filter((item) => item && item !== ".")) {
18638
+ for (const part of path.split(import_node_path21.sep).filter((item) => item && item !== ".")) {
18601
18639
  const next = (0, import_node_fs26.openSync)(descriptorPath(fd, part), flags);
18602
18640
  (0, import_node_fs26.closeSync)(fd);
18603
18641
  fd = next;
@@ -18641,9 +18679,9 @@ function safeReadHistory(directoryFd, name, uid) {
18641
18679
  }
18642
18680
  }
18643
18681
  function atomicWrite(path, data, mode = 384, owner, parentFd) {
18644
- const dirFd = parentFd ?? openDirectoryChain((0, import_node_path20.dirname)(path));
18682
+ const dirFd = parentFd ?? openDirectoryChain((0, import_node_path21.dirname)(path));
18645
18683
  const ownsDirFd = parentFd === void 0;
18646
- const name = (0, import_node_path20.basename)(path);
18684
+ const name = (0, import_node_path21.basename)(path);
18647
18685
  const temp = descriptorPath(dirFd, `${name}.${(0, import_node_crypto7.randomUUID)()}.tmp`);
18648
18686
  const destination = descriptorPath(dirFd, name);
18649
18687
  const noFollow = import_node_fs26.constants.O_NOFOLLOW ?? 0;
@@ -18679,9 +18717,9 @@ function atomicWrite(path, data, mode = 384, owner, parentFd) {
18679
18717
  function readCurrentBackup(path) {
18680
18718
  let fd;
18681
18719
  try {
18682
- const parentFd = openDirectoryChain((0, import_node_path20.dirname)(path));
18720
+ const parentFd = openDirectoryChain((0, import_node_path21.dirname)(path));
18683
18721
  try {
18684
- fd = (0, import_node_fs26.openSync)(descriptorPath(parentFd, (0, import_node_path20.basename)(path)), import_node_fs26.constants.O_RDONLY | (import_node_fs26.constants.O_NOFOLLOW ?? 0));
18722
+ fd = (0, import_node_fs26.openSync)(descriptorPath(parentFd, (0, import_node_path21.basename)(path)), import_node_fs26.constants.O_RDONLY | (import_node_fs26.constants.O_NOFOLLOW ?? 0));
18685
18723
  } finally {
18686
18724
  (0, import_node_fs26.closeSync)(parentFd);
18687
18725
  }
@@ -18706,7 +18744,7 @@ var CommandHistoryWatcher = class {
18706
18744
  this.pollMs = Math.max(1e4, opts.pollMs ?? POLL_MS2);
18707
18745
  this.now = opts.now ?? (() => /* @__PURE__ */ new Date());
18708
18746
  this.listAccounts = opts.listAccounts ?? historyAccounts;
18709
- this.root = (0, import_node_path20.join)(opts.stateDir, "command-history");
18747
+ this.root = (0, import_node_path21.join)(opts.stateDir, "command-history");
18710
18748
  }
18711
18749
  opts;
18712
18750
  timer = null;
@@ -18747,7 +18785,7 @@ var CommandHistoryWatcher = class {
18747
18785
  try {
18748
18786
  privateDirectory(this.root);
18749
18787
  for (const account of this.listAccounts()) {
18750
- if (!Number.isInteger(account.uid) || account.uid < 0 || !(0, import_node_path20.isAbsolute)(account.home)) continue;
18788
+ if (!Number.isInteger(account.uid) || account.uid < 0 || !(0, import_node_path21.isAbsolute)(account.home)) continue;
18751
18789
  const targets = this.targetsFor(account);
18752
18790
  for (const relative4 of targets) this.scanFile(account, relative4);
18753
18791
  }
@@ -18758,10 +18796,10 @@ var CommandHistoryWatcher = class {
18758
18796
  }
18759
18797
  }
18760
18798
  targetsFor(account) {
18761
- const targets = new Set(HISTORY_TARGETS[(0, import_node_path20.basename)(account.shell)] ?? []);
18799
+ const targets = new Set(HISTORY_TARGETS[(0, import_node_path21.basename)(account.shell)] ?? []);
18762
18800
  for (const relative4 of Object.values(HISTORY_TARGETS).flat()) {
18763
18801
  if (targets.has(relative4)) continue;
18764
- const path = (0, import_node_path20.join)(account.home, relative4);
18802
+ const path = (0, import_node_path21.join)(account.home, relative4);
18765
18803
  try {
18766
18804
  (0, import_node_fs26.lstatSync)(path);
18767
18805
  targets.add(relative4);
@@ -18769,25 +18807,25 @@ var CommandHistoryWatcher = class {
18769
18807
  } catch (error) {
18770
18808
  if (error.code !== "ENOENT") continue;
18771
18809
  }
18772
- const current = (0, import_node_path20.join)(this.root, String(account.uid), `${(0, import_node_path20.basename)(relative4)}.current.gz`);
18810
+ const current = (0, import_node_path21.join)(this.root, String(account.uid), `${(0, import_node_path21.basename)(relative4)}.current.gz`);
18773
18811
  if (readCurrentBackup(current) !== null) targets.add(relative4);
18774
18812
  }
18775
18813
  return [...targets];
18776
18814
  }
18777
18815
  scanFile(account, relative4) {
18778
- const path = (0, import_node_path20.join)(account.home, relative4);
18779
- const store = (0, import_node_path20.join)(this.root, String(account.uid), (0, import_node_path20.basename)(relative4));
18816
+ const path = (0, import_node_path21.join)(account.home, relative4);
18817
+ const store = (0, import_node_path21.join)(this.root, String(account.uid), (0, import_node_path21.basename)(relative4));
18780
18818
  const current = `${store}.current.gz`;
18781
18819
  let userParentFd;
18782
18820
  try {
18783
- userParentFd = openDirectoryChain((0, import_node_path20.dirname)(path));
18821
+ userParentFd = openDirectoryChain((0, import_node_path21.dirname)(path));
18784
18822
  } catch {
18785
- this.opts.log(`[command-history] skipped uid=${account.uid} ${(0, import_node_path20.basename)(relative4)} because its parent path is missing or not a real directory`);
18823
+ this.opts.log(`[command-history] skipped uid=${account.uid} ${(0, import_node_path21.basename)(relative4)} because its parent path is missing or not a real directory`);
18786
18824
  return;
18787
18825
  }
18788
18826
  try {
18789
- privateDirectory((0, import_node_path20.dirname)(store));
18790
- const userPath = descriptorPath(userParentFd, (0, import_node_path20.basename)(path));
18827
+ privateDirectory((0, import_node_path21.dirname)(store));
18828
+ const userPath = descriptorPath(userParentFd, (0, import_node_path21.basename)(path));
18791
18829
  let status;
18792
18830
  try {
18793
18831
  status = (0, import_node_fs26.lstatSync)(userPath);
@@ -18805,7 +18843,7 @@ var CommandHistoryWatcher = class {
18805
18843
  } else if (!status) {
18806
18844
  this.restore(path, Buffer.alloc(0), account, userParentFd);
18807
18845
  }
18808
- const data = safeReadHistory(userParentFd, (0, import_node_path20.basename)(path), account.uid);
18846
+ const data = safeReadHistory(userParentFd, (0, import_node_path21.basename)(path), account.uid);
18809
18847
  if (data === null) return;
18810
18848
  const previous = backup;
18811
18849
  if (previous?.equals(data)) {
@@ -18818,7 +18856,7 @@ var CommandHistoryWatcher = class {
18818
18856
  atomicWrite(current, compressed);
18819
18857
  this.pruneSnapshots(store);
18820
18858
  } catch (error) {
18821
- this.opts.log(`[command-history] could not snapshot uid=${account.uid} ${(0, import_node_path20.basename)(relative4)}: ${error.message}`);
18859
+ this.opts.log(`[command-history] could not snapshot uid=${account.uid} ${(0, import_node_path21.basename)(relative4)}: ${error.message}`);
18822
18860
  } finally {
18823
18861
  (0, import_node_fs26.closeSync)(userParentFd);
18824
18862
  }
@@ -18833,16 +18871,16 @@ var CommandHistoryWatcher = class {
18833
18871
  module: "command-history",
18834
18872
  category: "system",
18835
18873
  severity: "medium",
18836
- message: `Shell history for ${name} (${(0, import_node_path20.basename)(relative4)}) was ${reason}; restored${hadBackup ? " from the latest backup" : " as an empty file"}`,
18837
- details: { uid: account.uid, account: name, history_file: (0, import_node_path20.basename)(relative4), action: "restored", reason, had_backup: hadBackup }
18874
+ message: `Shell history for ${name} (${(0, import_node_path21.basename)(relative4)}) was ${reason}; restored${hadBackup ? " from the latest backup" : " as an empty file"}`,
18875
+ details: { uid: account.uid, account: name, history_file: (0, import_node_path21.basename)(relative4), action: "restored", reason, had_backup: hadBackup }
18838
18876
  };
18839
18877
  this.opts.bus.publish(event);
18840
18878
  this.opts.log(`[command-history] ${event.message}`);
18841
18879
  }
18842
18880
  pruneSnapshots(current) {
18843
- const dir = (0, import_node_path20.dirname)(current);
18844
- const prefix = `${(0, import_node_path20.basename)(current).replace(/\.current\.gz$/, "")}.`;
18845
- const snapshots = (0, import_node_fs26.readdirSync)(dir).filter((name) => name !== (0, import_node_path20.basename)(current) && name.startsWith(prefix) && name.endsWith(".gz")).map((name) => ({ path: (0, import_node_path20.join)(dir, name), name, time: (0, import_node_fs26.lstatSync)((0, import_node_path20.join)(dir, name)).mtimeMs })).sort((a, b) => a.time - b.time);
18881
+ const dir = (0, import_node_path21.dirname)(current);
18882
+ const prefix = `${(0, import_node_path21.basename)(current).replace(/\.current\.gz$/, "")}.`;
18883
+ const snapshots = (0, import_node_fs26.readdirSync)(dir).filter((name) => name !== (0, import_node_path21.basename)(current) && name.startsWith(prefix) && name.endsWith(".gz")).map((name) => ({ path: (0, import_node_path21.join)(dir, name), name, time: (0, import_node_fs26.lstatSync)((0, import_node_path21.join)(dir, name)).mtimeMs })).sort((a, b) => a.time - b.time);
18846
18884
  const cutoff = this.now().getTime() - SNAPSHOT_RETENTION_MS;
18847
18885
  const removeCount = Math.max(0, snapshots.length - MAX_SNAPSHOTS);
18848
18886
  snapshots.forEach((snapshot, index) => {
@@ -18860,7 +18898,7 @@ var CommandHistoryWatcher = class {
18860
18898
  var import_node_fs27 = require("fs");
18861
18899
  var import_promises3 = require("fs/promises");
18862
18900
  var import_node_crypto8 = require("crypto");
18863
- var import_node_path21 = require("path");
18901
+ var import_node_path22 = require("path");
18864
18902
  var DEFAULT_POLL_MS = 15 * 6e4;
18865
18903
  var MAX_FILES = 5e4;
18866
18904
  var MAX_FILE_BYTES = 64 * 1024 * 1024;
@@ -18875,8 +18913,8 @@ var READ_CHUNK_BYTES = 64 * 1024;
18875
18913
  var CANARY_CONTENT = "ThreatCrush file integrity canary v1\n";
18876
18914
  function fileIntegritySettings(section) {
18877
18915
  const safePath = (value) => {
18878
- if (typeof value !== "string" || !(0, import_node_path21.isAbsolute)(value) || value.split(import_node_path21.sep).includes("..")) return null;
18879
- const path = (0, import_node_path21.normalize)(value);
18916
+ if (typeof value !== "string" || !(0, import_node_path22.isAbsolute)(value) || value.split(import_node_path22.sep).includes("..")) return null;
18917
+ const path = (0, import_node_path22.normalize)(value);
18880
18918
  return path === "/" ? null : path;
18881
18919
  };
18882
18920
  const strings = (values) => Array.isArray(values) ? [...new Set(values.map(safePath).filter((path) => path !== null))] : [];
@@ -18905,7 +18943,7 @@ async function readState(path) {
18905
18943
  }
18906
18944
  }
18907
18945
  async function writeState(path, state) {
18908
- await (0, import_promises3.mkdir)((0, import_node_path21.dirname)(path), { recursive: true, mode: 448 });
18946
+ await (0, import_promises3.mkdir)((0, import_node_path22.dirname)(path), { recursive: true, mode: 448 });
18909
18947
  const temp = `${path}.${process.pid}.${(0, import_node_crypto8.randomUUID)()}.tmp`;
18910
18948
  await (0, import_promises3.writeFile)(temp, JSON.stringify(state), { mode: 384 });
18911
18949
  await (0, import_promises3.rename)(temp, path);
@@ -18935,10 +18973,10 @@ var OPEN_FILE_FLAGS = import_promises3.constants.O_RDONLY | import_promises3.con
18935
18973
  var OPEN_DIR_FLAGS = OPEN_FILE_FLAGS | import_promises3.constants.O_DIRECTORY;
18936
18974
  var CREATE_FILE_FLAGS = import_promises3.constants.O_WRONLY | import_promises3.constants.O_CREAT | import_promises3.constants.O_EXCL | import_promises3.constants.O_NOFOLLOW;
18937
18975
  function autoCanaryPath(directory) {
18938
- return (0, import_node_path21.join)(directory, ".threatcrush-canary");
18976
+ return (0, import_node_path22.join)(directory, ".threatcrush-canary");
18939
18977
  }
18940
18978
  async function openAbsoluteDirectory(path) {
18941
- const parts = path.split(import_node_path21.sep).filter((part) => part && part !== ".");
18979
+ const parts = path.split(import_node_path22.sep).filter((part) => part && part !== ".");
18942
18980
  if (parts.includes("..")) throw new Error("invalid canary directory");
18943
18981
  let directory = await (0, import_promises3.open)("/", OPEN_DIR_FLAGS);
18944
18982
  try {
@@ -18961,9 +18999,9 @@ async function createAutoCanary(path) {
18961
18999
  } catch (error) {
18962
19000
  if (error.code !== "ENOENT") return false;
18963
19001
  }
18964
- const directory = await openAbsoluteDirectory((0, import_node_path21.dirname)(path));
19002
+ const directory = await openAbsoluteDirectory((0, import_node_path22.dirname)(path));
18965
19003
  try {
18966
- const file = await (0, import_promises3.open)(`/proc/self/fd/${directory.fd}/${(0, import_node_path21.basename)(path)}`, CREATE_FILE_FLAGS, 438);
19004
+ const file = await (0, import_promises3.open)(`/proc/self/fd/${directory.fd}/${(0, import_node_path22.basename)(path)}`, CREATE_FILE_FLAGS, 438);
18967
19005
  try {
18968
19006
  await file.chmod(438);
18969
19007
  await file.writeFile(CANARY_CONTENT);
@@ -18980,7 +19018,7 @@ async function createAutoCanary(path) {
18980
19018
  }
18981
19019
  }
18982
19020
  async function openAbsoluteTarget(path) {
18983
- const parts = path.split(import_node_path21.sep).filter((part) => part && part !== ".");
19021
+ const parts = path.split(import_node_path22.sep).filter((part) => part && part !== ".");
18984
19022
  if (parts.length === 0 || parts.includes("..")) throw new Error("invalid file integrity path");
18985
19023
  let directory = await (0, import_promises3.open)("/", OPEN_DIR_FLAGS);
18986
19024
  try {
@@ -19015,7 +19053,7 @@ async function scanTargets(targets, canaries) {
19015
19053
  }
19016
19054
  let handle;
19017
19055
  try {
19018
- handle = parent ? await (0, import_promises3.open)(`/proc/self/fd/${parent.fd}/${path.slice(path.lastIndexOf(import_node_path21.sep) + 1)}`, OPEN_FILE_FLAGS) : await openAbsoluteTarget(path);
19056
+ handle = parent ? await (0, import_promises3.open)(`/proc/self/fd/${parent.fd}/${path.slice(path.lastIndexOf(import_node_path22.sep) + 1)}`, OPEN_FILE_FLAGS) : await openAbsoluteTarget(path);
19019
19057
  const stat = await handle.stat();
19020
19058
  if (stat.isDirectory()) {
19021
19059
  directories.push(path);
@@ -19033,7 +19071,7 @@ async function scanTargets(targets, canaries) {
19033
19071
  return;
19034
19072
  }
19035
19073
  for (const entry of entries) {
19036
- await walk((0, import_node_path21.join)(path, entry.name), handle);
19074
+ await walk((0, import_node_path22.join)(path, entry.name), handle);
19037
19075
  if (!complete) return;
19038
19076
  }
19039
19077
  return;
@@ -19243,7 +19281,7 @@ var FileIntegrityWatch = class {
19243
19281
  if (current.complete) {
19244
19282
  const directories = new Set(current.directories);
19245
19283
  for (const path of Object.keys(current.files)) {
19246
- if (!directories.has(path)) directories.add((0, import_node_path21.dirname)(path));
19284
+ if (!directories.has(path)) directories.add((0, import_node_path22.dirname)(path));
19247
19285
  }
19248
19286
  this.refreshWatchers([...directories]);
19249
19287
  }
@@ -19353,7 +19391,7 @@ var FileIntegrityWatch = class {
19353
19391
 
19354
19392
  // src/daemon/workers/edr.ts
19355
19393
  var import_node_fs28 = require("fs");
19356
- var import_node_path22 = require("path");
19394
+ var import_node_path23 = require("path");
19357
19395
  var import_node_child_process9 = require("child_process");
19358
19396
  var DEFAULT_AUDIT_LOG = "/var/log/audit/audit.log";
19359
19397
  var DEFAULT_WEB_USERS = ["www-data", "nginx", "apache", "httpd", "caddy", "node"];
@@ -19371,8 +19409,8 @@ var SHELLS = /* @__PURE__ */ new Set(["sh", "bash", "dash", "zsh", "ksh", "fish"
19371
19409
  var DOWNLOADERS = /* @__PURE__ */ new Set(["curl", "wget"]);
19372
19410
  var MINERS = /* @__PURE__ */ new Set(["xmrig", "minerd", "cpuminer", "cpuminer-multi", "kdevtmpfsi", "kinsing", "cryptonight"]);
19373
19411
  function safeAbsolutePath(value) {
19374
- if (typeof value !== "string" || !(0, import_node_path22.isAbsolute)(value) || value.split(import_node_path22.sep).includes("..")) return null;
19375
- const path = (0, import_node_path22.normalize)(value);
19412
+ if (typeof value !== "string" || !(0, import_node_path23.isAbsolute)(value) || value.split(import_node_path23.sep).includes("..")) return null;
19413
+ const path = (0, import_node_path23.normalize)(value);
19376
19414
  return path === "/" ? null : path;
19377
19415
  }
19378
19416
  function edrSettings(section) {
@@ -19418,7 +19456,7 @@ function parseAuditRecord(line) {
19418
19456
  serial: header[2],
19419
19457
  key: fields.key,
19420
19458
  executable,
19421
- comm: fields.comm ?? (0, import_node_path22.basename)(executable),
19459
+ comm: fields.comm ?? (0, import_node_path23.basename)(executable),
19422
19460
  euid,
19423
19461
  ...Number.isInteger(pid) && pid > 0 ? { pid } : {},
19424
19462
  ...Number.isInteger(ppid) && ppid > 0 ? { ppid } : {}
@@ -19448,7 +19486,7 @@ function pathWithin(path, root) {
19448
19486
  }
19449
19487
  function executableInWorldWritableDirectory(executable) {
19450
19488
  try {
19451
- return ((0, import_node_fs28.statSync)((0, import_node_path22.dirname)(executable)).mode & 2) !== 0;
19489
+ return ((0, import_node_fs28.statSync)((0, import_node_path23.dirname)(executable)).mode & 2) !== 0;
19452
19490
  } catch {
19453
19491
  return false;
19454
19492
  }
@@ -19534,7 +19572,7 @@ var EdrWatch = class {
19534
19572
  this.opts.bus.publish(event);
19535
19573
  }
19536
19574
  classify(execution) {
19537
- const name = (0, import_node_path22.basename)(execution.executable).toLowerCase();
19575
+ const name = (0, import_node_path23.basename)(execution.executable).toLowerCase();
19538
19576
  const account = this.usersById.get(execution.euid) ?? String(execution.euid);
19539
19577
  let severity;
19540
19578
  let ruleId;
@@ -19656,7 +19694,7 @@ var EdrWatch = class {
19656
19694
  let executable = (0, import_node_fs28.readlinkSync)(`${proc}/exe`);
19657
19695
  executable = executable.replace(/ \(deleted\)$/, "");
19658
19696
  if (!this.opts.settings.tempExecPaths.some((path) => pathWithin(executable, path))) continue;
19659
- const name = (0, import_node_path22.basename)(executable).toLowerCase();
19697
+ const name = (0, import_node_path23.basename)(executable).toLowerCase();
19660
19698
  if (MINERS.has(name)) continue;
19661
19699
  const key = `${pid}:${startTicks}`;
19662
19700
  const ticks = userTicks + systemTicks;
@@ -19693,7 +19731,7 @@ var EdrWatch = class {
19693
19731
 
19694
19732
  // src/daemon/workers/ssh-intrusion.ts
19695
19733
  var import_node_fs29 = require("fs");
19696
- var import_node_path23 = require("path");
19734
+ var import_node_path24 = require("path");
19697
19735
  var import_node_child_process10 = require("child_process");
19698
19736
 
19699
19737
  // src/core/asn.ts
@@ -19893,7 +19931,7 @@ function readJson2(path) {
19893
19931
  }
19894
19932
  }
19895
19933
  function writeJson2(path, value) {
19896
- (0, import_node_fs29.mkdirSync)((0, import_node_path23.dirname)(path), { recursive: true });
19934
+ (0, import_node_fs29.mkdirSync)((0, import_node_path24.dirname)(path), { recursive: true });
19897
19935
  (0, import_node_fs29.writeFileSync)(`${path}.tmp`, JSON.stringify(value));
19898
19936
  (0, import_node_fs29.renameSync)(`${path}.tmp`, path);
19899
19937
  }
@@ -20267,7 +20305,7 @@ var LightningWatch = class {
20267
20305
 
20268
20306
  // src/core/tor-exits.ts
20269
20307
  var import_node_fs32 = require("fs");
20270
- var import_node_path24 = require("path");
20308
+ var import_node_path25 = require("path");
20271
20309
  var import_node_net12 = require("net");
20272
20310
  var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
20273
20311
  function parseTorExitList(text) {
@@ -20370,7 +20408,7 @@ var TorExitList = class _TorExitList {
20370
20408
  const before = this.exits.size;
20371
20409
  this.load(parsed);
20372
20410
  try {
20373
- (0, import_node_fs32.mkdirSync)((0, import_node_path24.dirname)(this.opts.cachePath), { recursive: true });
20411
+ (0, import_node_fs32.mkdirSync)((0, import_node_path25.dirname)(this.opts.cachePath), { recursive: true });
20374
20412
  (0, import_node_fs32.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
20375
20413
  (0, import_node_fs32.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
20376
20414
  } catch (err) {
@@ -20594,7 +20632,7 @@ var RuleEngine = class {
20594
20632
 
20595
20633
  // src/daemon/rules/loader.ts
20596
20634
  var import_node_fs33 = require("fs");
20597
- var import_node_path25 = require("path");
20635
+ var import_node_path26 = require("path");
20598
20636
 
20599
20637
  // src/daemon/rules/default-rules.ts
20600
20638
  var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
@@ -21243,7 +21281,7 @@ function loadAllRules(customDir) {
21243
21281
  const files = (0, import_node_fs33.readdirSync)(dir).filter((f) => f.endsWith(".json"));
21244
21282
  for (const file of files) {
21245
21283
  try {
21246
- const raw = (0, import_node_fs33.readFileSync)((0, import_node_path25.join)(dir, file), "utf-8");
21284
+ const raw = (0, import_node_fs33.readFileSync)((0, import_node_path26.join)(dir, file), "utf-8");
21247
21285
  const parsed = JSON.parse(raw);
21248
21286
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
21249
21287
  for (const rule of customRules) {
@@ -21276,7 +21314,7 @@ function loadAllRules(customDir) {
21276
21314
  // src/daemon/firewall/adapters.ts
21277
21315
  var import_node_child_process11 = require("child_process");
21278
21316
  var import_node_fs34 = require("fs");
21279
- var import_node_path26 = require("path");
21317
+ var import_node_path27 = require("path");
21280
21318
  var import_node_net13 = require("net");
21281
21319
  function assertValidFirewallIp(ip) {
21282
21320
  if ((0, import_node_net13.isIP)(ip) !== 4) {
@@ -21289,7 +21327,7 @@ function assertBannableIp(ip) {
21289
21327
  }
21290
21328
  }
21291
21329
  function writeIfAbsent(path, contents) {
21292
- (0, import_node_fs34.mkdirSync)((0, import_node_path26.dirname)(path), { recursive: true });
21330
+ (0, import_node_fs34.mkdirSync)((0, import_node_path27.dirname)(path), { recursive: true });
21293
21331
  try {
21294
21332
  (0, import_node_fs34.writeFileSync)(path, contents, { flag: "wx" });
21295
21333
  } catch (err) {
@@ -22186,12 +22224,12 @@ function remediationSettings(section) {
22186
22224
 
22187
22225
  // src/daemon/watchdog-service.ts
22188
22226
  var import_node_fs37 = require("fs");
22189
- var import_node_path28 = require("path");
22227
+ var import_node_path29 = require("path");
22190
22228
 
22191
22229
  // src/core/watchdog.ts
22192
22230
  var import_node_fs36 = require("fs");
22193
22231
  var import_node_crypto9 = require("crypto");
22194
- var import_node_path27 = require("path");
22232
+ var import_node_path28 = require("path");
22195
22233
  var WATCHDOG_DIRNAME = "watchdog";
22196
22234
  var LOG_FILE2 = "attacks.jsonl";
22197
22235
  var ROTATED_FILE = "attacks.1.jsonl";
@@ -22280,7 +22318,7 @@ var WatchdogLog = class {
22280
22318
  stats = { logged: 0, answered: 0, errored: 0 };
22281
22319
  constructor(dir, options = {}) {
22282
22320
  this.dir = dir;
22283
- this.file = (0, import_node_path27.join)(dir, LOG_FILE2);
22321
+ this.file = (0, import_node_path28.join)(dir, LOG_FILE2);
22284
22322
  this.shareGid = options.shareGid;
22285
22323
  (0, import_node_fs36.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
22286
22324
  if (this.shareGid !== void 0) {
@@ -22315,7 +22353,7 @@ var WatchdogLog = class {
22315
22353
  this.buffer = [];
22316
22354
  try {
22317
22355
  if ((0, import_node_fs36.statSync)(this.file).size > ROTATE_BYTES) {
22318
- (0, import_node_fs36.renameSync)(this.file, (0, import_node_path27.join)(this.dir, ROTATED_FILE));
22356
+ (0, import_node_fs36.renameSync)(this.file, (0, import_node_path28.join)(this.dir, ROTATED_FILE));
22319
22357
  }
22320
22358
  } catch {
22321
22359
  }
@@ -22373,7 +22411,7 @@ function defaultShareGid() {
22373
22411
  }
22374
22412
  }
22375
22413
  function startWatchdog(opts) {
22376
- const dir = opts.config?.dir ?? (0, import_node_path28.join)(opts.stateDir, WATCHDOG_DIRNAME);
22414
+ const dir = opts.config?.dir ?? (0, import_node_path29.join)(opts.stateDir, WATCHDOG_DIRNAME);
22377
22415
  const base = { dir, logged: 0, answered: 0, errored: 0 };
22378
22416
  if (opts.config?.enabled === false) {
22379
22417
  opts.log("[watchdog] off ([watchdog] enabled = false)");
@@ -22480,7 +22518,7 @@ function daemonNodeProblem(version) {
22480
22518
  // src/daemon/index.ts
22481
22519
  function readVersion2() {
22482
22520
  try {
22483
- const pkg = JSON.parse((0, import_node_fs38.readFileSync)((0, import_node_path29.join)(__dirname, "..", "package.json"), "utf-8"));
22521
+ const pkg = JSON.parse((0, import_node_fs38.readFileSync)((0, import_node_path30.join)(__dirname, "..", "package.json"), "utf-8"));
22484
22522
  return pkg.version || "0.0.0";
22485
22523
  } catch {
22486
22524
  return "0.0.0";
@@ -22489,7 +22527,7 @@ function readVersion2() {
22489
22527
  async function runHardeningChecks() {
22490
22528
  const { stdout } = await (0, import_node_util.promisify)(import_node_child_process14.execFile)(
22491
22529
  process.execPath,
22492
- [(0, import_node_path29.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
22530
+ [(0, import_node_path30.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
22493
22531
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
22494
22532
  );
22495
22533
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -22503,7 +22541,7 @@ async function runHardeningChecks() {
22503
22541
  async function runPatchCheck() {
22504
22542
  const { stdout } = await (0, import_node_util.promisify)(import_node_child_process14.execFile)(
22505
22543
  process.execPath,
22506
- [(0, import_node_path29.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
22544
+ [(0, import_node_path30.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
22507
22545
  { timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
22508
22546
  );
22509
22547
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -22553,7 +22591,7 @@ async function runDaemon() {
22553
22591
  } catch (err) {
22554
22592
  logLine(`[daemon] state db unavailable: ${err.message}`);
22555
22593
  }
22556
- const loaded = loadDaemonConfig(PATHS.configFile, (0, import_node_path29.join)(PATHS.stateDir, "threatcrushd.conf.last-good"));
22594
+ const loaded = loadDaemonConfig(PATHS.configFile, (0, import_node_path30.join)(PATHS.stateDir, "threatcrushd.conf.last-good"));
22557
22595
  const config = loaded.config;
22558
22596
  if (loaded.error) {
22559
22597
  logLine(`[daemon] CONFIG ERROR: ${loaded.error}; ${loaded.usedLastGood ? "running on the last config that parsed" : "no earlier good copy, running on DEFAULTS (no protected list)"}`);
@@ -22624,7 +22662,7 @@ async function runDaemon() {
22624
22662
  const threatFeeds = new ThreatFeeds({
22625
22663
  settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
22626
22664
  enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
22627
- cachePath: (0, import_node_path29.join)(PATHS.stateDir, "threat-feeds.json"),
22665
+ cachePath: (0, import_node_path30.join)(PATHS.stateDir, "threat-feeds.json"),
22628
22666
  bus,
22629
22667
  log: logLine
22630
22668
  });
@@ -22632,9 +22670,9 @@ async function runDaemon() {
22632
22670
  const privilegeWatch = new PrivilegeWatch({
22633
22671
  settings: privilegeSettings(config.privileged),
22634
22672
  bus,
22635
- snapshotPath: (0, import_node_path29.join)(PATHS.stateDir, "privileges.json"),
22636
- loginsPath: (0, import_node_path29.join)(PATHS.stateDir, "login-countries.json"),
22637
- cursorPath: (0, import_node_path29.join)(PATHS.stateDir, "sudo-cursor.json"),
22673
+ snapshotPath: (0, import_node_path30.join)(PATHS.stateDir, "privileges.json"),
22674
+ loginsPath: (0, import_node_path30.join)(PATHS.stateDir, "login-countries.json"),
22675
+ cursorPath: (0, import_node_path30.join)(PATHS.stateDir, "sudo-cursor.json"),
22638
22676
  log: logLine
22639
22677
  });
22640
22678
  privilegeWatch.start();
@@ -22648,20 +22686,20 @@ async function runDaemon() {
22648
22686
  const fileIntegrity = new FileIntegrityWatch({
22649
22687
  bus,
22650
22688
  settings: fileIntegritySettings(config.file_integrity),
22651
- baselinePath: (0, import_node_path29.join)(PATHS.stateDir, "file-integrity-baseline.json"),
22652
- observedPath: (0, import_node_path29.join)(PATHS.stateDir, "file-integrity-observed.json"),
22689
+ baselinePath: (0, import_node_path30.join)(PATHS.stateDir, "file-integrity-baseline.json"),
22690
+ observedPath: (0, import_node_path30.join)(PATHS.stateDir, "file-integrity-observed.json"),
22653
22691
  log: logLine
22654
22692
  });
22655
22693
  fileIntegrity.start();
22656
22694
  const edr = new EdrWatch({
22657
22695
  bus,
22658
22696
  settings: edrSettings(config.edr),
22659
- networkBaselinePath: (0, import_node_path29.join)(PATHS.stateDir, "edr-outbound-executables.json"),
22697
+ networkBaselinePath: (0, import_node_path30.join)(PATHS.stateDir, "edr-outbound-executables.json"),
22660
22698
  log: logLine
22661
22699
  });
22662
22700
  edr.start();
22663
22701
  const torExits = new TorExitList({
22664
- cachePath: (0, import_node_path29.join)(PATHS.stateDir, "tor-exits.txt"),
22702
+ cachePath: (0, import_node_path30.join)(PATHS.stateDir, "tor-exits.txt"),
22665
22703
  url: config.remediation?.tor_exit_list_url,
22666
22704
  log: logLine
22667
22705
  });
@@ -22669,7 +22707,7 @@ async function runDaemon() {
22669
22707
  bus,
22670
22708
  manager: remediation,
22671
22709
  tor: torExits,
22672
- historyPath: (0, import_node_path29.join)(PATHS.stateDir, "key-logins.json"),
22710
+ historyPath: (0, import_node_path30.join)(PATHS.stateDir, "key-logins.json"),
22673
22711
  keyLoginWatch: config.privileged?.key_login_watch !== false,
22674
22712
  log: logLine
22675
22713
  });
@@ -22716,7 +22754,7 @@ async function runDaemon() {
22716
22754
  version,
22717
22755
  hostname: (0, import_node_os6.hostname)(),
22718
22756
  minSeverity,
22719
- spoolPath: (0, import_node_path29.join)(PATHS.stateDir, "cloud-spool.jsonl"),
22757
+ spoolPath: (0, import_node_path30.join)(PATHS.stateDir, "cloud-spool.jsonl"),
22720
22758
  log: logLine,
22721
22759
  ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
22722
22760
  runHardening: runHardeningChecks
@@ -22749,8 +22787,8 @@ async function runDaemon() {
22749
22787
  const autoUpdate = autoUpdateRef = new AutoUpdate({
22750
22788
  version,
22751
22789
  settings: updateSettings(config.update),
22752
- pkgRoot: (0, import_node_path29.join)(__dirname, ".."),
22753
- statePath: (0, import_node_path29.join)(PATHS.stateDir, "auto-update.json"),
22790
+ pkgRoot: (0, import_node_path30.join)(__dirname, ".."),
22791
+ statePath: (0, import_node_path30.join)(PATHS.stateDir, "auto-update.json"),
22754
22792
  bus,
22755
22793
  log: logLine,
22756
22794
  restartDaemon