cybersecurity · intermediate · ~15 min · safe pentest lab

Is the setuid bit set?

Test a permission bit with a mask.

Challenge

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.

Task

Implement int is_setuid(int mode) that returns 1 if the setuid bit (octal 04000) is set in mode, and 0 otherwise.

Input

  • mode: a Unix permission mode the grader provides (e.g. 04755, 0755).

Output

Returns 1 if the setuid bit is set, 0 otherwise.

Example

is_setuid(04755)   ->   1   (setuid bit present)
is_setuid(0755)    ->   0

Edge cases

  • Only bit 04000 matters; other permission bits are ignored.

Input format

A Unix permission mode (int).

Output format

1 if the setuid bit (octal 04000) is set; otherwise 0.

Constraints

Mask the mode with 04000 (octal).

Starter code

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.