Notes
The auth log
The first place a defender looks is the authentication log, called auth dot log on Debian and Ubuntu, or secure on Red Hat systems. It records SSH logins, both accepted and failed, sudo and su use, and account changes. A burst of failed passwords is a brute-force attempt. A successful login from an unexpected address, followed by sudo to root, is the shape of a break-in. Knowing these few lines by sight makes you fast at triage.
sshd: Accepted publickey for deploy from 10.0.0.9 sshd: Failed password for invalid user admin ... sudo: deploy : COMMAND=... su: session opened for root (RHEL: /var/log/secure)
journald
On modern systems, systemd's journal, read with journalctl, collects logs from services, the kernel and the system. You can filter by service, by user, by time or by priority, which makes it the fastest way to reconstruct what happened around an event. One setting matters for security: make the journal persistent, so it survives a reboot. By default some systems keep it only in memory, and a reboot, which an attacker might trigger, erases the evidence.
journalctl -u ssh a unit journalctl _UID=1000 a user journalctl --since "1 hour ago" journalctl -p err errors journalctl -k kernel persist across reboots: Storage=persistent in journald.conf
auditd
For precise detection you use the Linux audit framework, auditd. It works in the kernel and is driven by rules. You can watch a file, so any write to the password file is recorded with who did it. You can watch a system call, so every command execution is logged. Each rule carries a key so you can search for it later with ausearch. This is how you catch a service account spawning a shell, or a sensitive config being read, which ordinary logs miss.
- kernel-level, rule-driven
- watch a file: -w /etc/passwd -p wa -k passwd
- watch a syscall/command: -a always,exit -F arch=b64 -S execve -k exec
- logs to /var/log/audit/audit.log
- ausearch -k passwd to query
Rules worth having
A good starter policy watches the things attackers touch: writes to system directories, reads of the shadow file, changes to the sudoers and SSH configuration, new SUID files, kernel module loads, and use of su, sudo and passwd. Watching command execution by service accounts is especially powerful, because a web account running bash is almost always bad. Start from a published ruleset, such as the ones aligned to the CIS benchmarks, and tune out the noise for your systems.
- writes to /etc, /bin, /sbin
- reads of /etc/shadow
- changes to sudoers and SSH config
- new SUID files, module loads
- use of su, sudo, passwd
- execve by service accounts
- base it on a CIS/Auditd ruleset, then tune
Ship it off-box
Here is the rule that matters most. Logs stored only on the machine are evidence the attacker can edit or delete, and clearing them is one of the first things they do. So ship logs off the box in near real time, with a forwarder like rsyslog, Fluent Bit or an agent, into a central system. Now an attacker cannot erase what already left, and you can search across every host at once. Part thirteen builds that central pipeline; this episode is why it exists.
- forward to a central collector: rsyslog, journald remote, Fluent Bit, the Elastic/Wazuh agent
- then to a SIEM (Part 13)
- benefits: an attacker on the box cannot erase them; you can search across hosts
Anti-tampering
Assume the attacker will try to cover their tracks, so protect the record. The main defense is forwarding, because they cannot reach what already left. On the box, you can make audit logs append-only and lock the audit configuration. And you alert on tampering itself: the logging service being stopped, the journal being cleared, the auth log suddenly truncated. A gap in the logs where there should be activity is not nothing. It is a signal worth investigating on its own.
- forward before they can delete
- make audit logs append-only (chattr +a) and immutable config where possible
- alert on log service stopped, journal rotated oddly, or auth.log truncated
- gaps in logs are themselves a signal
What to alert on
Raw logs are not detection; alerts are. A handful carry most of the value. Many failed logins followed by a success means a brute force worked. A login from a new country or host. Sudo to root by a user who never does that. A service account spawning an interactive shell. A new SUID file or an edit to sudoers. And the logging service stopping. Each maps to a real attacker step, and each is rare enough in normal operation to be worth a human's attention.
- many failed logins then a success (brute force worked)
- login from a new country/host
- sudo to root by an unusual user
- service account runs a shell
- new SUID file, sudoers edited
- logging stopped or logs cleared
Common mistakes
Mistakes. Keeping logs only on the host, so the attacker deletes them. Leaving the journal in memory, so a reboot wipes it. Running no auditd, so there is no record of commands. Collecting everything and alerting on nothing, which is just expensive storage. Clocks not synchronised, so you cannot line up events across machines. No retention policy, so logs vanish before an investigation starts. And never running a drill to confirm the pipeline actually works.
- logs only on the host
- journal not persistent
- no auditd, so no command record
- collecting everything, alerting on nothing
- clocks not synced (bad timeline)
- no retention, logs gone in days
- never testing with a drill
Say it like this
In the interview: I rely on the auth log and the journal for logins and sudo, and on auditd for command execution and access to sensitive files like the shadow file and the sudoers configuration. I ship everything off the box to a SIEM in near real time so an attacker cannot erase it, keep clocks synchronised for a clean timeline, and alert on the high-signal events: brute force that succeeded, unusual sudo, a service account spawning a shell, and logging being stopped.
- "auth.log and the journal for logins and sudo, and auditd for command execution and sensitive
- file access. I ship everything
- off-box to a SIEM so it cannot
- be erased, keep clocks synced, and alert on brute force, odd
- sudo, service-account shells
- and logging being stopped."