Linux Incident Response: 6 Months of Battle-Tested Survival Tactics

Security tutorial - IT technology blog
Security tutorial - IT technology blog

Beyond the Firewall: When Production Goes Sideways

Six months ago, my morning coffee went cold when I saw a 98% CPU spike on a ‘quiet’ web server. A rogue kswapd0 process was running under a service account that hadn’t been touched in three years. That panic was a harsh reality check. Firewalls and IDSs are great, but they aren’t magic. When automated defenses fail, you need a manual, battle-tested incident response (IR) protocol to take back the wheel.

The first 30 minutes of a breach are a high-stakes race. Attackers want to scrub logs and plant backdoors. You want evidence. Move too slow, and they vanish. Move too fast with the wrong tools, and you might stomp on forensic data or tip off the intruder. This breakdown covers the hardened workflow I’ve spent the last half-year refining in the trenches.

The Forensic Toolbox: Stop Trusting System Binaries

Relying on ls, ps, or netstat during a breach is a rookie mistake. A clever rootkit replaces these first. It will patch ps to ignore malicious PIDs and hide files from ls. You are essentially asking the burglar if they’re in the house.

To fight back, I keep a ‘Forensic Toolbox’ on every production node. These are static binaries and auditing tools that don’t care about compromised system libraries. They give you the ground truth.

The Essential Kit

I prioritize busybox-static. It is a single, self-contained binary. It doesn’t rely on local libraries that an attacker might have poisoned. I also deploy auditd for deep logging and lynis for automated sanity checks.

# Deploying the core investigation tools on Debian/Ubuntu
sudo apt update
sudo apt install busybox-static auditd lynis debsums -y

debsums is my secret weapon. It compares MD5 hashes of your local files against the original repository records. If a hacker swapped your /bin/login binary for a malicious version, debsums catches it in seconds.

Forensic Readiness: Configuring for the Worst Case

Hardening isn’t just about closing ports; it’s about ensuring data exists when things break. Default Linux logs are too quiet. Over the last 6 months, I’ve tuned auditd to be significantly more aggressive.

Enabling Persistent Auditing

I force auditd to monitor sensitive files. If someone touches /etc/passwd or drops a new key into authorized_keys, I need a log entry showing exactly who did it. Add these to /etc/audit/rules.d/audit.rules:

# Track user account tampering
-w /etc/passwd -p wa -k user_changes
-w /etc/shadow -p wa -k user_changes

# Monitor SSH key injections
-w /root/.ssh/authorized_keys -p wa -k ssh_key_changes

# Flag suspicious tool usage
-w /usr/bin/wget -p x -k suspicious_download
-w /usr/bin/curl -p x -k suspicious_download

Apply the changes immediately: sudo systemctl restart auditd.

Credentials are another non-negotiable. If I suspect a breach, I isolate the server and rotate every admin password. I use the generator at toolcraft.app/en/tools/security/password-generator. It runs entirely in your browser, so no sensitive strings ever touch the wire. This ensures my recovery passwords stay off the network until I’m ready.

The Investigation: A 5-Step Hunt for Intruders

When the alarm rings, I follow a strict verification process. This isn’t about fixing yet. It’s about mapping the infection.

1. Analyze Active Sessions

Who is on the box right now? Use w for active users and last to spot 3:00 AM logins from unknown IP blocks.

# Current active sessions
w

# Review the last 20 logins
last -n 20

2. Map Network Traffic

Search for outbound connections to unknown IPs. Hackers love high-numbered ports (like 4444 or 31337) for reverse shells. Use ss—it’s faster and more modern than netstat.

# List all active and listening connections
sudo ss -tulpn

3. Hunt Rogue Processes

Look for orphans (processes with no parent) or binaries that have deleted themselves from the disk to run purely in memory. Always use the static busybox here.

# Use the trusted static binary to see everything
busybox ps auxf

Watch for the (deleted) tag in /proc/<pid>/exe. That is almost always a sign of a memory-only payload.

4. Uncover Persistence Hooks

Intruders want to survive a reboot. They hide scripts in /etc/cron.d/ or /etc/update-motd.d/. I scan for anything modified in the last hour.

# Audit all user crontabs
for user in $(cut -f1 -d: /etc/passwd); do crontab -u $user -l 2>/dev/null; done

# Find files modified in the last 60 minutes
find /etc /usr/bin /usr/sbin -mmin -60

5. Confirm Binary Integrity

Finally, let debsums verify the core OS. If debsums -c returns a match, your binaries are compromised. At that point, stop. A full reinstall from a clean image is your only safe path forward.

# Check for modified system binaries
sudo debsums -c

Closing Thoughts

Preparation is 90% of the win. Tools like busybox-static and auditd turn a chaotic midnight emergency into a systematic hunt. If you wait until you are breached to learn these commands, the race is already over. Set up your forensic environment today. Trust your logs, use your static binaries, and always verify your integrity from the ground up.

Share: