Tools¶
Both tools are read-only: they never stop, restart, reconfigure or write to anything they inspect. Safe to run on a live system you suspect is compromised (Chapter 14), and as part of the monthly audit (Chapter 12.4).
Downloads: triage-host.sh · rds-check.sql
triage-host.sh: Docker host compromise triage¶
Checks a Linux host running Postgres/Redis in Docker and prints a summary of RED (compromise indicators) and AMBER (exposure / bad practice) flags.
scp tools/triage-host.sh <server>:~/ # from the laptop
sudo bash ~/triage-host.sh # on the server
scp -r <server>:~/triage-* ./ # bring the results back (run as root → /root/triage-*)
Output folder ~/triage-<host>-<timestamp>/: report.txt (everything), flags.txt (summary), <container>.log (DB logs).
What it checks:
- Listening ports: 5432/6379/8000/… on all interfaces
- Which compose file started each container
- Postgres containers:
- processes inside the container
- extra superusers, known attacker role names
- whether the app connects as a superuser
- loaded
pg_hbarules (attackeradminrule, reject-all lockout, networktrust) archive_commandand settings pending a restart (pg_file_settings),postgresql.auto.conf- hidden attacker files,
docker diff - functions, triggers, event triggers and extensions in every database
- log analysis: failed logins, client IPs,
COPY … PROGRAM,ALTER SYSTEM, lockout - Redis: no password, hijacked
dir,backup*cron-injection keys - Host: processes, connections to known attacker IPs, cron, systemd changes, SSH keys and
sshdsettings, recent logins
Expected AMBER/RED on a setup that's merely exposed: public listeners, "app connects as superuser", "Redis has NO password". Compromise indicators: extra superusers, attacker pg_hba rules, archive_command set, hidden .gs_*/.temp* files, non-postgres processes in the DB container, COPY … PROGRAM in logs, Redis backup* keys, connections to attacker IPs.
Extend IOC_IPS / IOC_PROC at the top of the script as you learn new indicators.
rds-check.sql: RDS PostgreSQL read-only check¶
Lists login roles (and who holds rds_superuser), functions/triggers/event triggers/extensions, tables that don't look like Django tables, app prefixes, current connections, logging settings, Django admin/staff accounts, newest accounts, the Celery beat schedule and recent admin actions.
The SQL arrives on stdin, so psql can't prompt for a password: pass it via PGPASSWORD. Run it from the app server, taking the credentials from the running app container so nothing is typed or stored in shell history:
H=$(docker exec <api-container> printenv DB_HOST); U=$(docker exec <api-container> printenv DB_USER)
D=$(docker exec <api-container> printenv DB_NAME); P=$(docker exec <api-container> printenv DB_PORT || echo 5432)
export PGPASSWORD="$(docker exec <api-container> printenv DB_PASSWORD)"
echo "host=$H port=${P:-5432} user=$U db=$D password_set=$([ -n "$PGPASSWORD" ] && echo yes || echo NO)"
docker run --rm -i -e PGPASSWORD postgres:16-alpine psql \
"host=$H port=${P:-5432} user=$U dbname=$D sslmode=require connect_timeout=10" \
-X -f - < rds-check.sql > ~/rds-check.out 2>&1
unset PGPASSWORD
If password_set=NO: read -rsp "DB password: " PGPASSWORD; echo; export PGPASSWORD instead of the export line.
-e PGPASSWORD without a value passes the variable from your shell into the throwaway container without putting the password on the command line.