Lab16 Linux x64 ASLR Bypass
Lab16 Linux x64 ASLR Bypass
LAB 16
© 2019 Caendra Inc. | Hera for XDS | Linux x64 ASLR Bypass 1
SCENARIO
In this lab you will continue to learn x64 Linux exploitation. Both the Operating System
(Ubuntu 16) and the target binary are 64-bit. The Ubuntu system features ASLR. You will
have to find a way around it.
You can connect to the lab machine via SSH. The target IP is 172.16.172.152
In case you need root-level access for debugging, the user below is able to run sudo.
Username: xdev
Password: xdev
GOALS
• Discover vulnerabilities in the binary
• Utilize ROP
• Spawn an interactive bash shell
© 2019 Caendra Inc. | Hera for XDS | Linux x64 ASLR Bypass 2
RECOMMENDED TOOLS
• Gdb / gdb-peda
• ROPgadget
• Text editor
• Kali linux
ssh [email protected]
password: xdev
© 2019 Caendra Inc. | Hera for XDS | Linux x64 ASLR Bypass 3
TASKS
TASK 1: CONNECT TO THE COMPROMISED MACHINE
AND EXAMINE THE TARGET BINARY
The target binary is named bypass_aslr and is available in the xdev user’s Desktop directory.
As your first task, try to identify vulnerabilities within the binary.
Remember that:
Try to find a ROP gadget within the binary itself, where we will return first in order for the
argument’s address to be popped into an appropriate register. Then, the function will be
called.
Hints:
© 2019 Caendra Inc. | Hera for XDS | Linux x64 ASLR Bypass 4
It is time to combine all the above into a working exploit. Serve bypass_aslr with socat on
the remote machine and then launch the exploit from your attacker’s machine to see if it
works.
© 2019 Caendra Inc. | Hera for XDS | Linux x64 ASLR Bypass 5
SOLUTIONS
© 2019 Caendra Inc. | Hera for XDS | Linux x64 ASLR Bypass 6
Below, you can find solutions for each task. Remember though that you can follow your
own strategy (which may be different from the one explained in the following lab).
Let’s see how this program copes with overly large inputs. Gdb-peda’s pattern create will
be used to create an overly long input.
Let’s execute ulimit -c unlimited first and then provide the binary with the above input.
It looks like we managed to crash the target binary. Let’s utilize the dumped core file to
identify if we were able to overwrite the return address.
© 2019 Caendra Inc. | Hera for XDS | Linux x64 ASLR Bypass 7
Like in the Linux x64 Basic Stack Overflow lab, we receive no conclusive information about
the rip register. Let’s see the state of the other registers. Maybe we will have to utilize the
rbp as we did on that lab.
Indeed, rbp seems to contain a portion of our sent buffer/payload. Let’s use it to calculate
the offset.
© 2019 Caendra Inc. | Hera for XDS | Linux x64 ASLR Bypass 8
TASK 2: FURTHER EXAMINE THE BINARY AND IDENTIFY
A STRATEGY TO BYPASS ASLR
Let’s now focus on the functions the target binary includes.
© 2019 Caendra Inc. | Hera for XDS | Linux x64 ASLR Bypass 9
In order for system to be exploitable, we need to pass it an “sh” argument.
Luckily, there are “sh” occurrences within the binary (this ensures predictability).
Let’s now write the first “sh”’s address down. We will pass “sh” as an argument to system to
obtain a shell.
© 2019 Caendra Inc. | Hera for XDS | Linux x64 ASLR Bypass 10
Finally, it’s time to search for a ROP gadget within the binary, where we will return first in
order for the argument’s address to be popped into the rdi register Then, the function will
be called.
© 2019 Caendra Inc. | Hera for XDS | Linux x64 ASLR Bypass 11
buf+=p64(system_plt) # system
Then, from inside your attacking machine launch the exploit. You should see the below.
© 2019 Caendra Inc. | Hera for XDS | Linux x64 ASLR Bypass 12