@profullstack/threatcrush 0.13.3 → 0.13.5

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,20 +42,28 @@
42
42
 
43
43
  ---
44
44
 
45
- ThreatCrush is a security daemon that runs on your server, monitoring **every connection on every port**. It detects live attacks, scans your codebase, pentests your APIs, 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 21 attack signatures, runs 13 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
49
49
 
50
- [12:03:41] ✓ Monitoring all ports · nginx · sshd · postgres
51
- [12:03:42] ✓ Loaded 1,247 attack signatures
52
- [12:03:45] ⚠ SQLi attempt — :443 185.43.21.8 → /api/users?id=1 OR 1=1
53
- [12:03:47] ✗ SSH brute force — :22 91.232.105.3 → 47 failed attempts
54
- [12:03:50] ⚠ Port scan — 45.33.32.156 scanning :21-:8080 (SYN flood)
55
- [12:03:52] ⚠ DNS tunneling — :53 suspicious TXT queries from 103.44.8.2
56
- [12:04:01] ✓ 3,891 connections analyzed · 4 threats · 1 blocked
50
+ 2026-09-25 12:03:41 [INFO] Starting foreground monitor...
51
+ 2026-09-25 12:03:41 [INFO] Monitoring 3 log source(s):
52
+ ● ssh-guard → /var/log/auth.log
53
+ ● log-watcher → /var/log/nginx/access.log
54
+ ● log-watcher → /var/log/syslog
55
+
56
+ Press Ctrl+C to stop
57
+
58
+ 2026-09-25 12:03:45 [CRITICAL] [log-watcher] Attack detected [SQLI]: GET /api/users?id=1%20OR%201=1 (185.43.21.8)
59
+ 2026-09-25 12:03:46 [CRITICAL] [log-watcher] Attack detected [PATH_TRAVERSAL]: GET /../../etc/passwd (185.43.21.8)
60
+ 2026-09-25 12:03:47 [HIGH] [ssh-guard] Failed SSH login for root from 91.232.105.3 (91.232.105.3)
61
+ 2026-09-25 12:03:48 [HIGH] [ssh-guard] Invalid SSH user attempt: admin123 from 103.77.88.99 (103.77.88.99)
62
+ 2026-09-25 12:03:52 [LOW] [log-watcher] Client error 404: GET /wp-login.php (203.0.113.9)
57
63
  ```
58
64
 
65
+ `monitor` tails your logs in the foreground. The daemon (`threatcrush start`) adds the connection poller, DNS monitor, journald, the rule engine and auto-ban.
66
+
59
67
  ## Install
60
68
 
61
69
  **Preferred install:**
@@ -91,11 +99,11 @@ bun add -g @profullstack/threatcrush
91
99
 
92
100
  ```bash
93
101
  threatcrush # Get started
94
- threatcrush monitor # Real-time security monitoring (all ports)
102
+ threatcrush monitor # Watch nginx, auth & syslog for attacks (foreground)
95
103
  threatcrush tui # Interactive dashboard (htop for security)
96
104
  threatcrush scan ./src # Scan code for vulnerabilities & secrets
97
105
  threatcrush scan . --format sarif --output out.sarif --fail-on critical,high
98
- threatcrush pentest URL # Penetration test a URL/API
106
+ threatcrush pentest URL # Quick web security checks against a URL
99
107
  threatcrush init # Auto-detect services, generate config
100
108
  threatcrush status # Show daemon status & loaded modules
101
109
  threatcrush modules # Manage security modules
@@ -107,10 +115,10 @@ threatcrush update # Upgrade the CLI using the supported path
107
115
 
108
116
  | Feature | Description |
109
117
  |---------|-------------|
110
- | 🔍 **Live Attack Detection** | Monitors all inbound connections on every port. Detects SQLi, XSS, brute force, SSH attacks, port scans, DNS tunneling. |
118
+ | 🔍 **Live Attack Detection** | Tails nginx, auth, syslog and journald, and polls inbound connections to the ports you serve. Detects SQLi, XSS, path traversal, RFI, SSH brute force, port scans, SYN floods, DNS tunneling. |
111
119
  | 🛡️ **Code Security Scanner** | Scan your codebase for vulnerabilities, hardcoded secrets, and misconfigurations. |
112
- | 💥 **Pentest Engine** | Automated penetration testing on your URLs and APIs. |
113
- | 🔀 **Network Monitor** | Watches all TCP/UDP traffic across every port — HTTP, SSH, DNS, FTP, databases. |
120
+ | 💥 **Pentest Checks** | `threatcrush pentest URL` spot-checks security headers, CSP, CORS, cookie flags, server banners, directory listings and error leaks, then probes for SQL errors, path traversal and unsafe HTTP methods. |
121
+ | 🔀 **Network Monitor** | Polls conntrack/`ss` every 5 s for inbound TCP connections to your listening ports. Flags port scans (10+ ports in 30 s) and SYN floods (50+ half-open from one source). No packet capture. |
114
122
  | 🔔 **Real-time Alerts** | Slack, email, webhook notifications the instant a threat is detected. |
115
123
  | ⚙️ **systemd Daemon** | Runs as a background service on your server. Auto-starts on boot, monitors 24/7. |
116
124
  | 📊 **TUI Dashboard** | Interactive terminal dashboard — htop for security. |
@@ -124,21 +132,22 @@ threatcrush modules list # List installed
124
132
  threatcrush modules install ssh-guard # Install a module
125
133
  threatcrush modules install docker-monitor
126
134
  threatcrush store search "firewall" # Search marketplace
127
- threatcrush store publish ./my-module # Publish your own
135
+ threatcrush store publish https://github.com/you/my-module # Publish your own
128
136
  ```
129
137
 
130
- ### Core Modules (included)
131
-
132
- | Module | What it monitors |
133
- |--------|-----------------|
134
- | `network-monitor` | All TCP/UDP traffic, port scans, SYN floods |
135
- | `log-watcher` | nginx, Apache, syslog, journald |
136
- | `ssh-guard` | Failed logins, brute force, tunneling |
137
- | `code-scanner` | Vulnerabilities, secrets, dependency CVEs |
138
- | `pentest-engine` | SQLi, XSS, SSRF, API fuzzing |
139
- | `dns-monitor` | DNS tunneling, DGA detection |
140
- | `firewall-rules` | Auto-blocks via iptables/nftables |
141
- | `alert-system` | Slack, Discord, email, webhook, PagerDuty |
138
+ ### Built in
139
+
140
+ | Component | What it covers |
141
+ |-----------|----------------|
142
+ | `log-watcher` | nginx access log + syslog — 21 attack signatures (SQLi, XSS, path traversal, RFI) on every request |
143
+ | `ssh-guard` | auth.log / secure — failed logins, brute force, root logins, user enumeration |
144
+ | `user-journal` | journald — the systemd journal |
145
+ | `network-monitor` | Inbound connections to your listening ports — port scans, SYN floods |
146
+ | `dns-monitor` | Resolver logs (systemd-resolved, dnsmasq, bind, Pi-hole) — DNS tunneling, DGA detection |
147
+ | `threatcrush scan` | Vulnerabilities, secrets, dependency CVEs (OSV.dev, with `--deps`) |
148
+ | `threatcrush pentest` | Header, CORS, cookie, SQL-error, path-traversal and HTTP-method checks |
149
+ | auto-defend | Bans via fail2ban, nftables or iptables |
150
+ | alerts | Slack, Discord, email, webhook, PagerDuty |
142
151
 
143
152
  ### Community Modules
144
153
 
package/dist/daemon.js CHANGED
@@ -8804,6 +8804,38 @@ var DEFAULT_RULES = [
8804
8804
  },
8805
8805
  enabled: true
8806
8806
  },
8807
+ {
8808
+ // A 402 is a paywall saying "pay first". A caller that means to pay gets
8809
+ // one and pays; a podcast app polling a paid feed gets a handful an hour.
8810
+ // Thirty in a minute from one address is a scraper that ignores the answer
8811
+ // and keeps walking URLs: GoogleOther did ~40/min per IP against r4ck's
8812
+ // /api/v1/search on dev2, 2026-09-25. `web-scanner-detection` saw it too,
8813
+ // but it is `medium`, and auto-defence bans at `high` and above, so it fired
8814
+ // every minute and never banned. This one is `high` on purpose.
8815
+ //
8816
+ // It cannot see a proxy swarm that asks once per address; nothing per-IP can.
8817
+ id: "paywall-hammering",
8818
+ title: "Paywall Hammering",
8819
+ description: "Repeated 402 Payment Required responses to the same source",
8820
+ version: "1.0.0",
8821
+ category: "web",
8822
+ severity: "high",
8823
+ source_types: ["log-watcher", "web"],
8824
+ match: {
8825
+ field: "message",
8826
+ operator: "regex",
8827
+ value: "Client error 402:"
8828
+ },
8829
+ threshold: 30,
8830
+ window_seconds: 60,
8831
+ cooldown_seconds: 600,
8832
+ tags: ["web", "scraper", "x402", "paywall"],
8833
+ remediation: {
8834
+ action: "block",
8835
+ description: "Block a scraper that keeps walking a paywall without paying"
8836
+ },
8837
+ enabled: true
8838
+ },
8807
8839
  {
8808
8840
  id: "port-scan-indicator",
8809
8841
  title: "Port Scan Indicators",
@@ -9310,6 +9342,48 @@ function defaultGateways() {
9310
9342
  return [...found];
9311
9343
  }
9312
9344
 
9345
+ // src/daemon/firewall/crawlers.ts
9346
+ var import_node_dns = require("dns");
9347
+ var CRAWLER_DOMAINS = ["googlebot.com", "google.com", "search.msn.com"];
9348
+ var systemResolver = {
9349
+ reverse: (ip) => import_node_dns.promises.reverse(ip),
9350
+ lookup: async (host) => (await import_node_dns.promises.lookup(host, { all: true })).map((a) => a.address)
9351
+ };
9352
+ var TIMEOUT_MS = 2e3;
9353
+ var CACHE_MS = 6 * 36e5;
9354
+ function withTimeout(p) {
9355
+ return Promise.race([
9356
+ p,
9357
+ new Promise((_, reject) => setTimeout(() => reject(new Error("dns timeout")), TIMEOUT_MS).unref())
9358
+ ]);
9359
+ }
9360
+ function inCrawlerDomain(host) {
9361
+ const h = host.toLowerCase().replace(/\.$/, "");
9362
+ return CRAWLER_DOMAINS.some((d) => h === d || h.endsWith(`.${d}`));
9363
+ }
9364
+ function crawlerVerifier(resolver = systemResolver) {
9365
+ const cache = /* @__PURE__ */ new Map();
9366
+ return async (ip) => {
9367
+ const hit = cache.get(ip);
9368
+ if (hit && hit.until > Date.now()) return hit.host;
9369
+ let host = null;
9370
+ try {
9371
+ const names = await withTimeout(resolver.reverse(ip));
9372
+ for (const name of names.filter(inCrawlerDomain)) {
9373
+ const addrs = await withTimeout(resolver.lookup(name));
9374
+ if (addrs.includes(ip)) {
9375
+ host = name.replace(/\.$/, "");
9376
+ break;
9377
+ }
9378
+ }
9379
+ } catch {
9380
+ host = null;
9381
+ }
9382
+ cache.set(ip, { host, until: Date.now() + CACHE_MS });
9383
+ return host;
9384
+ };
9385
+ }
9386
+
9313
9387
  // src/daemon/firewall/remediation.ts
9314
9388
  var DEFAULT_CONFIG2 = {
9315
9389
  enabled: true,
@@ -9318,7 +9392,8 @@ var DEFAULT_CONFIG2 = {
9318
9392
  max_ban_seconds: 86400,
9319
9393
  strike_memory_seconds: 86400,
9320
9394
  allowlist: [],
9321
- protect_current_ssh_client: true
9395
+ protect_current_ssh_client: true,
9396
+ spare_verified_crawlers: true
9322
9397
  };
9323
9398
  var SEVERITY_RANK4 = {
9324
9399
  info: 0,
@@ -9338,9 +9413,10 @@ function explainBlockFailure(err, backend) {
9338
9413
  return `threatcrushd is running ${who} and cannot manage ${backend}. A ban is written by the daemon, not by whoever asked for it. Fix it with one command, which asks for root itself: threatcrush install-service`;
9339
9414
  }
9340
9415
  var RemediationManager = class {
9341
- constructor(adapter, bus2, config) {
9416
+ constructor(adapter, bus2, config, verifyCrawler = crawlerVerifier()) {
9342
9417
  this.adapter = adapter;
9343
9418
  this.bus = bus2;
9419
+ this.verifyCrawler = verifyCrawler;
9344
9420
  this.config = { ...DEFAULT_CONFIG2, ...config };
9345
9421
  this.protectedList = [...DEFAULT_PROTECTED, ...this.config.allowlist];
9346
9422
  for (const gateway of defaultGateways()) this.protectedList.push(gateway);
@@ -9352,6 +9428,7 @@ var RemediationManager = class {
9352
9428
  }
9353
9429
  adapter;
9354
9430
  bus;
9431
+ verifyCrawler;
9355
9432
  config;
9356
9433
  blocklist = [];
9357
9434
  strikes = {};
@@ -9393,6 +9470,13 @@ var RemediationManager = class {
9393
9470
  if (!ip || (0, import_node_net4.isIP)(ip) === 0) return;
9394
9471
  if (this.isAllowlisted(ip)) return;
9395
9472
  if (this.blocklist.some((b) => b.ip === ip)) return;
9473
+ if (this.config.spare_verified_crawlers) {
9474
+ const crawler = await this.verifyCrawler(ip);
9475
+ if (crawler) {
9476
+ this.logLine(`[remediation] not banning ${ip}: verified crawler ${crawler} (${event.message})`);
9477
+ return;
9478
+ }
9479
+ }
9396
9480
  const ruleId = event.details?.rule_id;
9397
9481
  await this.ban(ip, event.message, { ruleId, source: "auto" });
9398
9482
  }
@@ -9667,6 +9751,9 @@ function remediationSettings(section) {
9667
9751
  if (typeof section.protect_current_ssh_client === "boolean") {
9668
9752
  settings.protect_current_ssh_client = section.protect_current_ssh_client;
9669
9753
  }
9754
+ if (typeof section.spare_verified_crawlers === "boolean") {
9755
+ settings.spare_verified_crawlers = section.spare_verified_crawlers;
9756
+ }
9670
9757
  return settings;
9671
9758
  }
9672
9759