cybersecurity · intermediate · ~15 min · safe pentest lab
Detect a dangerous permission.
Detect a world-writable file from its mode — a world-writable sensitive file is a classic local privilege-escalation finding.
Implement int world_writable(int mode) that returns 1 if the other-write bit (octal 0002) is set in mode, and 0 otherwise.
mode: a Unix permission mode the grader provides (e.g. 0666, 0644).Returns 1 if the other-write bit is set, 0 otherwise.
world_writable(0666) -> 1 (others can write)
world_writable(0644) -> 0
0002 matters; owner/group write bits are ignored.A Unix permission mode (int).
1 if the other-write bit (octal 0002) is set; otherwise 0.
Mask the mode with 0002 (octal).
int world_writable(int mode) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.