cybersecurity · beginner · ~15 min · safe pentest lab

Count invalid-user attempts

Count probing for nonexistent accounts.

Challenge

Count the auth-log lines that probe for nonexistent accounts — a telltale sign of username enumeration during a brute force.

Task

Implement int count_invalid_user(const char *log) that returns how many lines contain "invalid user".

Input

  • log: a NUL-terminated, newline-separated auth-log string baked into the harness.

Output

Returns int: the number of lines containing the substring "invalid user".

Example

log: "Failed password for invalid user admin\nFailed password for root\nFailed password for invalid user test\n"
count_invalid_user(log)   ->   2

Edge cases

  • Lines without the marker are not counted.

Rules

  • Static buffer only — no real log-file access.

Input format

A NUL-terminated newline-separated auth-log string log.

Output format

An int: the count of lines containing "invalid user".

Constraints

Match the substring "invalid user". Static buffer only.

Starter code

#include <string.h>

int count_invalid_user(const char *log) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.