cybersecurity · intermediate · ~15 min · safe pentest lab
Scan a whole /etc/passwd and count UID-0 accounts whose name isn't `root`.
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.
The full passwd file as one string.
Count of non-root UID-0 accounts.
Handle a missing final newline and blank/malformed lines gracefully.
#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; }
Matching root as a prefix instead of the exact first field; mishandling the last line when there is no trailing newline.
root itself never counts; rooter (UID 0) does; blank lines are skipped.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.