Safe Penetration Testing Labs · beginner · ~12 min
Read Unix mode bits and flag world-writable, setuid, and setgid risks.
Three bit tests on a Unix mode: world-writable (0002), setuid (04000), setgid (02000), OR'd into a flag mask.
World-writable and setuid bits are the bread-and-butter of Linux privilege-escalation audits.
Two of the first things a Linux audit (and a privilege-escalation check) does:
find world-writable files and find setuid/setgid binaries. Both are
just bits in the file's mode, and reading them is pure bit masking.
setuid setgid sticky owner group other
4000 2000 1000 rwx rwx rwx
0002) — anyone can change the file.04000): the program runs as its owner (often root) — a classic
privilege-escalation target if misused.02000): runs with the file's group.A setuid-root binary that's also world-writable is a five-alarm finding.
Implement int audit_mode(unsigned int mode) returning a bitmask:
world-writable (bit 0), setuid (bit 1), setgid (bit 2). It's three independent
mode & MASK tests OR'd together.
auditd do the scanning; this is the check they run per file.mode & 0002 / 04000 / 02000 → the risky-bit trio every permission audit checks.