|
|
Takeaways from hints, description, and tags:
- Something important is in the /root file (the flag)
- We will have to use environment variables
- The binary lists contents of a directory as root
- We need to inject code into “ls”
Phase 1: Recon 🔍
It is important to get familiar with the machine we log into so that we can find important assets such as possible vulnerabilities, which we may be able to exploit to get us root access.
What do we notice?
- A binary that lists a directory as root
- Why this is important: It does it as root via an SUID bit, because the root user made the executable
- How it works: It takes the input for the directory as an environment variable
- Other important takeaways: If it is listing the contents of a directory, it is most probably doing something with the ls binary
|
|
SUID, short for Set User ID, is a special permission that can be assigned to executable files. When an executable file has the SUID permission enabled, it allows users who execute the file to temporarily assume the privileges of the file’s owner.
Phase 2: Constructing a Plan 🛠️
Using the information we have gathered, we can try to assess vulnerabilities on our target system. So far, we have thought of environment variable injection, but now it is time for us to plot out this plan.
The Plan
We make our own ls binary that spawns a shell. Since the file has an SUID, this will give us a root shell if the binary we are manipulating uses ls (in which according to the hints, it does).
There are however, some rather huge obstacles
Q1: How would we execute this plan so that the binary we are manipulating thinks our ls binary is the real ls binary?
A1: We could exploit the
PATH
environment variable. Many hints and tags tell us that the exploit has something to do with environment variables and the ls executable which the SUID binary is most likely using for its operations.
Q2: What directory should we put our binary into?
A2: The answer is /tmp. A directory with read, write, and execute permissions for everyone. This is perfect as it will be the perfect soil to plant our C code in.
The Theory:
When “ls” is typed into the command line, the system looks through path for an executable with the name “ls”. So in our injected PATH, because /tmp
is first, when the binary which runs ls as root runs “ls” as root it wil run our binary as root which will run /bin/bash root.
Phase 3: Execution 🧀
First, let’s log onto our machine. To logon, we will need to use ssh with the command format of:
ssh -p <port> <user>@<ip>
After logging on, let’s list our environment variables, and try editing the PATH.
|
|
It looks like the injection worked, so we can move on to making our fake ls executable.
Finally, we need to make our fake ls binary containing this C code:
|
|
|
|
Lets execute!
|
|
Disclaimer
The flag obtained in the command sequence example is obviously an edited version of the real flag. I highly reccomend you to try to solve the VNE problem and obtain its flag on your own.