Linux auth-log threat hunting. Finds the one successful login hiding in ten thousand failed ones, and shows what the attacker did next.
- The problem
- What authtrail does
- Quick start
- Demo: three logs, three stories
- Detection specification
- Severity and verdict model
- MITRE ATT&CK mapping
- Architecture
- Output formats
- Key design decisions
- Security of the tool itself
- Testing and CI
- Limitations and roadmap
- Legal and ethical use
Any Linux server with SSH open to the internet gets hit by automated password guessing within minutes of going online. Its /var/log/auth.log (/var/log/secure on Red Hat systems) fills with thousands of Failed password lines a day.
That volume is the problem. When an analyst is asked "was this server compromised?", the answer is in the log, but it is buried:
- The one
Accepted passwordline that followed 120 failures from the same address. - The
useraddline, two minutes later, that created a second account with UID 0. - The
sudoline that piped a download into a shell.
grep "Failed password" | sort | uniq -c tells you you're being attacked, which you already knew. It doesn't tell you whether the attack worked, and it can't connect the login to what happened afterwards.
authtrail reads the log the way an incident responder does. It separates background noise from real attacks, finds the login that turned an attack into a breach, and lays out everything that session did as a timeline.
Give it one or more auth logs (plain or gzipped, files or folders). You get back:
| Output | Why it matters |
|---|---|
| Verdict: COMPROMISE LIKELY, HIGH RISK, SUSPICIOUS or NO THREATS FOUND | Answers "do I need to act?" in one line |
| Plain-English summary | "203.0.113.45 made 120 failed logins against 5 accounts, then logged in as 'admin' at 03:14. Within 14 min the session opened a root shell, created UID 0 account 'sysadm'…" |
| Incident timelines | Every action tied to the compromised session, in order, with severity |
| Findings with severity, ATT&CK IDs and evidence | Each conclusion links to the exact file and line numbers that support it |
| Attack-source table | Each address classified as brute force, password spray, username probe or distributed, with the accounts it tried and whether it got in |
| Defanged IOCs | Attacker IPs, backdoor account names and payload URLs, ready for a blocklist |
| Terminal, JSON and HTML reports | Quick triage, SIEM/SOAR input, or a self-contained ticket attachment |
It runs entirely offline, uses only the Python standard library, and never modifies the logs it reads.
git clone https://github.com/BlazeXYZ/authtrail.git
cd authtrail
python -m authtrail samples/02_bruteforce_compromise.log --year 2026
python -m authtrail samples/ --year 2026 --html report.html
# On a real server (reading auth.log needs root or the adm group)
sudo python -m authtrail /var/log/auth.log /var/log/auth.log.1 /var/log/auth.log.2.gzIt requires Python 3.11+ and nothing else. pip install . also gives you an authtrail command.
The samples' timestamps carry no year, which is normal for classic syslog. --year 2026 pins the year the samples were written for; on live logs, leave it out and the year is inferred.
Recorded with termreel from docs/demo.reel.
All three samples are synthetic, generated by tools/make_samples.py from a fixed seed. Every public address comes from the documentation ranges (RFC 5737, RFC 3849), which never route on the internet.
Admin logins with keys, apt upgrade, a service restart, sudo tail /var/log/nginx/error.log, a user who mistyped her password once, and three internet scanners that tried a handful of passwords each.
Zero findings. That's the point of this sample: a tool that alerts on every failed login gets ignored. sudo tail /var/log/... is not log tampering, and three failed guesses are not an attack.
INCIDENT #1 db01: 'admin' from 203.0.113.45 03:14:11 → 03:29:10 (session closed)
03:14:11 CRITICAL Login as 'admin' after 120 failed attempts from 203.0.113.45
03:15:20 MEDIUM Interactive root shell (sudo by 'admin')
03:16:41 CRITICAL Second root account 'sysadm' created (UID 0)
03:17:05 CRITICAL 'sysadm' added to privileged group 'sudo'
03:17:30 MEDIUM Password changed for 'sysadm'
03:19:12 CRITICAL Download piped into a shell (sudo by 'admin')
03:21:40 HIGH SSH authorized_keys accessed (sudo by 'admin')
03:24:03 HIGH Cron job changed (sudo by 'admin')
03:27:55 CRITICAL Logs or shell history wiped (sudo by 'admin')
A 16-minute brute force guesses admin's password, and the session then runs a textbook persistence playbook. The same log also holds a second attacker who never gets in, and a user (bob) refused by sudo hours later. Both are reported separately and not attached to the incident, because neither belongs to it.
- Password spraying: one address tries 27 account names, once or twice each, staying under per-account lockout limits.
- Username probing: a second address tries 10 names against key-only accounts. No password is ever sent, and authtrail says so instead of calling it spraying.
- Distributed attack: six addresses take turns at the
deployaccount. Each one alone looks harmless and would slip past per-IP tools like fail2ban. - IPv6 brute force against root, and a direct root login with a key.
- In the middle of the distributed attack, the CI system logs in as
deploywith its key. authtrail doesn't flag it, because a key login is not a guessed password succeeding. - Two hostile usernames, which authtrail handles safely (see Security of the tool itself):
x from 10.0.0.5 port 22 ssh2, which tries to frame an internal host;<script>alert(1)</script>.
All windows are sliding (see design decision 4). Thresholds are configurable from the CLI.
| Rule | Fires when | Severity | ATT&CK |
|---|---|---|---|
ssh.bruteforce |
≥ 10 failures from one source in 10 min | MEDIUM | T1110.001 |
ssh.spray |
≥ 8 distinct accounts from one source in 30 min, ≤ 3 tries per account | MEDIUM | T1110.003 |
ssh.distributed |
≥ 5 sources failing against one account in 1 h | MEDIUM | T1110.001 |
| Rule | Fires when | Severity | ATT&CK |
|---|---|---|---|
ssh.compromise |
Password login from a source with ≥ 5 failures in the previous 6 h | CRITICAL (HIGH if the login used a key) | T1110, T1078, T1021.004 |
ssh.distributed_success |
Password login to an account under distributed attack | HIGH | T1110.001, T1078, T1021.004 |
ssh.root_login |
Direct root login over SSH | HIGH with a password, MEDIUM with a key | T1078.003, T1021.004 |
A ssh.compromise or ssh.distributed_success opens an incident. The incident runs from the login until that SSH session closes (matched by sshd PID), or for 12 hours if no close is logged.
| Rule | Fires when | Severity | ATT&CK |
|---|---|---|---|
account.uid0 |
An account is created with UID 0 | CRITICAL | T1136.001, T1078.003 |
account.created |
A login account is created (system accounts from packages are skipped) | LOW | T1136.001 |
account.priv_group |
A user is added to sudo, wheel, admin, root, docker or lxd |
HIGH | T1098 |
account.password_change |
A password is changed | MEDIUM for root, LOW otherwise | T1098 |
account.deleted |
An account is deleted | LOW | T1531 |
sudo.denied |
A user is refused by sudo | MEDIUM | T1548.003 |
sudo.badpass |
≥ 3 wrong sudo passwords | MEDIUM | T1110.001, T1548.003 |
su.bruteforce |
≥ 3 failed su attempts |
MEDIUM | T1110.001 |
sudo.command |
A sudo command matches a risky pattern (below) | per pattern | per pattern |
Risky sudo command patterns, most severe first (the first match wins):
| Pattern | Example | Severity | ATT&CK |
|---|---|---|---|
| Download piped into a shell | curl -fsSL http://… | bash |
HIGH | T1105, T1059.004 |
| Reverse shell | nc -e /bin/sh …, /dev/tcp/ |
HIGH | T1059.004 |
| Logs or history wiped | shred /var/log/…, history -c, unset HISTFILE |
HIGH | T1070.002, T1070.003 |
| Firewall disabled | ufw disable, iptables -F |
HIGH | T1562.004 |
| Security tooling disabled | systemctl stop auditd, setenforce 0 |
HIGH | T1562.001 |
| Setuid/setgid bit set | chmod u+s, chmod 4755 |
MEDIUM | T1548.001 |
| Password hash file accessed | /etc/shadow, unshadow |
MEDIUM | T1003.008 |
| SSH authorized_keys accessed | tee -a /root/.ssh/authorized_keys |
MEDIUM | T1098.004 |
| Cron job changed | crontab, /etc/cron* |
MEDIUM | T1053.003 |
| sudoers accessed | visudo, /etc/sudoers |
MEDIUM | T1548.003 |
| Service enabled or created | systemctl enable, /etc/systemd/system/ |
LOW | T1543.002 |
| Interactive root shell | sudo -i, sudo su |
LOW | T1548.003 |
Destructive verbs are required for the log rule: sudo tail /var/log/syslog reads a log and is not flagged.
The verdict is set by the single worst finding, not by a sum:
| Worst finding | Verdict |
|---|---|
| CRITICAL | COMPROMISE LIKELY |
| HIGH | HIGH RISK |
| MEDIUM | SUSPICIOUS |
| LOW or none | NO THREATS FOUND |
Context changes severity. Any finding inside an incident's time window is raised one level and attached to the incident. That applies to the compromised user's own sudo and su activity, and to account changes on that host, since useradd and usermod don't log who ran them. sudo -i on its own is LOW, because admins do it every day. Two minutes after a brute-forced login it is MEDIUM, and it appears in the incident's timeline.
| ID | Technique | Raised by |
|---|---|---|
| T1110 / .001 / .003 | Brute Force: Password Guessing / Password Spraying | Attack rules, compromise, sudo/su password guessing |
| T1078 / .003 | Valid Accounts / Local Accounts | Compromise, root login, UID 0 account |
| T1021.004 | Remote Services: SSH | Logins |
| T1136.001 | Create Account: Local Account | account.created, account.uid0 |
| T1098 / .004 | Account Manipulation / SSH Authorized Keys | Group and password changes, authorized_keys |
| T1531 | Account Access Removal | account.deleted |
| T1548.001 / .003 | Setuid and Setgid / Sudo and Sudo Caching | chmod +s, sudo abuse |
| T1059.004 | Unix Shell | Reverse shells, download-and-execute |
| T1105 | Ingress Tool Transfer | Download-and-execute |
| T1070.002 / .003 | Clear Linux System Logs / Clear Command History | Log wiping |
| T1053.003 | Cron | Cron changes |
| T1543.002 | Systemd Service | Service creation |
| T1562.001 / .004 | Disable Tools / Disable System Firewall | Security controls turned off |
| T1003.008 | /etc/passwd and /etc/shadow | Shadow file access |
auth.log, secure, *.gz, stdin
│
▼
parser.py syslog line ─► Event(ts, host, prog, pid, kind, user, ip, ...)
BSD + RFC 3339 timestamps, year inference, "message repeated" expansion,
end-anchored regexes, IP validation
│
▼
detections.py pass 1 sliding windows: brute force, spray/probe, distributed
pass 2 logins: compromise ─► incidents (ended by session close)
pass 3 host activity: accounts, groups, sudo, su
correlate findings in an incident window ─► +1 severity
summarize, IOCs, verdict
│
▼
report.py terminal (ANSI, ASCII fallback) · JSON (raw values) · HTML (no JS)
| Module | Lines | Responsibility |
|---|---|---|
parser.py |
~270 | Turn log lines into typed events |
detections.py |
~580 | Every detection, correlation, verdict, summary |
report.py |
~300 | Rendering; neutralizing attacker-controlled text |
__main__.py |
~120 | CLI, gzip/folder/stdin input, exit codes |
| Flag | Output |
|---|---|
| (default) | Colored terminal report; plain ASCII when the console can't print box-drawing characters |
--json FILE |
Full machine-readable result. --json - prints JSON to stdout instead of the text report |
--html FILE |
Self-contained HTML report: no JavaScript, no external resources, light and dark themes. See docs/example-report.html |
--min-severity |
Hide findings below a level in the terminal |
--fail-on |
Exit 1 if a finding is at or above this level (default high), for cron jobs and CI |
Exit codes: 0 clean below --fail-on, 1 findings at or above it, 2 unreadable input or no recognizable log lines.
Internet-facing SSH is brute-forced all day, every day. If every burst of failures were HIGH, the report would always be red, and analysts would learn to ignore it. The event that actually needs a human is the successful login from an address that was just failing. So that is the only SSH finding that reaches CRITICAL, and the brute-force finding's own text says it is noise unless a login follows.
My phishing tool (MailSleuth) sums weighted findings, because an email's suspicious signals add up. Logs are different. A thousand failed logins are not "more compromised" than one successful one, and summing them would let noise outvote a real breach. One CRITICAL finding means the host may be compromised, whatever else the log contains.
An analyst's real question after "did they get in?" is "what did they do?" Opening an incident at the compromising login, and ending it at the matching session close, turns scattered lines into a story. Raising severity inside the window encodes the same judgment a human applies: sudo -i is routine, but sudo -i from a session that just brute-forced its way in is not.
Counting failures per fixed 10-minute bucket misses a burst that straddles a boundary: 6 failures at 10:08 and 6 at 10:11 never reach 10 in one bucket. A two-pointer sliding window finds the true peak in O(n) and returns the exact events in it, which become the finding's evidence.
A password login after password failures means a guess worked. A key login after password failures is weaker evidence: it can be a real user behind the same NAT address. So it is HIGH, not CRITICAL. And during a distributed attack on deploy, the CI system's key login isn't flagged at all.
Three log details change the counts, and getting them wrong makes every threshold meaningless:
- rsyslog collapses identical lines into
message repeated 5 times: [ … ]. These are expanded into five attempts, not counted as one. - sshd logs invalid users twice:
Invalid user Xwhen the connection opens, thenFailed password for invalid user Xper guess. authtrail counts theFailedlines. It counts anInvalid userline only when that connection (host + sshd PID) produced noFailedline, which is what happens on key-only servers. - PAM duplicates sshd:
pam_unix(sshd:auth): authentication failurelines repeat what sshd already logged, so they are ignored.
Classic syslog (Oct 28 03:14:07) has no year. authtrail detects the December→January rollover inside a file. When --year isn't given, it anchors the file so its last line isn't in the future: December's logs read in January belong to last year. RFC 3339 timestamps (2026-10-28T03:14:07.123+00:00, the default on Debian 12+) are converted to UTC.
Python's ipaddress.is_private treats the RFC 5737 documentation ranges as private. The samples' attacker addresses would then be "internal" and left out of the IOC list. authtrail uses an explicit list (RFC 1918, loopback, link-local, CGNAT, IPv6 ULA and link-local), so its behavior is exactly what's written.
The samples come from a seeded generator, and a test regenerates them and compares the result byte for byte. Anyone can see exactly how the test data was made, and nobody's real logs are published.
Auth logs contain attacker-controlled text. Anyone who can reach port 22 chooses the username that gets logged.
| Threat | Defense |
|---|---|
Log injection: username x from 10.0.0.5 port 22 ssh2, to frame an internal host |
Every sshd pattern is anchored at the end of the line. Only the address sshd wrote last can be followed by end-of-line, so the fake one stays inside the username. Tested. |
Stored XSS in the HTML report: username <script>…</script> |
Every value is HTML-escaped, and the report contains no JavaScript at all, so a missed escape still couldn't run. Tested. |
Terminal escape injection: a username containing ESC[2J |
Control characters are shown as \x1b text before printing. Tested. |
| Invalid UTF-8 in usernames | Decoded with replacement, so one bad byte can't hide the rest of the file. |
| Unprintable characters on a cp1252 console | Output uses replacement instead of crashing. |
| Malformed addresses | Every IP is validated with ipaddress, and lines with a non-address are dropped. |
The tool only reads. It never edits, rotates or deletes logs, and it makes no network connections.
python -m unittest discover -s tests -t . -v44 tests, about 0.1 s, no network. They cover:
- Parser: both timestamp formats, year rollover and inference, Feb 29, repeat expansion, BOM and CRLF, OpenSSH 9.8's
sshd-session, IPv4-mapped IPv6, sudo commands that contain;. - Detections: every rule, including threshold boundaries (9 failures vs 10), window edges, key vs password logins, incident escalation, and activity correctly not attached to an incident.
- Samples: each sample's verdict, incident, counts and IOCs, plus a check that the committed samples match the generator byte for byte.
- Reports: XSS and terminal-escape payloads, ASCII fallback, JSON completeness.
- CLI: exit codes, gzip, folders, stdin.
- Hygiene: fails if a control character appears in source code. A stray byte (such as
\bturned into a literal backspace by a shell edit) can silently break a regex without failing any other test.
Key tests were mutation-checked: removing the end-of-line anchor, the PID deduplication, the repeat expansion or the incident correlation each makes at least one test fail.
CI runs on Ubuntu and Windows with Python 3.11, 3.13 and 3.14, and also runs the CLI against every sample.
Known limitations:
- Commands inside a root shell are invisible. After
sudo -i, the attacker's commands go to shell history, not auth.log. In the sample,useraddandpasswdshow up only because they log themselves. Full command visibility needs auditd (execve) or EDR. - Account changes have no actor.
useradddoesn't log who ran it, so changes during an incident are attributed by time and host. An administrator's unrelated change in the same window would be attached too. - A root attacker can edit the local log. Ship logs off the host (rsyslog forwarding, a SIEM) and run authtrail on the copy.
- Mixed time zones. BSD timestamps are local time, RFC 3339 ones are converted to UTC. Don't mix the two formats from different time zones in one run.
- Thresholds are expert defaults, not fitted to data. Tune them to your environment with the CLI flags.
- sshd PIDs can be reused over a long log, which in rare cases affects session matching and invalid-user deduplication.
- Linux auth logs only. It doesn't read the journald binary format, Windows events or cloud audit logs.
Roadmap:
journalctl -o jsoninput.- Per-user baselines: first login from a new network or at an unusual hour (T1078).
- auditd
execvecorrelation, to see inside root shells. - Sigma rule export for each detection, and ECS/SARIF output for SIEMs.
- A
--followmode that tails a live log.
authtrail is a defensive tool for analyzing logs from systems you own or are authorized to investigate. Auth logs contain usernames and IP addresses, which may be personal data, so handle reports according to your organization's data-handling rules.
MIT License · Built by BlazeXYZ · See also: Changelog · Part of blazexyz.com