CTF Arsenal
DFIR/Log & Timeline Forensics

Linux Authentication Log Analysis

Concept

Linux authentication events (SSH logins, sudo usage, su attempts) are recorded in /var/log/auth.log (Debian/Ubuntu) or via journalctl (systemd). Reviewing them reveals brute-force attempts, successful unauthorized logins, and privilege-escalation traces.

When to Use

  • Investigating suspected unauthorized access on a Linux host.
  • Challenge provides auth.log/journalctl export as evidence.

Workflow

  1. 1
    Search for failed login patterns

    Volume/frequency suggests brute-forcing.

  2. 2
    Find successful logins

    Correlate timing with failures to spot a successful brute-force.

  3. 3
    Review sudo/su usage

    Privilege escalation traces.

  4. 4
    Build a timeline

    Correlate with other evidence (network, filesystem).

Commands

grep 'Failed password' FILE_PATH
grep 'Failed password' auth.log

Lists every failed SSH password attempt recorded in the log.

When to use: Standard first query against any auth.log for brute-force indicators.

Expected output:

Mar 11 14:01:02 host sshd[1234]: Failed password for root from 203.0.113.9 port 51820 ssh2

Look for: A high volume of attempts from one IP in a short time window; attempts against multiple usernames (spraying) vs one username (brute-force).

Next step: Count attempts per source IP: grep 'Failed password' auth.log | awk '{print $11}' | sort | uniq -c | sort -rn.

grep 'Accepted password\|Accepted publickey' FILE_PATH
grep 'Accepted password\|Accepted publickey' auth.log

Lists successful SSH authentications.

When to use: To find whether a brute-force run ended in a successful login, and when.

Expected output:

Mar 11 14:03:45 host sshd[1240]: Accepted password for root from 203.0.113.9 port 51830 ssh2

Look for: A success immediately following a string of failures from the same IP — confirms a successful brute-force.

Next step: Note the exact timestamp as the compromise time; check what that session did next (sudo log, shell history if available).

grep 'sudo:' FILE_PATH
grep 'sudo:' auth.log

Lists every sudo invocation recorded, including the command run.

When to use: After confirming a login, to see if/how the attacker escalated privileges.

Expected output:

Mar 11 14:05:10 host sudo: ctfuser : TTY=pts/0 ; PWD=/home/ctfuser ; USER=root ; COMMAND=/bin/bash

Look for: Commands run as root shortly after a suspicious login.

Next step: Add this to the incident timeline; this is often the privilege-escalation moment.

journalctl -u ssh.service --since 'DATE' --until 'DATE'
journalctl -u ssh.service --since '2024-03-11 14:00' --until '2024-03-11 15:00'

On systemd-based systems without a flat auth.log file, queries the SSH service's journal for a specific time window.

  • -u — Filter to a specific systemd unit (service).
  • --since / --until — Time window bounds.

When to use: When the evidence is a systemd journal (binary format) rather than a plain-text auth.log.

Expected output:

Same style of SSH login events as auth.log, scoped to the given window.

Look for: Same patterns as above: failed/accepted logins, timing clusters.

Next step: Narrow the time window further once a suspicious cluster is found.

Tools

grep / awk

Fast, scriptable text filtering and field extraction — sufficient for most single-host log review.

When to use: Default tools for a flat-file log of manageable size.

grep 'pattern' FILE_PATH | awk '{print $FIELD}'

Example workflow: grep to isolate event type -> awk to pull the source IP/field -> sort/uniq -c to count.

journalctl

Query systemd's structured journal logs by unit, time range, priority.

When to use: Modern systemd-based distros where logs aren't plain auth.log files.

journalctl -u UNIT --since TIME

Example workflow: Narrow by unit and time window to the incident period before reading in detail.

Plaso / log2timeline

Builds a unified, sortable timeline (a 'super timeline') from many different log/artifact sources at once.

When to use: When correlating multiple log sources (auth, filesystem, browser, etc.) across a larger investigation.

pip install plaso (or use a prebuilt environment such as a Plaso/Timesketch container)
log2timeline.py OUTPUT.plaso EVIDENCE_SOURCE

Example workflow: log2timeline to parse -> psort.py to filter/export the combined timeline -> review in Timesketch.

Findings & Interpretation

Interesting

  • A successful login immediately after a burst of failures from the same IP
  • sudo commands run moments after an unfamiliar login session starts

Suspicious

  • Logins at times inconsistent with the legitimate user's normal pattern (if a baseline is known)

False Positives

  • Legitimate automated jobs/scripts using sudo regularly are normal — compare against a baseline before flagging

How to Validate

  • Correlate the suspicious login's source IP/timing against other evidence (pcap, memory image) before concluding it's the actual intrusion vector

Next Step

  • Feed the confirmed compromise timestamp and source IP into the Incident Response timeline/IOC list.

Troubleshooting

grep finds no 'Failed password' lines at all.

Likely cause: Wrong log file for this distro/auth method, log rotation moved older events to a .gz file, or SSH uses key-only auth (no password attempts logged that way).

Verify: ls -la /var/log/auth.log* to check for rotated/compressed older logs; confirm the SSH config's auth methods.

Fix: zgrep 'Failed password' auth.log.1.gz to search rotated/compressed logs too.

Recovery: Check for PAM-related failure messages instead if password auth isn't the relevant vector.

Avoid repeating: Always check for log rotation before concluding an event never happened.