cybersecurity · intermediate · ~15 min · safe pentest lab

Count backdoor root accounts

Scan a whole /etc/passwd and count UID-0 accounts whose name isn't `root`.

Challenge

Hunt for hidden root:

int count_backdoor_root(const char *text);

Given the full newline-separated /etc/passwd, count lines whose UID is 0 but whose username is NOT root. Those are backdoor accounts.

Input format

The full passwd file as one string.

Output format

Count of non-root UID-0 accounts.

Constraints

Handle a missing final newline and blank/malformed lines gracefully.

Starter code

#include <stddef.h>
/* Count lines (\n-separated) whose UID field == 0 but whose username is NOT "root". */
int count_backdoor_root(const char *text){ (void)text; return 0; }

Common mistakes

Matching root as a prefix instead of the exact first field; mishandling the last line when there is no trailing newline.

Edge cases to handle

root itself never counts; rooter (UID 0) does; blank lines are skipped.

Background lessons

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