Skip to content

Blue team log forensics cheat sheet

Read auth.log, nginx and audit logs from the shell, decode SQL injection, hunt persistence, check file integrity, build a timeline and write detections.

SSH brute force in auth.log

grep 'Failed password' auth.log | grep -o 'from [0-9.]*' | sort | uniq -c | sort -rn | head
grep 'Failed password' auth.log | grep -cw "from $ip"       # exact count, whole word
grep Accepted auth.log | grep -w "from $ip"                 # did they get in?

Anchor on from, not a field number: invalid user lines shift the columns.

nginx combined log

awk fieldHolds
$1client address
$4time [04/Nov/2026:00:52:51
$7path and query
$9 / $10status / bytes sent
awk -v ip="$ip" '$1 == ip {s += $10} END {print s}' access.log
python3 -c 'import sys,urllib.parse; [print(urllib.parse.unquote_plus(l), end="") for l in sys.stdin]' < access.log

%27 is ', %20 and + are spaces, %3D is =, %7C is |.

Persistence on Linux

WhereLook with
SSH keyssudo cat /home/*/.ssh/authorized_keys (keep it 600, owned by the account)
Crontabssudo crontab -l -u <account>, /etc/cron.d/
Services/etc/systemd/system/*.service, multi-user.target.wants/ links
Reverse shellsgrep -r /dev/tcp/ /usr/local/bin

Remove one crontab line: sudo crontab -l -u u | grep -v bad | sudo crontab -u u -.

File integrity

cd / && sudo sha256sum -c --quiet baseline.sha256          # modified files
comm -13 <(awk '{print $2}' baseline.sha256 | sort) <(sudo find DIRS -type f | sort)   # new files
TZ=Asia/Kolkata ls -l --time-style=full-iso FILE            # mtime in IST

Clocks

TZ=Asia/Kolkata date -d @1793735856 +%FT%T                 # audit.log epoch (UTC) to IST
awk 'BEGIN {m["Nov"] = 11} {printf "2026-%02d-%02dT%s%s\n", m[$1], $2, $3, substr($0, 16)}' auth.log

Detections

grep -Eic -f sqli.rules                                     # one ERE per line, any line matches
yara -r backdoor.yar /usr/local/bin                         # prints "rule file" per hit

Detect the behaviour (a quote then SQL, an interactive shell on /dev/tcp), never the address or user agent. Test every rule on normal traffic too.

Practise it on a real machineBlue Team & Forensics course
Open the lab