Lab 6: Control Flow Hijacking
Binary Exploitation (Part 2)
For this lab you will be completing the next set of challenges from the Binary Exploitation module and building control-flow hijacking attacks.
Handy Tricks and Resources
-
Writing arbitrary bytes to
stdiningdb:r < <(printf "\x00\x00\x00\x00\xef\xbe\xad\xde")- This will restart the program and load the bytes
0x00 0x00 0x00 0x00 0xef 0xbe 0xad 0xdetostdinbefore the program is invoked. - You will not be able to specify further data on
stdin, and you will not be prompted for input whenreadgets invoked, as input will already be available onstdin.
- This will restart the program and load the bytes
-
You can provide the same input to the actual function outside of
gdbwith the following:printf "\x00\x00\x00\x00\xef\xbe\xad\xde" | /challenge/<challenge_name>- Note again, that you will not be prompted for further input
-
You may need to craft some very long strings. A nice trick for generating them is by using python from the command line:
python -c "print('\x00' * 50)"- This will produce the string representation of the null byte that you can pipe to stdin.
- You could also use python to call the challenge program using the
pwntoolspackage, as you learned in earlier labs.
-
It is a good idea to take notes as you reverse engineer binaries, as you will need to remember many important addresses and details that can be difficult to hold in your head all at once.
Helpful Scripts
We have provided some helpful scripts that can be used to launch the challenge program in gdb using pwntools.
The workflow looks something like this:
-
Run
tmux -
Run
./launch-pwn.py- This will open a second tmux “pane” that has gdb attached to the program
- The first pane will have an IPython interpreter containing
pwn.tubes.processobject in a global variable namedp.
-
Introspect the program with gdb
-
print output in python using
recv()and send input usingp.send().
Tasks
Other control flow hijacking challenges can be completed for extra credit in the extra module:
- Tricky Control Hijack (hard)
- Hijack to (Mapped) Shellcode (easy)
- Hijack to (Mapped) Shellcode (hard)
- Hijack to Shellcode (hard)