Safe Penetration Testing Labs · intermediate · ~15 min
Read a baked auth.log buffer, classify each line, count failed-login bursts per source IP.
Parse auth.log line by line, count Failed password ... from <ip> per IP, return the count of IPs above a threshold.
This is the canonical SOC routine: triage attack noise vs. legitimate traffic. Every brute-force detection tool in the world starts from this five-line function.
The /var/log/auth.log file is the first place a defender looks after a
suspicious event. A brute-force attempt against SSH leaves a very recognisable
trail: many Failed password for ... lines from the same source IP, within a
short window.
This exercise teaches the detection side: read the log buffer, parse each line, count failures per IP, and report which IPs crossed a threshold.
Jan 23 12:01:02 host sshd[1234]: Failed password for invalid user root from 192.0.2.7 port 5413
Jan 23 12:01:04 host sshd[1235]: Failed password for invalid user admin from 192.0.2.7 port 5414
Jan 23 12:01:08 host sshd[1240]: Accepted publickey for gilos from 10.0.0.5 port 22001
The bytes you process are static, bundled in the harness. The function never opens a real log file.
Implement a function that walks the buffer, counts Failed password for ... from <ip> lines per IP, and returns the number of distinct IPs that
appear at least threshold times.
Accepted publickey as a failure. The string is Failed password.port after it.Token-walk the log, group by IP, threshold the counts. Pure string parsing on a static buffer.