In this section
LX1.2 Live Response — Volatile Data Collection
Live Response Commands: Capturing What Disappears
When you have shell access to a compromised Linux system and need to collect volatile evidence manually — either because UAC is not available, because you need immediate answers before running UAC, or because you need to verify UAC's output — the following command sequence captures the most critical volatile data in the correct order.
The principle: run the commands that reveal the attacker's current activity first. Process state and network connections tell you what the attacker is doing right now. Everything else tells you what the attacker did in the past. Current activity is the most volatile and the most immediately actionable.
Step 1: Record the Timestamp
# Record current time — UTC for consistency
date -u
# Also record the system's timezone configuration
cat /etc/timezone 2>/dev/null || timedatectl show --property=Timezone --value
# Record uptime — how long since last reboot
uptime# Who is logged in right now?
who
# More detail — what are they running?
w
# Last 20 login sessions (from wtmp — binary, survives log tampering)
last -20
# Failed login attempts (from btmp)
sudo lastb -20# Process tree — shows parent/child relationships
ps auxf
# Detailed process information with all fields
ps -eo pid,ppid,user,stat,%cpu,%mem,vsz,rss,tty,start_time,time,comm,args --sort=-%cpu
# For each process — read directly from /proc (bypasses rootkits)
for pid in /proc/[0-9]*/; do
p=$(basename "$pid")
echo "=== PID $p ==="
echo "CMD: $(cat /proc/$p/cmdline 2>/dev/null | tr '\0' ' ')"
echo "EXE: $(readlink -f /proc/$p/exe 2>/dev/null)"
echo "CWD: $(readlink -f /proc/$p/cwd 2>/dev/null)"
echo "USER: $(stat -c '%U' /proc/$p 2>/dev/null)"
echo "---"
done# All TCP connections — listening and established
ss -tlnp # TCP listeners with process names
ss -tnp # Established TCP connections with process names
# All UDP listeners
ss -ulnp
# Direct kernel read (bypasses rootkits)
cat /proc/net/tcp
cat /proc/net/tcp6
cat /proc/net/udp
# DNS resolver configuration
cat /etc/resolv.conf
# Routing table
ip route
# ARP cache — recently communicated hosts
ip neigh
# Firewall rules
sudo iptables-save 2>/dev/null
sudo nft list ruleset 2>/dev/null# All open files — network, disk, and special
sudo lsof -i # Network connections with file details
sudo lsof +D /tmp # Open files in /tmp
sudo lsof +D /dev/shm # Open files in /dev/shm
# Deleted files still held open by processes
sudo lsof +L1# Currently loaded modules
lsmod
# Module details for suspicious modules
for mod in $(lsmod | awk 'NR>1 {print $1}'); do
modinfo "$mod" 2>/dev/null | grep -E "^filename|^description|^author|^vermagic"
done
# Compare against known-good module list (if available)
# Modules loaded after the compromise timestamp are suspicious# Contents of /tmp — attacker staging area
ls -la /tmp/
ls -laR /tmp/ # Recursive — check subdirectories
# Contents of /dev/shm — RAM-backed staging area
ls -la /dev/shm/
ls -laR /dev/shm/
# Recently modified files across the system (last 24 hours)
find / -mtime -1 -type f -not -path "/proc/*" -not -path "/sys/*" 2>/dev/null | head -100
# Files with SUID bit set (potential priv escalation)
find / -perm -4000 -type f 2>/dev/null
# World-writable directories (attacker staging locations)
find / -type d -perm -0002 -not -path "/proc/*" -not -path "/sys/*" 2>/dev/nullMyth: "Running forensic commands on a live system contaminates the evidence and makes it inadmissible."
Reality: Live response is standard forensic practice and is accepted in legal proceedings worldwide. The key is documentation: record what commands you ran, when, and what they modified. The alternative — not collecting volatile evidence — results in permanent evidence loss. Courts and tribunals understand that some evidence modification is unavoidable during collection. What they require is that the modification is documented and the investigator can explain what changed. The SANS DFIR methodology, Mandiant's IR practice, and CrowdStrike's services team all perform live response as standard procedure. Not collecting volatile evidence because of theoretical contamination concerns is the error — not the collection itself.
Try it yourself
Exercise
On a test Linux VM (not a production system), run the full live response sequence from Steps 1-7. Save the output to a file: script /tmp/live-response-$(date +%Y%m%d).log. This records everything displayed on screen. After the collection, review the output: can you identify every running process? Can you identify every network connection? Are there any SUID files you do not recognize? Compare the process count from ps auxf | wc -l against ls /proc/[0-9]* -d | wc -l — are they the same? If they differ, investigate the discrepancy. This is the same review process you will perform on evidence from a compromised system.
Beyond this investigation
The live response commands in this subsection are the foundation for the "how to extract" step of the six-step investigation method. In LX4, you will run these commands on BASTION-NGE01 to identify the attacker's SSH session and post-compromise processes. In LX5, you will use the process tree to trace the web shell execution chain on WEBSRV-NGE01. In LX8, you will use the network connection commands to identify mining pool communications. In LX12, you will compare live response output against memory forensics output to detect rootkit-hidden processes and connections — the discrepancy technique described in Steps 3 and 4 becomes the foundation for rootkit confirmation.
Check your understanding:
1. Why should you read /proc/[pid]/exe directly instead of relying on the process name shown by ps? 2. You run ss -tnp and see 45 established connections. You run wc -l /proc/net/tcp and see 48 entries (minus the header). What does this discrepancy suggest, and what is your next step? 3. An attacker's binary at /dev/shm/.hidden/payload was deleted, but the process is still running as PID 9921. How do you recover the binary for analysis? 4. What does lsof +L1 show, and why is it forensically significant? 5. You are performing live response on a minimal Alpine Linux container. Neither ss nor lsof is installed. How do you collect network connection and open file evidence?
You are investigating a Linux server and discover evidence of both a cryptominer (resource abuse) and an SSH key theft (lateral movement preparation). The cryptominer is consuming 95% CPU and impacting production. Which do you address first?
Address the lateral movement first. The cryptominer is visible, noisy, and contained to this server — it is causing performance impact but not spreading. The SSH key theft is silent, potentially already exploited, and may have given the attacker access to additional servers. Contain the lateral movement risk: rotate the stolen SSH keys, check the target servers for unauthorized access, and apply network restrictions. Then address the cryptominer: kill the process, remove the binary and persistence mechanisms. Prioritizing the noisy but contained threat over the silent but spreading threat is the most common Linux IR prioritization mistake.
Get weekly detection and investigation techniques
KQL queries, detection rules, and investigation methods — the same depth as this course, delivered every Tuesday.
No spam. Unsubscribe anytime. ~2,000 security practitioners.