Skip to content

Lesson 10 of 19 · 24m

Linux Host Forensics: What Actually Survives a Compromise

journald persistence, auditd coverage, wtmp/utmp, package-manager integrity checks, and the systemd/cron/ssh persistence survey — everything except bash_history, which is decorative.

~/.bash_history is the first thing an analyst opens on a compromised Linux box and the last thing the evidence should rest on. No HISTTIMEFORMAT means no timestamps. HISTCONTROL=ignorespace — a bash default on many distros — means any command prefixed with a space is never written at all. unset HISTFILE followed by kill -9 $$ drops the whole session buffer before bash can flush it. And a non-interactive payload shell — bash -c, a reverse shell over socat, a cron-fired one-liner — never writes history in the first place. The history file isn't a log; it's a scratchpad the attacker controls.

journald and syslog: check persistence before you read

journalctl is the modern log spine, but its durability is a config question, not a default. /var/log/journal only exists when Storage=persistent in /etc/systemd/journald.conf; with Storage=auto on many distros the journal lives in volatile /run/log/journal and evaporates on reboot — the reboot the attacker may have just caused. Check the directory exists before you quote journal gaps as findings. Where syslog exists, auth.log (Debian/Ubuntu) and secure (RHEL-family) carry the sshd session lines; wtmp/utmp/btmp feed last, lastlog, and lastb for the raw login record. And note the spoofing caveat: anyone can logger a forged auth-looking line into syslog — the syslog socket takes anonymous input — so corroborate auth.log entries against journald's own records where both exist.

auditd: the tool that only helps if you had it

auditd records execve syscalls, file watches, and security-relevant syscalls into /var/log/audit/audit.log — but only for rules defined in /etc/audit/rules.d before the incident. auditctl -l shows what was being watched. If auditd wasn't deployed, it retroactively knows nothing; the honest output of this incident is a ruleset — execve logging, watches on /etc/passwd, /etc/sudoers, sshd configs, cron dirs — ending in -e 2 so the config can't be edited without a reboot. That line goes in the postmortem, not this investigation.

The persistence survey

Linux persistence is mostly additions, so enumerate what changed:

  • systemd: units and symlinks in /etc/systemd/system, /usr/lib/systemd/system, ~/.config/systemd/user — including masked units and .timer units (systemctl list-timers --all) which fire without a cron-looking artifact.
  • cron/at: /etc/crontab, /etc/cron.*, /var/spool/cron/*, @reboot lines, and pending at jobs.
  • ssh: appended keys in every authorized_keys (diff comments and key material against provisioning records), Include directives added to sshd_config, AuthorizedKeysCommand, PermitRootLogin deltas.
  • ld preload / PAM: /etc/ld.so.preload contents, LD_PRELOAD exports inside service unit files, edits to files under /etc/pam.d.
  • identity/escalation primitives: new UID-0 accounts (awk -F: '$3==0' /etc/passwd), fresh SUID/SGID binaries (find / -xdev \( -perm -4000 -o -perm -2000 \) -type f), rc.local, shell rc files.
  • kernel: lsmod against a known-good module list; userland rootkits hide via LD_PRELOAD, kernel ones hide from /proc/modules itself.

Proving binaries honest: package manifests

rpm -Va (RPM systems) and debsums -s / dpkg -V (Debian) verify every package-owned file's hash against the vendor manifest — the direct test for a modified sshd or sudo binary. Their blind spot is symmetric: files the attacker added aren't in any manifest, so a clean -V run doesn't clear the box — it clears the vendor-owned files. If AIDE or Tripwire was deployed, its baseline is the answer to both halves.

The trust hierarchy

Rank Linux evidence by how far it sits from attacker control: off-box syslog forwarder > persistent journald > auditd > wtmp/auth.log > shell history. The local logs are contested by definition; a host forwarding syslog to a collector the attacker never touched is the copy that matters. And if you captured RAM before shutdown, Volatility's linux.bash — built on a dwarf2json symbol file for the exact kernel — recovers the session's shell history straight out of memory, which is the answer to a wiped ~/.bash_history.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.