Skip to content

Artifact Analysis: Linux Connection Logs (wtmp, btmp, lastlog)

Unlike plain text logs, these files cannot be reliably parsed with standard tools like cat or grep without risking data corruption or misinterpretation. They are typically located in /var/log/ and require specific command-line utilities to decode their C-structure records.

wtmp (Successful Logins)

Records historical data of all successful user logins, logouts, and system reboots/shutdowns. Parsed using the last command.

btmp (Failed Logins)

Records all failed authentication attempts. Critical for identifying brute-force or password spraying attacks. Parsed using the lastb command.

lastlog (Latest Activity)

A sparse file database that records only the most recent login date and time for every UID on the system. Parsed using the lastlog command.

(Note: The utmp file records the current live state of logged-in users. It is highly volatile and generally cleared upon reboot, making it less relevant for offline post-mortem analysis.)

2. Tracking Successful Authentications (wtmp)

Section titled “2. Tracking Successful Authentications (wtmp)”

The wtmp file serves as the primary access timeline. When conducting offline analysis on a mounted forensic image (e.g., at /mnt/analysis/), analysts must force the tools to read the evidence file rather than the host system’s live logs.

parse_wtmp.sh
# -f targets the specific forensic artifact
# -F prints full dates (including the year) to avoid timeline confusion
last -F -f /mnt/analysis/var/log/wtmp
  • Anomalous Source IPs: A successful login from an external IP address on a server that should only be accessed via a management VPN is a critical red flag.
  • Service Account Hijacking: Observing an interactive shell session for accounts like www-data, apache, or postgres is a near-certain indicator of a Web Shell or a spawned reverse shell.
  • System Reboots: Attackers frequently reboot systems (shutdown or reboot entries in wtmp) to load malicious kernel modules or clear in-memory artifacts.

The btmp file is the primary artifact for quantifying credential attacks.

parse_btmp.sh
lastb -f /mnt/analysis/var/log/btmp
  • Brute-Force vs. Human Error: A few failed attempts followed by a success in wtmp usually indicates a typo. Thousands of failures from a single IP over a few minutes indicate an automated attack.
  • Targeted vs. Opportunistic: If the btmp file shows attempts targeting non-existent or generic accounts (admin, test, oracle), the attack is likely an opportunistic automated scan. Attempts specifically targeting valid, unprivileged employee usernames suggest a targeted password spraying campaign.

The lastlog file is uniquely structured; it is a table mapping UIDs to their latest login timestamp.

parse_lastlog.sh
# -R specifies the root directory, allowing the tool to map UIDs to usernames
# using the compromised system's /etc/passwd file rather than the analyst's workstation.
lastlog -R /mnt/analysis/

Analysts must look for the “awakening” of dormant accounts. If a former employee’s account or a service account (bin, daemon, adm) transitions from “Never logged in” to a recent date aligning with the incident window, the attacker has likely resurrected or hijacked that account for persistence.

5. Advanced Parsing & Anti-Forensics (utmpdump)

Section titled “5. Advanced Parsing & Anti-Forensics (utmpdump)”

Threat actors are aware of these logs and frequently attempt to wipe them using commands like echo > /var/log/wtmp or custom wiping tools.

When native commands like last fail due to file corruption, or when analysts need to export the data to a SIEM, utmpdump is the surgical tool of choice. It translates the raw binary structures into human-readable text.

utmpdump_export.sh
utmpdump /mnt/analysis/var/log/wtmp > wtmp_export_forensic.txt

If an attacker uses a crude log wiper that overwrites entries with null bytes (\x00), the last command might silently ignore the corruption and skip entries. However, utmpdump will reveal these anomalies, displaying malformed or empty records that definitively prove intentional anti-forensic tampering.

  1. The Timezone Trap: The last and lastb commands format timestamps based on the analyst workstation’s local timezone, not the timezone of the compromised system. Analysts must meticulously account for this offset or use utmpdump to view raw, unadjusted timestamps to avoid catastrophic errors in timeline reconstruction.
  2. Log Rotation: Linux aggressively rotates logs. Analysts must ensure they also parse archived files (wtmp.1, btmp.1) to capture the full scope of older intrusions.
  3. Empty Artifacts: If wtmp or btmp are 0 bytes in size on an operational server, it is highly probable that the threat actor executed a destructive wipe. Analysts must immediately pivot to searching for the attacker’s actions in the Linux Shell History.