@profullstack/threatcrush 0.13.79 → 0.13.81

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,96 @@ 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
+ /** Set once if nft is not installed here; stops retrying and logging. */
50276
+ unavailable = false;
50277
+ runNft;
50278
+ log;
50279
+ intervalMs;
50280
+ sshPort;
50281
+ start() {
50282
+ void this.sync();
50283
+ this.timer = setInterval(() => void this.sync(), this.intervalMs);
50284
+ this.timer.unref?.();
50285
+ }
50286
+ stop() {
50287
+ if (this.timer) clearInterval(this.timer);
50288
+ this.timer = null;
50289
+ }
50290
+ /** Apply (or tear down) the block to match the current setting and list. */
50291
+ async sync() {
50292
+ if (this.unavailable) return;
50293
+ if (!this.opts.enabled()) {
50294
+ await this.teardown();
50295
+ return;
50296
+ }
50297
+ const ipv4 = this.opts.exits.values().filter((ip) => (0, import_node_net17.isIP)(ip) === 4);
50298
+ if (ipv4.length === 0) return;
50299
+ try {
50300
+ await this.apply(ipv4);
50301
+ if (!this.applied) {
50302
+ this.log(`[tor] proactively blocking ${ipv4.length} Tor exits on tcp/${this.sshPort} (table inet ${TOR_NFT_TABLE})`);
50303
+ }
50304
+ this.applied = true;
50305
+ } catch (err) {
50306
+ if (err.code === "ENOENT") {
50307
+ this.unavailable = true;
50308
+ this.log("[tor] nft is not installed; the proactive Tor exit block is unavailable on this host");
50309
+ return;
50310
+ }
50311
+ this.log(`[tor] could not apply the proactive Tor exit block: ${err.message}`);
50312
+ }
50313
+ }
50314
+ /** One atomic `nft -f -` transaction: declare the table, then load the set. */
50315
+ async apply(ipv4) {
50316
+ const t = TOR_NFT_TABLE;
50317
+ const ruleset = `add table inet ${t}
50318
+ add set inet ${t} exits { type ipv4_addr; }
50319
+ add chain inet ${t} input { type filter hook input priority -100 ; policy accept ; }
50320
+ flush chain inet ${t} input
50321
+ add rule inet ${t} input tcp dport ${this.sshPort} ip saddr @exits counter drop
50322
+ flush set inet ${t} exits
50323
+ add element inet ${t} exits { ${ipv4.join(", ")} }
50324
+ `;
50325
+ await this.runNft(["-f", "-"], ruleset);
50326
+ }
50327
+ async teardown() {
50328
+ if (!this.applied) return;
50329
+ try {
50330
+ await this.runNft(["delete", "table", "inet", TOR_NFT_TABLE]);
50331
+ this.log("[tor] removed the proactive Tor exit block (block_tor_ssh off)");
50332
+ } catch {
50333
+ }
50334
+ this.applied = false;
50335
+ }
50336
+ };
50337
+
50244
50338
  // src/daemon/rules/engine.ts
50245
50339
  var MAX_WINDOW_ENTRIES = 1e3;
50246
50340
  function live(window) {
@@ -51166,17 +51260,17 @@ function loadAllRules(customDir) {
51166
51260
  }
51167
51261
 
51168
51262
  // src/daemon/firewall/adapters.ts
51169
- var import_node_child_process17 = require("child_process");
51263
+ var import_node_child_process18 = require("child_process");
51170
51264
  var import_node_fs56 = require("fs");
51171
51265
  var import_node_path44 = require("path");
51172
- var import_node_net17 = require("net");
51266
+ var import_node_net18 = require("net");
51173
51267
  function assertValidFirewallIp(ip) {
51174
- if ((0, import_node_net17.isIP)(ip) !== 4) {
51268
+ if ((0, import_node_net18.isIP)(ip) !== 4) {
51175
51269
  throw new Error(`Invalid IPv4 address: ${ip}`);
51176
51270
  }
51177
51271
  }
51178
51272
  function assertBannableIp(ip) {
51179
- if ((0, import_node_net17.isIP)(ip) === 0) {
51273
+ if ((0, import_node_net18.isIP)(ip) === 0) {
51180
51274
  throw new Error(`Invalid IP address: ${ip}`);
51181
51275
  }
51182
51276
  }
@@ -51202,11 +51296,11 @@ var Fail2banAdapter = class {
51202
51296
  enforces = true;
51203
51297
  jailReady = false;
51204
51298
  isAvailable() {
51205
- const result = (0, import_node_child_process17.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
51299
+ const result = (0, import_node_child_process18.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
51206
51300
  return result.status === 0;
51207
51301
  }
51208
51302
  client(args) {
51209
- return (0, import_node_child_process17.execFileSync)("fail2ban-client", args, {
51303
+ return (0, import_node_child_process18.execFileSync)("fail2ban-client", args, {
51210
51304
  encoding: "utf-8",
51211
51305
  stdio: ["ignore", "pipe", "pipe"]
51212
51306
  });
@@ -51282,7 +51376,7 @@ var Fail2banAdapter = class {
51282
51376
  const status = this.client(["status", this.jail]);
51283
51377
  const line2 = status.split("\n").find((l) => /Banned IP list:/i.test(l));
51284
51378
  if (!line2) return [];
51285
- return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net17.isIP)(s) !== 0);
51379
+ return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net18.isIP)(s) !== 0);
51286
51380
  } catch {
51287
51381
  return [];
51288
51382
  }
@@ -51292,45 +51386,45 @@ var Fail2banAdapter = class {
51292
51386
  function parseBannedList(output) {
51293
51387
  const found = [];
51294
51388
  for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
51295
- if ((0, import_node_net17.isIP)(match[1]) !== 0) found.push(match[1]);
51389
+ if ((0, import_node_net18.isIP)(match[1]) !== 0) found.push(match[1]);
51296
51390
  }
51297
51391
  if (found.length > 0) return found;
51298
- return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net17.isIP)(s) !== 0);
51392
+ return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net18.isIP)(s) !== 0);
51299
51393
  }
51300
51394
  var NftablesAdapter = class {
51301
51395
  name = "nftables";
51302
51396
  table = "threatcrush";
51303
51397
  set = "blocklist";
51304
51398
  isAvailable() {
51305
- const result = (0, import_node_child_process17.spawnSync)("nft", ["--version"], { stdio: "pipe" });
51399
+ const result = (0, import_node_child_process18.spawnSync)("nft", ["--version"], { stdio: "pipe" });
51306
51400
  return result.status === 0;
51307
51401
  }
51308
51402
  ensureSetup() {
51309
51403
  try {
51310
- (0, import_node_child_process17.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
51404
+ (0, import_node_child_process18.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
51311
51405
  } 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`);
51406
+ (0, import_node_child_process18.execSync)(`nft add table inet ${this.table}`);
51407
+ (0, import_node_child_process18.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
51408
+ (0, import_node_child_process18.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
51409
+ (0, import_node_child_process18.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
51316
51410
  }
51317
51411
  }
51318
51412
  async block(ip) {
51319
51413
  assertValidFirewallIp(ip);
51320
51414
  this.ensureSetup();
51321
- (0, import_node_child_process17.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
51415
+ (0, import_node_child_process18.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
51322
51416
  }
51323
51417
  async unblock(ip) {
51324
51418
  assertValidFirewallIp(ip);
51325
51419
  try {
51326
- (0, import_node_child_process17.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
51420
+ (0, import_node_child_process18.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
51327
51421
  } catch {
51328
51422
  }
51329
51423
  }
51330
51424
  async isBlocked(ip) {
51331
51425
  assertValidFirewallIp(ip);
51332
51426
  try {
51333
- 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" });
51334
51428
  return output.includes(ip);
51335
51429
  } catch {
51336
51430
  return false;
@@ -51338,7 +51432,7 @@ var NftablesAdapter = class {
51338
51432
  }
51339
51433
  async listBlocked() {
51340
51434
  try {
51341
- const output = (0, import_node_child_process17.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
51435
+ const output = (0, import_node_child_process18.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
51342
51436
  const match = output.match(/elements\s*=\s*\{([^}]*)\}/);
51343
51437
  if (!match) return [];
51344
51438
  return match[1].split(",").map((s) => s.trim().split(/\s/)[0]).filter(Boolean);
@@ -51351,34 +51445,34 @@ var IptablesAdapter = class {
51351
51445
  name = "iptables";
51352
51446
  chain = "THREATCRUSH";
51353
51447
  isAvailable() {
51354
- const result = (0, import_node_child_process17.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
51448
+ const result = (0, import_node_child_process18.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
51355
51449
  return result.status === 0;
51356
51450
  }
51357
51451
  ensureChain() {
51358
51452
  try {
51359
- (0, import_node_child_process17.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
51453
+ (0, import_node_child_process18.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
51360
51454
  } 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}`);
51455
+ (0, import_node_child_process18.execSync)(`iptables -N ${this.chain}`);
51456
+ (0, import_node_child_process18.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
51363
51457
  }
51364
51458
  }
51365
51459
  async block(ip) {
51366
51460
  assertValidFirewallIp(ip);
51367
51461
  this.ensureChain();
51368
51462
  if (await this.isBlocked(ip)) return;
51369
- (0, import_node_child_process17.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
51463
+ (0, import_node_child_process18.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
51370
51464
  }
51371
51465
  async unblock(ip) {
51372
51466
  assertValidFirewallIp(ip);
51373
51467
  try {
51374
- (0, import_node_child_process17.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
51468
+ (0, import_node_child_process18.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
51375
51469
  } catch {
51376
51470
  }
51377
51471
  }
51378
51472
  async isBlocked(ip) {
51379
51473
  assertValidFirewallIp(ip);
51380
51474
  try {
51381
- 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" });
51382
51476
  return output.includes(ip);
51383
51477
  } catch {
51384
51478
  return false;
@@ -51386,7 +51480,7 @@ var IptablesAdapter = class {
51386
51480
  }
51387
51481
  async listBlocked() {
51388
51482
  try {
51389
- const output = (0, import_node_child_process17.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
51483
+ const output = (0, import_node_child_process18.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
51390
51484
  const ips = [];
51391
51485
  for (const line2 of output.split("\n")) {
51392
51486
  const match = line2.match(/DROP\s+all\s+--\s+(\d+\.\d+\.\d+\.\d+)/);
@@ -51443,8 +51537,8 @@ function detectFirewallAdapter(backend = "auto") {
51443
51537
 
51444
51538
  // src/daemon/firewall/remediation.ts
51445
51539
  var import_node_fs57 = require("fs");
51446
- var import_node_child_process18 = require("child_process");
51447
- var import_node_net18 = require("net");
51540
+ var import_node_child_process19 = require("child_process");
51541
+ var import_node_net19 = require("net");
51448
51542
  init_paths();
51449
51543
  init_backoff();
51450
51544
 
@@ -51535,7 +51629,7 @@ var defaultDiscovery = {
51535
51629
  return out;
51536
51630
  },
51537
51631
  keyLoginJournal: (sinceSeconds) => new Promise((resolve9) => {
51538
- (0, import_node_child_process18.execFile)(
51632
+ (0, import_node_child_process19.execFile)(
51539
51633
  "journalctl",
51540
51634
  ["_COMM=sshd", "_COMM=sshd-session", `--since=-${Math.ceil(sinceSeconds / 86400)}d`, "-o", "short-unix", "--no-pager", "--grep", "Accepted publickey"],
51541
51635
  { maxBuffer: 32 * 1024 * 1024, timeout: 6e4 },
@@ -51615,7 +51709,7 @@ var RemediationManager = class {
51615
51709
  setTorExitCheck(check2) {
51616
51710
  this.isTorExit = check2;
51617
51711
  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));
51712
+ this.protectedList = this.protectedList.filter((a) => !(0, import_node_net19.isIP)(a) || !check2(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
51619
51713
  for (const ip of Object.keys(this.operators)) {
51620
51714
  if (!check2(ip)) continue;
51621
51715
  delete this.operators[ip];
@@ -51708,7 +51802,7 @@ var RemediationManager = class {
51708
51802
  if (remediation?.action !== "block") return;
51709
51803
  }
51710
51804
  const ip = event.source_ip;
51711
- if (!ip || (0, import_node_net18.isIP)(ip) === 0) return;
51805
+ if (!ip || (0, import_node_net19.isIP)(ip) === 0) return;
51712
51806
  const strict = remediation?.override_operator_protection === true;
51713
51807
  if (strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
51714
51808
  if (strict) this.logLine(`[remediation] not banning ${ip}: it is one of our own addresses (${event.message})`);
@@ -51737,7 +51831,7 @@ var RemediationManager = class {
51737
51831
  * 4th offence and so on, clamped to `max_ban_seconds`.
51738
51832
  */
51739
51833
  async ban(ip, reason, opts = {}) {
51740
- if ((0, import_node_net18.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
51834
+ if ((0, import_node_net19.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
51741
51835
  if (opts.strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
51742
51836
  return { ok: false, error: `${ip} is protected and can never be blocked` };
51743
51837
  }
@@ -52014,7 +52108,7 @@ var RemediationManager = class {
52014
52108
  if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
52015
52109
  const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
52016
52110
  for (const [ip, at] of Object.entries(saved)) {
52017
- if (typeof at !== "number" || at < cutoff || !(0, import_node_net18.isIP)(ip)) continue;
52111
+ if (typeof at !== "number" || at < cutoff || !(0, import_node_net19.isIP)(ip)) continue;
52018
52112
  if (this.blocklist.some((b) => b.ip === ip && b.strict)) continue;
52019
52113
  this.operators[ip] = at;
52020
52114
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
@@ -52189,7 +52283,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
52189
52283
  }
52190
52284
 
52191
52285
  // src/core/node-runtime.ts
52192
- var import_node_child_process19 = require("child_process");
52286
+ var import_node_child_process20 = require("child_process");
52193
52287
  var MIN_DAEMON_NODE_MAJOR = 22;
52194
52288
  function nodeMajor(version) {
52195
52289
  const m = String(version ?? "").trim().replace(/^v/, "").match(/^(\d+)\./);
@@ -52203,7 +52297,7 @@ function daemonNodeProblem(version) {
52203
52297
  }
52204
52298
  function versionOfNode(path2) {
52205
52299
  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 });
52300
+ const res = (0, import_node_child_process20.spawnSync)(path2, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
52207
52301
  return res.status === 0 ? res.stdout.trim() : null;
52208
52302
  }
52209
52303
 
@@ -52217,7 +52311,7 @@ function readVersion2() {
52217
52311
  }
52218
52312
  }
52219
52313
  async function runHardeningChecks() {
52220
- const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process20.execFile)(
52314
+ const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process21.execFile)(
52221
52315
  process.execPath,
52222
52316
  [(0, import_node_path46.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
52223
52317
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
@@ -52231,7 +52325,7 @@ async function runHardeningChecks() {
52231
52325
  return patches ? [...findings2, patches] : findings2;
52232
52326
  }
52233
52327
  async function runPatchCheck() {
52234
- const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process20.execFile)(
52328
+ const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process21.execFile)(
52235
52329
  process.execPath,
52236
52330
  [(0, import_node_path46.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
52237
52331
  { timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
@@ -52266,9 +52360,9 @@ async function runDaemon() {
52266
52360
  logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
52267
52361
  const restartDaemon = () => {
52268
52362
  if (PATHS.mode === "system") {
52269
- (0, import_node_child_process20.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
52363
+ (0, import_node_child_process21.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
52270
52364
  } else {
52271
- (0, import_node_child_process20.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
52365
+ (0, import_node_child_process21.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
52272
52366
  setTimeout(() => process.exit(0), 500).unref();
52273
52367
  }
52274
52368
  };
@@ -52404,6 +52498,12 @@ async function runDaemon() {
52404
52498
  log: logLine
52405
52499
  });
52406
52500
  sshIntrusion.start();
52501
+ const torBlock = new TorExitBlockEnforcer({
52502
+ exits: torExits,
52503
+ enabled: () => remediation.blockTorSsh,
52504
+ log: logLine
52505
+ });
52506
+ torBlock.start();
52407
52507
  const lightningWatch = new LightningWatch({
52408
52508
  bus,
52409
52509
  enabled: config.lightning?.enabled !== false,
@@ -52474,6 +52574,7 @@ async function runDaemon() {
52474
52574
  if (torPinned || typeof block_tor_ssh !== "boolean" || block_tor_ssh === remediation.blockTorSsh) return;
52475
52575
  remediation.setBlockTorSsh(block_tor_ssh);
52476
52576
  logLine(`[ssh-intrusion] Tor SSH ban ${block_tor_ssh ? "ON" : "OFF"} (org setting from the dashboard)`);
52577
+ void torBlock.sync();
52477
52578
  }
52478
52579
  });
52479
52580
  allowlistSync.start();
@@ -52644,7 +52745,7 @@ async function daemonStart() {
52644
52745
  }
52645
52746
  return;
52646
52747
  }
52647
- const child = (0, import_node_child_process21.spawn)(process.execPath, [DAEMON_ENTRY], {
52748
+ const child = (0, import_node_child_process22.spawn)(process.execPath, [DAEMON_ENTRY], {
52648
52749
  detached: true,
52649
52750
  stdio: ["ignore", out, err],
52650
52751
  env: { ...process.env, THREATCRUSH_DAEMON: "1" }
@@ -52731,7 +52832,7 @@ async function releaseStaleSocket() {
52731
52832
  }
52732
52833
 
52733
52834
  // src/commands/service.ts
52734
- var import_node_child_process22 = require("child_process");
52835
+ var import_node_child_process23 = require("child_process");
52735
52836
  var import_node_fs62 = require("fs");
52736
52837
  var import_node_path48 = require("path");
52737
52838
  var import_node_os20 = require("os");
@@ -52753,7 +52854,7 @@ function resolveBinPath() {
52753
52854
  const arg = process.argv[1];
52754
52855
  if (arg && (0, import_node_fs62.existsSync)(arg)) return stableBinPath(arg);
52755
52856
  try {
52756
- return (0, import_node_child_process22.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
52857
+ return (0, import_node_child_process23.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
52757
52858
  } catch {
52758
52859
  return "threatcrush";
52759
52860
  }
@@ -52792,18 +52893,18 @@ function isRoot3() {
52792
52893
  return typeof process.getuid === "function" && process.getuid() === 0;
52793
52894
  }
52794
52895
  function reexecWithSudo(args) {
52795
- if ((0, import_node_child_process22.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
52896
+ if ((0, import_node_child_process23.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
52796
52897
  console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
52797
52898
  const bin = resolveBinPath();
52798
52899
  const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
52799
- const result = (0, import_node_child_process22.spawnSync)("sudo", argv, { stdio: "inherit" });
52900
+ const result = (0, import_node_child_process23.spawnSync)("sudo", argv, { stdio: "inherit" });
52800
52901
  return result.status === 0;
52801
52902
  }
52802
52903
  function callerHome() {
52803
52904
  const user = process.env.SUDO_USER;
52804
52905
  if (!user) return null;
52805
52906
  try {
52806
- const line2 = (0, import_node_child_process22.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
52907
+ const line2 = (0, import_node_child_process23.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
52807
52908
  const home = line2.split(":")[5];
52808
52909
  return home && (0, import_node_fs62.existsSync)(home) ? home : null;
52809
52910
  } catch {
@@ -52838,7 +52939,7 @@ function stopUserModeDaemon() {
52838
52939
  }
52839
52940
  }
52840
52941
  function unitIsActive() {
52841
- const result = (0, import_node_child_process22.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
52942
+ const result = (0, import_node_child_process23.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
52842
52943
  return result.status === 0;
52843
52944
  }
52844
52945
  async function installServiceCommand() {
@@ -52849,7 +52950,7 @@ async function installServiceCommand() {
52849
52950
  return;
52850
52951
  }
52851
52952
  const noSystemd = systemdUnavailableReason({
52852
- hasSystemctl: (0, import_node_child_process22.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
52953
+ hasSystemctl: (0, import_node_child_process23.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
52853
52954
  booted: (0, import_node_fs62.existsSync)("/run/systemd/system")
52854
52955
  });
52855
52956
  if (noSystemd) {
@@ -52904,8 +53005,8 @@ async function installServiceCommand() {
52904
53005
  installLogrotate();
52905
53006
  stopUserModeDaemon();
52906
53007
  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" });
53008
+ (0, import_node_child_process23.execSync)("systemctl daemon-reload", { stdio: "inherit" });
53009
+ (0, import_node_child_process23.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
52909
53010
  } catch (err) {
52910
53011
  console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
52911
53012
  console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
@@ -52977,7 +53078,7 @@ function ensureSystemDirs(configDir) {
52977
53078
  try {
52978
53079
  if (groupWritable && admGid2 !== null) {
52979
53080
  (0, import_node_fs62.chmodSync)(path2, sticky ? 1533 : 509);
52980
- (0, import_node_child_process22.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
53081
+ (0, import_node_child_process23.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
52981
53082
  } else {
52982
53083
  (0, import_node_fs62.chmodSync)(path2, 493);
52983
53084
  }
@@ -52999,22 +53100,22 @@ async function uninstallServiceCommand() {
52999
53100
  return;
53000
53101
  }
53001
53102
  try {
53002
- (0, import_node_child_process22.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
53103
+ (0, import_node_child_process23.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
53003
53104
  } catch {
53004
53105
  }
53005
53106
  try {
53006
- (0, import_node_child_process22.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
53107
+ (0, import_node_child_process23.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
53007
53108
  } catch {
53008
53109
  }
53009
53110
  try {
53010
53111
  if ((0, import_node_fs62.existsSync)(UNIT_PATH)) {
53011
- (0, import_node_child_process22.execSync)(`rm -f ${UNIT_PATH}`);
53112
+ (0, import_node_child_process23.execSync)(`rm -f ${UNIT_PATH}`);
53012
53113
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
53013
53114
  }
53014
53115
  } catch {
53015
53116
  }
53016
53117
  try {
53017
- (0, import_node_child_process22.execSync)("systemctl daemon-reload", { stdio: "inherit" });
53118
+ (0, import_node_child_process23.execSync)("systemctl daemon-reload", { stdio: "inherit" });
53018
53119
  } catch {
53019
53120
  }
53020
53121
  console.log(source_default.green(" \u2713 threatcrushd service removed."));
@@ -53750,7 +53851,7 @@ async function rulesCommand(opts) {
53750
53851
 
53751
53852
  // src/commands/harden.ts
53752
53853
  var import_node_fs66 = require("fs");
53753
- var import_node_child_process23 = require("child_process");
53854
+ var import_node_child_process24 = require("child_process");
53754
53855
  init_cli_config();
53755
53856
 
53756
53857
  // src/commands/cis-report.ts
@@ -53961,7 +54062,7 @@ function writeCisReport(path2, format2, report) {
53961
54062
  // src/commands/harden.ts
53962
54063
  function tryExec(cmd) {
53963
54064
  try {
53964
- return (0, import_node_child_process23.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
54065
+ return (0, import_node_child_process24.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
53965
54066
  } catch {
53966
54067
  return null;
53967
54068
  }
@@ -54431,7 +54532,7 @@ async function hardenCommand(opts) {
54431
54532
  // src/core/patches/index.ts
54432
54533
  var import_node_fs67 = require("fs");
54433
54534
  var import_node_path50 = require("path");
54434
- var import_node_child_process24 = require("child_process");
54535
+ var import_node_child_process25 = require("child_process");
54435
54536
  var import_node_util5 = require("util");
54436
54537
 
54437
54538
  // src/core/patches/dpkg-version.ts
@@ -54491,7 +54592,7 @@ var STALE_AFTER_MS = 2 * 864e5;
54491
54592
  var SEVERITIES2 = ["info", "low", "medium", "high", "critical"];
54492
54593
  var RANK = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
54493
54594
  var defaultExec = async (file, args) => {
54494
- const { stdout } = await (0, import_node_util5.promisify)(import_node_child_process24.execFile)(file, args, {
54595
+ const { stdout } = await (0, import_node_util5.promisify)(import_node_child_process25.execFile)(file, args, {
54495
54596
  timeout: 12e4,
54496
54597
  maxBuffer: 32 * 1024 * 1024,
54497
54598
  env: { ...process.env, LC_ALL: "C" }
@@ -54835,12 +54936,12 @@ async function patchesCommand(opts) {
54835
54936
  }
54836
54937
 
54837
54938
  // src/commands/feeds.ts
54838
- var import_node_net19 = require("net");
54939
+ var import_node_net20 = require("net");
54839
54940
  var import_node_path52 = require("path");
54840
54941
  init_paths();
54841
54942
 
54842
54943
  // src/commands/feeds-resolver.ts
54843
- var import_node_child_process25 = require("child_process");
54944
+ var import_node_child_process26 = require("child_process");
54844
54945
  var import_node_fs68 = require("fs");
54845
54946
  var import_node_path51 = require("path");
54846
54947
  var realIO = {
@@ -54855,7 +54956,7 @@ var realIO = {
54855
54956
  write: (p, c) => (0, import_node_fs68.writeFileSync)(p, c),
54856
54957
  remove: (p) => (0, import_node_fs68.rmSync)(p, { force: true }),
54857
54958
  run: (cmd, args) => {
54858
- const r = (0, import_node_child_process25.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
54959
+ const r = (0, import_node_child_process26.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
54859
54960
  return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
54860
54961
  }
54861
54962
  };
@@ -54979,8 +55080,8 @@ async function feedsCommand(action, value, opts) {
54979
55080
  process.exitCode = 2;
54980
55081
  return;
54981
55082
  }
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);
55083
+ const ipHit = (0, import_node_net20.isIP)(value) ? matchIp(value, set) : null;
55084
+ const domainHit = (0, import_node_net20.isIP)(value) ? null : matchDomain(value, set);
54984
55085
  const listed = ipHit ?? domainHit?.indicator ?? null;
54985
55086
  if (opts.json) {
54986
55087
  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 +55110,7 @@ async function feedsCommand(action, value, opts) {
55009
55110
 
55010
55111
  // src/commands/tor.ts
55011
55112
  var import_node_fs69 = require("fs");
55012
- var import_node_net20 = require("net");
55113
+ var import_node_net21 = require("net");
55013
55114
  var import_node_path53 = require("path");
55014
55115
  init_paths();
55015
55116
  async function torCommand(action, value, opts) {
@@ -55041,7 +55142,7 @@ async function torCommand(action, value, opts) {
55041
55142
  const remediation = loadConfig((0, import_node_path53.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).remediation;
55042
55143
  const ban = remediation?.block_tor_ssh !== false && remediation?.enabled !== false;
55043
55144
  if (action === "check") {
55044
- if (!value || !(0, import_node_net20.isIP)(value)) {
55145
+ if (!value || !(0, import_node_net21.isIP)(value)) {
55045
55146
  console.error("Usage: threatcrush tor check <ip>");
55046
55147
  process.exitCode = 2;
55047
55148
  return;
@@ -55433,7 +55534,7 @@ init_paths();
55433
55534
 
55434
55535
  // src/daemon/auditd/rules.ts
55435
55536
  var import_node_fs73 = require("fs");
55436
- var import_node_child_process26 = require("child_process");
55537
+ var import_node_child_process27 = require("child_process");
55437
55538
  var import_node_path56 = require("path");
55438
55539
  var WEB_TOOLS = ["sh", "bash", "dash", "zsh", "curl", "wget"];
55439
55540
  var MINER_NAMES = ["xmrig", "minerd", "cpuminer", "cpuminer-multi", "kdevtmpfsi", "kinsing", "cryptonight"];
@@ -55442,7 +55543,7 @@ var LISTEN_KEY2 = "threatcrush_edr_listen";
55442
55543
  function passwdByName() {
55443
55544
  let raw = "";
55444
55545
  try {
55445
- raw = (0, import_node_child_process26.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
55546
+ raw = (0, import_node_child_process27.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
55446
55547
  } catch {
55447
55548
  try {
55448
55549
  raw = (0, import_node_fs73.readFileSync)("/etc/passwd", "utf8");
@@ -55807,11 +55908,11 @@ function abuseStatusCommand(opts = {}) {
55807
55908
  init_paths();
55808
55909
 
55809
55910
  // src/upgrade.ts
55810
- var import_node_child_process27 = require("child_process");
55911
+ var import_node_child_process28 = require("child_process");
55811
55912
  var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
55812
55913
  var defaultRunner = (cmd) => {
55813
55914
  try {
55814
- return (0, import_node_child_process27.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
55915
+ return (0, import_node_child_process28.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
55815
55916
  } catch {
55816
55917
  return null;
55817
55918
  }
@@ -55952,7 +56053,7 @@ function installUserAgent(target = globalThis) {
55952
56053
  }
55953
56054
 
55954
56055
  // src/core/cloud-upload.ts
55955
- var import_node_child_process28 = require("child_process");
56056
+ var import_node_child_process29 = require("child_process");
55956
56057
  var import_node_os23 = require("os");
55957
56058
  var import_node_path57 = require("path");
55958
56059
  init_cli_config();
@@ -55973,7 +56074,7 @@ function cleanUrl(raw) {
55973
56074
  return raw.split(/[?#]/)[0];
55974
56075
  }
55975
56076
  }
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()) {
56077
+ 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
56078
  const abs = (0, import_node_path57.resolve)(path2);
55978
56079
  try {
55979
56080
  const root = run2(["rev-parse", "--show-toplevel"]);
@@ -56349,22 +56450,22 @@ var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
56349
56450
  var INSTALL_CONFIG_PATH = (0, import_node_path58.join)((0, import_node_os24.homedir)(), ".threatcrush", "install.json");
56350
56451
  function detectPackageManager() {
56351
56452
  try {
56352
- const npmGlobal = (0, import_node_child_process29.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
56453
+ const npmGlobal = (0, import_node_child_process30.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
56353
56454
  if (npmGlobal.includes(PKG_NAME2)) return "npm";
56354
56455
  } catch {
56355
56456
  }
56356
56457
  try {
56357
- (0, import_node_child_process29.execSync)("pnpm --version", { stdio: "pipe" });
56458
+ (0, import_node_child_process30.execSync)("pnpm --version", { stdio: "pipe" });
56358
56459
  return "pnpm";
56359
56460
  } catch {
56360
56461
  }
56361
56462
  try {
56362
- (0, import_node_child_process29.execSync)("yarn --version", { stdio: "pipe" });
56463
+ (0, import_node_child_process30.execSync)("yarn --version", { stdio: "pipe" });
56363
56464
  return "yarn";
56364
56465
  } catch {
56365
56466
  }
56366
56467
  try {
56367
- (0, import_node_child_process29.execSync)("bun --version", { stdio: "pipe" });
56468
+ (0, import_node_child_process30.execSync)("bun --version", { stdio: "pipe" });
56368
56469
  return "bun";
56369
56470
  } catch {
56370
56471
  }
@@ -56379,7 +56480,7 @@ function readInstallConfig() {
56379
56480
  }
56380
56481
  function packageLooksInstalled(pm, pkgName) {
56381
56482
  try {
56382
- const output = (0, import_node_child_process29.execSync)(globalListCommand(pm, pkgName), {
56483
+ const output = (0, import_node_child_process30.execSync)(globalListCommand(pm, pkgName), {
56383
56484
  encoding: "utf-8",
56384
56485
  stdio: ["pipe", "pipe", "pipe"]
56385
56486
  });
@@ -56482,14 +56583,14 @@ async function promoteUnprivilegedDaemon() {
56482
56583
  function restartSystemdDaemon() {
56483
56584
  const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
56484
56585
  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;
56586
+ if (!asRoot && (0, import_node_child_process30.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
56486
56587
  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;
56588
+ if ((0, import_node_child_process30.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
56589
+ return (0, import_node_child_process30.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
56489
56590
  }
56490
56591
  function execQuiet(cmd) {
56491
56592
  try {
56492
- return (0, import_node_child_process29.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
56593
+ return (0, import_node_child_process30.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
56493
56594
  } catch {
56494
56595
  return null;
56495
56596
  }
@@ -56811,7 +56912,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
56811
56912
  console.log(source_default.green(` Tailing ${logPath2}...
56812
56913
  `));
56813
56914
  console.log(source_default.gray(" Press Ctrl+C to stop\n"));
56814
- (0, import_node_child_process29.execSync)(`tail -f ${logPath2}`, { stdio: "inherit" });
56915
+ (0, import_node_child_process30.execSync)(`tail -f ${logPath2}`, { stdio: "inherit" });
56815
56916
  });
56816
56917
  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
56918
  console.log(LOGO2);
@@ -56823,7 +56924,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
56823
56924
  for (const cmd of commands2) {
56824
56925
  console.log(source_default.green(` \u2192 ${cmd}
56825
56926
  `));
56826
- (0, import_node_child_process29.execSync)(cmd, { stdio: "inherit" });
56927
+ (0, import_node_child_process30.execSync)(cmd, { stdio: "inherit" });
56827
56928
  }
56828
56929
  console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
56829
56930
  await reportIfStillStale();
@@ -56848,7 +56949,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
56848
56949
  for (const cmd of commands) {
56849
56950
  console.log(source_default.green(` \u2192 ${cmd}
56850
56951
  `));
56851
- (0, import_node_child_process29.execSync)(cmd, { stdio: "inherit" });
56952
+ (0, import_node_child_process30.execSync)(cmd, { stdio: "inherit" });
56852
56953
  }
56853
56954
  console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
56854
56955
  if (installMode === "desktop") {
@@ -56899,7 +57000,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
56899
57000
  for (const cmd of commands) {
56900
57001
  console.log(source_default.green(` \u2192 ${cmd}
56901
57002
  `));
56902
- (0, import_node_child_process29.execSync)(cmd, { stdio: "inherit" });
57003
+ (0, import_node_child_process30.execSync)(cmd, { stdio: "inherit" });
56903
57004
  }
56904
57005
  console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
56905
57006
  console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));