Lesson 7 of 10
Log Analysis for IR
Log analysis is the primary mechanism for building an attack timeline, identifying the initial access vector, and understanding the attacker's full activity. Attackers increasingly try to minimize log noise and delete logs - knowing what to look for and where is critical.
Critical Log Sources
# Where to look for evidence
Linux:
/var/log/auth.log # SSH, sudo, PAM authentication
/var/log/syslog # Kernel, daemon messages
/var/log/secure # (RHEL/CentOS) Authentication events
/var/log/apache2/ # Web server access + error logs
/var/log/nginx/ # Nginx access + error logs
/var/log/audit/audit.log # Linux audit daemon (if configured)
~/.bash_history # Commands run by each user
/var/log/wtmp # Login records (use: last)
/var/log/btmp # Failed logins (use: lastb)
Windows Event Log (key Event IDs):
4624 = Successful logon
4625 = Failed logon (with logon type and source IP)
4648 = Explicit credential logon (RunAs, remote access with alternate creds)
4768 = Kerberos TGT requested
4769 = Kerberos service ticket requested
4776 = NTLM authentication attempt
4688 = New process created (if auditing enabled)
4697 = Service installed (malware persistence)
4720 = User account created
7045 = New service installed (correlate with 4697)
1102 = Audit log cleared (red flag!)
Cloud (AWS):
CloudTrail: API calls (who did what, when, from where)
VPC Flow Logs: Network connections
GuardDuty: Automated threat detection findingsLog Analysis with CLI Tools
# SSH brute force detection in auth.log
grep "Failed password" /var/log/auth.log | \
awk '{print $11}' | sort | uniq -c | sort -rn | head -20
# Shows: count IP_address - top sources of failed logins
# Identify when attacker succeeded after brute force
grep "Accepted password" /var/log/auth.log | grep -f attacker_ips.txt
# Find commands run by compromised account
# Check bash history (attacker may have cleared it - look for truncation)
cat /home/compromised_user/.bash_history
# Check for .bash_history deletion: ls -la ~/.bash_history
# Check for HISTFILE=/dev/null in .bashrc (disables history)
# Web server log analysis - find SQLi/XSS attempts
grep -E "(UNION|SELECT|script>|onerror=|../)" /var/log/nginx/access.log | \
awk '{print $1, $7}' | sort | head -30
# Find large data transfers (exfiltration)
awk '{sum[$1]+=$10} END {for (ip in sum) print sum[ip], ip}' /var/log/nginx/access.log | \
sort -rn | head -10
# Shows: total_bytes_uploaded source_IP
# Timeline reconstruction with awk
awk '/Mar 20/ {print $0}' /var/log/auth.log | \
grep -E "(Failed|Accepted|session)" | sortCommon Mistakes
- Storing logs on the compromised system - attackers routinely delete local logs (shred /var/log/auth.log); ship logs to a remote, immutable log aggregator in real-time
- Not enabling Windows process creation auditing (Event ID 4688) - without this, you cannot see what commands an attacker ran on Windows. Enable via: Computer Configuration → Audit Policy → Audit Process Creation
- Ignoring firewall and DNS logs - attackers often use DNS for C2 (DNS tunneling) and egress on allowed ports (HTTPS on 443). Firewall deny logs and DNS logs reveal these
Tip
Tip
Practice Log Analysis for IR in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
The foundational security model: Confidentiality (privacy), Integrity (trust), and Availability (uptime).
Practice Task
Note
Practice Task - (1) Write a working example of Log Analysis for IR from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Log Analysis for IR is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready cybersecurity code.
Key Takeaways
- Log analysis is the primary mechanism for building an attack timeline, identifying the initial access vector, and understanding the attacker's full activity.
- Storing logs on the compromised system - attackers routinely delete local logs (shred /var/log/auth.log); ship logs to a remote, immutable log aggregator in real-time
- Not enabling Windows process creation auditing (Event ID 4688) - without this, you cannot see what commands an attacker ran on Windows. Enable via: Computer Configuration → Audit Policy → Audit Process Creation
- Ignoring firewall and DNS logs - attackers often use DNS for C2 (DNS tunneling) and egress on allowed ports (HTTPS on 443). Firewall deny logs and DNS logs reveal these
Finished this lesson?