cybersecurity · intermediate · ~15 min · safe pentest lab
Test a permission bit with a mask.
Detect the setuid bit in a Unix file mode — setuid binaries run as the file owner, so finding them is core to privilege-escalation review.
Implement int is_setuid(int mode) that returns 1 if the setuid bit (octal 04000) is set in mode, and 0 otherwise.
mode: a Unix permission mode the grader provides (e.g. 04755, 0755).Returns 1 if the setuid bit is set, 0 otherwise.
is_setuid(04755) -> 1 (setuid bit present)
is_setuid(0755) -> 0
04000 matters; other permission bits are ignored.A Unix permission mode (int).
1 if the setuid bit (octal 04000) is set; otherwise 0.
Mask the mode with 04000 (octal).
int is_setuid(int mode) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.