@profullstack/threatcrush 0.13.82 → 0.15.0
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 +349 -13
- package/dist/daemon.js +11977 -1538
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +22689 -9617
- package/dist/index.js.map +1 -1
- package/dist/systemd/threatcrushd.service +10 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -103,6 +103,7 @@ threatcrush action-center # Fleet-wide detections, host health and queued action
|
|
|
103
103
|
threatcrush scan ./src # Scan code for vulnerabilities & secrets
|
|
104
104
|
threatcrush scan . --format sarif --output out.sarif --fail-on critical,high
|
|
105
105
|
sudo threatcrush scan --host # Rootkit / host integrity scan of this machine (alias: host-scan)
|
|
106
|
+
sudo threatcrush respond ... # Incident response: kill sessions, ban, pull stolen keys, lock sshd (dry run unless --apply)
|
|
106
107
|
threatcrush pentest URL # Quick web security checks against a URL
|
|
107
108
|
threatcrush init # Auto-detect services, generate config
|
|
108
109
|
threatcrush status # Show daemon status & loaded modules
|
|
@@ -123,6 +124,8 @@ sudo threatcrush host-scan --json > host-scan.json # machine-readable
|
|
|
123
124
|
sudo threatcrush host-scan --since 3d --deny-keys ./stolen-keys.txt
|
|
124
125
|
sudo threatcrush host-scan --checks ssh-keys,persistence,uid0-accounts
|
|
125
126
|
sudo threatcrush host-scan --skip-checks rkhunter,chkrootkit,suid-sgid # the slow ones
|
|
127
|
+
sudo threatcrush host-scan --checks network-exposure,secrets-on-disk # what an intruder reaches and harvests
|
|
128
|
+
sudo threatcrush host-scan --checks secrets-on-disk --deep --secrets-timeout 600
|
|
126
129
|
```
|
|
127
130
|
|
|
128
131
|
| Check | Fails when | Warns when |
|
|
@@ -134,16 +137,80 @@ sudo threatcrush host-scan --skip-checks rkhunter,chkrootkit,suid-sgid # the s
|
|
|
134
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)` | |
|
|
135
138
|
| `ld-preload` | `/etc/ld.so.preload` exists | |
|
|
136
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) |
|
|
137
|
-
| `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 |
|
|
138
141
|
| `sshd-config` | | `sshd -T` shows `PermitRootLogin` other than `no`, or `PasswordAuthentication yes` |
|
|
139
142
|
| `docker-containers` | | a running container is `--privileged`, `--pid=host`, or bind-mounts `/` or the Docker socket |
|
|
140
143
|
| `docker-group` | | anyone is in the `docker` group (docker group == root) |
|
|
141
144
|
| `persistence` | | a file under `/etc/cron*`, `/var/spool/cron`, `/etc/systemd/system`, `~/.config/systemd`, `/etc/pam.d`, `/etc/ssh/sshd_config.d`, `/etc/sudoers.d`, `/etc/profile.d`, `authorized_keys` and similar changed inside `--since` (default `7d`) |
|
|
142
145
|
| `uid0-accounts` | an account other than `root` has uid 0 | |
|
|
143
146
|
| `suid-sgid` | | a setuid/setgid file on the root filesystem is not owned by any package (container storage and snaps are skipped) |
|
|
147
|
+
| `network-exposure` | a datastore / admin port (see below) listens on a public address (`0.0.0.0`, `[::]`, a public IP) and no firewall rule blocks it | the `DOCKER-USER` chain is empty while Docker publishes ports on `0.0.0.0`; `DOCKER-USER` has live rules but nothing restores them at boot; a `DOCKER-USER` rule matches `--dport <host port>` for a mapping whose container port differs (it never fires); a sensitive port is explicitly allowed from anywhere in ufw; not root (firewall unreadable) |
|
|
148
|
+
| `secrets-on-disk` | a key, token or credential file is readable by other users (world-readable with every parent directory traversable, or group-readable by a shared group); `--deep`: a private key is in a git repository's history | each plaintext secret found (inventory: path, type, owner, mode, size, age; never the value) |
|
|
149
|
+
|
|
150
|
+
#### `network-exposure`
|
|
151
|
+
|
|
152
|
+
Sensitive ports: postgres 5432 / pgbouncer 6432 / 6543, mysql 3306, mongodb
|
|
153
|
+
27017, redis 6379, elasticsearch 9200 / 9300, clickhouse 8123 / 9000, couchdb
|
|
154
|
+
5984, memcached 11211, neo4j 7687 / 7474, influxdb 8086, rabbitmq 5672 / 15672,
|
|
155
|
+
kafka 9092, etcd 2379, Docker API 2375 / 2376, kubelet 10250, cups 631.
|
|
156
|
+
|
|
157
|
+
Listeners come from `ss -tlnpH` (or `/proc/net/tcp{,6}` without `ss`); Docker
|
|
158
|
+
port bindings from `docker ps`. A Docker mapping counts as sensitive when its
|
|
159
|
+
host port **or its container port** is on the list, so `-p 5601:5432` is postgres.
|
|
160
|
+
|
|
161
|
+
Docker-published ports never pass through ufw or the `INPUT` chain: only the
|
|
162
|
+
`DOCKER-USER` chain can block them, and it sees packets **after** DNAT. So for
|
|
163
|
+
`-p 6543:6432` the check looks for a `DROP`/`REJECT` matching `--dport 6432`
|
|
164
|
+
(the container port) or `-m conntrack --ctorigdstport 6543` (the host port),
|
|
165
|
+
walking the chain first-match (source-limited `ACCEPT`s are reported as an
|
|
166
|
+
allowlist, source-limited `DROP`s do not count as a block). Host processes are
|
|
167
|
+
judged by ufw when active, else the `INPUT` chain policy and rules, plus any
|
|
168
|
+
native nftables `hook input` chains. IPv6 bindings are only considered when the
|
|
169
|
+
host has a global IPv6 address.
|
|
170
|
+
|
|
171
|
+
Rules added with `iptables -I DOCKER-USER ...` live only in the kernel. The
|
|
172
|
+
check warns unless something restores them at boot: a file under
|
|
173
|
+
`/etc/systemd/system`, `/usr/local/{s,}bin`, `/etc/network/if-*.d`, `/etc/docker`,
|
|
174
|
+
a script a unit's `ExecStart` runs, `/etc/ufw/*.rules`, or `-A DOCKER-USER`
|
|
175
|
+
lines in `/etc/iptables/rules.v4`.
|
|
176
|
+
|
|
177
|
+
The check makes no outbound connections. To confirm from outside, from another
|
|
178
|
+
machine run `nc -vz -w3 <public-ip> 5432` (or `nmap -Pn -p 5432,6432,6543,3306,6379,27017 <public-ip>`)
|
|
179
|
+
for each port it lists; "Connection refused" or a timeout is what you want.
|
|
180
|
+
|
|
181
|
+
#### `secrets-on-disk`
|
|
182
|
+
|
|
183
|
+
Walks `/root` and `/home/*` (7 levels deep, never following symlinks; skips
|
|
184
|
+
`node_modules`, `.git`, `.cache`, package-manager caches, build output and
|
|
185
|
+
files over 1 MB) and `/etc` (4 levels; only world-readable findings are
|
|
186
|
+
reported there). It opens only files whose name suggests a secret and looks for:
|
|
187
|
+
|
|
188
|
+
- unencrypted private keys: `id_*`, `*.pem`, `*.key`, anything in `~/.ssh`
|
|
189
|
+
(OpenSSH keys with cipher `none`, PKCS#1/SEC1 without `Proc-Type: 4,ENCRYPTED`,
|
|
190
|
+
unencrypted PKCS#8; passphrase-protected keys are not reported)
|
|
191
|
+
- `~/.config/gh/hosts.yml` `oauth_token`, `.npmrc` `_authToken`, `.pypirc`
|
|
192
|
+
passwords, `.git-credentials`, `.netrc`, `.vault-token`, Terraform Cloud tokens
|
|
193
|
+
- `~/.docker/config.json` registries with stored `auth`, `~/.aws/credentials`,
|
|
194
|
+
`~/.config/gcloud` credentials, `~/.kube/config` with embedded tokens or keys
|
|
195
|
+
- `.env`, `.env.*`, `*.env` and backups such as `app.env.bak.<date>` (not `.example` / `.sample` / `.template`): the
|
|
196
|
+
count and **names** of variables that look like keys, tokens, secrets or
|
|
197
|
+
passwords, or URLs with an embedded password
|
|
198
|
+
- JSON identity / service-account files holding a private key, secret or token
|
|
199
|
+
- plaintext password-manager exports (Bitwarden / LastPass / 1Password /
|
|
200
|
+
browser CSV headers, unencrypted Bitwarden JSON, `.1pux` / `.1pif`)
|
|
201
|
+
|
|
202
|
+
Paths under `test/`, `fixtures/`, `examples/` and similar are labelled
|
|
203
|
+
`[test fixture path]` and never fail. `--deep` also runs
|
|
204
|
+
`git log --all --pickaxe-regex -S '-----BEGIN [A-Z ]*PRIVATE KEY-----'` in each
|
|
205
|
+
repository found (as the repository's owner when run as root, so a hostile repo
|
|
206
|
+
config cannot run anything as root); worktrees sharing a leaked commit are
|
|
207
|
+
reported once. The whole check is time-boxed by `--secrets-timeout <seconds>`
|
|
208
|
+
(default 120); what it found before the budget ran out is reported and the check
|
|
209
|
+
is marked `[partial]`.
|
|
144
210
|
|
|
145
211
|
The exit code is 1 when any check fails, 2 on bad arguments, 0 otherwise.
|
|
146
212
|
`--json` prints `{ host, kernel, root, summary: {pass, warn, fail, skip}, skipped, checks: [{ id, status, reason, items, partial, install }] }`.
|
|
213
|
+
`--deep` and `--secrets-timeout` only affect `secrets-on-disk`.
|
|
147
214
|
`--deny-keys` takes one entry per line: a full public key line, a bare base64
|
|
148
215
|
key blob, or a `SHA256:` fingerprint.
|
|
149
216
|
|
|
@@ -151,6 +218,132 @@ Run it as root. Without root, `rkhunter`, `chkrootkit` and `sshd-config` are
|
|
|
151
218
|
skipped and listed as such, and checks that could only read part of the system
|
|
152
219
|
(other users' keys, other users' processes) are marked `[partial]`.
|
|
153
220
|
|
|
221
|
+
### GitHub Actions workflow rules
|
|
222
|
+
|
|
223
|
+
`threatcrush scan <path>` parses every `.github/workflows/*.yml` (and Forgejo/Gitea
|
|
224
|
+
`.forgejo/workflows`, `.gitea/workflows`, or any YAML with top-level `on:` and
|
|
225
|
+
`jobs:`) as YAML and reads each `run:` script together with the workflow around
|
|
226
|
+
it: which inputs are free text, which `env:` variables hold input or secrets, and
|
|
227
|
+
what `ssh`, `sh -c` and `eval` do with their arguments. Findings carry the exact
|
|
228
|
+
`file:line` inside multi-line `run: |` blocks, and a fix hint (`Fix:` in the text
|
|
229
|
+
report, in the rule help in SARIF and in `fix` in JSON).
|
|
230
|
+
|
|
231
|
+
| Rule | Severity | Flags |
|
|
232
|
+
|---|---|---|
|
|
233
|
+
| `gha-expression-injection` | high | `${{ inputs.* }}`, `${{ github.event.inputs.* }}`, issue/PR/discussion `title`/`body`, `pull_request.head.ref`, `comment.body`, `github.head_ref`, commit messages, `client_payload` and other attacker-controllable contexts pasted directly into a `run:` script or an `actions/github-script` body. Fix: pass through `env:` and use `"$VAR"`. |
|
|
234
|
+
| `gha-input-in-remote-shell` | critical | Such a value, or an env var assigned from one (step, job or workflow `env:`, an in-script assignment, or a `$GITHUB_ENV` export from an earlier step), expanded into a string another shell parses: the `ssh` remote command line (including the `"VAR='$VAR' bash -s"` pattern), a here-string, pipe or unquoted heredoc into a remote shell, `bash -c`/`sh -c`, `eval`, or an `appleboy/ssh-action` `script:`. Env keeps it data locally only. Reported at medium when the variable is checked with `[[ … =~ … ]]` or `case` in the same step. |
|
|
235
|
+
| `gha-dispatch-remote-exec` | critical | A `workflow_dispatch`/`repository_dispatch` workflow that runs a free-text input as the whole remote command: `ssh host "$CMD"`, `ssh host bash -s <<<"$CMD"`, `echo "$CMD" \| ssh host bash`. |
|
|
236
|
+
| `gha-ssh-key-secret` | medium | A step writes a secret to `~/.ssh/id_*` (or uses an ssh-key action) and the job runs `ssh`/`scp`/`rsync`. Whether the server-side key is limited with `restrict,command=…` cannot be verified from the repository; the finding asks you to check. |
|
|
237
|
+
| `gha-pull-request-target-checkout` | high | A `pull_request_target` workflow whose `actions/checkout` `ref`/`repository` is the PR head (`github.event.pull_request.head.sha`/`ref`, `github.head_ref`). |
|
|
238
|
+
| `gha-secrets-to-log` | medium | `echo`/`printf` of `${{ secrets.* }}` or of a variable holding one to the log (not to a file or a `--password-stdin` consumer), a secret piped through `base64`/`openssl enc`/`gpg --armor` and printed (masking bypass), `toJSON(secrets)`, and `set -x` in a step that uses secrets. |
|
|
239
|
+
|
|
240
|
+
Not flagged: inputs used only in `with:` of other actions or in `if:` conditions,
|
|
241
|
+
`boolean`/`choice`/`number` inputs, env vars used by the local shell as `"$VAR"`,
|
|
242
|
+
single-quoted ssh commands (`ssh host 'echo $X'` does not expand locally), and
|
|
243
|
+
input piped as data to a non-shell remote command
|
|
244
|
+
(`printf '%s\n' "$IPS" | ssh host 'xargs -n1 threatcrush unblock --'`). Step
|
|
245
|
+
outputs and reusable-workflow inputs are not followed. Suppress a reviewed line
|
|
246
|
+
with `# threatcrush-disable-next-line <rule-id>`.
|
|
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
|
+
|
|
280
|
+
### Incident response: `threatcrush respond`
|
|
281
|
+
|
|
282
|
+
Containment for a box, or a fleet, after stolen SSH keys or a stolen password.
|
|
283
|
+
It is a **dry run by default**: it shows what it found and what it would do.
|
|
284
|
+
`--apply` acts. Every action is reported, in text or `--json`, with its status
|
|
285
|
+
(`planned`, `done`, `failed`, `refused`, `needs-root`); the exit code is 1 when
|
|
286
|
+
anything failed or was refused.
|
|
287
|
+
|
|
288
|
+
| Subcommand | What it does |
|
|
289
|
+
|---|---|
|
|
290
|
+
| `respond ip <ip...>` | Lists established connections and recent sshd logins/failures from the address; with `--apply` bans it (through `threatcrushd`, else a direct `nft`/`iptables` drop), then kills its per-connection `sshd-session` processes and closes its sockets with `ss -K`. Refuses private/loopback/tailnet ranges, Cloudflare and public resolvers, the gateway, the daemon's protected list and the address of your own session. `--ttl` sets the ban (default `30d`). |
|
|
291
|
+
| `respond key <SHA256:fp \| key-file...>` | Finds the key in **every** `authorized_keys*` file under `/root` and `/home/*` and every `AuthorizedKeysFile` (a non-root glob silently misses other users' homes, so run it as root), shows user, file, line and restrictions, and with `--apply` removes those lines, deletes stale copies (`authorized_keys.bak`, `.old`, ...) holding it, and shreds private-key files whose public half matches. `command=` (deploy) keys are removed like any other: a restricted key is still a stolen key. Nothing is backed up; the removed fingerprints are printed. |
|
|
292
|
+
| `respond sshd [--lockdown]` | Shows the effective `PermitRootLogin`, `PasswordAuthentication` and `KbdInteractiveAuthentication` (`sshd -T -C user=root,host=x,addr=1.2.3.4`). `--lockdown` writes `00-0-threatcrush-lockdown.conf` (all three `no`) and, only with `--allow-root-localhost`, `99-threatcrush-root-localhost.conf` (`Match Address 127.0.0.1,::1` then `PermitRootLogin prohibit-password`), validates with `sshd -t`, restores the old files and does **not** reload if that fails, then shows the values before and after. |
|
|
293
|
+
| `respond keys-audit` | Every authorized key on the box with user, file, fingerprint, comment, restrictions and last use (from the sshd journal), flagging unrestricted keys, the same key on several accounts, keys unused for 30 days, stale copies, and deploy keys (`command=`): treat those as secrets and rotate them if CI secrets may have leaked. |
|
|
294
|
+
|
|
295
|
+
Two guards come from the 2026-11-20 incident:
|
|
296
|
+
|
|
297
|
+
- **Lockout guard.** `respond key` refuses to remove a key when it would leave
|
|
298
|
+
the invoking user (`SUDO_USER`, or the ssh login user on a remote host) with
|
|
299
|
+
no key that gives a shell, and says so when the key is the one this very
|
|
300
|
+
session logged in with. `command=` and `restrict` keys do not count as a way
|
|
301
|
+
back in. It prints how to install and test a replacement first;
|
|
302
|
+
`--allow-lockout` overrides it when you have console access.
|
|
303
|
+
- **Drop-in ordering.** sshd keeps the **first** value it reads, and a `Match`
|
|
304
|
+
block swallows every directive after it. So the global settings go in a file
|
|
305
|
+
that sorts first and the `Match` in one that sorts last. `--lockdown` refuses
|
|
306
|
+
to write when `sshd_config` does not include `sshd_config.d`, when a file read
|
|
307
|
+
earlier sets a different value, or when another drop-in sorts after the
|
|
308
|
+
`Match` file.
|
|
309
|
+
|
|
310
|
+
`--hosts <file|list>` runs any subcommand on remote hosts over ssh (a file with
|
|
311
|
+
one host per line, or `dev1,dev2`), 3 at a time, and prints one report per host
|
|
312
|
+
plus a summary. A host with `threatcrush respond` installed runs
|
|
313
|
+
`sudo -n threatcrush respond ... --json` itself; any other host gets the same
|
|
314
|
+
read-only gather script streamed over ssh's stdin, the same analysis runs here,
|
|
315
|
+
and with `--apply` a second script performs exactly the planned actions. Key
|
|
316
|
+
targets travel as fingerprints only; private keys never leave their host and
|
|
317
|
+
nothing secret is put on a command line. `sudo` must work without a password
|
|
318
|
+
(`sudo -n`); otherwise the host is audited read-only.
|
|
319
|
+
|
|
320
|
+
Without root nothing is changed: the run is read-only and lists the actions that need root.
|
|
321
|
+
|
|
322
|
+
Incident runbook (stolen key `SHA256:AbC...`, attacker at `203.0.113.7`):
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
# 0. What is out there? Run read-only across the fleet first.
|
|
326
|
+
threatcrush respond keys-audit --hosts fleet.txt
|
|
327
|
+
threatcrush respond ip 203.0.113.7 --hosts fleet.txt
|
|
328
|
+
|
|
329
|
+
# 1. Cut the attacker off everywhere: ban, then kill live sessions.
|
|
330
|
+
threatcrush respond ip 203.0.113.7 --hosts fleet.txt --apply
|
|
331
|
+
|
|
332
|
+
# 2. Install and TEST your replacement key on every host before removing anything.
|
|
333
|
+
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_new
|
|
334
|
+
for h in $(cat fleet.txt); do ssh-copy-id -i ~/.ssh/id_ed25519_new.pub "$h"; done
|
|
335
|
+
|
|
336
|
+
# 3. Pull the stolen key (dry run first: read the lockout guard's verdict).
|
|
337
|
+
threatcrush respond key SHA256:AbC... --hosts fleet.txt
|
|
338
|
+
threatcrush respond key SHA256:AbC... --hosts fleet.txt --apply
|
|
339
|
+
|
|
340
|
+
# 4. No root and no passwords over ssh; validated before reload.
|
|
341
|
+
threatcrush respond sshd --lockdown --hosts fleet.txt --apply
|
|
342
|
+
|
|
343
|
+
# 5. Re-audit, and rotate every deploy key it flags.
|
|
344
|
+
threatcrush respond keys-audit --hosts fleet.txt --json > audit.json
|
|
345
|
+
```
|
|
346
|
+
|
|
154
347
|
### CIS evidence report export
|
|
155
348
|
|
|
156
349
|
Export the current `harden` findings as Markdown, JSON, or PDF:
|
|
@@ -161,12 +354,53 @@ threatcrush harden --report cis --format json --no-upload
|
|
|
161
354
|
threatcrush harden --report cis --format pdf --output ./cis-evidence.pdf --no-upload
|
|
162
355
|
```
|
|
163
356
|
|
|
164
|
-
The report
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
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.
|
|
170
404
|
|
|
171
405
|
## Features
|
|
172
406
|
|
|
@@ -201,7 +435,7 @@ threatcrush store publish https://github.com/you/my-module # Publish your own
|
|
|
201
435
|
| `user-journal` | journald — the systemd journal |
|
|
202
436
|
| `network-monitor` | Inbound connections to your listening ports — port scans, SYN floods |
|
|
203
437
|
| `dns-monitor` | Resolver logs (systemd-resolved, dnsmasq, bind, Pi-hole) — DNS tunneling, DGA detection |
|
|
204
|
-
| `threatcrush scan` | Vulnerabilities, secrets, dependency CVEs (OSV.dev, with `--deps`) |
|
|
438
|
+
| `threatcrush scan` | Vulnerabilities, secrets, GitHub Actions injection and remote-exec workflows, dependency CVEs (OSV.dev, with `--deps`) |
|
|
205
439
|
| `threatcrush scan --host` | Rootkit / host integrity scan: package file integrity, rkhunter, chkrootkit, hidden processes and kernel modules, `ld.so.preload`, SSH keys, Docker, recent persistence, SUID outside packages |
|
|
206
440
|
| `threatcrush pentest` | Header, CORS, cookie, SQL-error, path-traversal and HTTP-method checks |
|
|
207
441
|
| auto-defend | Bans via fail2ban, nftables or iptables |
|
|
@@ -239,6 +473,44 @@ poll_seconds = 15 # how soon new or restarted containers a
|
|
|
239
473
|
|
|
240
474
|
Check a line without touching the firewall: `threatcrush rules test postgres-auth-bruteforce --repeat 5 --line '<log line>'`.
|
|
241
475
|
|
|
476
|
+
### Postgres running a shell (COPY FROM PROGRAM)
|
|
477
|
+
|
|
478
|
+
A database superuser can run OS commands with `COPY ... FROM PROGRAM`, which starts `/bin/sh -c` as a child of the backend. Every few seconds the daemon walks `/proc` (which includes processes inside containers) and raises a critical `postgres-shell-exec` alert for any shell or common LOLBin (`sh`, `bash`, `dash`, `busybox`, `curl`, `wget`, `nc`, `ncat`, `python*`, `perl`, `base64`, anything touching `/dev/tcp`) whose parent chain includes `postgres`, `postmaster` or `.postgres-wrapper`. With `[docker_logs]` on, Postgres container log lines naming `FROM PROGRAM`/`TO PROGRAM` raise `postgres-copy-program` (critical), and plain shell errors or job-control output in that log (`sh: 1: curl: not found`, `Killed`, `Terminated`) raise `postgres-shell-output` (high). A command that finishes between two polls can be missed by the process check; reverse shells, downloaders and miners cannot.
|
|
479
|
+
|
|
480
|
+
```toml
|
|
481
|
+
[postgres_shell]
|
|
482
|
+
enabled = true # default on (Linux)
|
|
483
|
+
poll_seconds = 3
|
|
484
|
+
kill = false # SIGKILL the process tree postgres spawned; never postgres itself; not in dry_run
|
|
485
|
+
allow_cmdline = [] # extra regexes (whole command line) for programs postgres may run, e.g. an archive_command
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
Supabase's `pgsodium_getkey` and plain `sh -c wal-g|pgbackrest|barman-wal-* ...` archive commands (with no shell metacharacters) are allowed by default.
|
|
489
|
+
|
|
490
|
+
### Suspicious successful SSH logins
|
|
491
|
+
|
|
492
|
+
A stolen key logs in without a single failure. Every accepted SSH login is classified:
|
|
493
|
+
|
|
494
|
+
- `ssh-login-tor` (critical): from a Tor exit.
|
|
495
|
+
- `ssh-login-sensitive` (critical for root, high otherwise): root, a `sensitive_users` entry or a member of `sensitive_groups` logged in from an address outside `trusted_login_cidrs` and the `[remediation] protected` list. With no trusted CIDRs, every public login of those users alerts.
|
|
496
|
+
- `ssh-login-new-network` (medium): the user's first login from that /24 (IPv6: /48). Seen networks are kept in the state db; the first start learns the last 30 days from the journal.
|
|
497
|
+
|
|
498
|
+
A key pinned to a forced command in that user's `authorized_keys` (`restrict,command="... ci-deploy owner/repo" ssh-ed25519 ...`, as CI deploy keys are) logs from any address at info as `ssh-login-forced-command`, with the command, instead of raising `ssh-login-sensitive` or `ssh-login-new-network`; from a Tor exit it still raises `ssh-login-tor`. The fingerprint-to-command map is cached per user and re-read when `~/.ssh/authorized_keys` (or `authorized_keys2`) changes. Keys named by a custom `AuthorizedKeysFile` are not read.
|
|
499
|
+
|
|
500
|
+
Alerts name the user, address, auth method and key fingerprint. Private, loopback and tailnet ranges (10/8, 172.16/12, 192.168/16, 100.64/10, 127/8, ::1, fc00::/7) are never flagged or acted on.
|
|
501
|
+
|
|
502
|
+
```toml
|
|
503
|
+
[login_watch]
|
|
504
|
+
enabled = true
|
|
505
|
+
sensitive_users = ["root"] # root is always included
|
|
506
|
+
sensitive_groups = ["sudo", "admin", "wheel", "docker"]
|
|
507
|
+
trusted_login_cidrs = [] # e.g. ["203.0.113.0/24"]; empty = alert on every public login of those users
|
|
508
|
+
first_seen = true # first login per user per /24
|
|
509
|
+
auto_response = false # high/critical: ban the address and kill that user's sshd sessions from it (not in dry_run)
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
`kill` and `auto_response` need `CAP_KILL`, which the unit from `threatcrush install-service` now grants; re-run it after upgrading if you turn either on.
|
|
513
|
+
|
|
242
514
|
### Local shell history protection
|
|
243
515
|
|
|
244
516
|
Command-history collection is opt-in because shell histories may contain credentials or private work details:
|
|
@@ -283,13 +555,50 @@ least 10 changed files with a 0.5-bit average entropy increase is also critical.
|
|
|
283
555
|
Each configured
|
|
284
556
|
`canary_directories` entry gets a hidden, writable `.threatcrush-canary` file
|
|
285
557
|
on its first baseline; existing files are never replaced, and the canary is
|
|
286
|
-
not recreated after a baseline exists if it is deleted.
|
|
287
|
-
|
|
288
|
-
|
|
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)
|
|
562
|
+
|
|
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:
|
|
289
565
|
|
|
290
|
-
|
|
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
|
+
```
|
|
291
572
|
|
|
292
|
-
|
|
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
|
|
293
602
|
detects shells or downloaders started by configured web-service accounts,
|
|
294
603
|
execution from configured temporary or world-writable paths, and known miner
|
|
295
604
|
process names. It is disabled until you install the generated rules and opt in:
|
|
@@ -297,6 +606,7 @@ process names. It is disabled until you install the generated rules and opt in:
|
|
|
297
606
|
```toml
|
|
298
607
|
[edr]
|
|
299
608
|
enabled = true
|
|
609
|
+
source = "auditd" # "auditd" (default) | "ebpf" | "auto"
|
|
300
610
|
audit_log_path = "/var/log/audit/audit.log"
|
|
301
611
|
web_service_users = ["www-data", "nginx", "caddy"]
|
|
302
612
|
temp_exec_paths = ["/tmp", "/var/tmp", "/dev/shm"]
|
|
@@ -326,6 +636,32 @@ seconds raise a critical event, including when auditd is unavailable. These
|
|
|
326
636
|
signals are not proof of compromise; the agent does not kill processes or
|
|
327
637
|
automatically ban them.
|
|
328
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
|
+
|
|
329
665
|
### Findings in the cloud
|
|
330
666
|
|
|
331
667
|
Signed in (`threatcrush login`), every `scan`, `pentest` and `ai-scan` result is
|