overthewire-writeups

Bandit19 -> 20: The SetUID Secret

Challenge

Level Description

The password for the next level is stored in /etc/bandit_pass/bandit20. It can be accessed by using a setuid binary located in the home directory. You need to figure out how to use this binary to read the password file.

The Process

When I logged in and looked around the home directory, I found an executable file named bandit20-do.

In Linux, a SetUID (Set User ID) file is a special type of executable. When run, it executes with the permissions of the file’s owner rather than the person running it. In this case, bandit20-do is owned by bandit20. This means if I use this tool, I can act as bandit20 for a split second!

The name bandit20-do suggests it functions similarly to sudo. It “does” whatever command you tell it to do. To read the password, I simply told the binary to cat the protected file:

$ ./bandit20-do cat /etc/bandit_pass/bandit20

The binary executed the cat command with bandit20’s permissions, bypassed the usual restriction, and displayed the password.

Password For the Next Level

[SPOILER]

What I Learned

Helpful Reading Material