cybersecurity · intermediate · ~15 min · safe pentest lab

Is the file world-writable?

Detect a dangerous permission.

Challenge

Detect a world-writable file from its mode — a world-writable sensitive file is a classic local privilege-escalation finding.

Task

Implement int world_writable(int mode) that returns 1 if the other-write bit (octal 0002) is set in mode, and 0 otherwise.

Input

  • mode: a Unix permission mode the grader provides (e.g. 0666, 0644).

Output

Returns 1 if the other-write bit is set, 0 otherwise.

Example

world_writable(0666)   ->   1   (others can write)
world_writable(0644)   ->   0

Edge cases

  • Only bit 0002 matters; owner/group write bits are ignored.

Input format

A Unix permission mode (int).

Output format

1 if the other-write bit (octal 0002) is set; otherwise 0.

Constraints

Mask the mode with 0002 (octal).

Starter code

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.