PortGate

Blueprints · Server Hardening

Zero-Trust 20 min · Linux

Incident response triage playbook

Collects processes, listening sockets, recently changed files, SUID binaries, SSH authorized keys, and crontabs into a new directory. It does not stop services or delete files. The bundle does not run it.

Baked-in protections

Step 1 · bash

Read-only collection

/root/portgate-blueprints/incident-triage.sh

Run as root on the suspected host, copy the directory off the box, then decide whether to rebuild. Do not treat this as cleanup.

#!/bin/sh
set -eu
if [ "$(id -u)" -ne 0 ]; then
  echo "Run as root so sockets and cron are visible." >&2
  exit 1
fi
OUT="/root/portgate-triage-$(date +%Y%m%d%H%M%S)"
mkdir -p "$OUT"
ps -eo pid,user,lstart,cmd > "$OUT/processes.txt"
ss -tulpn > "$OUT/sockets.txt" 2>&1 || true
find / -xdev -perm -4000 -type f > "$OUT/suid.txt" 2>/dev/null || true
find /etc /home /root /var/www /tmp /var/tmp -xdev -mtime -2 -type f > "$OUT/modified-2d.txt" 2>/dev/null || true
find /root /home -name authorized_keys -type f -exec sh -c 'echo "== $1 =="; cat "$1"' _ {} \; > "$OUT/authorized_keys.txt" 2>/dev/null || true
{
  echo "== /etc/crontab =="
  cat /etc/crontab 2>/dev/null || true
  echo "== /etc/cron.d =="
  ls -la /etc/cron.d 2>/dev/null || true
  cat /etc/cron.d/* 2>/dev/null || true
  echo "== user crontabs =="
  cut -d: -f1 /etc/passwd | while IFS= read -r user; do
    echo "-- $user --"
    crontab -u "$user" -l 2>/dev/null || true
  done
} > "$OUT/cron.txt"
echo "Report written to $OUT"

Step 2 · text

What to read first

/root/portgate-blueprints/incident-readme.txt

A checklist. It is not a command.

1. sockets.txt for listeners you do not recognize.
2. authorized_keys.txt for keys you did not install.
3. cron.txt for new jobs.
4. suid.txt and modified-2d.txt for new privileged or recently written files.
5. Copy the directory off the host before you rebuild it.