cybersecurity · intermediate · ~15 min · safe pentest lab
Scan a streaming text log for stateful patterns (windows / streaks).
Find the longest burst of failed SSH logins for one user — the streak that brute-force detectors like fail2ban watch for.
Implement int max_failed_attempts(const char *auth_log, const char *username) that returns the length of the longest run of consecutive failed login lines for username.
auth_log: a NUL-terminated, multi-line auth-log string baked into the harness. A failure line contains Failed password for <user>; a success line contains Accepted password for <user>.username: the user to track.Returns an int: the longest consecutive run of failures for that user. A success line resets the running streak to 0. Returns 0 if the user never fails.
log: alice fails, fails, fails, accepted, fails
max_failed_attempts(log, "alice") -> 3 (run before the success)
max_failed_attempts(log, "carol") -> 0 (never appears)
/var/log access.A NUL-terminated auth-log string auth_log and a username to track.
An int: the longest consecutive run of failed logins for that user (0 if none).
Static buffer only — no real log-file access.
#include <stdio.h>
#include <string.h>
int max_failed_attempts(const char *auth_log, const char *username) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.