@profullstack/threatcrush 0.13.72 → 0.13.74

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/README.md CHANGED
@@ -42,7 +42,7 @@
42
42
 
43
43
  ---
44
44
 
45
- ThreatCrush is a security daemon that runs on your server, **reading your logs and watching inbound connections** for live attacks. It checks every nginx request against 96 OWASP CRS rules (paranoia level 1) + 4 ThreatCrush rules with CRS anomaly scoring, runs 23 detection rules over auth, web and network events, auto-bans attackers, scans your codebase, spot-checks your URLs, and alerts you in real-time.
45
+ ThreatCrush is a security daemon that runs on your server, **reading your logs and watching inbound connections** for live attacks. It checks every nginx request against 96 OWASP CRS rules (paranoia level 1) + 4 ThreatCrush rules with CRS anomaly scoring, runs 24 detection rules over auth, web and network events, auto-bans attackers, scans your codebase, spot-checks your URLs, and alerts you in real-time.
46
46
 
47
47
  ```
48
48
  $ threatcrush monitor
package/dist/daemon.js CHANGED
@@ -14956,7 +14956,8 @@ var SECRET_RULES = [
14956
14956
  pattern: /-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY(?: BLOCK)?-----/,
14957
14957
  severity: "critical",
14958
14958
  cwe: "CWE-798",
14959
- consequence: "Key material, committed. Rotation is the only remediation."
14959
+ consequence: "Key material, committed. Rotation is the only remediation.",
14960
+ confirm: (lines, index, match) => hasPemBody(lines, index, match)
14960
14961
  },
14961
14962
  {
14962
14963
  id: "secret-slack-token",
@@ -15105,6 +15106,18 @@ var KNOWN_PLACEHOLDERS = [
15105
15106
  function isKnownPlaceholder(text) {
15106
15107
  return KNOWN_PLACEHOLDERS.some((pattern) => pattern.test(text));
15107
15108
  }
15109
+ var PEM_BODY_LOOKAHEAD = 6;
15110
+ var PEM_BODY_RUN = /[A-Za-z0-9+/]{40,}/;
15111
+ var PEM_BODY_LINE = /^[\s'"`+(]*(?:\\n)?[A-Za-z0-9+/]{40,}={0,2}(?:\\n)?['"`,;+)\s]*$/;
15112
+ function hasPemBody(lines, index, match) {
15113
+ const rest = (lines[index] ?? "").slice(match.index + match[0].length).replace(/\\[nr]/g, " ");
15114
+ if (PEM_BODY_RUN.test(rest)) return true;
15115
+ const last = Math.min(lines.length - 1, index + PEM_BODY_LOOKAHEAD);
15116
+ for (let i = index + 1; i <= last; i++) {
15117
+ if (PEM_BODY_LINE.test(lines[i])) return true;
15118
+ }
15119
+ return false;
15120
+ }
15108
15121
  function isPlaceholderAttribute(line, value) {
15109
15122
  const at = line.lastIndexOf(value);
15110
15123
  if (at === -1) return false;
@@ -15364,14 +15377,6 @@ function isSuppressed(suppressions, index, ruleId) {
15364
15377
  if (!rules) return false;
15365
15378
  return rules.has("*") || rules.has(ruleId);
15366
15379
  }
15367
- function pemPlaceholder(lines, index) {
15368
- const first = lines[index] ?? "";
15369
- const header = /-----BEGIN ((?:RSA |EC |DSA |OPENSSH |PGP )?PRIVATE KEY(?: BLOCK)?)-----/.exec(first);
15370
- if (!header) return false;
15371
- const tail = [first.slice(header.index + header[0].length), ...lines.slice(index + 1, index + 21)].join("\n").replace(/\\n/g, "\n");
15372
- const end = tail.indexOf(`-----END ${header[1]}-----`);
15373
- return end >= 0 && ["your-pem-body-here", "your-private-key-here", "your-private-key-body-here"].includes(tail.slice(0, end).trim().toLowerCase());
15374
- }
15375
15380
  function isTestPath(relativePath) {
15376
15381
  const p = relativePath.replace(/\\/g, "/");
15377
15382
  return /(?:^|\/)(?:tests?|__tests__|__mocks__|spec|specs|fixtures?|mocks?|e2e|testdata|testutils?|harness)\//i.test(p) || /(?:^|\/)(?:test|conftest)_[^/]+$/i.test(p) || /[._-](?:test|spec)\.[a-z]+$/i.test(p) || /_test\.[a-z]+$/i.test(p);
@@ -15559,6 +15564,7 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
15559
15564
  const match = rule.pattern.exec(line);
15560
15565
  if (!match) continue;
15561
15566
  if (isKnownPlaceholder(match[0])) continue;
15567
+ if (rule.confirm && !rule.confirm(lines, index, match)) continue;
15562
15568
  if (isSuppressed(suppressions, index, rule.id)) continue;
15563
15569
  const value = match[1] ?? match[0];
15564
15570
  if (isVariableReference(value)) continue;
@@ -15567,7 +15573,9 @@ function scanText(relativePath, text, language = languageOf(relativePath)) {
15567
15573
  test: inTests,
15568
15574
  "test-block": inlineTests.has(index),
15569
15575
  suppressed: foreignSecurityMark(line),
15570
- placeholder: isPlaceholderAttribute(line, value) || rule.id === "secret-private-key" && pemPlaceholder(lines, index),
15576
+ // A dummy PEM body (`your-pem-body-here`) never reaches here: it is not a
15577
+ // base64 body, so `hasPemBody` already dropped it.
15578
+ placeholder: isPlaceholderAttribute(line, value),
15571
15579
  "self-describing": rule.keywordShaped === true && describesItsOwnKey(line, value)
15572
15580
  });
15573
15581
  findings.push({
@@ -20590,6 +20598,9 @@ var import_node_path25 = require("path");
20590
20598
 
20591
20599
  // src/daemon/rules/default-rules.ts
20592
20600
  var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
20601
+ var SSHD_IDENT = String.raw`\[sshd(?:-session|-auth)?\]`;
20602
+ var SSHD_LINE = `^${SSHD_IDENT}`;
20603
+ var NOT_SSHD_LINE = `^(?!${SSHD_IDENT})`;
20593
20604
  var DEFAULT_RULES = [
20594
20605
  {
20595
20606
  id: "ssh-brute-force",
@@ -20990,7 +21001,14 @@ var DEFAULT_RULES = [
20990
21001
  match: {
20991
21002
  field: "severity",
20992
21003
  operator: "equals",
20993
- value: "critical"
21004
+ value: "critical",
21005
+ // sshd's pre-auth failures are logged at syslog priority 2, so they used
21006
+ // to land here and every SSH bot arrived titled "Critical System Error".
21007
+ // They belong to `ssh-preauth-rejected` below. Excluded on `message`, not
21008
+ // on `details.process`: matchesCondition fails a condition whose field is
21009
+ // undefined, so an `and` on `process` would stop this rule matching every
21010
+ // critical line that has no process (the kernel's, for one).
21011
+ and: [{ field: "message", operator: "regex", value: NOT_SSHD_LINE }]
20994
21012
  },
20995
21013
  threshold: 1,
20996
21014
  window_seconds: 60,
@@ -20998,6 +21016,42 @@ var DEFAULT_RULES = [
20998
21016
  tags: ["system", "critical"],
20999
21017
  enabled: true
21000
21018
  },
21019
+ {
21020
+ // Anthony, 2026-11-04, on being called for these: "it can call me when
21021
+ // unauthorized access, i want to know" — so this stays `critical` and pages
21022
+ // exactly as `system-critical-error` did (store.ts pages on `critical`, or
21023
+ // on a rule in PAGED_ATTEMPT_RULES). What changes is what the page says.
21024
+ //
21025
+ // sshd logs a rejected handshake at priority 2 — "fatal: userauth_pubkey:
21026
+ // parse publickey packet: incomplete message [preauth]", "banner exchange:
21027
+ // ... invalid format" — so a bot that never authenticated used to raise
21028
+ // "Critical System Error", and because `dedupe_key` is
21029
+ // `detection:<server>:<rule_id>` it shared ONE incident with unrelated
21030
+ // critical lines (a local `sudo` password typo, say). A rule of its own
21031
+ // splits those apart and names what actually happened.
21032
+ //
21033
+ // No `remediation`: like the rule it came from, this one only reports. The
21034
+ // ban for these addresses comes from the ssh-* rules that match the
21035
+ // accompanying "Invalid user" line, which carries a source_ip to ban.
21036
+ id: "ssh-preauth-rejected",
21037
+ title: "SSH Connection Rejected Before Login",
21038
+ description: "A remote client failed the SSH handshake before authenticating; no session was established",
21039
+ version: "1.0.0",
21040
+ category: "auth",
21041
+ severity: "critical",
21042
+ source_types: ["user-journal", "system"],
21043
+ match: {
21044
+ field: "severity",
21045
+ operator: "equals",
21046
+ value: "critical",
21047
+ and: [{ field: "message", operator: "regex", value: SSHD_LINE }]
21048
+ },
21049
+ threshold: 1,
21050
+ window_seconds: 60,
21051
+ cooldown_seconds: 300,
21052
+ tags: ["ssh", "auth", "pre-auth", "reconnaissance"],
21053
+ enabled: true
21054
+ },
21001
21055
  {
21002
21056
  id: "exploit-probe-pattern",
21003
21057
  title: "Exploit Probe Pattern",