@profullstack/threatcrush 0.13.79 → 0.13.80

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
@@ -23786,7 +23786,7 @@ var source_default = chalk;
23786
23786
 
23787
23787
  // src/index.ts
23788
23788
  var import_readline = __toESM(require("readline"));
23789
- var import_node_child_process29 = require("child_process");
23789
+ var import_node_child_process30 = require("child_process");
23790
23790
  var import_node_fs76 = require("fs");
23791
23791
  var import_node_path58 = require("path");
23792
23792
  var import_node_os24 = require("os");
@@ -43431,14 +43431,14 @@ async function sshConnect(options) {
43431
43431
  }
43432
43432
 
43433
43433
  // src/commands/daemon.ts
43434
- var import_node_child_process21 = require("child_process");
43434
+ var import_node_child_process22 = require("child_process");
43435
43435
  var import_node_fs60 = require("fs");
43436
43436
  var import_node_path47 = require("path");
43437
43437
  var import_node_fs61 = require("fs");
43438
43438
 
43439
43439
  // src/daemon/index.ts
43440
43440
  var import_node_fs59 = require("fs");
43441
- var import_node_child_process20 = require("child_process");
43441
+ var import_node_child_process21 = require("child_process");
43442
43442
  var import_node_os19 = require("os");
43443
43443
  var import_node_path46 = require("path");
43444
43444
  var import_node_util4 = require("util");
@@ -50184,6 +50184,10 @@ var TorExitList = class _TorExitList {
50184
50184
  get size() {
50185
50185
  return this.exits.size;
50186
50186
  }
50187
+ /** Every exit address currently in memory, for the proactive firewall block. */
50188
+ values() {
50189
+ return [...this.exits];
50190
+ }
50187
50191
  /** When the list in memory was downloaded (ms), 0 if never. */
50188
50192
  get updated() {
50189
50193
  return this.updatedAt;
@@ -50241,6 +50245,88 @@ var TorExitList = class _TorExitList {
50241
50245
  }
50242
50246
  };
50243
50247
 
50248
+ // src/daemon/firewall/tor-block.ts
50249
+ var import_node_child_process17 = require("child_process");
50250
+ var import_node_net17 = require("net");
50251
+ var TOR_NFT_TABLE = "threatcrush-tor";
50252
+ function defaultNftRunner() {
50253
+ return (args, stdin) => new Promise((resolve9, reject) => {
50254
+ const child = (0, import_node_child_process17.execFile)(
50255
+ "nft",
50256
+ args,
50257
+ { maxBuffer: 16 * 1024 * 1024 },
50258
+ (err) => err ? reject(err) : resolve9()
50259
+ );
50260
+ if (stdin !== void 0) child.stdin?.end(stdin);
50261
+ });
50262
+ }
50263
+ var TorExitBlockEnforcer = class {
50264
+ constructor(opts) {
50265
+ this.opts = opts;
50266
+ this.runNft = opts.runNft ?? defaultNftRunner();
50267
+ this.log = opts.log ?? (() => {
50268
+ });
50269
+ this.intervalMs = Math.max(6e4, opts.intervalMs ?? 36e5);
50270
+ this.sshPort = opts.sshPort ?? 22;
50271
+ }
50272
+ opts;
50273
+ timer = null;
50274
+ applied = false;
50275
+ runNft;
50276
+ log;
50277
+ intervalMs;
50278
+ sshPort;
50279
+ start() {
50280
+ void this.sync();
50281
+ this.timer = setInterval(() => void this.sync(), this.intervalMs);
50282
+ this.timer.unref?.();
50283
+ }
50284
+ stop() {
50285
+ if (this.timer) clearInterval(this.timer);
50286
+ this.timer = null;
50287
+ }
50288
+ /** Apply (or tear down) the block to match the current setting and list. */
50289
+ async sync() {
50290
+ if (!this.opts.enabled()) {
50291
+ await this.teardown();
50292
+ return;
50293
+ }
50294
+ const ipv4 = this.opts.exits.values().filter((ip) => (0, import_node_net17.isIP)(ip) === 4);
50295
+ if (ipv4.length === 0) return;
50296
+ try {
50297
+ await this.apply(ipv4);
50298
+ if (!this.applied) {
50299
+ this.log(`[tor] proactively blocking ${ipv4.length} Tor exits on tcp/${this.sshPort} (table inet ${TOR_NFT_TABLE})`);
50300
+ }
50301
+ this.applied = true;
50302
+ } catch (err) {
50303
+ this.log(`[tor] could not apply the proactive Tor exit block: ${err.message}`);
50304
+ }
50305
+ }
50306
+ /** One atomic `nft -f -` transaction: declare the table, then load the set. */
50307
+ async apply(ipv4) {
50308
+ const t = TOR_NFT_TABLE;
50309
+ const ruleset = `add table inet ${t}
50310
+ add set inet ${t} exits { type ipv4_addr; }
50311
+ add chain inet ${t} input { type filter hook input priority -100 ; policy accept ; }
50312
+ flush chain inet ${t} input
50313
+ add rule inet ${t} input tcp dport ${this.sshPort} ip saddr @exits counter drop
50314
+ flush set inet ${t} exits
50315
+ add element inet ${t} exits { ${ipv4.join(", ")} }
50316
+ `;
50317
+ await this.runNft(["-f", "-"], ruleset);
50318
+ }
50319
+ async teardown() {
50320
+ if (!this.applied) return;
50321
+ try {
50322
+ await this.runNft(["delete", "table", "inet", TOR_NFT_TABLE]);
50323
+ this.log("[tor] removed the proactive Tor exit block (block_tor_ssh off)");
50324
+ } catch {
50325
+ }
50326
+ this.applied = false;
50327
+ }
50328
+ };
50329
+
50244
50330
  // src/daemon/rules/engine.ts
50245
50331
  var MAX_WINDOW_ENTRIES = 1e3;
50246
50332
  function live(window) {
@@ -51166,17 +51252,17 @@ function loadAllRules(customDir) {
51166
51252
  }
51167
51253
 
51168
51254
  // src/daemon/firewall/adapters.ts
51169
- var import_node_child_process17 = require("child_process");
51255
+ var import_node_child_process18 = require("child_process");
51170
51256
  var import_node_fs56 = require("fs");
51171
51257
  var import_node_path44 = require("path");
51172
- var import_node_net17 = require("net");
51258
+ var import_node_net18 = require("net");
51173
51259
  function assertValidFirewallIp(ip) {
51174
- if ((0, import_node_net17.isIP)(ip) !== 4) {
51260
+ if ((0, import_node_net18.isIP)(ip) !== 4) {
51175
51261
  throw new Error(`Invalid IPv4 address: ${ip}`);
51176
51262
  }
51177
51263
  }
51178
51264
  function assertBannableIp(ip) {
51179
- if ((0, import_node_net17.isIP)(ip) === 0) {
51265
+ if ((0, import_node_net18.isIP)(ip) === 0) {
51180
51266
  throw new Error(`Invalid IP address: ${ip}`);
51181
51267
  }
51182
51268
  }
@@ -51202,11 +51288,11 @@ var Fail2banAdapter = class {
51202
51288
  enforces = true;
51203
51289
  jailReady = false;
51204
51290
  isAvailable() {
51205
- const result = (0, import_node_child_process17.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
51291
+ const result = (0, import_node_child_process18.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
51206
51292
  return result.status === 0;
51207
51293
  }
51208
51294
  client(args) {
51209
- return (0, import_node_child_process17.execFileSync)("fail2ban-client", args, {
51295
+ return (0, import_node_child_process18.execFileSync)("fail2ban-client", args, {
51210
51296
  encoding: "utf-8",
51211
51297
  stdio: ["ignore", "pipe", "pipe"]
51212
51298
  });
@@ -51282,7 +51368,7 @@ var Fail2banAdapter = class {
51282
51368
  const status = this.client(["status", this.jail]);
51283
51369
  const line2 = status.split("\n").find((l) => /Banned IP list:/i.test(l));
51284
51370
  if (!line2) return [];
51285
- return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net17.isIP)(s) !== 0);
51371
+ return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net18.isIP)(s) !== 0);
51286
51372
  } catch {
51287
51373
  return [];
51288
51374
  }
@@ -51292,45 +51378,45 @@ var Fail2banAdapter = class {
51292
51378
  function parseBannedList(output) {
51293
51379
  const found = [];
51294
51380
  for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
51295
- if ((0, import_node_net17.isIP)(match[1]) !== 0) found.push(match[1]);
51381
+ if ((0, import_node_net18.isIP)(match[1]) !== 0) found.push(match[1]);
51296
51382
  }
51297
51383
  if (found.length > 0) return found;
51298
- return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net17.isIP)(s) !== 0);
51384
+ return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net18.isIP)(s) !== 0);
51299
51385
  }
51300
51386
  var NftablesAdapter = class {
51301
51387
  name = "nftables";
51302
51388
  table = "threatcrush";
51303
51389
  set = "blocklist";
51304
51390
  isAvailable() {
51305
- const result = (0, import_node_child_process17.spawnSync)("nft", ["--version"], { stdio: "pipe" });
51391
+ const result = (0, import_node_child_process18.spawnSync)("nft", ["--version"], { stdio: "pipe" });
51306
51392
  return result.status === 0;
51307
51393
  }
51308
51394
  ensureSetup() {
51309
51395
  try {
51310
- (0, import_node_child_process17.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
51396
+ (0, import_node_child_process18.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
51311
51397
  } catch {
51312
- (0, import_node_child_process17.execSync)(`nft add table inet ${this.table}`);
51313
- (0, import_node_child_process17.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
51314
- (0, import_node_child_process17.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
51315
- (0, import_node_child_process17.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
51398
+ (0, import_node_child_process18.execSync)(`nft add table inet ${this.table}`);
51399
+ (0, import_node_child_process18.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
51400
+ (0, import_node_child_process18.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
51401
+ (0, import_node_child_process18.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
51316
51402
  }
51317
51403
  }
51318
51404
  async block(ip) {
51319
51405
  assertValidFirewallIp(ip);
51320
51406
  this.ensureSetup();
51321
- (0, import_node_child_process17.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
51407
+ (0, import_node_child_process18.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
51322
51408
  }
51323
51409
  async unblock(ip) {
51324
51410
  assertValidFirewallIp(ip);
51325
51411
  try {
51326
- (0, import_node_child_process17.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
51412
+ (0, import_node_child_process18.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
51327
51413
  } catch {
51328
51414
  }
51329
51415
  }
51330
51416
  async isBlocked(ip) {
51331
51417
  assertValidFirewallIp(ip);
51332
51418
  try {
51333
- const output = (0, import_node_child_process17.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
51419
+ const output = (0, import_node_child_process18.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
51334
51420
  return output.includes(ip);
51335
51421
  } catch {
51336
51422
  return false;
@@ -51338,7 +51424,7 @@ var NftablesAdapter = class {
51338
51424
  }
51339
51425
  async listBlocked() {
51340
51426
  try {
51341
- const output = (0, import_node_child_process17.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
51427
+ const output = (0, import_node_child_process18.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
51342
51428
  const match = output.match(/elements\s*=\s*\{([^}]*)\}/);
51343
51429
  if (!match) return [];
51344
51430
  return match[1].split(",").map((s) => s.trim().split(/\s/)[0]).filter(Boolean);
@@ -51351,34 +51437,34 @@ var IptablesAdapter = class {
51351
51437
  name = "iptables";
51352
51438
  chain = "THREATCRUSH";
51353
51439
  isAvailable() {
51354
- const result = (0, import_node_child_process17.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
51440
+ const result = (0, import_node_child_process18.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
51355
51441
  return result.status === 0;
51356
51442
  }
51357
51443
  ensureChain() {
51358
51444
  try {
51359
- (0, import_node_child_process17.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
51445
+ (0, import_node_child_process18.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
51360
51446
  } catch {
51361
- (0, import_node_child_process17.execSync)(`iptables -N ${this.chain}`);
51362
- (0, import_node_child_process17.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
51447
+ (0, import_node_child_process18.execSync)(`iptables -N ${this.chain}`);
51448
+ (0, import_node_child_process18.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
51363
51449
  }
51364
51450
  }
51365
51451
  async block(ip) {
51366
51452
  assertValidFirewallIp(ip);
51367
51453
  this.ensureChain();
51368
51454
  if (await this.isBlocked(ip)) return;
51369
- (0, import_node_child_process17.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
51455
+ (0, import_node_child_process18.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
51370
51456
  }
51371
51457
  async unblock(ip) {
51372
51458
  assertValidFirewallIp(ip);
51373
51459
  try {
51374
- (0, import_node_child_process17.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
51460
+ (0, import_node_child_process18.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
51375
51461
  } catch {
51376
51462
  }
51377
51463
  }
51378
51464
  async isBlocked(ip) {
51379
51465
  assertValidFirewallIp(ip);
51380
51466
  try {
51381
- const output = (0, import_node_child_process17.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
51467
+ const output = (0, import_node_child_process18.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
51382
51468
  return output.includes(ip);
51383
51469
  } catch {
51384
51470
  return false;
@@ -51386,7 +51472,7 @@ var IptablesAdapter = class {
51386
51472
  }
51387
51473
  async listBlocked() {
51388
51474
  try {
51389
- const output = (0, import_node_child_process17.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
51475
+ const output = (0, import_node_child_process18.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
51390
51476
  const ips = [];
51391
51477
  for (const line2 of output.split("\n")) {
51392
51478
  const match = line2.match(/DROP\s+all\s+--\s+(\d+\.\d+\.\d+\.\d+)/);
@@ -51443,8 +51529,8 @@ function detectFirewallAdapter(backend = "auto") {
51443
51529
 
51444
51530
  // src/daemon/firewall/remediation.ts
51445
51531
  var import_node_fs57 = require("fs");
51446
- var import_node_child_process18 = require("child_process");
51447
- var import_node_net18 = require("net");
51532
+ var import_node_child_process19 = require("child_process");
51533
+ var import_node_net19 = require("net");
51448
51534
  init_paths();
51449
51535
  init_backoff();
51450
51536
 
@@ -51535,7 +51621,7 @@ var defaultDiscovery = {
51535
51621
  return out;
51536
51622
  },
51537
51623
  keyLoginJournal: (sinceSeconds) => new Promise((resolve9) => {
51538
- (0, import_node_child_process18.execFile)(
51624
+ (0, import_node_child_process19.execFile)(
51539
51625
  "journalctl",
51540
51626
  ["_COMM=sshd", "_COMM=sshd-session", `--since=-${Math.ceil(sinceSeconds / 86400)}d`, "-o", "short-unix", "--no-pager", "--grep", "Accepted publickey"],
51541
51627
  { maxBuffer: 32 * 1024 * 1024, timeout: 6e4 },
@@ -51615,7 +51701,7 @@ var RemediationManager = class {
51615
51701
  setTorExitCheck(check2) {
51616
51702
  this.isTorExit = check2;
51617
51703
  let dropped = 0;
51618
- this.protectedList = this.protectedList.filter((a) => !(0, import_node_net18.isIP)(a) || !check2(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
51704
+ this.protectedList = this.protectedList.filter((a) => !(0, import_node_net19.isIP)(a) || !check2(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
51619
51705
  for (const ip of Object.keys(this.operators)) {
51620
51706
  if (!check2(ip)) continue;
51621
51707
  delete this.operators[ip];
@@ -51708,7 +51794,7 @@ var RemediationManager = class {
51708
51794
  if (remediation?.action !== "block") return;
51709
51795
  }
51710
51796
  const ip = event.source_ip;
51711
- if (!ip || (0, import_node_net18.isIP)(ip) === 0) return;
51797
+ if (!ip || (0, import_node_net19.isIP)(ip) === 0) return;
51712
51798
  const strict = remediation?.override_operator_protection === true;
51713
51799
  if (strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
51714
51800
  if (strict) this.logLine(`[remediation] not banning ${ip}: it is one of our own addresses (${event.message})`);
@@ -51737,7 +51823,7 @@ var RemediationManager = class {
51737
51823
  * 4th offence and so on, clamped to `max_ban_seconds`.
51738
51824
  */
51739
51825
  async ban(ip, reason, opts = {}) {
51740
- if ((0, import_node_net18.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
51826
+ if ((0, import_node_net19.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
51741
51827
  if (opts.strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
51742
51828
  return { ok: false, error: `${ip} is protected and can never be blocked` };
51743
51829
  }
@@ -52014,7 +52100,7 @@ var RemediationManager = class {
52014
52100
  if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
52015
52101
  const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
52016
52102
  for (const [ip, at] of Object.entries(saved)) {
52017
- if (typeof at !== "number" || at < cutoff || !(0, import_node_net18.isIP)(ip)) continue;
52103
+ if (typeof at !== "number" || at < cutoff || !(0, import_node_net19.isIP)(ip)) continue;
52018
52104
  if (this.blocklist.some((b) => b.ip === ip && b.strict)) continue;
52019
52105
  this.operators[ip] = at;
52020
52106
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
@@ -52189,7 +52275,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
52189
52275
  }
52190
52276
 
52191
52277
  // src/core/node-runtime.ts
52192
- var import_node_child_process19 = require("child_process");
52278
+ var import_node_child_process20 = require("child_process");
52193
52279
  var MIN_DAEMON_NODE_MAJOR = 22;
52194
52280
  function nodeMajor(version) {
52195
52281
  const m = String(version ?? "").trim().replace(/^v/, "").match(/^(\d+)\./);
@@ -52203,7 +52289,7 @@ function daemonNodeProblem(version) {
52203
52289
  }
52204
52290
  function versionOfNode(path2) {
52205
52291
  if (path2 === process.execPath) return process.versions.node;
52206
- const res = (0, import_node_child_process19.spawnSync)(path2, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
52292
+ const res = (0, import_node_child_process20.spawnSync)(path2, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
52207
52293
  return res.status === 0 ? res.stdout.trim() : null;
52208
52294
  }
52209
52295
 
@@ -52217,7 +52303,7 @@ function readVersion2() {
52217
52303
  }
52218
52304
  }
52219
52305
  async function runHardeningChecks() {
52220
- const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process20.execFile)(
52306
+ const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process21.execFile)(
52221
52307
  process.execPath,
52222
52308
  [(0, import_node_path46.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
52223
52309
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
@@ -52231,7 +52317,7 @@ async function runHardeningChecks() {
52231
52317
  return patches ? [...findings2, patches] : findings2;
52232
52318
  }
52233
52319
  async function runPatchCheck() {
52234
- const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process20.execFile)(
52320
+ const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process21.execFile)(
52235
52321
  process.execPath,
52236
52322
  [(0, import_node_path46.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
52237
52323
  { timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
@@ -52266,9 +52352,9 @@ async function runDaemon() {
52266
52352
  logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
52267
52353
  const restartDaemon = () => {
52268
52354
  if (PATHS.mode === "system") {
52269
- (0, import_node_child_process20.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
52355
+ (0, import_node_child_process21.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
52270
52356
  } else {
52271
- (0, import_node_child_process20.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
52357
+ (0, import_node_child_process21.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
52272
52358
  setTimeout(() => process.exit(0), 500).unref();
52273
52359
  }
52274
52360
  };
@@ -52404,6 +52490,12 @@ async function runDaemon() {
52404
52490
  log: logLine
52405
52491
  });
52406
52492
  sshIntrusion.start();
52493
+ const torBlock = new TorExitBlockEnforcer({
52494
+ exits: torExits,
52495
+ enabled: () => remediation.blockTorSsh && firewallAdapter.name === "nftables",
52496
+ log: logLine
52497
+ });
52498
+ torBlock.start();
52407
52499
  const lightningWatch = new LightningWatch({
52408
52500
  bus,
52409
52501
  enabled: config.lightning?.enabled !== false,
@@ -52474,6 +52566,7 @@ async function runDaemon() {
52474
52566
  if (torPinned || typeof block_tor_ssh !== "boolean" || block_tor_ssh === remediation.blockTorSsh) return;
52475
52567
  remediation.setBlockTorSsh(block_tor_ssh);
52476
52568
  logLine(`[ssh-intrusion] Tor SSH ban ${block_tor_ssh ? "ON" : "OFF"} (org setting from the dashboard)`);
52569
+ void torBlock.sync();
52477
52570
  }
52478
52571
  });
52479
52572
  allowlistSync.start();
@@ -52644,7 +52737,7 @@ async function daemonStart() {
52644
52737
  }
52645
52738
  return;
52646
52739
  }
52647
- const child = (0, import_node_child_process21.spawn)(process.execPath, [DAEMON_ENTRY], {
52740
+ const child = (0, import_node_child_process22.spawn)(process.execPath, [DAEMON_ENTRY], {
52648
52741
  detached: true,
52649
52742
  stdio: ["ignore", out, err],
52650
52743
  env: { ...process.env, THREATCRUSH_DAEMON: "1" }
@@ -52731,7 +52824,7 @@ async function releaseStaleSocket() {
52731
52824
  }
52732
52825
 
52733
52826
  // src/commands/service.ts
52734
- var import_node_child_process22 = require("child_process");
52827
+ var import_node_child_process23 = require("child_process");
52735
52828
  var import_node_fs62 = require("fs");
52736
52829
  var import_node_path48 = require("path");
52737
52830
  var import_node_os20 = require("os");
@@ -52753,7 +52846,7 @@ function resolveBinPath() {
52753
52846
  const arg = process.argv[1];
52754
52847
  if (arg && (0, import_node_fs62.existsSync)(arg)) return stableBinPath(arg);
52755
52848
  try {
52756
- return (0, import_node_child_process22.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
52849
+ return (0, import_node_child_process23.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
52757
52850
  } catch {
52758
52851
  return "threatcrush";
52759
52852
  }
@@ -52792,18 +52885,18 @@ function isRoot3() {
52792
52885
  return typeof process.getuid === "function" && process.getuid() === 0;
52793
52886
  }
52794
52887
  function reexecWithSudo(args) {
52795
- if ((0, import_node_child_process22.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
52888
+ if ((0, import_node_child_process23.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
52796
52889
  console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
52797
52890
  const bin = resolveBinPath();
52798
52891
  const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
52799
- const result = (0, import_node_child_process22.spawnSync)("sudo", argv, { stdio: "inherit" });
52892
+ const result = (0, import_node_child_process23.spawnSync)("sudo", argv, { stdio: "inherit" });
52800
52893
  return result.status === 0;
52801
52894
  }
52802
52895
  function callerHome() {
52803
52896
  const user = process.env.SUDO_USER;
52804
52897
  if (!user) return null;
52805
52898
  try {
52806
- const line2 = (0, import_node_child_process22.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
52899
+ const line2 = (0, import_node_child_process23.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
52807
52900
  const home = line2.split(":")[5];
52808
52901
  return home && (0, import_node_fs62.existsSync)(home) ? home : null;
52809
52902
  } catch {
@@ -52838,7 +52931,7 @@ function stopUserModeDaemon() {
52838
52931
  }
52839
52932
  }
52840
52933
  function unitIsActive() {
52841
- const result = (0, import_node_child_process22.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
52934
+ const result = (0, import_node_child_process23.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
52842
52935
  return result.status === 0;
52843
52936
  }
52844
52937
  async function installServiceCommand() {
@@ -52849,7 +52942,7 @@ async function installServiceCommand() {
52849
52942
  return;
52850
52943
  }
52851
52944
  const noSystemd = systemdUnavailableReason({
52852
- hasSystemctl: (0, import_node_child_process22.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
52945
+ hasSystemctl: (0, import_node_child_process23.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
52853
52946
  booted: (0, import_node_fs62.existsSync)("/run/systemd/system")
52854
52947
  });
52855
52948
  if (noSystemd) {
@@ -52904,8 +52997,8 @@ async function installServiceCommand() {
52904
52997
  installLogrotate();
52905
52998
  stopUserModeDaemon();
52906
52999
  try {
52907
- (0, import_node_child_process22.execSync)("systemctl daemon-reload", { stdio: "inherit" });
52908
- (0, import_node_child_process22.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
53000
+ (0, import_node_child_process23.execSync)("systemctl daemon-reload", { stdio: "inherit" });
53001
+ (0, import_node_child_process23.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
52909
53002
  } catch (err) {
52910
53003
  console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
52911
53004
  console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
@@ -52977,7 +53070,7 @@ function ensureSystemDirs(configDir) {
52977
53070
  try {
52978
53071
  if (groupWritable && admGid2 !== null) {
52979
53072
  (0, import_node_fs62.chmodSync)(path2, sticky ? 1533 : 509);
52980
- (0, import_node_child_process22.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
53073
+ (0, import_node_child_process23.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
52981
53074
  } else {
52982
53075
  (0, import_node_fs62.chmodSync)(path2, 493);
52983
53076
  }
@@ -52999,22 +53092,22 @@ async function uninstallServiceCommand() {
52999
53092
  return;
53000
53093
  }
53001
53094
  try {
53002
- (0, import_node_child_process22.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
53095
+ (0, import_node_child_process23.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
53003
53096
  } catch {
53004
53097
  }
53005
53098
  try {
53006
- (0, import_node_child_process22.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
53099
+ (0, import_node_child_process23.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
53007
53100
  } catch {
53008
53101
  }
53009
53102
  try {
53010
53103
  if ((0, import_node_fs62.existsSync)(UNIT_PATH)) {
53011
- (0, import_node_child_process22.execSync)(`rm -f ${UNIT_PATH}`);
53104
+ (0, import_node_child_process23.execSync)(`rm -f ${UNIT_PATH}`);
53012
53105
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
53013
53106
  }
53014
53107
  } catch {
53015
53108
  }
53016
53109
  try {
53017
- (0, import_node_child_process22.execSync)("systemctl daemon-reload", { stdio: "inherit" });
53110
+ (0, import_node_child_process23.execSync)("systemctl daemon-reload", { stdio: "inherit" });
53018
53111
  } catch {
53019
53112
  }
53020
53113
  console.log(source_default.green(" \u2713 threatcrushd service removed."));
@@ -53750,7 +53843,7 @@ async function rulesCommand(opts) {
53750
53843
 
53751
53844
  // src/commands/harden.ts
53752
53845
  var import_node_fs66 = require("fs");
53753
- var import_node_child_process23 = require("child_process");
53846
+ var import_node_child_process24 = require("child_process");
53754
53847
  init_cli_config();
53755
53848
 
53756
53849
  // src/commands/cis-report.ts
@@ -53961,7 +54054,7 @@ function writeCisReport(path2, format2, report) {
53961
54054
  // src/commands/harden.ts
53962
54055
  function tryExec(cmd) {
53963
54056
  try {
53964
- return (0, import_node_child_process23.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
54057
+ return (0, import_node_child_process24.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
53965
54058
  } catch {
53966
54059
  return null;
53967
54060
  }
@@ -54431,7 +54524,7 @@ async function hardenCommand(opts) {
54431
54524
  // src/core/patches/index.ts
54432
54525
  var import_node_fs67 = require("fs");
54433
54526
  var import_node_path50 = require("path");
54434
- var import_node_child_process24 = require("child_process");
54527
+ var import_node_child_process25 = require("child_process");
54435
54528
  var import_node_util5 = require("util");
54436
54529
 
54437
54530
  // src/core/patches/dpkg-version.ts
@@ -54491,7 +54584,7 @@ var STALE_AFTER_MS = 2 * 864e5;
54491
54584
  var SEVERITIES2 = ["info", "low", "medium", "high", "critical"];
54492
54585
  var RANK = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
54493
54586
  var defaultExec = async (file, args) => {
54494
- const { stdout } = await (0, import_node_util5.promisify)(import_node_child_process24.execFile)(file, args, {
54587
+ const { stdout } = await (0, import_node_util5.promisify)(import_node_child_process25.execFile)(file, args, {
54495
54588
  timeout: 12e4,
54496
54589
  maxBuffer: 32 * 1024 * 1024,
54497
54590
  env: { ...process.env, LC_ALL: "C" }
@@ -54835,12 +54928,12 @@ async function patchesCommand(opts) {
54835
54928
  }
54836
54929
 
54837
54930
  // src/commands/feeds.ts
54838
- var import_node_net19 = require("net");
54931
+ var import_node_net20 = require("net");
54839
54932
  var import_node_path52 = require("path");
54840
54933
  init_paths();
54841
54934
 
54842
54935
  // src/commands/feeds-resolver.ts
54843
- var import_node_child_process25 = require("child_process");
54936
+ var import_node_child_process26 = require("child_process");
54844
54937
  var import_node_fs68 = require("fs");
54845
54938
  var import_node_path51 = require("path");
54846
54939
  var realIO = {
@@ -54855,7 +54948,7 @@ var realIO = {
54855
54948
  write: (p, c) => (0, import_node_fs68.writeFileSync)(p, c),
54856
54949
  remove: (p) => (0, import_node_fs68.rmSync)(p, { force: true }),
54857
54950
  run: (cmd, args) => {
54858
- const r = (0, import_node_child_process25.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
54951
+ const r = (0, import_node_child_process26.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
54859
54952
  return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
54860
54953
  }
54861
54954
  };
@@ -54979,8 +55072,8 @@ async function feedsCommand(action, value, opts) {
54979
55072
  process.exitCode = 2;
54980
55073
  return;
54981
55074
  }
54982
- const ipHit = (0, import_node_net19.isIP)(value) ? matchIp(value, set) : null;
54983
- const domainHit = (0, import_node_net19.isIP)(value) ? null : matchDomain(value, set);
55075
+ const ipHit = (0, import_node_net20.isIP)(value) ? matchIp(value, set) : null;
55076
+ const domainHit = (0, import_node_net20.isIP)(value) ? null : matchDomain(value, set);
54984
55077
  const listed = ipHit ?? domainHit?.indicator ?? null;
54985
55078
  if (opts.json) {
54986
55079
  console.log(JSON.stringify({ value, listed: Boolean(listed), indicator: listed, matched: domainHit?.domain ?? (ipHit ? value : null), fetched_at: set.fetched_at }, null, 2));
@@ -55009,7 +55102,7 @@ async function feedsCommand(action, value, opts) {
55009
55102
 
55010
55103
  // src/commands/tor.ts
55011
55104
  var import_node_fs69 = require("fs");
55012
- var import_node_net20 = require("net");
55105
+ var import_node_net21 = require("net");
55013
55106
  var import_node_path53 = require("path");
55014
55107
  init_paths();
55015
55108
  async function torCommand(action, value, opts) {
@@ -55041,7 +55134,7 @@ async function torCommand(action, value, opts) {
55041
55134
  const remediation = loadConfig((0, import_node_path53.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).remediation;
55042
55135
  const ban = remediation?.block_tor_ssh !== false && remediation?.enabled !== false;
55043
55136
  if (action === "check") {
55044
- if (!value || !(0, import_node_net20.isIP)(value)) {
55137
+ if (!value || !(0, import_node_net21.isIP)(value)) {
55045
55138
  console.error("Usage: threatcrush tor check <ip>");
55046
55139
  process.exitCode = 2;
55047
55140
  return;
@@ -55433,7 +55526,7 @@ init_paths();
55433
55526
 
55434
55527
  // src/daemon/auditd/rules.ts
55435
55528
  var import_node_fs73 = require("fs");
55436
- var import_node_child_process26 = require("child_process");
55529
+ var import_node_child_process27 = require("child_process");
55437
55530
  var import_node_path56 = require("path");
55438
55531
  var WEB_TOOLS = ["sh", "bash", "dash", "zsh", "curl", "wget"];
55439
55532
  var MINER_NAMES = ["xmrig", "minerd", "cpuminer", "cpuminer-multi", "kdevtmpfsi", "kinsing", "cryptonight"];
@@ -55442,7 +55535,7 @@ var LISTEN_KEY2 = "threatcrush_edr_listen";
55442
55535
  function passwdByName() {
55443
55536
  let raw = "";
55444
55537
  try {
55445
- raw = (0, import_node_child_process26.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
55538
+ raw = (0, import_node_child_process27.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
55446
55539
  } catch {
55447
55540
  try {
55448
55541
  raw = (0, import_node_fs73.readFileSync)("/etc/passwd", "utf8");
@@ -55807,11 +55900,11 @@ function abuseStatusCommand(opts = {}) {
55807
55900
  init_paths();
55808
55901
 
55809
55902
  // src/upgrade.ts
55810
- var import_node_child_process27 = require("child_process");
55903
+ var import_node_child_process28 = require("child_process");
55811
55904
  var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
55812
55905
  var defaultRunner = (cmd) => {
55813
55906
  try {
55814
- return (0, import_node_child_process27.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
55907
+ return (0, import_node_child_process28.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
55815
55908
  } catch {
55816
55909
  return null;
55817
55910
  }
@@ -55952,7 +56045,7 @@ function installUserAgent(target = globalThis) {
55952
56045
  }
55953
56046
 
55954
56047
  // src/core/cloud-upload.ts
55955
- var import_node_child_process28 = require("child_process");
56048
+ var import_node_child_process29 = require("child_process");
55956
56049
  var import_node_os23 = require("os");
55957
56050
  var import_node_path57 = require("path");
55958
56051
  init_cli_config();
@@ -55973,7 +56066,7 @@ function cleanUrl(raw) {
55973
56066
  return raw.split(/[?#]/)[0];
55974
56067
  }
55975
56068
  }
55976
- function repoTarget(path2, run2 = (args) => (0, import_node_child_process28.execFileSync)("git", args, { cwd: (0, import_node_path57.resolve)(path2), encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }).trim()) {
56069
+ function repoTarget(path2, run2 = (args) => (0, import_node_child_process29.execFileSync)("git", args, { cwd: (0, import_node_path57.resolve)(path2), encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }).trim()) {
55977
56070
  const abs = (0, import_node_path57.resolve)(path2);
55978
56071
  try {
55979
56072
  const root = run2(["rev-parse", "--show-toplevel"]);
@@ -56349,22 +56442,22 @@ var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
56349
56442
  var INSTALL_CONFIG_PATH = (0, import_node_path58.join)((0, import_node_os24.homedir)(), ".threatcrush", "install.json");
56350
56443
  function detectPackageManager() {
56351
56444
  try {
56352
- const npmGlobal = (0, import_node_child_process29.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
56445
+ const npmGlobal = (0, import_node_child_process30.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
56353
56446
  if (npmGlobal.includes(PKG_NAME2)) return "npm";
56354
56447
  } catch {
56355
56448
  }
56356
56449
  try {
56357
- (0, import_node_child_process29.execSync)("pnpm --version", { stdio: "pipe" });
56450
+ (0, import_node_child_process30.execSync)("pnpm --version", { stdio: "pipe" });
56358
56451
  return "pnpm";
56359
56452
  } catch {
56360
56453
  }
56361
56454
  try {
56362
- (0, import_node_child_process29.execSync)("yarn --version", { stdio: "pipe" });
56455
+ (0, import_node_child_process30.execSync)("yarn --version", { stdio: "pipe" });
56363
56456
  return "yarn";
56364
56457
  } catch {
56365
56458
  }
56366
56459
  try {
56367
- (0, import_node_child_process29.execSync)("bun --version", { stdio: "pipe" });
56460
+ (0, import_node_child_process30.execSync)("bun --version", { stdio: "pipe" });
56368
56461
  return "bun";
56369
56462
  } catch {
56370
56463
  }
@@ -56379,7 +56472,7 @@ function readInstallConfig() {
56379
56472
  }
56380
56473
  function packageLooksInstalled(pm, pkgName) {
56381
56474
  try {
56382
- const output = (0, import_node_child_process29.execSync)(globalListCommand(pm, pkgName), {
56475
+ const output = (0, import_node_child_process30.execSync)(globalListCommand(pm, pkgName), {
56383
56476
  encoding: "utf-8",
56384
56477
  stdio: ["pipe", "pipe", "pipe"]
56385
56478
  });
@@ -56482,14 +56575,14 @@ async function promoteUnprivilegedDaemon() {
56482
56575
  function restartSystemdDaemon() {
56483
56576
  const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
56484
56577
  const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
56485
- if (!asRoot && (0, import_node_child_process29.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
56578
+ if (!asRoot && (0, import_node_child_process30.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
56486
56579
  const [cmd, ...args] = argv;
56487
- if ((0, import_node_child_process29.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
56488
- return (0, import_node_child_process29.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
56580
+ if ((0, import_node_child_process30.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
56581
+ return (0, import_node_child_process30.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
56489
56582
  }
56490
56583
  function execQuiet(cmd) {
56491
56584
  try {
56492
- return (0, import_node_child_process29.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
56585
+ return (0, import_node_child_process30.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
56493
56586
  } catch {
56494
56587
  return null;
56495
56588
  }
@@ -56811,7 +56904,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
56811
56904
  console.log(source_default.green(` Tailing ${logPath2}...
56812
56905
  `));
56813
56906
  console.log(source_default.gray(" Press Ctrl+C to stop\n"));
56814
- (0, import_node_child_process29.execSync)(`tail -f ${logPath2}`, { stdio: "inherit" });
56907
+ (0, import_node_child_process30.execSync)(`tail -f ${logPath2}`, { stdio: "inherit" });
56815
56908
  });
56816
56909
  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) => {
56817
56910
  console.log(LOGO2);
@@ -56823,7 +56916,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
56823
56916
  for (const cmd of commands2) {
56824
56917
  console.log(source_default.green(` \u2192 ${cmd}
56825
56918
  `));
56826
- (0, import_node_child_process29.execSync)(cmd, { stdio: "inherit" });
56919
+ (0, import_node_child_process30.execSync)(cmd, { stdio: "inherit" });
56827
56920
  }
56828
56921
  console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
56829
56922
  await reportIfStillStale();
@@ -56848,7 +56941,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
56848
56941
  for (const cmd of commands) {
56849
56942
  console.log(source_default.green(` \u2192 ${cmd}
56850
56943
  `));
56851
- (0, import_node_child_process29.execSync)(cmd, { stdio: "inherit" });
56944
+ (0, import_node_child_process30.execSync)(cmd, { stdio: "inherit" });
56852
56945
  }
56853
56946
  console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
56854
56947
  if (installMode === "desktop") {
@@ -56899,7 +56992,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
56899
56992
  for (const cmd of commands) {
56900
56993
  console.log(source_default.green(` \u2192 ${cmd}
56901
56994
  `));
56902
- (0, import_node_child_process29.execSync)(cmd, { stdio: "inherit" });
56995
+ (0, import_node_child_process30.execSync)(cmd, { stdio: "inherit" });
56903
56996
  }
56904
56997
  console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
56905
56998
  console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));