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 stdin in gdb: 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 0xde to stdin before the program is invoked.
    • You will not be able to specify further data on stdin, and you will not be prompted for input when read gets invoked, as input will already be available on stdin.
  • You can provide the same input to the actual function outside of gdb with 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 pwntools package, 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:

  1. Run tmux

  2. 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.process object in a global variable named p.
  3. Introspect the program with gdb

  4. print output in python using recv() and send input using p.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)

Post-Lab