@profullstack/threatcrush 0.13.77 → 0.13.79

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
@@ -23787,7 +23787,7 @@ var source_default = chalk;
23787
23787
  // src/index.ts
23788
23788
  var import_readline = __toESM(require("readline"));
23789
23789
  var import_node_child_process29 = require("child_process");
23790
- var import_node_fs75 = require("fs");
23790
+ var import_node_fs76 = require("fs");
23791
23791
  var import_node_path58 = require("path");
23792
23792
  var import_node_os24 = require("os");
23793
23793
 
@@ -30533,13 +30533,13 @@ var CrsEngine = class {
30533
30533
  }
30534
30534
  return hits;
30535
30535
  }
30536
- assess(request) {
30536
+ assess(request2) {
30537
30537
  const ctx = new RequestContext({
30538
- method: request.method,
30539
- uri: asBytes(request.uri),
30540
- protocol: request.protocol,
30541
- userAgent: asBytes(request.userAgent),
30542
- referer: asBytes(request.referer)
30538
+ method: request2.method,
30539
+ uri: asBytes(request2.uri),
30540
+ protocol: request2.protocol,
30541
+ userAgent: asBytes(request2.userAgent),
30542
+ referer: asBytes(request2.referer)
30543
30543
  });
30544
30544
  const hit = new Uint8Array(this.rules.length);
30545
30545
  for (const [target, rules] of this.byTarget) {
@@ -30612,9 +30612,9 @@ function parseCaddyAccessLog(line2) {
30612
30612
  return null;
30613
30613
  }
30614
30614
  if (typeof entry.logger !== "string" || !/^http\.log\.access(?:\.log\d+)?$/.test(entry.logger)) return null;
30615
- const request = entry.request;
30616
- if (!request || typeof request !== "object" || Array.isArray(request)) return null;
30617
- const req = request;
30615
+ const request2 = entry.request;
30616
+ if (!request2 || typeof request2 !== "object" || Array.isArray(request2)) return null;
30617
+ const req = request2;
30618
30618
  const host = typeof req.host === "string" ? req.host.toLowerCase() : "";
30619
30619
  if (host !== "agent.database.pit.world") return null;
30620
30620
  const required = [req.method, req.uri, entry.status, entry.size];
@@ -30846,6 +30846,7 @@ function parseConfigText(raw) {
30846
30846
  file_integrity: parsed.file_integrity,
30847
30847
  edr: parsed.edr,
30848
30848
  lightning: parsed.lightning,
30849
+ docker_logs: parsed.docker_logs,
30849
30850
  storage: parsed.storage,
30850
30851
  // TOML's `[abuse-reporter]` parses to a hyphenated key; expose it under
30851
30852
  // the JS-friendly name the rest of the daemon reads.
@@ -31063,7 +31064,7 @@ function getTopSources(limit = 10) {
31063
31064
  `).all(RECENT_WINDOW, limit);
31064
31065
  }
31065
31066
  var DEFAULT_EVENT_RETENTION_SECONDS = 14 * 86400;
31066
- var DEFAULT_MAX_EVENTS = 2e6;
31067
+ var DEFAULT_MAX_EVENTS = 25e4;
31067
31068
  function pruneEvents(opts = {}) {
31068
31069
  const database = tryDb();
31069
31070
  if (!database) return 0;
@@ -39214,11 +39215,11 @@ async function startLinkLogin(pkce, deviceName = (0, import_node_os8.hostname)()
39214
39215
  return data;
39215
39216
  }
39216
39217
  var sleep = (ms) => new Promise((resolve9) => setTimeout(resolve9, ms));
39217
- async function waitForApproval(request, pkce, opts = {}) {
39218
+ async function waitForApproval(request2, pkce, opts = {}) {
39218
39219
  const wait = opts.sleepMs ?? sleep;
39219
39220
  const now = opts.now ?? Date.now;
39220
- const deadline = Date.parse(request.expires_at) || now() + 10 * 6e4;
39221
- const intervalMs = Math.max(1, request.interval || 3) * 1e3;
39221
+ const deadline = Date.parse(request2.expires_at) || now() + 10 * 6e4;
39222
+ const intervalMs = Math.max(1, request2.interval || 3) * 1e3;
39222
39223
  while (now() < deadline) {
39223
39224
  await wait(intervalMs);
39224
39225
  let res;
@@ -39226,7 +39227,7 @@ async function waitForApproval(request, pkce, opts = {}) {
39226
39227
  res = await fetch(`${apiUrl()}/api/auth/cli/token`, {
39227
39228
  method: "POST",
39228
39229
  headers: { "Content-Type": "application/json" },
39229
- body: JSON.stringify({ request_id: request.request_id, code_verifier: pkce.verifier }),
39230
+ body: JSON.stringify({ request_id: request2.request_id, code_verifier: pkce.verifier }),
39230
39231
  signal: AbortSignal.timeout(15e3)
39231
39232
  });
39232
39233
  } catch {
@@ -39339,9 +39340,9 @@ async function loginCommand(opts = {}) {
39339
39340
  }
39340
39341
  async function linkLoginCommand() {
39341
39342
  const pkce = createPkce();
39342
- let request;
39343
+ let request2;
39343
39344
  try {
39344
- request = await startLinkLogin(pkce);
39345
+ request2 = await startLinkLogin(pkce);
39345
39346
  } catch (err) {
39346
39347
  console.log(source_default.red(` \u2717 ${err.message}
39347
39348
  `));
@@ -39352,12 +39353,12 @@ async function linkLoginCommand() {
39352
39353
  console.log(source_default.gray(" " + "\u2500".repeat(40)));
39353
39354
  console.log(` Open this link in a browser where you are signed in:
39354
39355
  `);
39355
- console.log(` ${source_default.white.underline(request.verification_url)}
39356
+ console.log(` ${source_default.white.underline(request2.verification_url)}
39356
39357
  `);
39357
- console.log(` Check it shows this code: ${source_default.green.bold(request.user_code)}
39358
+ console.log(` Check it shows this code: ${source_default.green.bold(request2.user_code)}
39358
39359
  `);
39359
39360
  console.log(source_default.dim(" Waiting for approval\u2026 (Ctrl-C to cancel)"));
39360
- const result = await waitForApproval(request, pkce);
39361
+ const result = await waitForApproval(request2, pkce);
39361
39362
  if (!result.ok) {
39362
39363
  console.log(source_default.red(`
39363
39364
  \u2717 ${result.error}
@@ -43431,12 +43432,12 @@ async function sshConnect(options) {
43431
43432
 
43432
43433
  // src/commands/daemon.ts
43433
43434
  var import_node_child_process21 = require("child_process");
43434
- var import_node_fs59 = require("fs");
43435
- var import_node_path47 = require("path");
43436
43435
  var import_node_fs60 = require("fs");
43436
+ var import_node_path47 = require("path");
43437
+ var import_node_fs61 = require("fs");
43437
43438
 
43438
43439
  // src/daemon/index.ts
43439
- var import_node_fs58 = require("fs");
43440
+ var import_node_fs59 = require("fs");
43440
43441
  var import_node_child_process20 = require("child_process");
43441
43442
  var import_node_os19 = require("os");
43442
43443
  var import_node_path46 = require("path");
@@ -49827,10 +49828,307 @@ var LightningWatch = class {
49827
49828
  }
49828
49829
  };
49829
49830
 
49830
- // src/core/tor-exits.ts
49831
+ // src/daemon/workers/docker-logs.ts
49831
49832
  var import_node_fs53 = require("fs");
49832
- var import_node_path42 = require("path");
49833
+ var import_node_http = require("http");
49833
49834
  var import_node_net15 = require("net");
49835
+ var DEFAULT_DOCKER_SOCKET = "/var/run/docker.sock";
49836
+ var DEFAULT_NAME_PATTERN = "supabase-db$";
49837
+ var DEFAULT_IMAGE_PATTERN = "(^|/)postgres(:|@|$)";
49838
+ function regexOr(source, fallback) {
49839
+ if (typeof source === "string" && source) {
49840
+ try {
49841
+ return new RegExp(source, "i");
49842
+ } catch {
49843
+ }
49844
+ }
49845
+ return new RegExp(fallback, "i");
49846
+ }
49847
+ function dockerLogsSettings(section) {
49848
+ const poll = Number(section?.poll_seconds);
49849
+ return {
49850
+ enabled: section?.enabled !== false,
49851
+ socket: typeof section?.socket === "string" && section.socket ? section.socket : DEFAULT_DOCKER_SOCKET,
49852
+ namePattern: regexOr(section?.name_pattern, DEFAULT_NAME_PATTERN),
49853
+ imagePattern: regexOr(section?.image_pattern, DEFAULT_IMAGE_PATTERN),
49854
+ pollMs: Number.isFinite(poll) && poll >= 2 ? poll * 1e3 : 15e3
49855
+ };
49856
+ }
49857
+ var PASSWORD_FAILED = /FATAL:\s+password authentication failed for user "([^"]*)"/;
49858
+ var HBA_REJECT = /FATAL:\s+no pg_hba\.conf entry for (?:replication connection from )?host "([^"]+)", user "([^"]*)"(?:, database "([^"]*)")?/;
49859
+ function cleanPgHost(raw) {
49860
+ if (!raw) return void 0;
49861
+ let host = raw.trim().replace(/\(\d+\)$/, "").replace(/^\[|\]$/g, "");
49862
+ if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(host)) host = host.slice(7);
49863
+ return (0, import_node_net15.isIP)(host) ? host : void 0;
49864
+ }
49865
+ function prefixHost(line2) {
49866
+ const first = cleanPgHost(line2.split(/\s/, 1)[0]);
49867
+ if (first) return first;
49868
+ const m = /\b(?:host|client|remote)=(\S+?)[\s,]/.exec(line2);
49869
+ return cleanPgHost(m?.[1]);
49870
+ }
49871
+ function parsePostgresAuthFailure(line2) {
49872
+ const hba = HBA_REJECT.exec(line2);
49873
+ if (hba) {
49874
+ return {
49875
+ kind: "pg_hba",
49876
+ ip: cleanPgHost(hba[1]) ?? prefixHost(line2),
49877
+ user: hba[2],
49878
+ ...hba[3] !== void 0 ? { database: hba[3] } : {}
49879
+ };
49880
+ }
49881
+ const pw = PASSWORD_FAILED.exec(line2);
49882
+ if (pw) {
49883
+ const ip = prefixHost(line2);
49884
+ const db2 = /\s([^\s@]+)@([^\s@]+)\s+FATAL:/.exec(line2);
49885
+ return { kind: "password", ...ip ? { ip } : {}, user: pw[1], ...db2 ? { database: db2[2] } : {} };
49886
+ }
49887
+ return null;
49888
+ }
49889
+ function isUnbannableSource(ip, protectedList = []) {
49890
+ return isProtected(ip, [...DEFAULT_PROTECTED, ...protectedList]);
49891
+ }
49892
+ function postgresAuthEvent(line2, container, protectedList = [], now = /* @__PURE__ */ new Date()) {
49893
+ const failure = parsePostgresAuthFailure(line2);
49894
+ if (!failure?.ip) return null;
49895
+ if (isUnbannableSource(failure.ip, protectedList)) return null;
49896
+ const who = `user "${failure.user ?? ""}"${failure.database !== void 0 ? ` database "${failure.database}"` : ""}`;
49897
+ const message = failure.kind === "password" ? `Postgres password authentication failed for ${who} from ${failure.ip} (${container})` : `Postgres connection rejected by pg_hba for ${who} from ${failure.ip} (${container})`;
49898
+ return {
49899
+ timestamp: now,
49900
+ module: "postgres-guard",
49901
+ category: "auth",
49902
+ // One failure is not an attack, and anything at the remediation floor
49903
+ // (`min_severity`, high by default) bans on its own. The rule decides.
49904
+ severity: "low",
49905
+ message,
49906
+ source_ip: failure.ip,
49907
+ details: {
49908
+ service: "postgres",
49909
+ container,
49910
+ kind: failure.kind,
49911
+ ...failure.user !== void 0 ? { user: failure.user } : {},
49912
+ ...failure.database !== void 0 ? { database: failure.database } : {},
49913
+ line: line2.slice(0, 500)
49914
+ }
49915
+ };
49916
+ }
49917
+ var DockerLogDecoder = class {
49918
+ constructor(tty4, onLine) {
49919
+ this.tty = tty4;
49920
+ this.onLine = onLine;
49921
+ }
49922
+ tty;
49923
+ onLine;
49924
+ pending = Buffer.alloc(0);
49925
+ partial = /* @__PURE__ */ new Map();
49926
+ push(chunk2) {
49927
+ if (this.tty) {
49928
+ this.text(1, chunk2.toString("utf-8"));
49929
+ return;
49930
+ }
49931
+ this.pending = this.pending.length ? Buffer.concat([this.pending, chunk2]) : chunk2;
49932
+ while (this.pending.length >= 8) {
49933
+ const stream = this.pending[0];
49934
+ const size = this.pending.readUInt32BE(4);
49935
+ if (stream > 2 || this.pending[1] !== 0 || this.pending[2] !== 0 || this.pending[3] !== 0) {
49936
+ this.tty = true;
49937
+ const rest = this.pending;
49938
+ this.pending = Buffer.alloc(0);
49939
+ this.text(1, rest.toString("utf-8"));
49940
+ return;
49941
+ }
49942
+ if (this.pending.length < 8 + size) break;
49943
+ this.text(stream, this.pending.subarray(8, 8 + size).toString("utf-8"));
49944
+ this.pending = this.pending.subarray(8 + size);
49945
+ }
49946
+ }
49947
+ text(stream, text) {
49948
+ let buf = (this.partial.get(stream) ?? "") + text;
49949
+ let idx;
49950
+ while ((idx = buf.indexOf("\n")) >= 0) {
49951
+ const line2 = buf.slice(0, idx).replace(/\r$/, "");
49952
+ buf = buf.slice(idx + 1);
49953
+ if (line2) this.onLine(line2);
49954
+ }
49955
+ this.partial.set(stream, buf.length > 65536 ? "" : buf);
49956
+ }
49957
+ };
49958
+ function socketDeps(socketPath) {
49959
+ return {
49960
+ getJson: (path2) => new Promise((resolve9, reject) => {
49961
+ const req = (0, import_node_http.request)({ socketPath, path: path2, method: "GET", timeout: 1e4 }, (res) => {
49962
+ const chunks = [];
49963
+ res.on("data", (c) => chunks.push(c));
49964
+ res.on("end", () => {
49965
+ const body = Buffer.concat(chunks).toString("utf-8");
49966
+ if ((res.statusCode ?? 500) >= 300) return reject(new Error(`docker ${path2}: HTTP ${res.statusCode} ${body.slice(0, 200)}`));
49967
+ try {
49968
+ resolve9(JSON.parse(body));
49969
+ } catch (err) {
49970
+ reject(err);
49971
+ }
49972
+ });
49973
+ res.on("error", reject);
49974
+ });
49975
+ req.on("timeout", () => req.destroy(new Error(`docker ${path2}: timed out`)));
49976
+ req.on("error", reject);
49977
+ req.end();
49978
+ }),
49979
+ stream: (path2, onData, onEnd) => {
49980
+ let ended = false;
49981
+ const end = () => {
49982
+ if (!ended) {
49983
+ ended = true;
49984
+ onEnd();
49985
+ }
49986
+ };
49987
+ const req = (0, import_node_http.request)({ socketPath, path: path2, method: "GET" }, (res) => {
49988
+ if ((res.statusCode ?? 500) >= 300) {
49989
+ res.resume();
49990
+ end();
49991
+ return;
49992
+ }
49993
+ res.on("data", onData);
49994
+ res.on("end", end);
49995
+ res.on("close", end);
49996
+ res.on("error", end);
49997
+ });
49998
+ req.on("error", end);
49999
+ req.on("close", end);
50000
+ req.end();
50001
+ return req;
50002
+ }
50003
+ };
50004
+ }
50005
+ var DockerLogsWatch = class {
50006
+ constructor(opts) {
50007
+ this.opts = opts;
50008
+ this.deps = opts.deps ?? socketDeps(opts.settings.socket);
50009
+ }
50010
+ opts;
50011
+ follows = /* @__PURE__ */ new Map();
50012
+ /** When each container's stream last closed: a restart resumes from there. */
50013
+ closedAt = /* @__PURE__ */ new Map();
50014
+ timer = null;
50015
+ lastPoll = 0;
50016
+ stopped = false;
50017
+ deps;
50018
+ warned = false;
50019
+ /** False when off or there is no Docker here. */
50020
+ start() {
50021
+ const { settings } = this.opts;
50022
+ if (!settings.enabled) return false;
50023
+ if (!this.opts.deps && !(0, import_node_fs53.existsSync)(settings.socket)) return false;
50024
+ this.opts.log(`[docker-logs] following containers named /${settings.namePattern.source}/ or with image /${settings.imagePattern.source}/ for Postgres auth failures`);
50025
+ void this.poll();
50026
+ this.timer = setInterval(() => {
50027
+ void this.poll();
50028
+ }, settings.pollMs);
50029
+ this.timer.unref?.();
50030
+ return true;
50031
+ }
50032
+ stop() {
50033
+ this.stopped = true;
50034
+ if (this.timer) clearInterval(this.timer);
50035
+ this.timer = null;
50036
+ for (const f of this.follows.values()) {
50037
+ try {
50038
+ f.req.destroy();
50039
+ } catch {
50040
+ }
50041
+ }
50042
+ this.follows.clear();
50043
+ }
50044
+ /** Names of the containers being followed now. */
50045
+ following() {
50046
+ return [...this.follows.values()].map((f) => f.name).sort();
50047
+ }
50048
+ matches(c) {
50049
+ const name = (c.Names?.[0] ?? "").replace(/^\//, "");
50050
+ return this.opts.settings.namePattern.test(name) || this.opts.settings.imagePattern.test(c.Image ?? "");
50051
+ }
50052
+ /** One discovery pass: follow new or restarted matches, drop gone ones. */
50053
+ async poll() {
50054
+ if (this.stopped) return;
50055
+ const now = Date.now();
50056
+ const previous = this.lastPoll;
50057
+ let list;
50058
+ try {
50059
+ list = await this.deps.getJson("/containers/json");
50060
+ this.warned = false;
50061
+ } catch (err) {
50062
+ if (!this.warned) this.opts.log(`[docker-logs] cannot list containers: ${err.message}`);
50063
+ this.warned = true;
50064
+ return;
50065
+ }
50066
+ this.lastPoll = now;
50067
+ const running = /* @__PURE__ */ new Set();
50068
+ for (const c of Array.isArray(list) ? list : []) {
50069
+ if (!c?.Id || !this.matches(c)) continue;
50070
+ running.add(c.Id);
50071
+ if (this.follows.has(c.Id)) continue;
50072
+ const from = this.closedAt.get(c.Id) ?? (previous || now);
50073
+ await this.follow(c, from);
50074
+ }
50075
+ for (const [id, f] of this.follows) {
50076
+ if (!running.has(id)) {
50077
+ try {
50078
+ f.req.destroy();
50079
+ } catch {
50080
+ }
50081
+ this.follows.delete(id);
50082
+ }
50083
+ }
50084
+ for (const id of this.closedAt.keys()) if (!running.has(id)) this.closedAt.delete(id);
50085
+ }
50086
+ async follow(c, fromMs) {
50087
+ const name = (c.Names?.[0] ?? c.Id.slice(0, 12)).replace(/^\//, "");
50088
+ let tty4 = false;
50089
+ try {
50090
+ const info2 = await this.deps.getJson(`/containers/${c.Id}/json`);
50091
+ tty4 = info2?.Config?.Tty === true;
50092
+ } catch {
50093
+ }
50094
+ if (this.stopped || this.follows.has(c.Id)) return;
50095
+ const since = Math.max(1, Math.floor(fromMs / 1e3));
50096
+ const decoder = new DockerLogDecoder(tty4, (line2) => this.line(line2, name));
50097
+ const req = this.deps.stream(
50098
+ `/containers/${c.Id}/logs?follow=1&stdout=1&stderr=1&since=${since}`,
50099
+ (chunk2) => {
50100
+ try {
50101
+ decoder.push(chunk2);
50102
+ } catch {
50103
+ }
50104
+ },
50105
+ () => {
50106
+ if (this.follows.get(c.Id)?.req === req) {
50107
+ this.follows.delete(c.Id);
50108
+ this.closedAt.set(c.Id, Date.now());
50109
+ }
50110
+ }
50111
+ );
50112
+ this.follows.set(c.Id, { req, name });
50113
+ this.opts.log(`[docker-logs] following ${name}`);
50114
+ }
50115
+ /** Exposed for tests and `rules test`: one container log line through the parser. */
50116
+ line(line2, container) {
50117
+ const event = postgresAuthEvent(line2, container, this.opts.protectedList ?? []);
50118
+ if (!event) return null;
50119
+ try {
50120
+ insertEvent(event);
50121
+ } catch {
50122
+ }
50123
+ this.opts.bus.publish(event);
50124
+ return event;
50125
+ }
50126
+ };
50127
+
50128
+ // src/core/tor-exits.ts
50129
+ var import_node_fs54 = require("fs");
50130
+ var import_node_path42 = require("path");
50131
+ var import_node_net16 = require("net");
49834
50132
  var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
49835
50133
  function parseTorExitList(text) {
49836
50134
  const out = /* @__PURE__ */ new Set();
@@ -49838,7 +50136,7 @@ function parseTorExitList(text) {
49838
50136
  const line2 = raw.trim();
49839
50137
  if (!line2 || line2.startsWith("#")) continue;
49840
50138
  const ip = line2.split(/\s+/)[0];
49841
- if ((0, import_node_net15.isIP)(ip)) out.add(normalizeIp(ip));
50139
+ if ((0, import_node_net16.isIP)(ip)) out.add(normalizeIp(ip));
49842
50140
  }
49843
50141
  return out;
49844
50142
  }
@@ -49897,10 +50195,10 @@ var TorExitList = class _TorExitList {
49897
50195
  }
49898
50196
  loadCache() {
49899
50197
  try {
49900
- if (!(0, import_node_fs53.existsSync)(this.opts.cachePath)) return false;
49901
- const parsed = parseTorExitList((0, import_node_fs53.readFileSync)(this.opts.cachePath, "utf-8"));
50198
+ if (!(0, import_node_fs54.existsSync)(this.opts.cachePath)) return false;
50199
+ const parsed = parseTorExitList((0, import_node_fs54.readFileSync)(this.opts.cachePath, "utf-8"));
49902
50200
  if (parsed.size === 0) return false;
49903
- this.load(parsed, (0, import_node_fs53.statSync)(this.opts.cachePath).mtimeMs);
50201
+ this.load(parsed, (0, import_node_fs54.statSync)(this.opts.cachePath).mtimeMs);
49904
50202
  this.log(`[tor] loaded ${parsed.size} Tor exit addresses from cache (${new Date(this.updatedAt).toISOString()})`);
49905
50203
  return true;
49906
50204
  } catch (err) {
@@ -49932,9 +50230,9 @@ var TorExitList = class _TorExitList {
49932
50230
  const before2 = this.exits.size;
49933
50231
  this.load(parsed);
49934
50232
  try {
49935
- (0, import_node_fs53.mkdirSync)((0, import_node_path42.dirname)(this.opts.cachePath), { recursive: true });
49936
- (0, import_node_fs53.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
49937
- (0, import_node_fs53.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
50233
+ (0, import_node_fs54.mkdirSync)((0, import_node_path42.dirname)(this.opts.cachePath), { recursive: true });
50234
+ (0, import_node_fs54.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
50235
+ (0, import_node_fs54.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
49938
50236
  } catch (err) {
49939
50237
  this.log(`[tor] could not save the exit list cache: ${err.message}`);
49940
50238
  }
@@ -50155,7 +50453,7 @@ var RuleEngine = class {
50155
50453
  };
50156
50454
 
50157
50455
  // src/daemon/rules/loader.ts
50158
- var import_node_fs54 = require("fs");
50456
+ var import_node_fs55 = require("fs");
50159
50457
  var import_node_path43 = require("path");
50160
50458
 
50161
50459
  // src/daemon/rules/default-rules.ts
@@ -50793,6 +51091,33 @@ var DEFAULT_RULES = [
50793
51091
  tags: ["agentdb", "rate-limit", "data-access"],
50794
51092
  remediation: { action: "alert", description: "Review AgentDB audit metadata for the token and request pattern" },
50795
51093
  enabled: true
51094
+ },
51095
+ {
51096
+ // 2026-11-20 dev2: ~10,150 failed `postgres` logins from ~60 addresses in
51097
+ // 72h against a Supabase Postgres published on 0.0.0.0, none banned. Fed by
51098
+ // docker-logs (`[docker_logs]`), which already drops private, Docker-bridge
51099
+ // and protected sources, so every event here names a public client.
51100
+ id: "postgres-auth-bruteforce",
51101
+ title: "Postgres Brute Force Detected",
51102
+ description: "Repeated Postgres password failures or pg_hba rejects from the same source",
51103
+ version: "1.0.0",
51104
+ category: "auth",
51105
+ severity: "high",
51106
+ source_types: ["postgres-guard"],
51107
+ match: {
51108
+ field: "message",
51109
+ operator: "regex",
51110
+ value: "^Postgres (?:password authentication failed|connection rejected by pg_hba) "
51111
+ },
51112
+ threshold: 5,
51113
+ window_seconds: 600,
51114
+ cooldown_seconds: 600,
51115
+ tags: ["postgres", "database", "brute-force", "credential-stuffing"],
51116
+ remediation: {
51117
+ action: "block",
51118
+ description: "Block source IP brute-forcing Postgres"
51119
+ },
51120
+ enabled: true
50796
51121
  }
50797
51122
  ];
50798
51123
 
@@ -50801,11 +51126,16 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
50801
51126
  function loadAllRules(customDir) {
50802
51127
  const rules = [...DEFAULT_RULES];
50803
51128
  const dir = customDir || RULES_DIR;
50804
- if ((0, import_node_fs54.existsSync)(dir)) {
50805
- const files = (0, import_node_fs54.readdirSync)(dir).filter((f) => f.endsWith(".json"));
51129
+ if ((0, import_node_fs55.existsSync)(dir)) {
51130
+ let files = [];
51131
+ try {
51132
+ files = (0, import_node_fs55.readdirSync)(dir).filter((f) => f.endsWith(".json"));
51133
+ } catch (err) {
51134
+ console.warn(`[rules] cannot read ${dir}: ${err.message}; custom rules not loaded`);
51135
+ }
50806
51136
  for (const file of files) {
50807
51137
  try {
50808
- const raw = (0, import_node_fs54.readFileSync)((0, import_node_path43.join)(dir, file), "utf-8");
51138
+ const raw = (0, import_node_fs55.readFileSync)((0, import_node_path43.join)(dir, file), "utf-8");
50809
51139
  const parsed = JSON.parse(raw);
50810
51140
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
50811
51141
  for (const rule of customRules) {
@@ -50837,23 +51167,23 @@ function loadAllRules(customDir) {
50837
51167
 
50838
51168
  // src/daemon/firewall/adapters.ts
50839
51169
  var import_node_child_process17 = require("child_process");
50840
- var import_node_fs55 = require("fs");
51170
+ var import_node_fs56 = require("fs");
50841
51171
  var import_node_path44 = require("path");
50842
- var import_node_net16 = require("net");
51172
+ var import_node_net17 = require("net");
50843
51173
  function assertValidFirewallIp(ip) {
50844
- if ((0, import_node_net16.isIP)(ip) !== 4) {
51174
+ if ((0, import_node_net17.isIP)(ip) !== 4) {
50845
51175
  throw new Error(`Invalid IPv4 address: ${ip}`);
50846
51176
  }
50847
51177
  }
50848
51178
  function assertBannableIp(ip) {
50849
- if ((0, import_node_net16.isIP)(ip) === 0) {
51179
+ if ((0, import_node_net17.isIP)(ip) === 0) {
50850
51180
  throw new Error(`Invalid IP address: ${ip}`);
50851
51181
  }
50852
51182
  }
50853
51183
  function writeIfAbsent(path2, contents) {
50854
- (0, import_node_fs55.mkdirSync)((0, import_node_path44.dirname)(path2), { recursive: true });
51184
+ (0, import_node_fs56.mkdirSync)((0, import_node_path44.dirname)(path2), { recursive: true });
50855
51185
  try {
50856
- (0, import_node_fs55.writeFileSync)(path2, contents, { flag: "wx" });
51186
+ (0, import_node_fs56.writeFileSync)(path2, contents, { flag: "wx" });
50857
51187
  } catch (err) {
50858
51188
  if (err.code !== "EEXIST") throw err;
50859
51189
  }
@@ -50952,7 +51282,7 @@ var Fail2banAdapter = class {
50952
51282
  const status = this.client(["status", this.jail]);
50953
51283
  const line2 = status.split("\n").find((l) => /Banned IP list:/i.test(l));
50954
51284
  if (!line2) return [];
50955
- return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net16.isIP)(s) !== 0);
51285
+ return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net17.isIP)(s) !== 0);
50956
51286
  } catch {
50957
51287
  return [];
50958
51288
  }
@@ -50962,10 +51292,10 @@ var Fail2banAdapter = class {
50962
51292
  function parseBannedList(output) {
50963
51293
  const found = [];
50964
51294
  for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
50965
- if ((0, import_node_net16.isIP)(match[1]) !== 0) found.push(match[1]);
51295
+ if ((0, import_node_net17.isIP)(match[1]) !== 0) found.push(match[1]);
50966
51296
  }
50967
51297
  if (found.length > 0) return found;
50968
- return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net16.isIP)(s) !== 0);
51298
+ return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net17.isIP)(s) !== 0);
50969
51299
  }
50970
51300
  var NftablesAdapter = class {
50971
51301
  name = "nftables";
@@ -51112,9 +51442,9 @@ function detectFirewallAdapter(backend = "auto") {
51112
51442
  }
51113
51443
 
51114
51444
  // src/daemon/firewall/remediation.ts
51115
- var import_node_fs56 = require("fs");
51445
+ var import_node_fs57 = require("fs");
51116
51446
  var import_node_child_process18 = require("child_process");
51117
- var import_node_net17 = require("net");
51447
+ var import_node_net18 = require("net");
51118
51448
  init_paths();
51119
51449
  init_backoff();
51120
51450
 
@@ -51184,19 +51514,19 @@ var defaultDiscovery = {
51184
51514
  const snapshot = takeSnapshot({
51185
51515
  readFile: (p) => {
51186
51516
  try {
51187
- return (0, import_node_fs56.readFileSync)(p, "utf-8");
51517
+ return (0, import_node_fs57.readFileSync)(p, "utf-8");
51188
51518
  } catch {
51189
51519
  return null;
51190
51520
  }
51191
51521
  },
51192
51522
  readDir: (p) => {
51193
51523
  try {
51194
- return (0, import_node_fs56.readdirSync)(p);
51524
+ return (0, import_node_fs57.readdirSync)(p);
51195
51525
  } catch {
51196
51526
  return null;
51197
51527
  }
51198
51528
  },
51199
- exists: (p) => (0, import_node_fs56.existsSync)(p)
51529
+ exists: (p) => (0, import_node_fs57.existsSync)(p)
51200
51530
  });
51201
51531
  const out = /* @__PURE__ */ new Set();
51202
51532
  for (const keys of Object.values(snapshot.keys)) {
@@ -51285,7 +51615,7 @@ var RemediationManager = class {
51285
51615
  setTorExitCheck(check2) {
51286
51616
  this.isTorExit = check2;
51287
51617
  let dropped = 0;
51288
- this.protectedList = this.protectedList.filter((a) => !(0, import_node_net17.isIP)(a) || !check2(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
51618
+ this.protectedList = this.protectedList.filter((a) => !(0, import_node_net18.isIP)(a) || !check2(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
51289
51619
  for (const ip of Object.keys(this.operators)) {
51290
51620
  if (!check2(ip)) continue;
51291
51621
  delete this.operators[ip];
@@ -51378,7 +51708,7 @@ var RemediationManager = class {
51378
51708
  if (remediation?.action !== "block") return;
51379
51709
  }
51380
51710
  const ip = event.source_ip;
51381
- if (!ip || (0, import_node_net17.isIP)(ip) === 0) return;
51711
+ if (!ip || (0, import_node_net18.isIP)(ip) === 0) return;
51382
51712
  const strict = remediation?.override_operator_protection === true;
51383
51713
  if (strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
51384
51714
  if (strict) this.logLine(`[remediation] not banning ${ip}: it is one of our own addresses (${event.message})`);
@@ -51407,7 +51737,7 @@ var RemediationManager = class {
51407
51737
  * 4th offence and so on, clamped to `max_ban_seconds`.
51408
51738
  */
51409
51739
  async ban(ip, reason, opts = {}) {
51410
- if ((0, import_node_net17.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
51740
+ if ((0, import_node_net18.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
51411
51741
  if (opts.strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
51412
51742
  return { ok: false, error: `${ip} is protected and can never be blocked` };
51413
51743
  }
@@ -51684,7 +52014,7 @@ var RemediationManager = class {
51684
52014
  if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
51685
52015
  const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
51686
52016
  for (const [ip, at] of Object.entries(saved)) {
51687
- if (typeof at !== "number" || at < cutoff || !(0, import_node_net17.isIP)(ip)) continue;
52017
+ if (typeof at !== "number" || at < cutoff || !(0, import_node_net18.isIP)(ip)) continue;
51688
52018
  if (this.blocklist.some((b) => b.ip === ip && b.strict)) continue;
51689
52019
  this.operators[ip] = at;
51690
52020
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
@@ -51709,7 +52039,7 @@ var RemediationManager = class {
51709
52039
  }
51710
52040
  logLine(line2) {
51711
52041
  try {
51712
- (0, import_node_fs56.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
52042
+ (0, import_node_fs57.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
51713
52043
  `);
51714
52044
  } catch {
51715
52045
  }
@@ -51753,13 +52083,13 @@ function remediationSettings(section) {
51753
52083
  init_backoff();
51754
52084
 
51755
52085
  // src/daemon/watchdog-service.ts
51756
- var import_node_fs57 = require("fs");
52086
+ var import_node_fs58 = require("fs");
51757
52087
  var import_node_path45 = require("path");
51758
52088
  function defaultShareGid() {
51759
52089
  const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
51760
52090
  if (!isRoot4) return void 0;
51761
52091
  try {
51762
- return (0, import_node_fs57.statSync)("/var/log/auth.log").gid;
52092
+ return (0, import_node_fs58.statSync)("/var/log/auth.log").gid;
51763
52093
  } catch {
51764
52094
  return void 0;
51765
52095
  }
@@ -51880,7 +52210,7 @@ function versionOfNode(path2) {
51880
52210
  // src/daemon/index.ts
51881
52211
  function readVersion2() {
51882
52212
  try {
51883
- const pkg = JSON.parse((0, import_node_fs58.readFileSync)((0, import_node_path46.join)(__dirname, "..", "package.json"), "utf-8"));
52213
+ const pkg = JSON.parse((0, import_node_fs59.readFileSync)((0, import_node_path46.join)(__dirname, "..", "package.json"), "utf-8"));
51884
52214
  return pkg.version || "0.0.0";
51885
52215
  } catch {
51886
52216
  return "0.0.0";
@@ -51911,7 +52241,7 @@ async function runPatchCheck() {
51911
52241
  }
51912
52242
  function logLine(line2) {
51913
52243
  try {
51914
- (0, import_node_fs58.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
52244
+ (0, import_node_fs59.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
51915
52245
  `);
51916
52246
  } catch {
51917
52247
  }
@@ -52081,6 +52411,13 @@ async function runDaemon() {
52081
52411
  log: logLine
52082
52412
  });
52083
52413
  lightningWatch.start();
52414
+ const dockerLogs = new DockerLogsWatch({
52415
+ bus,
52416
+ settings: dockerLogsSettings(config.docker_logs),
52417
+ protectedList: remediation.getAllowlist(),
52418
+ log: logLine
52419
+ });
52420
+ dockerLogs.start();
52084
52421
  let cloudSyncRef = null;
52085
52422
  new AlertDispatcher(bus, config, { cloudHealthy: () => cloudSyncRef?.healthy ?? false, log: logLine });
52086
52423
  if (loaded.error) {
@@ -52225,6 +52562,10 @@ async function runDaemon() {
52225
52562
  lightningWatch.stop();
52226
52563
  } catch {
52227
52564
  }
52565
+ try {
52566
+ dockerLogs.stop();
52567
+ } catch {
52568
+ }
52228
52569
  try {
52229
52570
  await ipc.stop();
52230
52571
  } catch {
@@ -52281,7 +52622,7 @@ async function daemonStart() {
52281
52622
  return;
52282
52623
  }
52283
52624
  ensureRuntimeDirs();
52284
- if (!(0, import_node_fs59.existsSync)(DAEMON_ENTRY)) {
52625
+ if (!(0, import_node_fs60.existsSync)(DAEMON_ENTRY)) {
52285
52626
  console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
52286
52627
  console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
52287
52628
  return;
@@ -52289,8 +52630,8 @@ async function daemonStart() {
52289
52630
  let out;
52290
52631
  let err;
52291
52632
  try {
52292
- out = (0, import_node_fs60.openSync)(PATHS.logFile, "a");
52293
- err = (0, import_node_fs60.openSync)(PATHS.logFile, "a");
52633
+ out = (0, import_node_fs61.openSync)(PATHS.logFile, "a");
52634
+ err = (0, import_node_fs61.openSync)(PATHS.logFile, "a");
52294
52635
  } catch (e) {
52295
52636
  const code = e.code;
52296
52637
  console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
@@ -52378,12 +52719,12 @@ async function waitForExit(pid, timeoutMs) {
52378
52719
  }
52379
52720
  async function releaseStaleSocket() {
52380
52721
  const deadline = Date.now() + 2e3;
52381
- while ((0, import_node_fs59.existsSync)(PATHS.socket) && Date.now() < deadline) {
52722
+ while ((0, import_node_fs60.existsSync)(PATHS.socket) && Date.now() < deadline) {
52382
52723
  await new Promise((r) => setTimeout(r, 50));
52383
52724
  }
52384
- if ((0, import_node_fs59.existsSync)(PATHS.socket)) {
52725
+ if ((0, import_node_fs60.existsSync)(PATHS.socket)) {
52385
52726
  try {
52386
- (0, import_node_fs59.unlinkSync)(PATHS.socket);
52727
+ (0, import_node_fs60.unlinkSync)(PATHS.socket);
52387
52728
  } catch {
52388
52729
  }
52389
52730
  }
@@ -52391,26 +52732,26 @@ async function releaseStaleSocket() {
52391
52732
 
52392
52733
  // src/commands/service.ts
52393
52734
  var import_node_child_process22 = require("child_process");
52394
- var import_node_fs61 = require("fs");
52735
+ var import_node_fs62 = require("fs");
52395
52736
  var import_node_path48 = require("path");
52396
52737
  var import_node_os20 = require("os");
52397
52738
  var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
52398
52739
  var DAEMON_UNIT_NAME = "threatcrushd.service";
52399
52740
  function resolveTemplate() {
52400
52741
  const templatePath = (0, import_node_path48.join)(__dirname, "systemd", "threatcrushd.service");
52401
- if (!(0, import_node_fs61.existsSync)(templatePath)) {
52742
+ if (!(0, import_node_fs62.existsSync)(templatePath)) {
52402
52743
  throw new Error(`systemd unit template not found at ${templatePath}`);
52403
52744
  }
52404
- return (0, import_node_fs61.readFileSync)(templatePath, "utf-8");
52745
+ return (0, import_node_fs62.readFileSync)(templatePath, "utf-8");
52405
52746
  }
52406
52747
  function stableBinPath(binPath) {
52407
52748
  const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
52408
52749
  if (stable === binPath) return binPath;
52409
- return (0, import_node_fs61.existsSync)(stable) ? stable : binPath;
52750
+ return (0, import_node_fs62.existsSync)(stable) ? stable : binPath;
52410
52751
  }
52411
52752
  function resolveBinPath() {
52412
52753
  const arg = process.argv[1];
52413
- if (arg && (0, import_node_fs61.existsSync)(arg)) return stableBinPath(arg);
52754
+ if (arg && (0, import_node_fs62.existsSync)(arg)) return stableBinPath(arg);
52414
52755
  try {
52415
52756
  return (0, import_node_child_process22.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
52416
52757
  } catch {
@@ -52420,11 +52761,11 @@ function resolveBinPath() {
52420
52761
  function stableNodePath(execPath) {
52421
52762
  const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
52422
52763
  if (stable === execPath) return execPath;
52423
- return (0, import_node_fs61.existsSync)(stable) ? stable : execPath;
52764
+ return (0, import_node_fs62.existsSync)(stable) ? stable : execPath;
52424
52765
  }
52425
52766
  function looksLikeNodeScript(path2) {
52426
52767
  try {
52427
- const head2 = (0, import_node_fs61.readFileSync)(path2, "utf-8").slice(0, 120);
52768
+ const head2 = (0, import_node_fs62.readFileSync)(path2, "utf-8").slice(0, 120);
52428
52769
  return /^#!.*\bnode\b/.test(head2);
52429
52770
  } catch {
52430
52771
  return false;
@@ -52464,7 +52805,7 @@ function callerHome() {
52464
52805
  try {
52465
52806
  const line2 = (0, import_node_child_process22.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
52466
52807
  const home = line2.split(":")[5];
52467
- return home && (0, import_node_fs61.existsSync)(home) ? home : null;
52808
+ return home && (0, import_node_fs62.existsSync)(home) ? home : null;
52468
52809
  } catch {
52469
52810
  return null;
52470
52811
  }
@@ -52475,10 +52816,10 @@ function stopUserModeDaemon() {
52475
52816
  const runDir = (0, import_node_path48.join)(home, ".threatcrush", "run");
52476
52817
  const pidFile = (0, import_node_path48.join)(runDir, "threatcrushd.pid");
52477
52818
  const socket = (0, import_node_path48.join)(runDir, "threatcrushd.sock");
52478
- if (!(0, import_node_fs61.existsSync)(pidFile) && !(0, import_node_fs61.existsSync)(socket)) return;
52819
+ if (!(0, import_node_fs62.existsSync)(pidFile) && !(0, import_node_fs62.existsSync)(socket)) return;
52479
52820
  let pid = null;
52480
52821
  try {
52481
- pid = Number.parseInt((0, import_node_fs61.readFileSync)(pidFile, "utf-8").trim(), 10);
52822
+ pid = Number.parseInt((0, import_node_fs62.readFileSync)(pidFile, "utf-8").trim(), 10);
52482
52823
  } catch {
52483
52824
  pid = null;
52484
52825
  }
@@ -52491,7 +52832,7 @@ function stopUserModeDaemon() {
52491
52832
  }
52492
52833
  for (const path2 of [socket, pidFile]) {
52493
52834
  try {
52494
- if ((0, import_node_fs61.existsSync)(path2)) (0, import_node_fs61.rmSync)(path2);
52835
+ if ((0, import_node_fs62.existsSync)(path2)) (0, import_node_fs62.rmSync)(path2);
52495
52836
  } catch {
52496
52837
  }
52497
52838
  }
@@ -52509,7 +52850,7 @@ async function installServiceCommand() {
52509
52850
  }
52510
52851
  const noSystemd = systemdUnavailableReason({
52511
52852
  hasSystemctl: (0, import_node_child_process22.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
52512
- booted: (0, import_node_fs61.existsSync)("/run/systemd/system")
52853
+ booted: (0, import_node_fs62.existsSync)("/run/systemd/system")
52513
52854
  });
52514
52855
  if (noSystemd) {
52515
52856
  console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
@@ -52531,7 +52872,7 @@ async function installServiceCommand() {
52531
52872
  const isNodeScript = looksLikeNodeScript(binPath);
52532
52873
  let nodePath = stableNodePath(process.execPath);
52533
52874
  if (isNodeScript && nodeVersionDir(binPath)) {
52534
- binPath = (0, import_node_fs61.realpathSync)(binPath);
52875
+ binPath = (0, import_node_fs62.realpathSync)(binPath);
52535
52876
  nodePath = process.execPath;
52536
52877
  }
52537
52878
  if (isNodeScript) {
@@ -52548,7 +52889,7 @@ async function installServiceCommand() {
52548
52889
  const commandHistoryEnabled = commandHistorySettings(loadConfig().command_history).enabled;
52549
52890
  const historyPaths = commandHistoryEnabled ? historyWritableHomes() : [];
52550
52891
  const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir, historyPaths });
52551
- (0, import_node_fs61.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
52892
+ (0, import_node_fs62.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
52552
52893
  console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
52553
52894
  console.log(source_default.dim(` ExecStart=${exec}`));
52554
52895
  const nodeDir = nodeVersionDir(nodePath);
@@ -52601,9 +52942,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
52601
52942
  ].join("\n");
52602
52943
  }
52603
52944
  function installLogrotate() {
52604
- if (!(0, import_node_fs61.existsSync)((0, import_node_path48.dirname)(LOGROTATE_PATH))) return;
52945
+ if (!(0, import_node_fs62.existsSync)((0, import_node_path48.dirname)(LOGROTATE_PATH))) return;
52605
52946
  try {
52606
- (0, import_node_fs61.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
52947
+ (0, import_node_fs62.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
52607
52948
  console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
52608
52949
  } catch (err) {
52609
52950
  console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
@@ -52625,20 +52966,20 @@ function ensureSystemDirs(configDir) {
52625
52966
  ];
52626
52967
  let admGid2 = null;
52627
52968
  try {
52628
- admGid2 = (0, import_node_fs61.statSync)("/var/log/auth.log").gid;
52969
+ admGid2 = (0, import_node_fs62.statSync)("/var/log/auth.log").gid;
52629
52970
  } catch {
52630
52971
  }
52631
52972
  for (const { path: path2, groupWritable, sticky } of dirs) {
52632
52973
  try {
52633
- (0, import_node_fs61.mkdirSync)(path2, { recursive: true });
52974
+ (0, import_node_fs62.mkdirSync)(path2, { recursive: true });
52634
52975
  } catch {
52635
52976
  }
52636
52977
  try {
52637
52978
  if (groupWritable && admGid2 !== null) {
52638
- (0, import_node_fs61.chmodSync)(path2, sticky ? 1533 : 509);
52979
+ (0, import_node_fs62.chmodSync)(path2, sticky ? 1533 : 509);
52639
52980
  (0, import_node_child_process22.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
52640
52981
  } else {
52641
- (0, import_node_fs61.chmodSync)(path2, 493);
52982
+ (0, import_node_fs62.chmodSync)(path2, 493);
52642
52983
  }
52643
52984
  } catch {
52644
52985
  }
@@ -52666,7 +53007,7 @@ async function uninstallServiceCommand() {
52666
53007
  } catch {
52667
53008
  }
52668
53009
  try {
52669
- if ((0, import_node_fs61.existsSync)(UNIT_PATH)) {
53010
+ if ((0, import_node_fs62.existsSync)(UNIT_PATH)) {
52670
53011
  (0, import_node_child_process22.execSync)(`rm -f ${UNIT_PATH}`);
52671
53012
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
52672
53013
  }
@@ -52680,7 +53021,7 @@ async function uninstallServiceCommand() {
52680
53021
  }
52681
53022
 
52682
53023
  // src/commands/save.ts
52683
- var import_node_fs62 = require("fs");
53024
+ var import_node_fs63 = require("fs");
52684
53025
  var import_toml6 = __toESM(require_toml());
52685
53026
  init_cli_config();
52686
53027
  init_paths();
@@ -52719,9 +53060,9 @@ async function saveCommand(opts = {}) {
52719
53060
  }
52720
53061
  const path2 = opts.config ?? PATHS.configFile;
52721
53062
  let config = {};
52722
- if ((0, import_node_fs62.existsSync)(path2)) {
53063
+ if ((0, import_node_fs63.existsSync)(path2)) {
52723
53064
  try {
52724
- config = import_toml6.default.parse((0, import_node_fs62.readFileSync)(path2, "utf-8"));
53065
+ config = import_toml6.default.parse((0, import_node_fs63.readFileSync)(path2, "utf-8"));
52725
53066
  } catch (err) {
52726
53067
  console.log(source_default.red(` \u2717 ${path2} is not valid TOML: ${err.message}
52727
53068
  `));
@@ -52834,7 +53175,7 @@ function welcomeCommand() {
52834
53175
  }
52835
53176
 
52836
53177
  // src/commands/properties.ts
52837
- var import_node_fs63 = require("fs");
53178
+ var import_node_fs64 = require("fs");
52838
53179
  var import_node_path49 = require("path");
52839
53180
  var import_node_readline4 = __toESM(require("readline"));
52840
53181
  init_cli_config();
@@ -53166,7 +53507,7 @@ async function propertiesRunsCommand(opts) {
53166
53507
  }
53167
53508
  function parseImportFile(path2) {
53168
53509
  const ext = (0, import_node_path49.extname)(path2).toLowerCase();
53169
- const raw = (0, import_node_fs63.readFileSync)(path2, "utf-8");
53510
+ const raw = (0, import_node_fs64.readFileSync)(path2, "utf-8");
53170
53511
  if (ext === ".json") {
53171
53512
  const parsed = JSON.parse(raw);
53172
53513
  if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
@@ -53338,6 +53679,45 @@ async function rulesShowCommand(ruleId) {
53338
53679
  show(rule.match, "", 0);
53339
53680
  console.log();
53340
53681
  }
53682
+ async function rulesTestCommand(ruleId, line2, repeat = 1, json2 = false) {
53683
+ const config = loadConfig();
53684
+ const protectedList = [...config.remediation?.protected ?? [], ...config.remediation?.allowlist ?? []].map(String);
53685
+ const rules = loadAllRules();
53686
+ const rule = rules.find((r) => r.id === ruleId);
53687
+ const parsed = parsePostgresAuthFailure(line2);
53688
+ const event = postgresAuthEvent(line2, "dry-run", protectedList);
53689
+ const fired = [];
53690
+ if (rule && event) {
53691
+ const engine2 = new RuleEngine((d) => fired.push({ rule_id: d.rule_id, source_ip: d.source_ip, description: d.description }));
53692
+ engine2.loadRules([rule]);
53693
+ for (let i = 0; i < Math.max(1, repeat); i++) engine2.evaluate({ ...event, timestamp: /* @__PURE__ */ new Date() });
53694
+ }
53695
+ const wouldBan = fired.length > 0 && rule?.remediation?.action === "block" && !!fired[0].source_ip;
53696
+ const result = {
53697
+ rule: rule ? rule.id : null,
53698
+ parsed,
53699
+ event: event ? { module: event.module, severity: event.severity, source_ip: event.source_ip, message: event.message } : null,
53700
+ skipped_reason: !rule ? "unknown rule" : !parsed ? "not a recognised line" : !parsed.ip ? "no client address in the line" : !event ? "protected/private source, never banned" : void 0,
53701
+ repeat,
53702
+ threshold: rule?.threshold,
53703
+ fired: fired.length > 0,
53704
+ would_ban: wouldBan,
53705
+ detections: fired
53706
+ };
53707
+ if (json2) {
53708
+ console.log(JSON.stringify(result, null, 2));
53709
+ } else {
53710
+ banner();
53711
+ console.log(source_default.green.bold(` Dry run: ${ruleId}`));
53712
+ console.log(` Parsed: ${source_default.gray(parsed ? JSON.stringify(parsed) : "no match")}`);
53713
+ console.log(` Event: ${source_default.gray(event ? `${event.module} ${event.severity} ${event.source_ip} ${event.message}` : result.skipped_reason ?? "none")}`);
53714
+ console.log(` Fed: ${repeat}x (threshold ${rule?.threshold ?? "?"})`);
53715
+ console.log(` Fires: ${fired.length ? source_default.red("yes") : source_default.green("no")}`);
53716
+ console.log(` Would ban: ${wouldBan ? source_default.red(fired[0].source_ip) : source_default.green("no")}`);
53717
+ console.log(source_default.gray(" (dry run: nothing was blocked)\n"));
53718
+ }
53719
+ return fired.length > 0;
53720
+ }
53341
53721
  async function rulesCommand(opts) {
53342
53722
  const action = opts.action || "list";
53343
53723
  switch (action) {
@@ -53353,21 +53733,29 @@ async function rulesCommand(opts) {
53353
53733
  }
53354
53734
  await rulesShowCommand(opts.id);
53355
53735
  break;
53736
+ case "test":
53737
+ if (!opts.id || !opts.line) {
53738
+ console.log(source_default.red(' Usage: threatcrush rules test <rule-id> --line "<log line>" [--repeat N] [--json]\n'));
53739
+ process.exitCode = 1;
53740
+ return;
53741
+ }
53742
+ await rulesTestCommand(opts.id, opts.line, opts.repeat ?? 1, opts.json === true);
53743
+ break;
53356
53744
  default:
53357
53745
  console.log(source_default.yellow(` Unknown action: ${action}`));
53358
- console.log(source_default.gray(" Available: list, show\n"));
53746
+ console.log(source_default.gray(" Available: list, show, test\n"));
53359
53747
  break;
53360
53748
  }
53361
53749
  }
53362
53750
 
53363
53751
  // src/commands/harden.ts
53364
- var import_node_fs65 = require("fs");
53752
+ var import_node_fs66 = require("fs");
53365
53753
  var import_node_child_process23 = require("child_process");
53366
53754
  init_cli_config();
53367
53755
 
53368
53756
  // src/commands/cis-report.ts
53369
53757
  var import_node_os21 = require("os");
53370
- var import_node_fs64 = require("fs");
53758
+ var import_node_fs65 = require("fs");
53371
53759
  var CIS_UBUNTU_URL = "https://www.cisecurity.org/benchmark/ubuntu_linux";
53372
53760
  var CIS_DEBIAN_URL = "https://www.cisecurity.org/benchmark/debian_linux";
53373
53761
  var UBUNTU_2404_CIS_CONTROL_SOURCE = "https://github.com/ComplianceAsCode/content/blob/v0.1.78/controls/cis_ubuntu2404.yml";
@@ -53387,7 +53775,7 @@ var EDITIONS = {
53387
53775
  function osRelease() {
53388
53776
  let raw = "";
53389
53777
  try {
53390
- raw = (0, import_node_fs64.readFileSync)("/etc/os-release", "utf8");
53778
+ raw = (0, import_node_fs65.readFileSync)("/etc/os-release", "utf8");
53391
53779
  } catch {
53392
53780
  return {};
53393
53781
  }
@@ -53567,7 +53955,7 @@ function writeCisReport(path2, format2, report) {
53567
53955
  const markdown = renderCisMarkdown(report);
53568
53956
  const content = format2 === "json" ? `${JSON.stringify(report, null, 2)}
53569
53957
  ` : format2 === "pdf" ? renderCisPdf(markdown) : markdown;
53570
- (0, import_node_fs64.writeFileSync)(path2, content);
53958
+ (0, import_node_fs65.writeFileSync)(path2, content);
53571
53959
  }
53572
53960
 
53573
53961
  // src/commands/harden.ts
@@ -53580,7 +53968,7 @@ function tryExec(cmd) {
53580
53968
  }
53581
53969
  function tryRead(path2) {
53582
53970
  try {
53583
- return (0, import_node_fs65.readFileSync)(path2, "utf-8");
53971
+ return (0, import_node_fs66.readFileSync)(path2, "utf-8");
53584
53972
  } catch {
53585
53973
  return null;
53586
53974
  }
@@ -53694,8 +54082,8 @@ function checkSshWeakConfig() {
53694
54082
  };
53695
54083
  }
53696
54084
  function checkAutoUpdates() {
53697
- const unattended = (0, import_node_fs65.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs65.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
53698
- const dnfAuto = (0, import_node_fs65.existsSync)("/etc/dnf/automatic.conf");
54085
+ const unattended = (0, import_node_fs66.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs66.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
54086
+ const dnfAuto = (0, import_node_fs66.existsSync)("/etc/dnf/automatic.conf");
53699
54087
  if (unattended || dnfAuto) {
53700
54088
  return {
53701
54089
  key: "auto-updates",
@@ -53821,7 +54209,7 @@ function checkFail2ban() {
53821
54209
  explanation: "fail2ban is installed and running."
53822
54210
  };
53823
54211
  }
53824
- if ((0, import_node_fs65.existsSync)("/etc/fail2ban/fail2ban.conf")) {
54212
+ if ((0, import_node_fs66.existsSync)("/etc/fail2ban/fail2ban.conf")) {
53825
54213
  return {
53826
54214
  key: checkKey,
53827
54215
  status: "warn",
@@ -54041,7 +54429,7 @@ async function hardenCommand(opts) {
54041
54429
  }
54042
54430
 
54043
54431
  // src/core/patches/index.ts
54044
- var import_node_fs66 = require("fs");
54432
+ var import_node_fs67 = require("fs");
54045
54433
  var import_node_path50 = require("path");
54046
54434
  var import_node_child_process24 = require("child_process");
54047
54435
  var import_node_util5 = require("util");
@@ -54202,9 +54590,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
54202
54590
  function newestReleaseMtime(dir) {
54203
54591
  try {
54204
54592
  let newest = 0;
54205
- for (const name of (0, import_node_fs66.readdirSync)(dir)) {
54593
+ for (const name of (0, import_node_fs67.readdirSync)(dir)) {
54206
54594
  if (!/Release$/.test(name)) continue;
54207
- newest = Math.max(newest, (0, import_node_fs66.statSync)((0, import_node_path50.join)(dir, name)).mtimeMs);
54595
+ newest = Math.max(newest, (0, import_node_fs67.statSync)((0, import_node_path50.join)(dir, name)).mtimeMs);
54208
54596
  }
54209
54597
  return newest > 0 ? new Date(newest) : null;
54210
54598
  } catch {
@@ -54221,7 +54609,7 @@ async function checkPatches(opts = {}) {
54221
54609
  let osText = opts.osRelease;
54222
54610
  if (osText === void 0) {
54223
54611
  try {
54224
- osText = (0, import_node_fs66.readFileSync)("/etc/os-release", "utf-8");
54612
+ osText = (0, import_node_fs67.readFileSync)("/etc/os-release", "utf-8");
54225
54613
  } catch {
54226
54614
  osText = "";
54227
54615
  }
@@ -54447,25 +54835,25 @@ async function patchesCommand(opts) {
54447
54835
  }
54448
54836
 
54449
54837
  // src/commands/feeds.ts
54450
- var import_node_net18 = require("net");
54838
+ var import_node_net19 = require("net");
54451
54839
  var import_node_path52 = require("path");
54452
54840
  init_paths();
54453
54841
 
54454
54842
  // src/commands/feeds-resolver.ts
54455
54843
  var import_node_child_process25 = require("child_process");
54456
- var import_node_fs67 = require("fs");
54844
+ var import_node_fs68 = require("fs");
54457
54845
  var import_node_path51 = require("path");
54458
54846
  var realIO = {
54459
- exists: (p) => (0, import_node_fs67.existsSync)(p),
54847
+ exists: (p) => (0, import_node_fs68.existsSync)(p),
54460
54848
  read: (p) => {
54461
54849
  try {
54462
- return (0, import_node_fs67.readFileSync)(p, "utf-8");
54850
+ return (0, import_node_fs68.readFileSync)(p, "utf-8");
54463
54851
  } catch {
54464
54852
  return null;
54465
54853
  }
54466
54854
  },
54467
- write: (p, c) => (0, import_node_fs67.writeFileSync)(p, c),
54468
- remove: (p) => (0, import_node_fs67.rmSync)(p, { force: true }),
54855
+ write: (p, c) => (0, import_node_fs68.writeFileSync)(p, c),
54856
+ remove: (p) => (0, import_node_fs68.rmSync)(p, { force: true }),
54469
54857
  run: (cmd, args) => {
54470
54858
  const r = (0, import_node_child_process25.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
54471
54859
  return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
@@ -54591,8 +54979,8 @@ async function feedsCommand(action, value, opts) {
54591
54979
  process.exitCode = 2;
54592
54980
  return;
54593
54981
  }
54594
- const ipHit = (0, import_node_net18.isIP)(value) ? matchIp(value, set) : null;
54595
- const domainHit = (0, import_node_net18.isIP)(value) ? null : matchDomain(value, set);
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);
54596
54984
  const listed = ipHit ?? domainHit?.indicator ?? null;
54597
54985
  if (opts.json) {
54598
54986
  console.log(JSON.stringify({ value, listed: Boolean(listed), indicator: listed, matched: domainHit?.domain ?? (ipHit ? value : null), fetched_at: set.fetched_at }, null, 2));
@@ -54620,8 +55008,8 @@ async function feedsCommand(action, value, opts) {
54620
55008
  }
54621
55009
 
54622
55010
  // src/commands/tor.ts
54623
- var import_node_fs68 = require("fs");
54624
- var import_node_net19 = require("net");
55011
+ var import_node_fs69 = require("fs");
55012
+ var import_node_net20 = require("net");
54625
55013
  var import_node_path53 = require("path");
54626
55014
  init_paths();
54627
55015
  async function torCommand(action, value, opts) {
@@ -54631,10 +55019,10 @@ async function torCommand(action, value, opts) {
54631
55019
  for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
54632
55020
  const path2 = (0, import_node_path53.join)(dir, "tor-exits.txt");
54633
55021
  try {
54634
- if (!(0, import_node_fs68.existsSync)(path2)) continue;
54635
- exits = parseTorExitList((0, import_node_fs68.readFileSync)(path2, "utf-8"));
55022
+ if (!(0, import_node_fs69.existsSync)(path2)) continue;
55023
+ exits = parseTorExitList((0, import_node_fs69.readFileSync)(path2, "utf-8"));
54636
55024
  from = path2;
54637
- updated = (0, import_node_fs68.statSync)(path2).mtime;
55025
+ updated = (0, import_node_fs69.statSync)(path2).mtime;
54638
55026
  break;
54639
55027
  } catch {
54640
55028
  }
@@ -54653,7 +55041,7 @@ async function torCommand(action, value, opts) {
54653
55041
  const remediation = loadConfig((0, import_node_path53.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).remediation;
54654
55042
  const ban = remediation?.block_tor_ssh !== false && remediation?.enabled !== false;
54655
55043
  if (action === "check") {
54656
- if (!value || !(0, import_node_net19.isIP)(value)) {
55044
+ if (!value || !(0, import_node_net20.isIP)(value)) {
54657
55045
  console.error("Usage: threatcrush tor check <ip>");
54658
55046
  process.exitCode = 2;
54659
55047
  return;
@@ -54682,13 +55070,13 @@ async function torCommand(action, value, opts) {
54682
55070
 
54683
55071
  // src/commands/reputation.ts
54684
55072
  var import_node_os22 = require("os");
54685
- var import_node_fs69 = require("fs");
55073
+ var import_node_fs70 = require("fs");
54686
55074
  var import_node_path54 = require("path");
54687
55075
  var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
54688
55076
  var CONFIG_PATH4 = (0, import_node_path54.join)((0, import_node_os22.homedir)(), ".threatcrush", "config.json");
54689
55077
  function readConfig3() {
54690
55078
  try {
54691
- return JSON.parse((0, import_node_fs69.readFileSync)(CONFIG_PATH4, "utf-8"));
55079
+ return JSON.parse((0, import_node_fs70.readFileSync)(CONFIG_PATH4, "utf-8"));
54692
55080
  } catch {
54693
55081
  return {};
54694
55082
  }
@@ -54876,7 +55264,7 @@ async function reputationSubscribeCommand(opts) {
54876
55264
  }
54877
55265
 
54878
55266
  // src/commands/privileged.ts
54879
- var import_node_fs70 = require("fs");
55267
+ var import_node_fs71 = require("fs");
54880
55268
  init_paths();
54881
55269
  var SEV2 = {
54882
55270
  critical: source_default.red.bold,
@@ -54889,19 +55277,19 @@ async function privilegedCommand(opts) {
54889
55277
  const snapshot = takeSnapshot({
54890
55278
  readFile: (p) => {
54891
55279
  try {
54892
- return (0, import_node_fs70.readFileSync)(p, "utf-8");
55280
+ return (0, import_node_fs71.readFileSync)(p, "utf-8");
54893
55281
  } catch {
54894
55282
  return null;
54895
55283
  }
54896
55284
  },
54897
55285
  readDir: (p) => {
54898
55286
  try {
54899
- return (0, import_node_fs70.readdirSync)(p);
55287
+ return (0, import_node_fs71.readdirSync)(p);
54900
55288
  } catch {
54901
55289
  return null;
54902
55290
  }
54903
55291
  },
54904
- exists: (p) => (0, import_node_fs70.existsSync)(p)
55292
+ exists: (p) => (0, import_node_fs71.existsSync)(p)
54905
55293
  });
54906
55294
  let events = [];
54907
55295
  let ledgerNote = "";
@@ -54943,12 +55331,12 @@ async function privilegedCommand(opts) {
54943
55331
  }
54944
55332
 
54945
55333
  // src/commands/integrity.ts
54946
- var import_node_fs71 = require("fs");
55334
+ var import_node_fs72 = require("fs");
54947
55335
  var import_node_path55 = require("path");
54948
55336
  init_paths();
54949
55337
  function readState2(path2) {
54950
55338
  try {
54951
- return JSON.parse((0, import_node_fs71.readFileSync)(path2, "utf8"));
55339
+ return JSON.parse((0, import_node_fs72.readFileSync)(path2, "utf8"));
54952
55340
  } catch {
54953
55341
  return null;
54954
55342
  }
@@ -54969,7 +55357,7 @@ async function integrityCommand(action = "status", opts = {}) {
54969
55357
  const config = loadConfig();
54970
55358
  const settings = fileIntegritySettings(config.file_integrity);
54971
55359
  const systemBaseline = (0, import_node_path55.join)(SYSTEM_PATHS.stateDir, "file-integrity-baseline.json");
54972
- const useSystemState = PATHS.mode === "system" || systemDaemonPresent() || (0, import_node_fs71.existsSync)(systemBaseline);
55360
+ const useSystemState = PATHS.mode === "system" || systemDaemonPresent() || (0, import_node_fs72.existsSync)(systemBaseline);
54973
55361
  const stateDir = useSystemState ? SYSTEM_PATHS.stateDir : PATHS.stateDir;
54974
55362
  const baselinePath = (0, import_node_path55.join)(stateDir, "file-integrity-baseline.json");
54975
55363
  const observedPath = (0, import_node_path55.join)(stateDir, "file-integrity-observed.json");
@@ -55040,11 +55428,11 @@ async function integrityCommand(action = "status", opts = {}) {
55040
55428
  }
55041
55429
 
55042
55430
  // src/commands/edr.ts
55043
- var import_node_fs73 = require("fs");
55431
+ var import_node_fs74 = require("fs");
55044
55432
  init_paths();
55045
55433
 
55046
55434
  // src/daemon/auditd/rules.ts
55047
- var import_node_fs72 = require("fs");
55435
+ var import_node_fs73 = require("fs");
55048
55436
  var import_node_child_process26 = require("child_process");
55049
55437
  var import_node_path56 = require("path");
55050
55438
  var WEB_TOOLS = ["sh", "bash", "dash", "zsh", "curl", "wget"];
@@ -55057,7 +55445,7 @@ function passwdByName() {
55057
55445
  raw = (0, import_node_child_process26.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
55058
55446
  } catch {
55059
55447
  try {
55060
- raw = (0, import_node_fs72.readFileSync)("/etc/passwd", "utf8");
55448
+ raw = (0, import_node_fs73.readFileSync)("/etc/passwd", "utf8");
55061
55449
  } catch {
55062
55450
  return /* @__PURE__ */ new Map();
55063
55451
  }
@@ -55076,8 +55464,8 @@ function existingExecutables(names) {
55076
55464
  for (const prefix of ["/bin", "/usr/bin", "/usr/local/bin"]) {
55077
55465
  const candidate = `${prefix}/${name}`;
55078
55466
  try {
55079
- if (!(0, import_node_fs72.existsSync)(candidate) || !(0, import_node_fs72.statSync)(candidate).isFile()) continue;
55080
- paths.add((0, import_node_fs72.realpathSync)(candidate));
55467
+ if (!(0, import_node_fs73.existsSync)(candidate) || !(0, import_node_fs73.statSync)(candidate).isFile()) continue;
55468
+ paths.add((0, import_node_fs73.realpathSync)(candidate));
55081
55469
  } catch {
55082
55470
  }
55083
55471
  }
@@ -55088,7 +55476,7 @@ function existingDirectories(paths) {
55088
55476
  return [...new Set(paths)].filter((path2) => {
55089
55477
  if (!(0, import_node_path56.isAbsolute)(path2) || /[\s\r\n]/.test(path2)) return false;
55090
55478
  try {
55091
- return (0, import_node_fs72.statSync)(path2).isDirectory();
55479
+ return (0, import_node_fs73.statSync)(path2).isDirectory();
55092
55480
  } catch {
55093
55481
  return false;
55094
55482
  }
@@ -55149,8 +55537,8 @@ async function edrCommand(action = "status", opts = {}) {
55149
55537
  }
55150
55538
  let readable = false;
55151
55539
  try {
55152
- if ((0, import_node_fs73.existsSync)(settings.auditLogPath)) (0, import_node_fs73.accessSync)(settings.auditLogPath, import_node_fs73.constants.R_OK);
55153
- readable = (0, import_node_fs73.existsSync)(settings.auditLogPath);
55540
+ if ((0, import_node_fs74.existsSync)(settings.auditLogPath)) (0, import_node_fs74.accessSync)(settings.auditLogPath, import_node_fs74.constants.R_OK);
55541
+ readable = (0, import_node_fs74.existsSync)(settings.auditLogPath);
55154
55542
  } catch {
55155
55543
  }
55156
55544
  let events = [];
@@ -55336,7 +55724,7 @@ async function allowlistCommand(opts) {
55336
55724
  }
55337
55725
 
55338
55726
  // src/commands/abuse.ts
55339
- var import_node_fs74 = require("fs");
55727
+ var import_node_fs75 = require("fs");
55340
55728
  init_paths();
55341
55729
  function rows(records) {
55342
55730
  if (records.length === 0) {
@@ -55396,7 +55784,7 @@ function abuseRetractCommand(id, opts = {}) {
55396
55784
  );
55397
55785
  }
55398
55786
  function abuseStatusCommand(opts = {}) {
55399
- const config = loadConfig((0, import_node_fs74.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
55787
+ const config = loadConfig((0, import_node_fs75.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
55400
55788
  const cfg = resolveConfig(config.abuse_reporter);
55401
55789
  const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
55402
55790
  const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
@@ -55984,7 +56372,7 @@ function detectPackageManager() {
55984
56372
  }
55985
56373
  function readInstallConfig() {
55986
56374
  try {
55987
- return JSON.parse((0, import_node_fs75.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
56375
+ return JSON.parse((0, import_node_fs76.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
55988
56376
  } catch {
55989
56377
  return {};
55990
56378
  }
@@ -56342,8 +56730,8 @@ webhooks.command("retry <deliveryId>").description("Send one delivery again").ac
56342
56730
  program2.command("status").description("Show daemon status and loaded modules").action(async () => {
56343
56731
  await statusCommand();
56344
56732
  });
56345
- program2.command("rules").description("Manage detection rules").argument("[action]", "list | show", "list").argument("[id]", "Rule ID (for show)").action(async (action, id) => {
56346
- await rulesCommand({ action, id });
56733
+ program2.command("rules").description("Manage detection rules").argument("[action]", "list | show | test", "list").argument("[id]", "Rule ID (for show / test)").option("--line <text>", "test: a log line to feed through the parser and rule (dry run, nothing is blocked)").option("--repeat <n>", "test: feed the line this many times", (v) => parseInt(v, 10), 1).option("--json", "test: machine-readable result").action(async (action, id, opts) => {
56734
+ await rulesCommand({ action, id, ...opts });
56347
56735
  });
56348
56736
  program2.command("harden").description("Run hardening security scan").option("--json", "Output results as JSON").option("--report <framework>", "Export evidence report (cis)").option("--format <format>", "Report format: md, pdf, or json").option("--output <path>", "Write the report to a file (PDF requires this)").option("--no-upload", "Do not upload findings to the dashboard (uploaded when this machine is linked)").action(async (opts) => {
56349
56737
  await hardenCommand(opts);
@@ -56415,7 +56803,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
56415
56803
  program2.command("logs").description("Tail daemon logs").action(async () => {
56416
56804
  console.log(LOGO2);
56417
56805
  const logPath2 = PATHS.logFile;
56418
- if (!(0, import_node_fs75.existsSync)(logPath2)) {
56806
+ if (!(0, import_node_fs76.existsSync)(logPath2)) {
56419
56807
  console.log(source_default.yellow(` No log file found at ${logPath2}`));
56420
56808
  console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
56421
56809
  return;
@@ -56591,7 +56979,7 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
56591
56979
  const configPath = (0, import_node_path58.join)((0, import_node_os24.homedir)(), ".threatcrush", "config.json");
56592
56980
  let email = "";
56593
56981
  try {
56594
- const config = JSON.parse((0, import_node_fs75.readFileSync)(configPath, "utf-8"));
56982
+ const config = JSON.parse((0, import_node_fs76.readFileSync)(configPath, "utf-8"));
56595
56983
  email = config.email || "";
56596
56984
  } catch {
56597
56985
  }
@@ -56609,8 +56997,8 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
56609
56997
  }
56610
56998
  try {
56611
56999
  const dir = (0, import_node_path58.join)((0, import_node_os24.homedir)(), ".threatcrush");
56612
- if (!(0, import_node_fs75.existsSync)(dir)) (0, import_node_fs75.mkdirSync)(dir, { recursive: true });
56613
- (0, import_node_fs75.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
57000
+ if (!(0, import_node_fs76.existsSync)(dir)) (0, import_node_fs76.mkdirSync)(dir, { recursive: true });
57001
+ (0, import_node_fs76.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
56614
57002
  console.log(source_default.dim(` Saved email to ${configPath}`));
56615
57003
  } catch {
56616
57004
  }