Linux systems log everything - every login, every command (if configured), every service event. For defenders, these logs reveal attacker activity, from initial access to privilege escalation to persistence. The key is knowing where to look and what to look for.
Unlike Windows with its Event Viewer, Linux logs are typically text files scattered across directories. Think of it like a library where every department keeps its own logbook. Authentication logs go in one place, web server logs in another, kernel messages somewhere else. Learning the layout is half the battle.
Log Management Varies
Modern Linux uses systemd with journald. Older systems use rsyslog or syslog-ng. The concepts are similar, but commands differ. We'll cover both approaches.
Linux Log Locations
Authentication Log Analysis
Brute Force Indicators
Many "Failed password" entries from the same IP followed by "Accepted" = the password was cracked! Investigate immediately. Also watch for "Invalid user" - attackers trying common usernames.
Using journalctl (systemd)
Journal Persistence
By default, journald may only store logs in memory (lost on reboot). To persist: edit /etc/systemd/journald.conf and set Storage=persistent, then restart systemd-journald.
Detecting Attack Patterns
Command History Analysis
History Limitations
Bash history is easily manipulated by users. Attackers often run "unset HISTFILE" or "history -c" to avoid logging. For reliable command logging, use auditd with proper rules.
Auditd - Linux Auditing
Laurel - Better Audit Parsing
Consider using Laurel (github.com/threathunters-io/laurel) to transform audit logs into JSON. Much easier to ingest into SIEM and analyze!
Binary Log Analysis
Investigation Workflow
Log Analysis Methodology
Linux Log Investigation
1
Current Statewho/w - Who's logged in now?
2
Authenticationlast/lastb - Login successes and failures
3
Privilege Usegrep sudo - What commands ran as root?
4
System ChangesCheck cron, services, startup scripts
5
File ActivityFind recently modified files
6
NetworkCheck connections and listeners
7
TimelineCorrelate events across log sources
Knowledge Check
Challenges
Key Takeaways
- Authentication logs (/var/log/auth.log or /var/log/secure) are critical
- Use journalctl -u sshd for systemd-based systems
- lastb shows failed logins, last shows successful logins
- Bash history is unreliable - attackers can clear it; use auditd instead
- Look for brute force: many failures followed by success = compromised
- Check cron, systemd, and authorized_keys for persistence