@profullstack/threatcrush 0.13.68 → 0.13.70

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
@@ -2026,7 +2026,7 @@ var require_toml = __commonJS({
2026
2026
  });
2027
2027
 
2028
2028
  // src/daemon/index.ts
2029
- var import_node_fs37 = require("fs");
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
2032
  var import_node_path29 = require("path");
@@ -10432,6 +10432,12 @@ var DEFAULT_PROTECTED = [
10432
10432
  "172.16.0.0/12",
10433
10433
  "192.168.0.0/16",
10434
10434
  "169.254.0.0/16",
10435
+ // RFC 6598 shared address space. Never routed on the public internet, so a
10436
+ // source here is a tailnet peer (Tailscale hands out 100.64.0.0/10) or the
10437
+ // carrier's own NAT, not an attacker. 2026-11-02: dev3's port-scan detector
10438
+ // banned a Tailscale peer four times for dialling several c0mpute ports.
10439
+ // Tailscale's IPv6 range (fd7a:115c:a1e0::/48) is already inside fc00::/7.
10440
+ "100.64.0.0/10",
10435
10441
  "fc00::/7",
10436
10442
  "fe80::/10"
10437
10443
  ];
@@ -20098,8 +20104,68 @@ var SshIntrusionWatch = class {
20098
20104
  }
20099
20105
  };
20100
20106
 
20101
- // src/daemon/workers/lightning-watch.ts
20107
+ // src/daemon/key-directory.ts
20102
20108
  var import_node_fs30 = require("fs");
20109
+ var fsIO3 = {
20110
+ readFile: (p) => {
20111
+ try {
20112
+ return (0, import_node_fs30.readFileSync)(p, "utf-8");
20113
+ } catch {
20114
+ return null;
20115
+ }
20116
+ },
20117
+ readDir: (p) => {
20118
+ try {
20119
+ return (0, import_node_fs30.readdirSync)(p);
20120
+ } catch {
20121
+ return null;
20122
+ }
20123
+ },
20124
+ exists: (p) => (0, import_node_fs30.existsSync)(p)
20125
+ };
20126
+ var KeyDirectory = class {
20127
+ constructor(io = fsIO3, now = Date.now, ttlMs = 3e5) {
20128
+ this.io = io;
20129
+ this.now = now;
20130
+ this.ttlMs = ttlMs;
20131
+ }
20132
+ io;
20133
+ now;
20134
+ ttlMs;
20135
+ cache = { at: -Infinity, byFp: /* @__PURE__ */ new Map() };
20136
+ lookup(fingerprint) {
20137
+ if (this.now() - this.cache.at > this.ttlMs) {
20138
+ const byFp = /* @__PURE__ */ new Map();
20139
+ for (const [account, keys] of Object.entries(takeSnapshot(this.io).keys)) {
20140
+ for (const [fp, k] of Object.entries(keys)) if (!byFp.has(fp)) byFp.set(fp, { account, comment: k.comment });
20141
+ }
20142
+ this.cache = { at: this.now(), byFp };
20143
+ }
20144
+ return this.cache.byFp.get(fingerprint) ?? null;
20145
+ }
20146
+ };
20147
+ function enrichLoginEvent(event, keys) {
20148
+ if (event.module !== "ssh-guard") return;
20149
+ const details = event.details;
20150
+ const fp = details?.fingerprint;
20151
+ if (!details || typeof fp !== "string" || !fp.startsWith("SHA256:") || "key_kind" in details) return;
20152
+ let entry = null;
20153
+ try {
20154
+ entry = keys.lookup(fp);
20155
+ } catch {
20156
+ entry = null;
20157
+ }
20158
+ if (!entry) {
20159
+ details.key_kind = "unknown";
20160
+ return;
20161
+ }
20162
+ details.key_account = entry.account;
20163
+ if (entry.comment) details.key_comment = entry.comment;
20164
+ details.key_kind = isAutomationKeyComment(entry.comment) ? "automation" : "person";
20165
+ }
20166
+
20167
+ // src/daemon/workers/lightning-watch.ts
20168
+ var import_node_fs31 = require("fs");
20103
20169
  var DEFAULT_CLN_LOGS = [
20104
20170
  "/home/lightning/.lightning/cln.log",
20105
20171
  "/root/.lightning/cln.log",
@@ -20155,9 +20221,9 @@ var LightningWatch = class {
20155
20221
  if (this.opts.enabled === false) return [];
20156
20222
  const found = [];
20157
20223
  for (const path of this.opts.paths?.length ? this.opts.paths : DEFAULT_CLN_LOGS) {
20158
- if (!(0, import_node_fs30.existsSync)(path)) continue;
20224
+ if (!(0, import_node_fs31.existsSync)(path)) continue;
20159
20225
  try {
20160
- (0, import_node_fs30.accessSync)(path, import_node_fs30.constants.R_OK);
20226
+ (0, import_node_fs31.accessSync)(path, import_node_fs31.constants.R_OK);
20161
20227
  } catch {
20162
20228
  continue;
20163
20229
  }
@@ -20192,7 +20258,7 @@ var LightningWatch = class {
20192
20258
  };
20193
20259
 
20194
20260
  // src/core/tor-exits.ts
20195
- var import_node_fs31 = require("fs");
20261
+ var import_node_fs32 = require("fs");
20196
20262
  var import_node_path24 = require("path");
20197
20263
  var import_node_net12 = require("net");
20198
20264
  var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
@@ -20261,10 +20327,10 @@ var TorExitList = class _TorExitList {
20261
20327
  }
20262
20328
  loadCache() {
20263
20329
  try {
20264
- if (!(0, import_node_fs31.existsSync)(this.opts.cachePath)) return false;
20265
- const parsed = parseTorExitList((0, import_node_fs31.readFileSync)(this.opts.cachePath, "utf-8"));
20330
+ if (!(0, import_node_fs32.existsSync)(this.opts.cachePath)) return false;
20331
+ const parsed = parseTorExitList((0, import_node_fs32.readFileSync)(this.opts.cachePath, "utf-8"));
20266
20332
  if (parsed.size === 0) return false;
20267
- this.load(parsed, (0, import_node_fs31.statSync)(this.opts.cachePath).mtimeMs);
20333
+ this.load(parsed, (0, import_node_fs32.statSync)(this.opts.cachePath).mtimeMs);
20268
20334
  this.log(`[tor] loaded ${parsed.size} Tor exit addresses from cache (${new Date(this.updatedAt).toISOString()})`);
20269
20335
  return true;
20270
20336
  } catch (err) {
@@ -20296,9 +20362,9 @@ var TorExitList = class _TorExitList {
20296
20362
  const before = this.exits.size;
20297
20363
  this.load(parsed);
20298
20364
  try {
20299
- (0, import_node_fs31.mkdirSync)((0, import_node_path24.dirname)(this.opts.cachePath), { recursive: true });
20300
- (0, import_node_fs31.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
20301
- (0, import_node_fs31.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
20365
+ (0, import_node_fs32.mkdirSync)((0, import_node_path24.dirname)(this.opts.cachePath), { recursive: true });
20366
+ (0, import_node_fs32.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
20367
+ (0, import_node_fs32.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
20302
20368
  } catch (err) {
20303
20369
  this.log(`[tor] could not save the exit list cache: ${err.message}`);
20304
20370
  }
@@ -20339,6 +20405,9 @@ var EVIDENCE_FIELDS = [
20339
20405
  "system_uid",
20340
20406
  "fingerprint",
20341
20407
  "key_type",
20408
+ "key_comment",
20409
+ "key_kind",
20410
+ "key_account",
20342
20411
  "auth_method",
20343
20412
  "port",
20344
20413
  "path",
@@ -20516,7 +20585,7 @@ var RuleEngine = class {
20516
20585
  };
20517
20586
 
20518
20587
  // src/daemon/rules/loader.ts
20519
- var import_node_fs32 = require("fs");
20588
+ var import_node_fs33 = require("fs");
20520
20589
  var import_node_path25 = require("path");
20521
20590
 
20522
20591
  // src/daemon/rules/default-rules.ts
@@ -20581,7 +20650,15 @@ var DEFAULT_RULES = [
20581
20650
  operator: "regex",
20582
20651
  // Attempts only. Matching `accepted` here meant a successful root login
20583
20652
  // banned the administrator who had just made it.
20584
- value: "failed.*\\broot\\b"
20653
+ //
20654
+ // Anchored to the start of an sshd failure ("Failed SSH login for root
20655
+ // from …" from classifySshAuth, or a raw "[sshd] Failed password for
20656
+ // root …" journal line). Unanchored, `failed.*\broot\b` matched any auth
20657
+ // event that said "failed" anywhere before "root": privilege-watch logs
20658
+ // every sudo as "sudo: <user> ran <command> as root", so a backup script
20659
+ // whose text read "the copy failed its integrity check" paged a
20660
+ // high-severity "Root SSH Login Attempt" against the admin's own account.
20661
+ value: "^(?:\\[[^\\]]*\\] )?failed (?:ssh login|password|publickey|keyboard-interactive\\S*|none) for (?:invalid user )?root\\b"
20585
20662
  },
20586
20663
  threshold: 1,
20587
20664
  window_seconds: 60,
@@ -21108,11 +21185,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
21108
21185
  function loadAllRules(customDir) {
21109
21186
  const rules = [...DEFAULT_RULES];
21110
21187
  const dir = customDir || RULES_DIR;
21111
- if ((0, import_node_fs32.existsSync)(dir)) {
21112
- const files = (0, import_node_fs32.readdirSync)(dir).filter((f) => f.endsWith(".json"));
21188
+ if ((0, import_node_fs33.existsSync)(dir)) {
21189
+ const files = (0, import_node_fs33.readdirSync)(dir).filter((f) => f.endsWith(".json"));
21113
21190
  for (const file of files) {
21114
21191
  try {
21115
- const raw = (0, import_node_fs32.readFileSync)((0, import_node_path25.join)(dir, file), "utf-8");
21192
+ const raw = (0, import_node_fs33.readFileSync)((0, import_node_path25.join)(dir, file), "utf-8");
21116
21193
  const parsed = JSON.parse(raw);
21117
21194
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
21118
21195
  for (const rule of customRules) {
@@ -21144,7 +21221,7 @@ function loadAllRules(customDir) {
21144
21221
 
21145
21222
  // src/daemon/firewall/adapters.ts
21146
21223
  var import_node_child_process11 = require("child_process");
21147
- var import_node_fs33 = require("fs");
21224
+ var import_node_fs34 = require("fs");
21148
21225
  var import_node_path26 = require("path");
21149
21226
  var import_node_net13 = require("net");
21150
21227
  function assertValidFirewallIp(ip) {
@@ -21158,9 +21235,9 @@ function assertBannableIp(ip) {
21158
21235
  }
21159
21236
  }
21160
21237
  function writeIfAbsent(path, contents) {
21161
- (0, import_node_fs33.mkdirSync)((0, import_node_path26.dirname)(path), { recursive: true });
21238
+ (0, import_node_fs34.mkdirSync)((0, import_node_path26.dirname)(path), { recursive: true });
21162
21239
  try {
21163
- (0, import_node_fs33.writeFileSync)(path, contents, { flag: "wx" });
21240
+ (0, import_node_fs34.writeFileSync)(path, contents, { flag: "wx" });
21164
21241
  } catch (err) {
21165
21242
  if (err.code !== "EEXIST") throw err;
21166
21243
  }
@@ -21419,7 +21496,7 @@ function detectFirewallAdapter(backend = "auto") {
21419
21496
  }
21420
21497
 
21421
21498
  // src/daemon/firewall/remediation.ts
21422
- var import_node_fs34 = require("fs");
21499
+ var import_node_fs35 = require("fs");
21423
21500
  var import_node_child_process12 = require("child_process");
21424
21501
  var import_node_net14 = require("net");
21425
21502
 
@@ -21489,19 +21566,19 @@ var defaultDiscovery = {
21489
21566
  const snapshot = takeSnapshot({
21490
21567
  readFile: (p) => {
21491
21568
  try {
21492
- return (0, import_node_fs34.readFileSync)(p, "utf-8");
21569
+ return (0, import_node_fs35.readFileSync)(p, "utf-8");
21493
21570
  } catch {
21494
21571
  return null;
21495
21572
  }
21496
21573
  },
21497
21574
  readDir: (p) => {
21498
21575
  try {
21499
- return (0, import_node_fs34.readdirSync)(p);
21576
+ return (0, import_node_fs35.readdirSync)(p);
21500
21577
  } catch {
21501
21578
  return null;
21502
21579
  }
21503
21580
  },
21504
- exists: (p) => (0, import_node_fs34.existsSync)(p)
21581
+ exists: (p) => (0, import_node_fs35.existsSync)(p)
21505
21582
  });
21506
21583
  const out = /* @__PURE__ */ new Set();
21507
21584
  for (const keys of Object.values(snapshot.keys)) {
@@ -22014,7 +22091,7 @@ var RemediationManager = class {
22014
22091
  }
22015
22092
  logLine(line) {
22016
22093
  try {
22017
- (0, import_node_fs34.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
22094
+ (0, import_node_fs35.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
22018
22095
  `);
22019
22096
  } catch {
22020
22097
  }
@@ -22054,11 +22131,11 @@ function remediationSettings(section) {
22054
22131
  }
22055
22132
 
22056
22133
  // src/daemon/watchdog-service.ts
22057
- var import_node_fs36 = require("fs");
22134
+ var import_node_fs37 = require("fs");
22058
22135
  var import_node_path28 = require("path");
22059
22136
 
22060
22137
  // src/core/watchdog.ts
22061
- var import_node_fs35 = require("fs");
22138
+ var import_node_fs36 = require("fs");
22062
22139
  var import_node_crypto9 = require("crypto");
22063
22140
  var import_node_path27 = require("path");
22064
22141
  var WATCHDOG_DIRNAME = "watchdog";
@@ -22151,10 +22228,10 @@ var WatchdogLog = class {
22151
22228
  this.dir = dir;
22152
22229
  this.file = (0, import_node_path27.join)(dir, LOG_FILE2);
22153
22230
  this.shareGid = options.shareGid;
22154
- (0, import_node_fs35.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
22231
+ (0, import_node_fs36.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
22155
22232
  if (this.shareGid !== void 0) {
22156
- (0, import_node_fs35.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
22157
- (0, import_node_fs35.chmodSync)(dir, 1528);
22233
+ (0, import_node_fs36.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
22234
+ (0, import_node_fs36.chmodSync)(dir, 1528);
22158
22235
  }
22159
22236
  for (const r of readTail(this.file, 512 * 1024)) this.remember(dedupeKey(r));
22160
22237
  }
@@ -22183,16 +22260,16 @@ var WatchdogLog = class {
22183
22260
  const chunk = this.buffer.join("\n") + "\n";
22184
22261
  this.buffer = [];
22185
22262
  try {
22186
- if ((0, import_node_fs35.statSync)(this.file).size > ROTATE_BYTES) {
22187
- (0, import_node_fs35.renameSync)(this.file, (0, import_node_path27.join)(this.dir, ROTATED_FILE));
22263
+ if ((0, import_node_fs36.statSync)(this.file).size > ROTATE_BYTES) {
22264
+ (0, import_node_fs36.renameSync)(this.file, (0, import_node_path27.join)(this.dir, ROTATED_FILE));
22188
22265
  }
22189
22266
  } catch {
22190
22267
  }
22191
- (0, import_node_fs35.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
22268
+ (0, import_node_fs36.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
22192
22269
  if (this.shareGid !== void 0) {
22193
22270
  try {
22194
- (0, import_node_fs35.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
22195
- (0, import_node_fs35.chmodSync)(this.file, 432);
22271
+ (0, import_node_fs36.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
22272
+ (0, import_node_fs36.chmodSync)(this.file, 432);
22196
22273
  } catch {
22197
22274
  }
22198
22275
  }
@@ -22213,21 +22290,21 @@ function parseLines(text) {
22213
22290
  function readTail(file, bytes) {
22214
22291
  let fd;
22215
22292
  try {
22216
- fd = (0, import_node_fs35.openSync)(file, "r");
22293
+ fd = (0, import_node_fs36.openSync)(file, "r");
22217
22294
  } catch (err) {
22218
22295
  if (err.code === "ENOENT") return [];
22219
22296
  throw err;
22220
22297
  }
22221
22298
  try {
22222
- const size = (0, import_node_fs35.fstatSync)(fd).size;
22299
+ const size = (0, import_node_fs36.fstatSync)(fd).size;
22223
22300
  const start = Math.max(0, size - bytes);
22224
22301
  const buf = Buffer.alloc(size - start);
22225
- (0, import_node_fs35.readSync)(fd, buf, 0, buf.length, start);
22302
+ (0, import_node_fs36.readSync)(fd, buf, 0, buf.length, start);
22226
22303
  let text = buf.toString("utf8");
22227
22304
  if (start > 0) text = text.slice(text.indexOf("\n") + 1);
22228
22305
  return parseLines(text);
22229
22306
  } finally {
22230
- (0, import_node_fs35.closeSync)(fd);
22307
+ (0, import_node_fs36.closeSync)(fd);
22231
22308
  }
22232
22309
  }
22233
22310
 
@@ -22236,7 +22313,7 @@ function defaultShareGid() {
22236
22313
  const isRoot2 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
22237
22314
  if (!isRoot2) return void 0;
22238
22315
  try {
22239
- return (0, import_node_fs36.statSync)("/var/log/auth.log").gid;
22316
+ return (0, import_node_fs37.statSync)("/var/log/auth.log").gid;
22240
22317
  } catch {
22241
22318
  return void 0;
22242
22319
  }
@@ -22349,7 +22426,7 @@ function daemonNodeProblem(version) {
22349
22426
  // src/daemon/index.ts
22350
22427
  function readVersion2() {
22351
22428
  try {
22352
- const pkg = JSON.parse((0, import_node_fs37.readFileSync)((0, import_node_path29.join)(__dirname, "..", "package.json"), "utf-8"));
22429
+ const pkg = JSON.parse((0, import_node_fs38.readFileSync)((0, import_node_path29.join)(__dirname, "..", "package.json"), "utf-8"));
22353
22430
  return pkg.version || "0.0.0";
22354
22431
  } catch {
22355
22432
  return "0.0.0";
@@ -22380,7 +22457,7 @@ async function runPatchCheck() {
22380
22457
  }
22381
22458
  function logLine(line) {
22382
22459
  try {
22383
- (0, import_node_fs37.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
22460
+ (0, import_node_fs38.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
22384
22461
  `);
22385
22462
  } catch {
22386
22463
  }
@@ -22463,8 +22540,11 @@ async function runDaemon() {
22463
22540
  bus.publish(event);
22464
22541
  });
22465
22542
  ruleEngine.loadRules(loadAllRules());
22543
+ const keyDirectory = new KeyDirectory();
22466
22544
  bus.on("event", (event) => {
22467
- if (event.module !== "rule-engine") ruleEngine.evaluate(event);
22545
+ if (event.module === "rule-engine") return;
22546
+ enrichLoginEvent(event, keyDirectory);
22547
+ ruleEngine.evaluate(event);
22468
22548
  });
22469
22549
  logLine(`[daemon] rule engine loaded ${ruleEngine.getRules().length} rules`);
22470
22550
  setInterval(() => ruleEngine.cleanup(), 6e4);