@profullstack/threatcrush 0.12.4 → 0.12.6

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
@@ -10420,11 +10420,15 @@ function isRoot() {
10420
10420
  return process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
10421
10421
  }
10422
10422
  function resolveClientSocket() {
10423
- if ((0, import_node_fs2.existsSync)(PATHS.socket)) return PATHS.socket;
10424
- const other = PATHS.mode === "system" ? USER_PATHS.socket : SYSTEM_PATHS.socket;
10425
- if ((0, import_node_fs2.existsSync)(other)) return other;
10423
+ const override = process.env.THREATCRUSH_SOCKET;
10424
+ if (override) return override;
10425
+ if ((0, import_node_fs2.existsSync)(SYSTEM_PATHS.socket)) return SYSTEM_PATHS.socket;
10426
+ if ((0, import_node_fs2.existsSync)(USER_PATHS.socket)) return USER_PATHS.socket;
10426
10427
  return PATHS.socket;
10427
10428
  }
10429
+ function systemDaemonPresent() {
10430
+ return (0, import_node_fs2.existsSync)(SYSTEM_PATHS.socket) || (0, import_node_fs2.existsSync)(SYSTEM_PATHS.pidFile);
10431
+ }
10428
10432
  function ensureRuntimeDirs() {
10429
10433
  for (const dir of [PATHS.configDir, PATHS.confD, PATHS.moduleDir, PATHS.logDir, PATHS.stateDir, PATHS.runDir]) {
10430
10434
  try {
@@ -23159,8 +23163,8 @@ var IpcServer = class {
23159
23163
  nodeFs.chmodSync(PATHS.socket, 432);
23160
23164
  } catch {
23161
23165
  }
23162
- const isRoot3 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
23163
- if (isRoot3) {
23166
+ const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
23167
+ if (isRoot4) {
23164
23168
  try {
23165
23169
  const { gid } = nodeFs.statSync("/var/log/auth.log");
23166
23170
  nodeFs.chownSync(PATHS.socket, 0, gid);
@@ -23512,8 +23516,8 @@ var JournalWatcher = class _JournalWatcher {
23512
23516
  // would give us root's mostly-empty per-user journal. Otherwise we use
23513
23517
  // --user so the daemon can run unprivileged on a workstation.
23514
23518
  static scopeArgs() {
23515
- const isRoot3 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
23516
- return isRoot3 ? [] : ["--user"];
23519
+ const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
23520
+ return isRoot4 ? [] : ["--user"];
23517
23521
  }
23518
23522
  static isAvailable() {
23519
23523
  const probe = (0, import_node_child_process4.spawnSync)("journalctl", [...this.scopeArgs(), "-n", "0", "--no-pager"], {
@@ -24774,8 +24778,12 @@ var DEFAULT_RULES = [
24774
24778
  },
24775
24779
  {
24776
24780
  id: "ssh-success-after-failures",
24777
- title: "SSH Login After Failed Attempts",
24778
- description: "Successful SSH login from an IP that had recent failures",
24781
+ title: "SSH Login Accepted",
24782
+ // Honest description: this rule does NOT correlate with earlier failures —
24783
+ // it matches any accepted login. It is an alert, and it declares no
24784
+ // remediation precisely because banning the person who just logged in is
24785
+ // never the right response.
24786
+ description: "Successful SSH login (alert only \u2014 never grounds for a ban)",
24779
24787
  version: "1.0.0",
24780
24788
  category: "auth",
24781
24789
  severity: "critical",
@@ -24802,7 +24810,9 @@ var DEFAULT_RULES = [
24802
24810
  match: {
24803
24811
  field: "message",
24804
24812
  operator: "regex",
24805
- value: "(failed|accepted).*\\broot\\b"
24813
+ // Attempts only. Matching `accepted` here meant a successful root login
24814
+ // banned the administrator who had just made it.
24815
+ value: "failed.*\\broot\\b"
24806
24816
  },
24807
24817
  threshold: 1,
24808
24818
  window_seconds: 60,
@@ -25479,6 +25489,9 @@ var SEVERITY_RANK4 = {
25479
25489
  high: 3,
25480
25490
  critical: 4
25481
25491
  };
25492
+ function isSuccessfulAuth(message) {
25493
+ return /login accepted|accepted (?:publickey|password|keyboard-interactive)|session opened/i.test(message);
25494
+ }
25482
25495
  function explainBlockFailure(err, backend) {
25483
25496
  const raw = err.message || String(err);
25484
25497
  const denied = /not permitted|EACCES|EPERM|permission denied|must be root/i.test(raw);
@@ -25533,6 +25546,11 @@ var RemediationManager = class {
25533
25546
  const eventRank = SEVERITY_RANK4[event.severity] ?? 0;
25534
25547
  const minRank = SEVERITY_RANK4[this.config.min_severity] ?? 3;
25535
25548
  if (eventRank < minRank) return;
25549
+ if (isSuccessfulAuth(event.message)) return;
25550
+ if (event.details?.rule_id) {
25551
+ const remediation = event.details?.remediation;
25552
+ if (remediation?.action !== "block") return;
25553
+ }
25536
25554
  const ip = event.source_ip;
25537
25555
  if (!ip || (0, import_node_net5.isIP)(ip) === 0) return;
25538
25556
  if (this.isAllowlisted(ip)) return;
@@ -25714,14 +25732,25 @@ var RemediationManager = class {
25714
25732
  }
25715
25733
  this.blocklist = live;
25716
25734
  this.saveState();
25717
- if (this.config.dry_run) return;
25718
- let applied = [];
25735
+ let applied = null;
25719
25736
  try {
25720
25737
  applied = await this.adapter.listBlocked();
25721
25738
  } catch {
25722
25739
  }
25740
+ if (applied) {
25741
+ const known = new Set(live.filter((b) => !b.dry_run).map((b) => b.ip));
25742
+ for (const ip of applied) {
25743
+ if (known.has(ip)) continue;
25744
+ this.logLine(`[firewall] reconcile: dropping stale rule for ${ip} (no record of why)`);
25745
+ try {
25746
+ await this.adapter.unblock(ip);
25747
+ } catch {
25748
+ }
25749
+ }
25750
+ }
25751
+ if (this.config.dry_run) return;
25723
25752
  for (const entry of live) {
25724
- if (applied.includes(entry.ip)) continue;
25753
+ if (applied?.includes(entry.ip)) continue;
25725
25754
  try {
25726
25755
  await this.adapter.block(entry.ip);
25727
25756
  } catch {
@@ -25990,6 +26019,10 @@ async function runDaemon() {
25990
26019
  // src/commands/daemon.ts
25991
26020
  init_paths();
25992
26021
  init_ipc_client();
26022
+ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
26023
+ function isRoot2() {
26024
+ return typeof process.getuid === "function" && process.getuid() === 0;
26025
+ }
25993
26026
  var DAEMON_ENTRY = (0, import_node_path20.join)(__dirname, "daemon.js");
25994
26027
  async function daemonForeground() {
25995
26028
  await runDaemon();
@@ -26000,6 +26033,16 @@ async function daemonStart() {
26000
26033
  console.log(source_default.yellow(` threatcrushd already running (pid ${pid}).`));
26001
26034
  return;
26002
26035
  }
26036
+ if (!isRoot2() && systemDaemonPresent()) {
26037
+ console.log(source_default.yellow(" A system threatcrushd is already installed on this host."));
26038
+ console.log(source_default.dim(" Starting a second, user-mode daemon would shadow it: the CLI would"));
26039
+ console.log(source_default.dim(" talk to yours while the root one keeps enforcing the firewall."));
26040
+ console.log();
26041
+ console.log(source_default.dim(" Manage that one instead: sudo systemctl restart threatcrushd"));
26042
+ console.log(source_default.dim(` Or address it directly: THREATCRUSH_SOCKET=${SYSTEM_SOCKET} threatcrush status`));
26043
+ console.log();
26044
+ return;
26045
+ }
26003
26046
  ensureRuntimeDirs();
26004
26047
  if (!(0, import_node_fs28.existsSync)(DAEMON_ENTRY)) {
26005
26048
  console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
@@ -26150,7 +26193,7 @@ function looksLikeNodeScript(path) {
26150
26193
  function execStartCommand(binPath, nodePath, isNodeScript) {
26151
26194
  return isNodeScript ? `${nodePath} ${binPath} daemon` : `${binPath} daemon`;
26152
26195
  }
26153
- function isRoot2() {
26196
+ function isRoot3() {
26154
26197
  return typeof process.getuid === "function" && process.getuid() === 0;
26155
26198
  }
26156
26199
  function reexecWithSudo(args) {
@@ -26209,7 +26252,7 @@ async function installServiceCommand() {
26209
26252
  console.log(source_default.yellow(" systemd install is only supported on Linux."));
26210
26253
  return;
26211
26254
  }
26212
- if (!isRoot2()) {
26255
+ if (!isRoot3()) {
26213
26256
  if (reexecWithSudo(["install-service"])) return;
26214
26257
  console.log(source_default.red(" Needs root and sudo is unavailable or was declined."));
26215
26258
  console.log(source_default.dim(" Run this as root: threatcrush install-service"));
@@ -26284,7 +26327,7 @@ async function uninstallServiceCommand() {
26284
26327
  console.log(source_default.yellow(" systemd uninstall is only supported on Linux."));
26285
26328
  return;
26286
26329
  }
26287
- if (!isRoot2()) {
26330
+ if (!isRoot3()) {
26288
26331
  if (reexecWithSudo(["uninstall-service"])) return;
26289
26332
  console.log(source_default.red(" Needs root and sudo is unavailable or was declined."));
26290
26333
  console.log(source_default.dim(" Run this as root: threatcrush uninstall-service"));