@profullstack/threatcrush 0.13.67 → 0.13.69

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
@@ -30,9 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  mod
31
31
  ));
32
32
 
33
- // ../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/parser.js
33
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/parser.js
34
34
  var require_parser = __commonJS({
35
- "../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/parser.js"(exports2, module2) {
35
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/parser.js"(exports2, module2) {
36
36
  "use strict";
37
37
  var ParserEND = 1114112;
38
38
  var ParserError = class _ParserError extends Error {
@@ -155,9 +155,9 @@ var require_parser = __commonJS({
155
155
  }
156
156
  });
157
157
 
158
- // ../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime.js
158
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime.js
159
159
  var require_create_datetime = __commonJS({
160
- "../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime.js"(exports2, module2) {
160
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime.js"(exports2, module2) {
161
161
  "use strict";
162
162
  module2.exports = (value) => {
163
163
  const date = new Date(value);
@@ -170,9 +170,9 @@ var require_create_datetime = __commonJS({
170
170
  }
171
171
  });
172
172
 
173
- // ../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/format-num.js
173
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/format-num.js
174
174
  var require_format_num = __commonJS({
175
- "../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/format-num.js"(exports2, module2) {
175
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/format-num.js"(exports2, module2) {
176
176
  "use strict";
177
177
  module2.exports = (d, num) => {
178
178
  num = String(num);
@@ -182,9 +182,9 @@ var require_format_num = __commonJS({
182
182
  }
183
183
  });
184
184
 
185
- // ../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime-float.js
185
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime-float.js
186
186
  var require_create_datetime_float = __commonJS({
187
- "../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime-float.js"(exports2, module2) {
187
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-datetime-float.js"(exports2, module2) {
188
188
  "use strict";
189
189
  var f = require_format_num();
190
190
  var FloatingDateTime = class extends Date {
@@ -209,9 +209,9 @@ var require_create_datetime_float = __commonJS({
209
209
  }
210
210
  });
211
211
 
212
- // ../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-date.js
212
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-date.js
213
213
  var require_create_date = __commonJS({
214
- "../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-date.js"(exports2, module2) {
214
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-date.js"(exports2, module2) {
215
215
  "use strict";
216
216
  var f = require_format_num();
217
217
  var DateTime = global.Date;
@@ -235,9 +235,9 @@ var require_create_date = __commonJS({
235
235
  }
236
236
  });
237
237
 
238
- // ../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-time.js
238
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-time.js
239
239
  var require_create_time = __commonJS({
240
- "../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-time.js"(exports2, module2) {
240
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/create-time.js"(exports2, module2) {
241
241
  "use strict";
242
242
  var f = require_format_num();
243
243
  var Time = class extends Date {
@@ -260,9 +260,9 @@ var require_create_time = __commonJS({
260
260
  }
261
261
  });
262
262
 
263
- // ../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/toml-parser.js
263
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/toml-parser.js
264
264
  var require_toml_parser = __commonJS({
265
- "../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/toml-parser.js"(exports, module) {
265
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/lib/toml-parser.js"(exports, module) {
266
266
  "use strict";
267
267
  module.exports = makeParserClass(require_parser());
268
268
  module.exports.makeParserClass = makeParserClass;
@@ -1573,9 +1573,9 @@ var require_toml_parser = __commonJS({
1573
1573
  }
1574
1574
  });
1575
1575
 
1576
- // ../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-pretty-error.js
1576
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-pretty-error.js
1577
1577
  var require_parse_pretty_error = __commonJS({
1578
- "../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-pretty-error.js"(exports2, module2) {
1578
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-pretty-error.js"(exports2, module2) {
1579
1579
  "use strict";
1580
1580
  module2.exports = prettyError;
1581
1581
  function prettyError(err, buf) {
@@ -1609,9 +1609,9 @@ var require_parse_pretty_error = __commonJS({
1609
1609
  }
1610
1610
  });
1611
1611
 
1612
- // ../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-string.js
1612
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-string.js
1613
1613
  var require_parse_string = __commonJS({
1614
- "../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-string.js"(exports2, module2) {
1614
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-string.js"(exports2, module2) {
1615
1615
  "use strict";
1616
1616
  module2.exports = parseString;
1617
1617
  var TOMLParser = require_toml_parser();
@@ -1631,9 +1631,9 @@ var require_parse_string = __commonJS({
1631
1631
  }
1632
1632
  });
1633
1633
 
1634
- // ../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-async.js
1634
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-async.js
1635
1635
  var require_parse_async = __commonJS({
1636
- "../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-async.js"(exports2, module2) {
1636
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-async.js"(exports2, module2) {
1637
1637
  "use strict";
1638
1638
  module2.exports = parseAsync;
1639
1639
  var TOMLParser = require_toml_parser();
@@ -1665,9 +1665,9 @@ var require_parse_async = __commonJS({
1665
1665
  }
1666
1666
  });
1667
1667
 
1668
- // ../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-stream.js
1668
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-stream.js
1669
1669
  var require_parse_stream = __commonJS({
1670
- "../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-stream.js"(exports2, module2) {
1670
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse-stream.js"(exports2, module2) {
1671
1671
  "use strict";
1672
1672
  module2.exports = parseStream;
1673
1673
  var stream = require("stream");
@@ -1744,9 +1744,9 @@ var require_parse_stream = __commonJS({
1744
1744
  }
1745
1745
  });
1746
1746
 
1747
- // ../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse.js
1747
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse.js
1748
1748
  var require_parse = __commonJS({
1749
- "../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse.js"(exports2, module2) {
1749
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/parse.js"(exports2, module2) {
1750
1750
  "use strict";
1751
1751
  module2.exports = require_parse_string();
1752
1752
  module2.exports.async = require_parse_async();
@@ -1755,9 +1755,9 @@ var require_parse = __commonJS({
1755
1755
  }
1756
1756
  });
1757
1757
 
1758
- // ../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/stringify.js
1758
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/stringify.js
1759
1759
  var require_stringify = __commonJS({
1760
- "../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/stringify.js"(exports2, module2) {
1760
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/stringify.js"(exports2, module2) {
1761
1761
  "use strict";
1762
1762
  module2.exports = stringify;
1763
1763
  module2.exports.value = stringifyInline;
@@ -2016,9 +2016,9 @@ var require_stringify = __commonJS({
2016
2016
  }
2017
2017
  });
2018
2018
 
2019
- // ../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/toml.js
2019
+ // ../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/toml.js
2020
2020
  var require_toml = __commonJS({
2021
- "../../../../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/toml.js"(exports2) {
2021
+ "../../node_modules/.pnpm/@iarna+toml@2.2.5/node_modules/@iarna/toml/toml.js"(exports2) {
2022
2022
  "use strict";
2023
2023
  exports2.parse = require_parse();
2024
2024
  exports2.stringify = require_stringify();
@@ -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");
@@ -11677,7 +11677,8 @@ var DEDUPE_MS = 10 * 6e4;
11677
11677
  var MAX_PER_HOUR = 6;
11678
11678
  function smshubText(event, host = (0, import_node_os2.hostname)()) {
11679
11679
  const evidence = event.details?.evidence?.message;
11680
- const text = `ThreatCrush ${event.severity.toUpperCase()} on ${host}: ${event.message}${evidence && !event.message.includes(evidence) ? ` | ${evidence}` : ""}`;
11680
+ const ip = event.source_ip && ![event.message, evidence ?? ""].some((t) => t.includes(event.source_ip)) ? ` from ${event.source_ip}` : "";
11681
+ const text = `ThreatCrush ${event.severity.toUpperCase()} on ${host}: ${event.message}${evidence && !event.message.includes(evidence) ? ` | ${evidence}` : ""}${ip}`;
11681
11682
  return text.replace(/\s+/g, " ").slice(0, 600);
11682
11683
  }
11683
11684
  function smshubChannel(config, opts = {}) {
@@ -12008,7 +12009,7 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
12008
12009
  var import_node_fs19 = require("fs");
12009
12010
  var import_node_path13 = require("path");
12010
12011
 
12011
- // ../../../../../node_modules/.pnpm/chalk@6.0.1/node_modules/chalk/source/utilities.js
12012
+ // ../../node_modules/.pnpm/chalk@6.0.1/node_modules/chalk/source/utilities.js
12012
12013
  function stringReplaceAll(string, substring, postfix) {
12013
12014
  let index = string.indexOf(substring);
12014
12015
  if (index === -1) {
@@ -12038,7 +12039,7 @@ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
12038
12039
  return returnValue;
12039
12040
  }
12040
12041
 
12041
- // ../../../../../node_modules/.pnpm/chalk@6.0.1/node_modules/chalk/source/vendor/ansi-styles/index.js
12042
+ // ../../node_modules/.pnpm/chalk@6.0.1/node_modules/chalk/source/vendor/ansi-styles/index.js
12042
12043
  var ANSI_BACKGROUND_OFFSET = 10;
12043
12044
  var ANSI_UNDERLINE_OFFSET = 20;
12044
12045
  var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
@@ -12260,7 +12261,7 @@ function assembleStyles() {
12260
12261
  var ansiStyles = assembleStyles();
12261
12262
  var ansi_styles_default = ansiStyles;
12262
12263
 
12263
- // ../../../../../node_modules/.pnpm/chalk@6.0.1/node_modules/chalk/source/vendor/supports-color/index.js
12264
+ // ../../node_modules/.pnpm/chalk@6.0.1/node_modules/chalk/source/vendor/supports-color/index.js
12264
12265
  var import_node_process = __toESM(require("process"), 1);
12265
12266
  var import_node_os4 = __toESM(require("os"), 1);
12266
12267
  var import_node_tty = __toESM(require("tty"), 1);
@@ -12402,7 +12403,7 @@ var supportsColor = {
12402
12403
  };
12403
12404
  var supports_color_default = supportsColor;
12404
12405
 
12405
- // ../../../../../node_modules/.pnpm/chalk@6.0.1/node_modules/chalk/source/index.js
12406
+ // ../../node_modules/.pnpm/chalk@6.0.1/node_modules/chalk/source/index.js
12406
12407
  var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
12407
12408
  var GENERATOR = /* @__PURE__ */ Symbol("GENERATOR");
12408
12409
  var STYLER = /* @__PURE__ */ Symbol("STYLER");
@@ -20097,8 +20098,68 @@ var SshIntrusionWatch = class {
20097
20098
  }
20098
20099
  };
20099
20100
 
20100
- // src/daemon/workers/lightning-watch.ts
20101
+ // src/daemon/key-directory.ts
20101
20102
  var import_node_fs30 = require("fs");
20103
+ var fsIO3 = {
20104
+ readFile: (p) => {
20105
+ try {
20106
+ return (0, import_node_fs30.readFileSync)(p, "utf-8");
20107
+ } catch {
20108
+ return null;
20109
+ }
20110
+ },
20111
+ readDir: (p) => {
20112
+ try {
20113
+ return (0, import_node_fs30.readdirSync)(p);
20114
+ } catch {
20115
+ return null;
20116
+ }
20117
+ },
20118
+ exists: (p) => (0, import_node_fs30.existsSync)(p)
20119
+ };
20120
+ var KeyDirectory = class {
20121
+ constructor(io = fsIO3, now = Date.now, ttlMs = 3e5) {
20122
+ this.io = io;
20123
+ this.now = now;
20124
+ this.ttlMs = ttlMs;
20125
+ }
20126
+ io;
20127
+ now;
20128
+ ttlMs;
20129
+ cache = { at: -Infinity, byFp: /* @__PURE__ */ new Map() };
20130
+ lookup(fingerprint) {
20131
+ if (this.now() - this.cache.at > this.ttlMs) {
20132
+ const byFp = /* @__PURE__ */ new Map();
20133
+ for (const [account, keys] of Object.entries(takeSnapshot(this.io).keys)) {
20134
+ for (const [fp, k] of Object.entries(keys)) if (!byFp.has(fp)) byFp.set(fp, { account, comment: k.comment });
20135
+ }
20136
+ this.cache = { at: this.now(), byFp };
20137
+ }
20138
+ return this.cache.byFp.get(fingerprint) ?? null;
20139
+ }
20140
+ };
20141
+ function enrichLoginEvent(event, keys) {
20142
+ if (event.module !== "ssh-guard") return;
20143
+ const details = event.details;
20144
+ const fp = details?.fingerprint;
20145
+ if (!details || typeof fp !== "string" || !fp.startsWith("SHA256:") || "key_kind" in details) return;
20146
+ let entry = null;
20147
+ try {
20148
+ entry = keys.lookup(fp);
20149
+ } catch {
20150
+ entry = null;
20151
+ }
20152
+ if (!entry) {
20153
+ details.key_kind = "unknown";
20154
+ return;
20155
+ }
20156
+ details.key_account = entry.account;
20157
+ if (entry.comment) details.key_comment = entry.comment;
20158
+ details.key_kind = isAutomationKeyComment(entry.comment) ? "automation" : "person";
20159
+ }
20160
+
20161
+ // src/daemon/workers/lightning-watch.ts
20162
+ var import_node_fs31 = require("fs");
20102
20163
  var DEFAULT_CLN_LOGS = [
20103
20164
  "/home/lightning/.lightning/cln.log",
20104
20165
  "/root/.lightning/cln.log",
@@ -20154,9 +20215,9 @@ var LightningWatch = class {
20154
20215
  if (this.opts.enabled === false) return [];
20155
20216
  const found = [];
20156
20217
  for (const path of this.opts.paths?.length ? this.opts.paths : DEFAULT_CLN_LOGS) {
20157
- if (!(0, import_node_fs30.existsSync)(path)) continue;
20218
+ if (!(0, import_node_fs31.existsSync)(path)) continue;
20158
20219
  try {
20159
- (0, import_node_fs30.accessSync)(path, import_node_fs30.constants.R_OK);
20220
+ (0, import_node_fs31.accessSync)(path, import_node_fs31.constants.R_OK);
20160
20221
  } catch {
20161
20222
  continue;
20162
20223
  }
@@ -20191,7 +20252,7 @@ var LightningWatch = class {
20191
20252
  };
20192
20253
 
20193
20254
  // src/core/tor-exits.ts
20194
- var import_node_fs31 = require("fs");
20255
+ var import_node_fs32 = require("fs");
20195
20256
  var import_node_path24 = require("path");
20196
20257
  var import_node_net12 = require("net");
20197
20258
  var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
@@ -20260,10 +20321,10 @@ var TorExitList = class _TorExitList {
20260
20321
  }
20261
20322
  loadCache() {
20262
20323
  try {
20263
- if (!(0, import_node_fs31.existsSync)(this.opts.cachePath)) return false;
20264
- const parsed = parseTorExitList((0, import_node_fs31.readFileSync)(this.opts.cachePath, "utf-8"));
20324
+ if (!(0, import_node_fs32.existsSync)(this.opts.cachePath)) return false;
20325
+ const parsed = parseTorExitList((0, import_node_fs32.readFileSync)(this.opts.cachePath, "utf-8"));
20265
20326
  if (parsed.size === 0) return false;
20266
- this.load(parsed, (0, import_node_fs31.statSync)(this.opts.cachePath).mtimeMs);
20327
+ this.load(parsed, (0, import_node_fs32.statSync)(this.opts.cachePath).mtimeMs);
20267
20328
  this.log(`[tor] loaded ${parsed.size} Tor exit addresses from cache (${new Date(this.updatedAt).toISOString()})`);
20268
20329
  return true;
20269
20330
  } catch (err) {
@@ -20295,9 +20356,9 @@ var TorExitList = class _TorExitList {
20295
20356
  const before = this.exits.size;
20296
20357
  this.load(parsed);
20297
20358
  try {
20298
- (0, import_node_fs31.mkdirSync)((0, import_node_path24.dirname)(this.opts.cachePath), { recursive: true });
20299
- (0, import_node_fs31.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
20300
- (0, import_node_fs31.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
20359
+ (0, import_node_fs32.mkdirSync)((0, import_node_path24.dirname)(this.opts.cachePath), { recursive: true });
20360
+ (0, import_node_fs32.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
20361
+ (0, import_node_fs32.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
20301
20362
  } catch (err) {
20302
20363
  this.log(`[tor] could not save the exit list cache: ${err.message}`);
20303
20364
  }
@@ -20338,6 +20399,9 @@ var EVIDENCE_FIELDS = [
20338
20399
  "system_uid",
20339
20400
  "fingerprint",
20340
20401
  "key_type",
20402
+ "key_comment",
20403
+ "key_kind",
20404
+ "key_account",
20341
20405
  "auth_method",
20342
20406
  "port",
20343
20407
  "path",
@@ -20515,7 +20579,7 @@ var RuleEngine = class {
20515
20579
  };
20516
20580
 
20517
20581
  // src/daemon/rules/loader.ts
20518
- var import_node_fs32 = require("fs");
20582
+ var import_node_fs33 = require("fs");
20519
20583
  var import_node_path25 = require("path");
20520
20584
 
20521
20585
  // src/daemon/rules/default-rules.ts
@@ -21107,11 +21171,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
21107
21171
  function loadAllRules(customDir) {
21108
21172
  const rules = [...DEFAULT_RULES];
21109
21173
  const dir = customDir || RULES_DIR;
21110
- if ((0, import_node_fs32.existsSync)(dir)) {
21111
- const files = (0, import_node_fs32.readdirSync)(dir).filter((f) => f.endsWith(".json"));
21174
+ if ((0, import_node_fs33.existsSync)(dir)) {
21175
+ const files = (0, import_node_fs33.readdirSync)(dir).filter((f) => f.endsWith(".json"));
21112
21176
  for (const file of files) {
21113
21177
  try {
21114
- const raw = (0, import_node_fs32.readFileSync)((0, import_node_path25.join)(dir, file), "utf-8");
21178
+ const raw = (0, import_node_fs33.readFileSync)((0, import_node_path25.join)(dir, file), "utf-8");
21115
21179
  const parsed = JSON.parse(raw);
21116
21180
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
21117
21181
  for (const rule of customRules) {
@@ -21143,7 +21207,7 @@ function loadAllRules(customDir) {
21143
21207
 
21144
21208
  // src/daemon/firewall/adapters.ts
21145
21209
  var import_node_child_process11 = require("child_process");
21146
- var import_node_fs33 = require("fs");
21210
+ var import_node_fs34 = require("fs");
21147
21211
  var import_node_path26 = require("path");
21148
21212
  var import_node_net13 = require("net");
21149
21213
  function assertValidFirewallIp(ip) {
@@ -21157,9 +21221,9 @@ function assertBannableIp(ip) {
21157
21221
  }
21158
21222
  }
21159
21223
  function writeIfAbsent(path, contents) {
21160
- (0, import_node_fs33.mkdirSync)((0, import_node_path26.dirname)(path), { recursive: true });
21224
+ (0, import_node_fs34.mkdirSync)((0, import_node_path26.dirname)(path), { recursive: true });
21161
21225
  try {
21162
- (0, import_node_fs33.writeFileSync)(path, contents, { flag: "wx" });
21226
+ (0, import_node_fs34.writeFileSync)(path, contents, { flag: "wx" });
21163
21227
  } catch (err) {
21164
21228
  if (err.code !== "EEXIST") throw err;
21165
21229
  }
@@ -21418,7 +21482,7 @@ function detectFirewallAdapter(backend = "auto") {
21418
21482
  }
21419
21483
 
21420
21484
  // src/daemon/firewall/remediation.ts
21421
- var import_node_fs34 = require("fs");
21485
+ var import_node_fs35 = require("fs");
21422
21486
  var import_node_child_process12 = require("child_process");
21423
21487
  var import_node_net14 = require("net");
21424
21488
 
@@ -21488,19 +21552,19 @@ var defaultDiscovery = {
21488
21552
  const snapshot = takeSnapshot({
21489
21553
  readFile: (p) => {
21490
21554
  try {
21491
- return (0, import_node_fs34.readFileSync)(p, "utf-8");
21555
+ return (0, import_node_fs35.readFileSync)(p, "utf-8");
21492
21556
  } catch {
21493
21557
  return null;
21494
21558
  }
21495
21559
  },
21496
21560
  readDir: (p) => {
21497
21561
  try {
21498
- return (0, import_node_fs34.readdirSync)(p);
21562
+ return (0, import_node_fs35.readdirSync)(p);
21499
21563
  } catch {
21500
21564
  return null;
21501
21565
  }
21502
21566
  },
21503
- exists: (p) => (0, import_node_fs34.existsSync)(p)
21567
+ exists: (p) => (0, import_node_fs35.existsSync)(p)
21504
21568
  });
21505
21569
  const out = /* @__PURE__ */ new Set();
21506
21570
  for (const keys of Object.values(snapshot.keys)) {
@@ -22013,7 +22077,7 @@ var RemediationManager = class {
22013
22077
  }
22014
22078
  logLine(line) {
22015
22079
  try {
22016
- (0, import_node_fs34.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
22080
+ (0, import_node_fs35.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
22017
22081
  `);
22018
22082
  } catch {
22019
22083
  }
@@ -22053,11 +22117,11 @@ function remediationSettings(section) {
22053
22117
  }
22054
22118
 
22055
22119
  // src/daemon/watchdog-service.ts
22056
- var import_node_fs36 = require("fs");
22120
+ var import_node_fs37 = require("fs");
22057
22121
  var import_node_path28 = require("path");
22058
22122
 
22059
22123
  // src/core/watchdog.ts
22060
- var import_node_fs35 = require("fs");
22124
+ var import_node_fs36 = require("fs");
22061
22125
  var import_node_crypto9 = require("crypto");
22062
22126
  var import_node_path27 = require("path");
22063
22127
  var WATCHDOG_DIRNAME = "watchdog";
@@ -22150,10 +22214,10 @@ var WatchdogLog = class {
22150
22214
  this.dir = dir;
22151
22215
  this.file = (0, import_node_path27.join)(dir, LOG_FILE2);
22152
22216
  this.shareGid = options.shareGid;
22153
- (0, import_node_fs35.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
22217
+ (0, import_node_fs36.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
22154
22218
  if (this.shareGid !== void 0) {
22155
- (0, import_node_fs35.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
22156
- (0, import_node_fs35.chmodSync)(dir, 1528);
22219
+ (0, import_node_fs36.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
22220
+ (0, import_node_fs36.chmodSync)(dir, 1528);
22157
22221
  }
22158
22222
  for (const r of readTail(this.file, 512 * 1024)) this.remember(dedupeKey(r));
22159
22223
  }
@@ -22182,16 +22246,16 @@ var WatchdogLog = class {
22182
22246
  const chunk = this.buffer.join("\n") + "\n";
22183
22247
  this.buffer = [];
22184
22248
  try {
22185
- if ((0, import_node_fs35.statSync)(this.file).size > ROTATE_BYTES) {
22186
- (0, import_node_fs35.renameSync)(this.file, (0, import_node_path27.join)(this.dir, ROTATED_FILE));
22249
+ if ((0, import_node_fs36.statSync)(this.file).size > ROTATE_BYTES) {
22250
+ (0, import_node_fs36.renameSync)(this.file, (0, import_node_path27.join)(this.dir, ROTATED_FILE));
22187
22251
  }
22188
22252
  } catch {
22189
22253
  }
22190
- (0, import_node_fs35.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
22254
+ (0, import_node_fs36.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
22191
22255
  if (this.shareGid !== void 0) {
22192
22256
  try {
22193
- (0, import_node_fs35.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
22194
- (0, import_node_fs35.chmodSync)(this.file, 432);
22257
+ (0, import_node_fs36.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
22258
+ (0, import_node_fs36.chmodSync)(this.file, 432);
22195
22259
  } catch {
22196
22260
  }
22197
22261
  }
@@ -22212,21 +22276,21 @@ function parseLines(text) {
22212
22276
  function readTail(file, bytes) {
22213
22277
  let fd;
22214
22278
  try {
22215
- fd = (0, import_node_fs35.openSync)(file, "r");
22279
+ fd = (0, import_node_fs36.openSync)(file, "r");
22216
22280
  } catch (err) {
22217
22281
  if (err.code === "ENOENT") return [];
22218
22282
  throw err;
22219
22283
  }
22220
22284
  try {
22221
- const size = (0, import_node_fs35.fstatSync)(fd).size;
22285
+ const size = (0, import_node_fs36.fstatSync)(fd).size;
22222
22286
  const start = Math.max(0, size - bytes);
22223
22287
  const buf = Buffer.alloc(size - start);
22224
- (0, import_node_fs35.readSync)(fd, buf, 0, buf.length, start);
22288
+ (0, import_node_fs36.readSync)(fd, buf, 0, buf.length, start);
22225
22289
  let text = buf.toString("utf8");
22226
22290
  if (start > 0) text = text.slice(text.indexOf("\n") + 1);
22227
22291
  return parseLines(text);
22228
22292
  } finally {
22229
- (0, import_node_fs35.closeSync)(fd);
22293
+ (0, import_node_fs36.closeSync)(fd);
22230
22294
  }
22231
22295
  }
22232
22296
 
@@ -22235,7 +22299,7 @@ function defaultShareGid() {
22235
22299
  const isRoot2 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
22236
22300
  if (!isRoot2) return void 0;
22237
22301
  try {
22238
- return (0, import_node_fs36.statSync)("/var/log/auth.log").gid;
22302
+ return (0, import_node_fs37.statSync)("/var/log/auth.log").gid;
22239
22303
  } catch {
22240
22304
  return void 0;
22241
22305
  }
@@ -22348,7 +22412,7 @@ function daemonNodeProblem(version) {
22348
22412
  // src/daemon/index.ts
22349
22413
  function readVersion2() {
22350
22414
  try {
22351
- const pkg = JSON.parse((0, import_node_fs37.readFileSync)((0, import_node_path29.join)(__dirname, "..", "package.json"), "utf-8"));
22415
+ const pkg = JSON.parse((0, import_node_fs38.readFileSync)((0, import_node_path29.join)(__dirname, "..", "package.json"), "utf-8"));
22352
22416
  return pkg.version || "0.0.0";
22353
22417
  } catch {
22354
22418
  return "0.0.0";
@@ -22379,7 +22443,7 @@ async function runPatchCheck() {
22379
22443
  }
22380
22444
  function logLine(line) {
22381
22445
  try {
22382
- (0, import_node_fs37.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
22446
+ (0, import_node_fs38.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
22383
22447
  `);
22384
22448
  } catch {
22385
22449
  }
@@ -22462,8 +22526,11 @@ async function runDaemon() {
22462
22526
  bus.publish(event);
22463
22527
  });
22464
22528
  ruleEngine.loadRules(loadAllRules());
22529
+ const keyDirectory = new KeyDirectory();
22465
22530
  bus.on("event", (event) => {
22466
- if (event.module !== "rule-engine") ruleEngine.evaluate(event);
22531
+ if (event.module === "rule-engine") return;
22532
+ enrichLoginEvent(event, keyDirectory);
22533
+ ruleEngine.evaluate(event);
22467
22534
  });
22468
22535
  logLine(`[daemon] rule engine loaded ${ruleEngine.getRules().length} rules`);
22469
22536
  setInterval(() => ruleEngine.cleanup(), 6e4);