@profullstack/threatcrush 0.14.0 → 0.15.1

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
@@ -137,7 +137,7 @@ sudo threatcrush host-scan --checks secrets-on-disk --deep --secrets-timeout 600
137
137
  | `kernel-modules` | a module has an initstate in `/sys/module` but is missing from `/proc/modules`, or a loaded module is not from `/lib/modules/$(uname -r)` | |
138
138
  | `ld-preload` | `/etc/ld.so.preload` exists | |
139
139
  | `suspicious-exe` | | a process runs a `(deleted)` executable or one under `/tmp`, `/dev/shm`, `/var/tmp` (deleted after a package upgrade is common, so this is a warning) |
140
- | `ssh-keys` | a key in any `authorized_keys` (root, every account home, `/home/*`, honouring `AuthorizedKeysFile`) matches `--deny-keys` | a key has no `command=` and no `from=`; the same key appears more than once |
140
+ | `ssh-keys` | a key in any `authorized_keys` (root, every account home, `/home/*`, honouring `AuthorizedKeysFile`) matches `--deny-keys`; the same key authorizes root and another account; an unrestricted key has a dated CI/diagnostic-style comment (`ci-diag-YYYYMMDD`); an unrestricted key sits in a file modified inside `--since` | a key has no `command=` and no `from=`; the same key appears more than once; a restricted key has a dated CI/diagnostic-style comment |
141
141
  | `sshd-config` | | `sshd -T` shows `PermitRootLogin` other than `no`, or `PasswordAuthentication yes` |
142
142
  | `docker-containers` | | a running container is `--privileged`, `--pid=host`, or bind-mounts `/` or the Docker socket |
143
143
  | `docker-group` | | anyone is in the `docker` group (docker group == root) |
@@ -192,7 +192,7 @@ reported there). It opens only files whose name suggests a secret and looks for:
192
192
  passwords, `.git-credentials`, `.netrc`, `.vault-token`, Terraform Cloud tokens
193
193
  - `~/.docker/config.json` registries with stored `auth`, `~/.aws/credentials`,
194
194
  `~/.config/gcloud` credentials, `~/.kube/config` with embedded tokens or keys
195
- - `.env`, `.env.*` and `*.env` (not `.example` / `.sample` / `.template`): the
195
+ - `.env`, `.env.*`, `*.env` and backups such as `app.env.bak.<date>` (not `.example` / `.sample` / `.template`): the
196
196
  count and **names** of variables that look like keys, tokens, secrets or
197
197
  passwords, or URLs with an embedded password
198
198
  - JSON identity / service-account files holding a private key, secret or token
@@ -245,6 +245,38 @@ input piped as data to a non-shell remote command
245
245
  outputs and reusable-workflow inputs are not followed. Suppress a reviewed line
246
246
  with `# threatcrush-disable-next-line <rule-id>`.
247
247
 
248
+ ### Deploy-path rules
249
+
250
+ `threatcrush scan <path>` also reads whole files for the relationships that
251
+ turn write access to a repository into a shell on a host. Each finding links
252
+ (`Ref:` in the text report, `helpUri` in SARIF) to the matching write-up in
253
+ [`attack-vectors/`](../../attack-vectors/README.md).
254
+
255
+ | Rule | Severity | Flags |
256
+ |---|---|---|
257
+ | `compose-host-root-mount` | critical | A `compose*.yml` / `docker-compose*.yml` service bind-mounts `/`, `/root`, `/etc`, `/boot`, `/home` or a home directory, or any `.ssh` directory (short or long volume syntax, read-only included). |
258
+ | `compose-docker-socket` | high | A service mounts `/var/run/docker.sock`. |
259
+ | `compose-privileged` | high | `privileged: true`, or `cap_add` of `SYS_ADMIN` / `ALL`. |
260
+ | `compose-root-user` | medium | `user: 0`, `0:0` or `root`. |
261
+ | `deploy-compose-from-synced-repo` | high | In a shell script, workflow or `SSH_ORIGINAL_COMMAND` wrapper: `docker compose -f <path>` run on a host where the path is under a directory the same file uploads to with `rsync`/`scp`, under a checkout updated with `git pull` on the host, or in a forced-command allowlist that also accepts `rsync --server`. |
262
+ | `deploy-remote-exec-uploaded-script` | high | A script uploaded with `rsync`/`scp`/`appleboy/scp-action` then run over ssh (`bash /srv/app/deploy.sh`, `cd /srv/app && ./deploy.sh`, an `appleboy/ssh-action` `script:`), and `ssh host bash -s < scripts/deploy.sh`. |
263
+ | `github-app-installation-idor` | high | Source code: a handler reads `installation_id` from the query string and writes it to a database without calling `GET /user/installations` (or a helper in the same file that does). |
264
+ | `authorized-keys-unrestricted` | medium | An `authorized_keys` file in the tree has a key with no `from=`, `command=` or `restrict`. |
265
+ | `authorized-keys-suspicious-comment` | high | A key comment that is a temporary role word plus a date (`ci-diag-20261120`, `ops-recovery-20261027`), with no `user@host`. |
266
+ | `authorized-keys-sftp-unjailed` | medium | A key forced to `internal-sftp` / `sftp-server`: limits what it runs, not what it reads. |
267
+ | `sshd-sftp-without-chroot` | medium | An `sshd_config` (or `sshd_config.d/*.conf`) `ForceCommand internal-sftp` with no `ChrootDirectory`. |
268
+
269
+ Credential rules added alongside them: `secret-github-app-private-key`
270
+ (a PEM key with a body in a file that also names `GITHUB_APP_ID`/`APP_ID`),
271
+ `secret-resend-key`, `secret-supabase-service-role` (a JWT whose payload role
272
+ is `service_role`; the anon key is not flagged) and
273
+ `secret-generic-high-entropy` (an unquoted `*_SECRET=`, `*_PRIVATE_KEY=`,
274
+ `*_TOKEN=`, `*_API_KEY=` or `*_PASSWORD=` value that is long, mixed-class and
275
+ high-entropy). `secret-private-key` now also matches `ENCRYPTED PRIVATE KEY`.
276
+ Env backups (`*.env.bak*`, `.env.old`, ...) are read for secrets and, when none
277
+ match, reported by name as critical; `id_rsa`/`id_ed25519`/`id_ecdsa`/`id_dsa`
278
+ are reported by name. Excerpts are always masked.
279
+
248
280
  ### Incident response: `threatcrush respond`
249
281
 
250
282
  Containment for a box, or a fleet, after stolen SSH keys or a stolen password.
@@ -322,12 +354,53 @@ threatcrush harden --report cis --format json --no-upload
322
354
  threatcrush harden --report cis --format pdf --output ./cis-evidence.pdf --no-upload
323
355
  ```
324
356
 
325
- The report identifies the host's current CIS benchmark edition when known and
326
- includes the `harden` evidence and timestamp. The one verified SSH root-login
327
- crosswalk is against the CIS Ubuntu 24.04 LTS v1.0.0 implementation; the current
328
- catalog lists v2.0.0, so the report names the v1.0.0 mapping reference and does
329
- not claim that mapping applies to v2.0.0. Other checks remain unverified. The
330
- report does not claim a CIS assessment or certification.
357
+ The report is **evidence for an auditor, not certification**; that disclaimer
358
+ is in every format. It carries the timestamp, host, OS, the current CIS edition
359
+ for that OS, and each `harden` check's result, observed evidence and CIS mapping.
360
+
361
+ **Where the CIS ids come from.** Every id, title and level is copied from a
362
+ [ComplianceAsCode](https://github.com/ComplianceAsCode/content) control file at
363
+ the pinned release tag `v0.1.82`, never guessed. A check is mapped only when a
364
+ CaC rule under the control tests the same setting the check reads. Each mapping
365
+ records the profile, benchmark edition, CaC tag, file, git blob SHA and rule id.
366
+ The catalog lives in `packages/scan/src/cis/crosswalk.ts`, and
367
+ `CIS_VERIFY_ONLINE=1 pnpm --filter @threatcrush/scan exec vitest run cis-crosswalk`
368
+ re-checks it against the pinned files.
369
+
370
+ | Pinned profile (CaC file) | Edition it implements | Current CIS edition |
371
+ |---|---|---|
372
+ | Ubuntu 24.04 (`cis_ubuntu2404.yml`) | v1.0.0 | v2.0.0 |
373
+ | Ubuntu 22.04 (`cis_ubuntu2204.yml`) | v2.0.0 | v3.0.0 |
374
+ | Debian 12 (`cis_debian12.yml`) | v1.1.0 | v2.0.0 |
375
+ | Debian 13 (`cis_debian13.yml`) | v1.0.0 | v1.1.0 |
376
+
377
+ CaC `v0.1.82` does not yet carry the current editions, so the report names the
378
+ edition each id comes from and claims no mapping to the newer one. Other OS
379
+ releases (Ubuntu 26.04 and 20.04, Debian 11, non-Debian distros) have no pinned
380
+ profile, so every check is reported as `unverified` with no id.
381
+
382
+ | Check | Ubuntu 24.04 | Ubuntu 22.04 | Debian 12 | Debian 13 | Coverage |
383
+ |---|---|---|---|---|---|
384
+ | `ssh-root-login` | 5.1.20 | 5.1.20 | 5.1.20 | 5.1.21 | full |
385
+ | `ssh-weak-config` (MaxAuthTries only) | 5.1.16 | 5.1.16 | 5.1.16 | 5.1.17 | partial |
386
+ | `firewall-active` | 4.2.3, 4.3.4 | 4.1.3, 4.2.4 | 4.2.3, 4.3.4 | 4.1.2 | partial |
387
+ | `world-writable-dirs` | 7.1.11 | 7.1.11 | 7.1.11 | 7.1.11 | partial |
388
+ | `risky-services` (tftp only) | 2.1.16 | 2.1.16 | 2.1.16 | 2.1.17 | partial |
389
+ | `ssh-password-auth`, `auto-updates`, `exposed-ports`, `fail2ban-present` | unmapped | unmapped | unmapped | unmapped | - |
390
+
391
+ *Partial* means the check reads the same setting with a narrower scope or a
392
+ looser threshold (for example ThreatCrush flags `MaxAuthTries` above 6, CIS
393
+ wants 4 or less): a FAIL is a real finding against the control, a PASS does not
394
+ satisfy it. Unmapped checks have no matching control in any pinned profile, and
395
+ the report says why. The PRD 0005 `code-scanner config` checks are in the same
396
+ catalog: `world-writable` maps to 7.1.11 (partial); the web-root, debug,
397
+ container, CORS and credential-file checks are unmapped because the OS
398
+ benchmarks have no control for them.
399
+
400
+ The dashboard's fleet export (Findings, Export MD/JSON/PDF) re-derives each
401
+ mapping from the same catalog using the OS the agent reported, and never trusts
402
+ ids sent by the agent. Most findings uploaded by agents older than this release show
403
+ as `unverified` until the host runs `harden` again.
331
404
 
332
405
  ## Features
333
406
 
@@ -482,13 +555,50 @@ least 10 changed files with a 0.5-bit average entropy increase is also critical.
482
555
  Each configured
483
556
  `canary_directories` entry gets a hidden, writable `.threatcrush-canary` file
484
557
  on its first baseline; existing files are never replaced, and the canary is
485
- not recreated after a baseline exists if it is deleted. Process killing
486
- remains unavailable; the entropy signal is a mass-change heuristic, not a
487
- content classifier.
558
+ not recreated after a baseline exists if it is deleted. The entropy signal is
559
+ a mass-change heuristic, not a content classifier.
560
+
561
+ #### Stopping the writer (opt-in)
488
562
 
489
- ### Auditd process detections
563
+ By default a canary hit or mass change only alerts. Set `contain_writer` to
564
+ have the daemon find the process doing the writing and freeze or kill it:
490
565
 
491
- The first EDR phase reads selected execution records from Linux auditd. It
566
+ ```toml
567
+ [file_integrity]
568
+ contain_writer = "stop" # "off" (default) | "stop" (SIGSTOP, recommended) | "kill" (SIGKILL)
569
+ contain_max_processes = 3 # more candidate writers than this: alert only
570
+ never_contain = ["/usr/bin/rsync", "/opt/backup/bin/"] # exact executables, or a directory ending in /
571
+ ```
572
+
573
+ inotify does not say which process changed a file, so the daemon walks
574
+ `/proc/<pid>/fd` and keeps processes holding a changed file open **for
575
+ writing** (read from `/proc/<pid>/fdinfo`). Only when nobody holds the changed
576
+ files does it fall back to processes writing inside the same directories. The
577
+ walk is bounded (8,192 processes, 4,096 descriptors each, 1.5 s); a writer that
578
+ already closed its files cannot be found.
579
+
580
+ It never signals pid 1, the daemon or its parent, kernel threads, `sshd`
581
+ (including `sshd-session`), anything named `systemd*`, or a `never_contain`
582
+ executable. It alerts without acting when the `/proc` walk was incomplete,
583
+ when it finds more than `contain_max_processes` candidates, or when nobody
584
+ holds the files. Each pid's start time is re-checked just before the signal so
585
+ a recycled pid is never hit, and `[remediation] dry_run = true` reports the
586
+ signal instead of sending it. The critical event and the daemon log record
587
+ what was done under `details.containment` (pid, executable, signal, result,
588
+ files).
589
+
590
+ `"stop"` is reversible: after reviewing, resume with `kill -CONT <pid>` or end
591
+ it with `kill -KILL <pid>`. Use `"kill"` only if you would rather lose the
592
+ process than leave it suspended.
593
+
594
+ Reading another user's `/proc/<pid>/fd` needs `CAP_SYS_PTRACE`. Re-run
595
+ `sudo threatcrush install-service` after enabling `contain_writer`; the unit
596
+ gets that capability only while `contain_writer` is on. Without it, only
597
+ writers running as root can be identified.
598
+
599
+ ### Auditd and eBPF process detections
600
+
601
+ EDR reads process events from Linux auditd or, optionally, eBPF. It
492
602
  detects shells or downloaders started by configured web-service accounts,
493
603
  execution from configured temporary or world-writable paths, and known miner
494
604
  process names. It is disabled until you install the generated rules and opt in:
@@ -496,6 +606,7 @@ process names. It is disabled until you install the generated rules and opt in:
496
606
  ```toml
497
607
  [edr]
498
608
  enabled = true
609
+ source = "auditd" # "auditd" (default) | "ebpf" | "auto"
499
610
  audit_log_path = "/var/log/audit/audit.log"
500
611
  web_service_users = ["www-data", "nginx", "caddy"]
501
612
  temp_exec_paths = ["/tmp", "/var/tmp", "/dev/shm"]
@@ -525,6 +636,32 @@ seconds raise a critical event, including when auditd is unavailable. These
525
636
  signals are not proof of compromise; the agent does not kill processes or
526
637
  automatically ban them.
527
638
 
639
+ #### eBPF source (bpftrace)
640
+
641
+ `source = "ebpf"` feeds the same rules from eBPF instead of the audit log,
642
+ with no audit rules to load and no native npm dependency: the daemon runs the
643
+ `bpftrace` CLI as a child process (argv, no shell) with an embedded program
644
+ that traces successful `exec` (pid, ppid, effective uid, file name) and, when
645
+ `watch_network_syscalls = true`, TCP connect (`SYN_SENT`) and listen
646
+ transitions. Each event becomes the same normalized record the auditd parser
647
+ produces, so reverse-shell, web-service shell, writable-path execution, miner,
648
+ new-outbound and listener detections behave identically on either source.
649
+ Command arguments and remote addresses are not traced.
650
+
651
+ It needs root, `bpftrace` (`apt install bpftrace`) and kernel BTF
652
+ (`/sys/kernel/btf/vmlinux`). `source = "auto"` picks eBPF when all three are
653
+ present and auditd otherwise; `source = "ebpf"` logs why and uses auditd when
654
+ they are not. If bpftrace exits it is restarted with exponential backoff (1s
655
+ up to 60s); if it fails to start three times in a row, the daemon falls back
656
+ to auditd. The daemon logs the active source and records it in
657
+ `edr-source.json` in its state directory; `threatcrush edr status` shows the
658
+ configured source, what this host would select, and what the daemon is using.
659
+ Review the exact program with:
660
+
661
+ ```bash
662
+ threatcrush edr bpftrace
663
+ ```
664
+
528
665
  ### Findings in the cloud
529
666
 
530
667
  Signed in (`threatcrush login`), every `scan`, `pentest` and `ai-scan` result is