Reverse-Engineering & Exploitation Fundamentals

GCC 2022 (Taiwan-Online)

Overview

We've prepared this series of lectures and mini-challenges to teach the fundamentals of
Reverse-Engineering and Exploitation.

If you need supplementary materials, you can find more in our omu platform.


Specifically, the ASM (x86-64) module would be most relevant.

# Lesson 1: x86-64 Assembly

Learn about the basic building blocks running our computer programs!

Slides

## Challenges

Mini #1: Move It!

For this challenge, we will familiarise ourselves with the basics operations of copy (mov)ing data from register to memory, and vice versa.

In omulator, we have an input memory region from 0x1000-0x1fff, and output in 0x2000-0x2fff.

We will refer to these regions as IN and OUT.


Write the x86-64 assembly code to do the following:

  1. 1. Copy the value from rdi to rax.
  2. 2. Copy 1 DWORD from input (at address 0x1000) to ebx.
  3. 3. Copy the DWORD value from esi to output (at address 0x2000).

Hint: An example for loading a DWORD from memory is mov eax, DWORD PTR [r9].

Click the to test your solution.

You can also click on each test case to load their input values as the omulator's initial state.

To simplify your experience, r8 is initialised to 0x1000(IN), and r9 to 0x2000(OUT).

Initializing...

CODE [0x400000]
Registers
rax:
rbx:
rcx:
rdx:
rdi:
rsi:
r8 :
r9 :
r10:
r11:
r12:
r13:
r14:
r15:
rbp:
rsp:
rip:
IN [0x1000-0x1fff]
1000 | 00 00 00 00 00 00 00 00
|........|
1008 | 00 00 00 00 00 00 00 00
|........|
1010 | 00 00 00 00 00 00 00 00
|........|
1018 | 00 00 00 00 00 00 00 00
|........|
1020 | 00 00 00 00 00 00 00 00
|........|
1028 | 00 00 00 00 00 00 00 00
|........|
1030 | 00 00 00 00 00 00 00 00
|........|
1038 | 00 00 00 00 00 00 00 00
|........|
1040 | 00 00 00 00 00 00 00 00
|........|
1048 | 00 00 00 00 00 00 00 00
|........|
1050 | 00 00 00 00 00 00 00 00
|........|
1058 | 00 00 00 00 00 00 00 00
|........|
1060 | 00 00 00 00 00 00 00 00
|........|
1068 | 00 00 00 00 00 00 00 00
|........|
1070 | 00 00 00 00 00 00 00 00
|........|
1078 | 00 00 00 00 00 00 00 00
|........|
1080 | 00 00 00 00 00 00 00 00
|........|
1088 | 00 00 00 00 00 00 00 00
|........|
1090 | 00 00 00 00 00 00 00 00
|........|
1098 | 00 00 00 00 00 00 00 00
|........|
10a0 | 00 00 00 00 00 00 00 00
|........|
10a8 | 00 00 00 00 00 00 00 00
|........|
10b0 | 00 00 00 00 00 00 00 00
|........|
10b8 | 00 00 00 00 00 00 00 00
|........|
10c0 | 00 00 00 00 00 00 00 00
|........|
10c8 | 00 00 00 00 00 00 00 00
|........|
10d0 | 00 00 00 00 00 00 00 00
|........|
10d8 | 00 00 00 00 00 00 00 00
|........|
10e0 | 00 00 00 00 00 00 00 00
|........|
10e8 | 00 00 00 00 00 00 00 00
|........|
10f0 | 00 00 00 00 00 00 00 00
|........|
10f8 | 00 00 00 00 00 00 00 00
|........|
OUT [0x2000-0x2fff]
2000 | 00 00 00 00 00 00 00 00
|........|
2008 | 00 00 00 00 00 00 00 00
|........|
2010 | 00 00 00 00 00 00 00 00
|........|
2018 | 00 00 00 00 00 00 00 00
|........|
2020 | 00 00 00 00 00 00 00 00
|........|
2028 | 00 00 00 00 00 00 00 00
|........|
2030 | 00 00 00 00 00 00 00 00
|........|
2038 | 00 00 00 00 00 00 00 00
|........|
2040 | 00 00 00 00 00 00 00 00
|........|
2048 | 00 00 00 00 00 00 00 00
|........|
2050 | 00 00 00 00 00 00 00 00
|........|
2058 | 00 00 00 00 00 00 00 00
|........|
2060 | 00 00 00 00 00 00 00 00
|........|
2068 | 00 00 00 00 00 00 00 00
|........|
2070 | 00 00 00 00 00 00 00 00
|........|
2078 | 00 00 00 00 00 00 00 00
|........|
2080 | 00 00 00 00 00 00 00 00
|........|
2088 | 00 00 00 00 00 00 00 00
|........|
2090 | 00 00 00 00 00 00 00 00
|........|
2098 | 00 00 00 00 00 00 00 00
|........|
20a0 | 00 00 00 00 00 00 00 00
|........|
20a8 | 00 00 00 00 00 00 00 00
|........|
20b0 | 00 00 00 00 00 00 00 00
|........|
20b8 | 00 00 00 00 00 00 00 00
|........|
20c0 | 00 00 00 00 00 00 00 00
|........|
20c8 | 00 00 00 00 00 00 00 00
|........|
20d0 | 00 00 00 00 00 00 00 00
|........|
20d8 | 00 00 00 00 00 00 00 00
|........|
20e0 | 00 00 00 00 00 00 00 00
|........|
20e8 | 00 00 00 00 00 00 00 00
|........|
20f0 | 00 00 00 00 00 00 00 00
|........|
20f8 | 00 00 00 00 00 00 00 00
|........|
STACK [0xf000-0xffff]
ff00 (+00) | 0x0000000000000000
ff08 (+08) | 0x0000000000000000
ff10 (+10) | 0x0000000000000000
ff18 (+18) | 0x0000000000000000
ff20 (+20) | 0x0000000000000000
ff28 (+28) | 0x0000000000000000
ff30 (+30) | 0x0000000000000000
ff38 (+38) | 0x0000000000000000
ff40 (+40) | 0x0000000000000000
ff48 (+48) | 0x0000000000000000
ff50 (+50) | 0x0000000000000000
ff58 (+58) | 0x0000000000000000
ff60 (+60) | 0x0000000000000000
ff68 (+68) | 0x0000000000000000
ff70 (+70) | 0x0000000000000000
ff78 (+78) | 0x0000000000000000
ff80 (+80) | 0x0000000000000000
ff88 (+88) | 0x0000000000000000
ff90 (+90) | 0x0000000000000000
ff98 (+98) | 0x0000000000000000
ffa0 (+a0) | 0x0000000000000000
ffa8 (+a8) | 0x0000000000000000
ffb0 (+b0) | 0x0000000000000000
ffb8 (+b8) | 0x0000000000000000
ffc0 (+c0) | 0x0000000000000000
ffc8 (+c8) | 0x0000000000000000
ffd0 (+d0) | 0x0000000000000000
ffd8 (+d8) | 0x0000000000000000
ffe0 (+e0) | 0x0000000000000000
ffe8 (+e8) | 0x0000000000000000
fff0 (+f0) | 0x0000000000000000
fff8 (+f8) | 0x0000000000000000

Mini #2: Two Plus Two Is Four Minus One Thats Three

In this challenge, we will do some simple arithmetic operations.


Write the x86-64 assembly code to do the following:

Given 3 values stored in rdi, rsi, rdx, and a WORD value in IN(call it n):

  1. 1. Save the result of rdi + rsi - rdx * n into rax.
  2. 2. Save the result (QWORD) of rdi + rsi - rdx * n into the OUT.

Click the to test your solution.

You can also click on each test case to load their input values as the omulator's initial state.

To simplify your experience, r8 is initialised to 0x1000(IN), and r9 to 0x2000(OUT).

Initializing...

CODE [0x400000]
Registers
rax:
rbx:
rcx:
rdx:
rdi:
rsi:
r8 :
r9 :
r10:
r11:
r12:
r13:
r14:
r15:
rbp:
rsp:
rip:
IN [0x1000-0x1fff]
1000 | 00 00 00 00 00 00 00 00
|........|
1008 | 00 00 00 00 00 00 00 00
|........|
1010 | 00 00 00 00 00 00 00 00
|........|
1018 | 00 00 00 00 00 00 00 00
|........|
1020 | 00 00 00 00 00 00 00 00
|........|
1028 | 00 00 00 00 00 00 00 00
|........|
1030 | 00 00 00 00 00 00 00 00
|........|
1038 | 00 00 00 00 00 00 00 00
|........|
1040 | 00 00 00 00 00 00 00 00
|........|
1048 | 00 00 00 00 00 00 00 00
|........|
1050 | 00 00 00 00 00 00 00 00
|........|
1058 | 00 00 00 00 00 00 00 00
|........|
1060 | 00 00 00 00 00 00 00 00
|........|
1068 | 00 00 00 00 00 00 00 00
|........|
1070 | 00 00 00 00 00 00 00 00
|........|
1078 | 00 00 00 00 00 00 00 00
|........|
1080 | 00 00 00 00 00 00 00 00
|........|
1088 | 00 00 00 00 00 00 00 00
|........|
1090 | 00 00 00 00 00 00 00 00
|........|
1098 | 00 00 00 00 00 00 00 00
|........|
10a0 | 00 00 00 00 00 00 00 00
|........|
10a8 | 00 00 00 00 00 00 00 00
|........|
10b0 | 00 00 00 00 00 00 00 00
|........|
10b8 | 00 00 00 00 00 00 00 00
|........|
10c0 | 00 00 00 00 00 00 00 00
|........|
10c8 | 00 00 00 00 00 00 00 00
|........|
10d0 | 00 00 00 00 00 00 00 00
|........|
10d8 | 00 00 00 00 00 00 00 00
|........|
10e0 | 00 00 00 00 00 00 00 00
|........|
10e8 | 00 00 00 00 00 00 00 00
|........|
10f0 | 00 00 00 00 00 00 00 00
|........|
10f8 | 00 00 00 00 00 00 00 00
|........|
OUT [0x2000-0x2fff]
2000 | 00 00 00 00 00 00 00 00
|........|
2008 | 00 00 00 00 00 00 00 00
|........|
2010 | 00 00 00 00 00 00 00 00
|........|
2018 | 00 00 00 00 00 00 00 00
|........|
2020 | 00 00 00 00 00 00 00 00
|........|
2028 | 00 00 00 00 00 00 00 00
|........|
2030 | 00 00 00 00 00 00 00 00
|........|
2038 | 00 00 00 00 00 00 00 00
|........|
2040 | 00 00 00 00 00 00 00 00
|........|
2048 | 00 00 00 00 00 00 00 00
|........|
2050 | 00 00 00 00 00 00 00 00
|........|
2058 | 00 00 00 00 00 00 00 00
|........|
2060 | 00 00 00 00 00 00 00 00
|........|
2068 | 00 00 00 00 00 00 00 00
|........|
2070 | 00 00 00 00 00 00 00 00
|........|
2078 | 00 00 00 00 00 00 00 00
|........|
2080 | 00 00 00 00 00 00 00 00
|........|
2088 | 00 00 00 00 00 00 00 00
|........|
2090 | 00 00 00 00 00 00 00 00
|........|
2098 | 00 00 00 00 00 00 00 00
|........|
20a0 | 00 00 00 00 00 00 00 00
|........|
20a8 | 00 00 00 00 00 00 00 00
|........|
20b0 | 00 00 00 00 00 00 00 00
|........|
20b8 | 00 00 00 00 00 00 00 00
|........|
20c0 | 00 00 00 00 00 00 00 00
|........|
20c8 | 00 00 00 00 00 00 00 00
|........|
20d0 | 00 00 00 00 00 00 00 00
|........|
20d8 | 00 00 00 00 00 00 00 00
|........|
20e0 | 00 00 00 00 00 00 00 00
|........|
20e8 | 00 00 00 00 00 00 00 00
|........|
20f0 | 00 00 00 00 00 00 00 00
|........|
20f8 | 00 00 00 00 00 00 00 00
|........|
STACK [0xf000-0xffff]
ff00 (+00) | 0x0000000000000000
ff08 (+08) | 0x0000000000000000
ff10 (+10) | 0x0000000000000000
ff18 (+18) | 0x0000000000000000
ff20 (+20) | 0x0000000000000000
ff28 (+28) | 0x0000000000000000
ff30 (+30) | 0x0000000000000000
ff38 (+38) | 0x0000000000000000
ff40 (+40) | 0x0000000000000000
ff48 (+48) | 0x0000000000000000
ff50 (+50) | 0x0000000000000000
ff58 (+58) | 0x0000000000000000
ff60 (+60) | 0x0000000000000000
ff68 (+68) | 0x0000000000000000
ff70 (+70) | 0x0000000000000000
ff78 (+78) | 0x0000000000000000
ff80 (+80) | 0x0000000000000000
ff88 (+88) | 0x0000000000000000
ff90 (+90) | 0x0000000000000000
ff98 (+98) | 0x0000000000000000
ffa0 (+a0) | 0x0000000000000000
ffa8 (+a8) | 0x0000000000000000
ffb0 (+b0) | 0x0000000000000000
ffb8 (+b8) | 0x0000000000000000
ffc0 (+c0) | 0x0000000000000000
ffc8 (+c8) | 0x0000000000000000
ffd0 (+d0) | 0x0000000000000000
ffd8 (+d8) | 0x0000000000000000
ffe0 (+e0) | 0x0000000000000000
ffe8 (+e8) | 0x0000000000000000
fff0 (+f0) | 0x0000000000000000
fff8 (+f8) | 0x0000000000000000

Mini #3: Height Check

In this challenge, we will do some simple control flow branching.


Write the x86-64 assembly code to do the following:

Given n (stored in rdi) values stored in IN:

  1. 1. For each of BYTE value x taken from IN:
    1. i. If x > 0x50, write x - 0x37 to OUT.
    2. ii. Else, write x + 0x13 to OUT.

Hint: Note that values from 0x80 to 0xff are considered as negative values when they are a BYTE (because MSB is set). Make sure you use the unsigned versions of the jcc instructions.

Click the to test your solution.

You can also click on each test case to load their input values as the omulator's initial state.

To simplify your experience, r8 is initialised to 0x1000(IN), and r9 to 0x2000(OUT).

Initializing...

CODE [0x400000]
Registers
rax:
rbx:
rcx:
rdx:
rdi:
rsi:
r8 :
r9 :
r10:
r11:
r12:
r13:
r14:
r15:
rbp:
rsp:
rip:
IN [0x1000-0x1fff]
1000 | 00 00 00 00 00 00 00 00
|........|
1008 | 00 00 00 00 00 00 00 00
|........|
1010 | 00 00 00 00 00 00 00 00
|........|
1018 | 00 00 00 00 00 00 00 00
|........|
1020 | 00 00 00 00 00 00 00 00
|........|
1028 | 00 00 00 00 00 00 00 00
|........|
1030 | 00 00 00 00 00 00 00 00
|........|
1038 | 00 00 00 00 00 00 00 00
|........|
1040 | 00 00 00 00 00 00 00 00
|........|
1048 | 00 00 00 00 00 00 00 00
|........|
1050 | 00 00 00 00 00 00 00 00
|........|
1058 | 00 00 00 00 00 00 00 00
|........|
1060 | 00 00 00 00 00 00 00 00
|........|
1068 | 00 00 00 00 00 00 00 00
|........|
1070 | 00 00 00 00 00 00 00 00
|........|
1078 | 00 00 00 00 00 00 00 00
|........|
1080 | 00 00 00 00 00 00 00 00
|........|
1088 | 00 00 00 00 00 00 00 00
|........|
1090 | 00 00 00 00 00 00 00 00
|........|
1098 | 00 00 00 00 00 00 00 00
|........|
10a0 | 00 00 00 00 00 00 00 00
|........|
10a8 | 00 00 00 00 00 00 00 00
|........|
10b0 | 00 00 00 00 00 00 00 00
|........|
10b8 | 00 00 00 00 00 00 00 00
|........|
10c0 | 00 00 00 00 00 00 00 00
|........|
10c8 | 00 00 00 00 00 00 00 00
|........|
10d0 | 00 00 00 00 00 00 00 00
|........|
10d8 | 00 00 00 00 00 00 00 00
|........|
10e0 | 00 00 00 00 00 00 00 00
|........|
10e8 | 00 00 00 00 00 00 00 00
|........|
10f0 | 00 00 00 00 00 00 00 00
|........|
10f8 | 00 00 00 00 00 00 00 00
|........|
OUT [0x2000-0x2fff]
2000 | 00 00 00 00 00 00 00 00
|........|
2008 | 00 00 00 00 00 00 00 00
|........|
2010 | 00 00 00 00 00 00 00 00
|........|
2018 | 00 00 00 00 00 00 00 00
|........|
2020 | 00 00 00 00 00 00 00 00
|........|
2028 | 00 00 00 00 00 00 00 00
|........|
2030 | 00 00 00 00 00 00 00 00
|........|
2038 | 00 00 00 00 00 00 00 00
|........|
2040 | 00 00 00 00 00 00 00 00
|........|
2048 | 00 00 00 00 00 00 00 00
|........|
2050 | 00 00 00 00 00 00 00 00
|........|
2058 | 00 00 00 00 00 00 00 00
|........|
2060 | 00 00 00 00 00 00 00 00
|........|
2068 | 00 00 00 00 00 00 00 00
|........|
2070 | 00 00 00 00 00 00 00 00
|........|
2078 | 00 00 00 00 00 00 00 00
|........|
2080 | 00 00 00 00 00 00 00 00
|........|
2088 | 00 00 00 00 00 00 00 00
|........|
2090 | 00 00 00 00 00 00 00 00
|........|
2098 | 00 00 00 00 00 00 00 00
|........|
20a0 | 00 00 00 00 00 00 00 00
|........|
20a8 | 00 00 00 00 00 00 00 00
|........|
20b0 | 00 00 00 00 00 00 00 00
|........|
20b8 | 00 00 00 00 00 00 00 00
|........|
20c0 | 00 00 00 00 00 00 00 00
|........|
20c8 | 00 00 00 00 00 00 00 00
|........|
20d0 | 00 00 00 00 00 00 00 00
|........|
20d8 | 00 00 00 00 00 00 00 00
|........|
20e0 | 00 00 00 00 00 00 00 00
|........|
20e8 | 00 00 00 00 00 00 00 00
|........|
20f0 | 00 00 00 00 00 00 00 00
|........|
20f8 | 00 00 00 00 00 00 00 00
|........|
STACK [0xf000-0xffff]
ff00 (+00) | 0x0000000000000000
ff08 (+08) | 0x0000000000000000
ff10 (+10) | 0x0000000000000000
ff18 (+18) | 0x0000000000000000
ff20 (+20) | 0x0000000000000000
ff28 (+28) | 0x0000000000000000
ff30 (+30) | 0x0000000000000000
ff38 (+38) | 0x0000000000000000
ff40 (+40) | 0x0000000000000000
ff48 (+48) | 0x0000000000000000
ff50 (+50) | 0x0000000000000000
ff58 (+58) | 0x0000000000000000
ff60 (+60) | 0x0000000000000000
ff68 (+68) | 0x0000000000000000
ff70 (+70) | 0x0000000000000000
ff78 (+78) | 0x0000000000000000
ff80 (+80) | 0x0000000000000000
ff88 (+88) | 0x0000000000000000
ff90 (+90) | 0x0000000000000000
ff98 (+98) | 0x0000000000000000
ffa0 (+a0) | 0x0000000000000000
ffa8 (+a8) | 0x0000000000000000
ffb0 (+b0) | 0x0000000000000000
ffb8 (+b8) | 0x0000000000000000
ffc0 (+c0) | 0x0000000000000000
ffc8 (+c8) | 0x0000000000000000
ffd0 (+d0) | 0x0000000000000000
ffd8 (+d8) | 0x0000000000000000
ffe0 (+e0) | 0x0000000000000000
ffe8 (+e8) | 0x0000000000000000
fff0 (+f0) | 0x0000000000000000
fff8 (+f8) | 0x0000000000000000

# Lesson 2: Linux Reverse-Engineering

Reversing programs written for Linux operating systems >:)

Slides

## Challenges

Mini #1: intern decompiler

For the following challenges, we will provide a snippet of assembly code (x86-64) generated from a C function.

In the panel on the right, you are expected to write the corresponding C code to create a function that would match the behaviour of the assembly snippet provided.


Tip #1: Register convention

The register convention used by our code snippets follow the System V ABI, which is the default with GCC on Linux.

The most important piece of information you need from the link is this:

This is a 64-bit platform. The stack grows downwards. Parameters to functions are passed in the registers rdi, rsi, rdx, rcx, r8, r9, and further values are passed on the stack in reverse order.
...
The return value is stored in the rax register

Make sure you place your return value in rax!


We'll start easy with this one, try to read each instruction and understand what's going on.

Quiz

Write the equivalent C code for the following assembly (x86-64) snippet.

Assembly (x86-64)

C code

Mini #2: junior decompiler

This should be a code structure that you use very often when programming!

Quiz

Write the equivalent C code for the following assembly (x86-64) snippet.

Assembly (x86-64)

C code

Mini #3: middle decompiler

The final challenge, you're almost there!

Quiz

Write the equivalent C code for the following assembly (x86-64) snippet.

Assembly (x86-64)

C code

## Resources

# Lesson 3: Buffer Overflows

First steps in exploitation!

Slides

## Challenges

Mini #1: No Touching!

For this challenge, you will be trying to create buffer overflow exploit payloads yourselves.

Each of the following mini-challenges will provide you with a code snippet, that has code reflected in the omulator.

The code snippets call the custom gets() function, which will read input from IN till it reaches a null (00) byte.

Your goal is to provide the right payload in IN to cause the program to trigger the win() function!


Write a payload in IN that will achieve the following:

  1. 1. call win()

Click the to test your solution.

C code:


int main() {
    char buf[16];
    int untouched = 0;
    gets(buf);
    if (untouched) { // How can you change this?
        win();
    }
}
            

Initializing...

CODE [0x400000]
Registers
rax:
rbx:
rcx:
rdx:
rdi:
rsi:
r8 :
r9 :
r10:
r11:
r12:
r13:
r14:
r15:
rbp:
rsp:
rip:
IN [0x1000-0x1fff]
1000 | 00 00 00 00 00 00 00 00
|........|
1008 | 00 00 00 00 00 00 00 00
|........|
1010 | 00 00 00 00 00 00 00 00
|........|
1018 | 00 00 00 00 00 00 00 00
|........|
1020 | 00 00 00 00 00 00 00 00
|........|
1028 | 00 00 00 00 00 00 00 00
|........|
1030 | 00 00 00 00 00 00 00 00
|........|
1038 | 00 00 00 00 00 00 00 00
|........|
1040 | 00 00 00 00 00 00 00 00
|........|
1048 | 00 00 00 00 00 00 00 00
|........|
1050 | 00 00 00 00 00 00 00 00
|........|
1058 | 00 00 00 00 00 00 00 00
|........|
1060 | 00 00 00 00 00 00 00 00
|........|
1068 | 00 00 00 00 00 00 00 00
|........|
1070 | 00 00 00 00 00 00 00 00
|........|
1078 | 00 00 00 00 00 00 00 00
|........|
1080 | 00 00 00 00 00 00 00 00
|........|
1088 | 00 00 00 00 00 00 00 00
|........|
1090 | 00 00 00 00 00 00 00 00
|........|
1098 | 00 00 00 00 00 00 00 00
|........|
10a0 | 00 00 00 00 00 00 00 00
|........|
10a8 | 00 00 00 00 00 00 00 00
|........|
10b0 | 00 00 00 00 00 00 00 00
|........|
10b8 | 00 00 00 00 00 00 00 00
|........|
10c0 | 00 00 00 00 00 00 00 00
|........|
10c8 | 00 00 00 00 00 00 00 00
|........|
10d0 | 00 00 00 00 00 00 00 00
|........|
10d8 | 00 00 00 00 00 00 00 00
|........|
10e0 | 00 00 00 00 00 00 00 00
|........|
10e8 | 00 00 00 00 00 00 00 00
|........|
10f0 | 00 00 00 00 00 00 00 00
|........|
10f8 | 00 00 00 00 00 00 00 00
|........|
OUT [0x2000-0x2fff]
2000 | 00 00 00 00 00 00 00 00
|........|
2008 | 00 00 00 00 00 00 00 00
|........|
2010 | 00 00 00 00 00 00 00 00
|........|
2018 | 00 00 00 00 00 00 00 00
|........|
2020 | 00 00 00 00 00 00 00 00
|........|
2028 | 00 00 00 00 00 00 00 00
|........|
2030 | 00 00 00 00 00 00 00 00
|........|
2038 | 00 00 00 00 00 00 00 00
|........|
2040 | 00 00 00 00 00 00 00 00
|........|
2048 | 00 00 00 00 00 00 00 00
|........|
2050 | 00 00 00 00 00 00 00 00
|........|
2058 | 00 00 00 00 00 00 00 00
|........|
2060 | 00 00 00 00 00 00 00 00
|........|
2068 | 00 00 00 00 00 00 00 00
|........|
2070 | 00 00 00 00 00 00 00 00
|........|
2078 | 00 00 00 00 00 00 00 00
|........|
2080 | 00 00 00 00 00 00 00 00
|........|
2088 | 00 00 00 00 00 00 00 00
|........|
2090 | 00 00 00 00 00 00 00 00
|........|
2098 | 00 00 00 00 00 00 00 00
|........|
20a0 | 00 00 00 00 00 00 00 00
|........|
20a8 | 00 00 00 00 00 00 00 00
|........|
20b0 | 00 00 00 00 00 00 00 00
|........|
20b8 | 00 00 00 00 00 00 00 00
|........|
20c0 | 00 00 00 00 00 00 00 00
|........|
20c8 | 00 00 00 00 00 00 00 00
|........|
20d0 | 00 00 00 00 00 00 00 00
|........|
20d8 | 00 00 00 00 00 00 00 00
|........|
20e0 | 00 00 00 00 00 00 00 00
|........|
20e8 | 00 00 00 00 00 00 00 00
|........|
20f0 | 00 00 00 00 00 00 00 00
|........|
20f8 | 00 00 00 00 00 00 00 00
|........|
STACK [0xf000-0xffff]
ff00 (+00) | 0x0000000000000000
ff08 (+08) | 0x0000000000000000
ff10 (+10) | 0x0000000000000000
ff18 (+18) | 0x0000000000000000
ff20 (+20) | 0x0000000000000000
ff28 (+28) | 0x0000000000000000
ff30 (+30) | 0x0000000000000000
ff38 (+38) | 0x0000000000000000
ff40 (+40) | 0x0000000000000000
ff48 (+48) | 0x0000000000000000
ff50 (+50) | 0x0000000000000000
ff58 (+58) | 0x0000000000000000
ff60 (+60) | 0x0000000000000000
ff68 (+68) | 0x0000000000000000
ff70 (+70) | 0x0000000000000000
ff78 (+78) | 0x0000000000000000
ff80 (+80) | 0x0000000000000000
ff88 (+88) | 0x0000000000000000
ff90 (+90) | 0x0000000000000000
ff98 (+98) | 0x0000000000000000
ffa0 (+a0) | 0x0000000000000000
ffa8 (+a8) | 0x0000000000000000
ffb0 (+b0) | 0x0000000000000000
ffb8 (+b8) | 0x0000000000000000
ffc0 (+c0) | 0x0000000000000000
ffc8 (+c8) | 0x0000000000000000
ffd0 (+d0) | 0x0000000000000000
ffd8 (+d8) | 0x0000000000000000
ffe0 (+e0) | 0x0000000000000000
ffe8 (+e8) | 0x0000000000000000
fff0 (+f0) | 0x0000000000000000
fff8 (+f8) | 0x0000000000000000

Mini #2: Mind-control


Write a payload in IN that will achieve the following:

  1. 1. call win()

Click the to test your solution.

Tip: Remember that integers are stored in little-endian in x86-64 cpus.

C code:


int main() {
    char buf[16];
    int untouched = 0;
    gets(buf);
    if (untouched == 0xdeadbeef) { // How can you control this value?
        win();
    }
}
            

Initializing...

CODE [0x400000]
Registers
rax:
rbx:
rcx:
rdx:
rdi:
rsi:
r8 :
r9 :
r10:
r11:
r12:
r13:
r14:
r15:
rbp:
rsp:
rip:
IN [0x1000-0x1fff]
1000 | 00 00 00 00 00 00 00 00
|........|
1008 | 00 00 00 00 00 00 00 00
|........|
1010 | 00 00 00 00 00 00 00 00
|........|
1018 | 00 00 00 00 00 00 00 00
|........|
1020 | 00 00 00 00 00 00 00 00
|........|
1028 | 00 00 00 00 00 00 00 00
|........|
1030 | 00 00 00 00 00 00 00 00
|........|
1038 | 00 00 00 00 00 00 00 00
|........|
1040 | 00 00 00 00 00 00 00 00
|........|
1048 | 00 00 00 00 00 00 00 00
|........|
1050 | 00 00 00 00 00 00 00 00
|........|
1058 | 00 00 00 00 00 00 00 00
|........|
1060 | 00 00 00 00 00 00 00 00
|........|
1068 | 00 00 00 00 00 00 00 00
|........|
1070 | 00 00 00 00 00 00 00 00
|........|
1078 | 00 00 00 00 00 00 00 00
|........|
1080 | 00 00 00 00 00 00 00 00
|........|
1088 | 00 00 00 00 00 00 00 00
|........|
1090 | 00 00 00 00 00 00 00 00
|........|
1098 | 00 00 00 00 00 00 00 00
|........|
10a0 | 00 00 00 00 00 00 00 00
|........|
10a8 | 00 00 00 00 00 00 00 00
|........|
10b0 | 00 00 00 00 00 00 00 00
|........|
10b8 | 00 00 00 00 00 00 00 00
|........|
10c0 | 00 00 00 00 00 00 00 00
|........|
10c8 | 00 00 00 00 00 00 00 00
|........|
10d0 | 00 00 00 00 00 00 00 00
|........|
10d8 | 00 00 00 00 00 00 00 00
|........|
10e0 | 00 00 00 00 00 00 00 00
|........|
10e8 | 00 00 00 00 00 00 00 00
|........|
10f0 | 00 00 00 00 00 00 00 00
|........|
10f8 | 00 00 00 00 00 00 00 00
|........|
OUT [0x2000-0x2fff]
2000 | 00 00 00 00 00 00 00 00
|........|
2008 | 00 00 00 00 00 00 00 00
|........|
2010 | 00 00 00 00 00 00 00 00
|........|
2018 | 00 00 00 00 00 00 00 00
|........|
2020 | 00 00 00 00 00 00 00 00
|........|
2028 | 00 00 00 00 00 00 00 00
|........|
2030 | 00 00 00 00 00 00 00 00
|........|
2038 | 00 00 00 00 00 00 00 00
|........|
2040 | 00 00 00 00 00 00 00 00
|........|
2048 | 00 00 00 00 00 00 00 00
|........|
2050 | 00 00 00 00 00 00 00 00
|........|
2058 | 00 00 00 00 00 00 00 00
|........|
2060 | 00 00 00 00 00 00 00 00
|........|
2068 | 00 00 00 00 00 00 00 00
|........|
2070 | 00 00 00 00 00 00 00 00
|........|
2078 | 00 00 00 00 00 00 00 00
|........|
2080 | 00 00 00 00 00 00 00 00
|........|
2088 | 00 00 00 00 00 00 00 00
|........|
2090 | 00 00 00 00 00 00 00 00
|........|
2098 | 00 00 00 00 00 00 00 00
|........|
20a0 | 00 00 00 00 00 00 00 00
|........|
20a8 | 00 00 00 00 00 00 00 00
|........|
20b0 | 00 00 00 00 00 00 00 00
|........|
20b8 | 00 00 00 00 00 00 00 00
|........|
20c0 | 00 00 00 00 00 00 00 00
|........|
20c8 | 00 00 00 00 00 00 00 00
|........|
20d0 | 00 00 00 00 00 00 00 00
|........|
20d8 | 00 00 00 00 00 00 00 00
|........|
20e0 | 00 00 00 00 00 00 00 00
|........|
20e8 | 00 00 00 00 00 00 00 00
|........|
20f0 | 00 00 00 00 00 00 00 00
|........|
20f8 | 00 00 00 00 00 00 00 00
|........|
STACK [0xf000-0xffff]
ff00 (+00) | 0x0000000000000000
ff08 (+08) | 0x0000000000000000
ff10 (+10) | 0x0000000000000000
ff18 (+18) | 0x0000000000000000
ff20 (+20) | 0x0000000000000000
ff28 (+28) | 0x0000000000000000
ff30 (+30) | 0x0000000000000000
ff38 (+38) | 0x0000000000000000
ff40 (+40) | 0x0000000000000000
ff48 (+48) | 0x0000000000000000
ff50 (+50) | 0x0000000000000000
ff58 (+58) | 0x0000000000000000
ff60 (+60) | 0x0000000000000000
ff68 (+68) | 0x0000000000000000
ff70 (+70) | 0x0000000000000000
ff78 (+78) | 0x0000000000000000
ff80 (+80) | 0x0000000000000000
ff88 (+88) | 0x0000000000000000
ff90 (+90) | 0x0000000000000000
ff98 (+98) | 0x0000000000000000
ffa0 (+a0) | 0x0000000000000000
ffa8 (+a8) | 0x0000000000000000
ffb0 (+b0) | 0x0000000000000000
ffb8 (+b8) | 0x0000000000000000
ffc0 (+c0) | 0x0000000000000000
ffc8 (+c8) | 0x0000000000000000
ffd0 (+d0) | 0x0000000000000000
ffd8 (+d8) | 0x0000000000000000
ffe0 (+e0) | 0x0000000000000000
ffe8 (+e8) | 0x0000000000000000
fff0 (+f0) | 0x0000000000000000
fff8 (+f8) | 0x0000000000000000

Mini #3: Teleportation


Write a payload in IN that will achieve the following:

  1. 1. call win()

Click the to test your solution.

Tip: What else could we overwrite other than user variables?

C code:


int main() {
    char buf[16];
    gets(buf);
}

// Never called in main! How can we even reach this?
void win(){
  ...
}
            

Initializing...

CODE [0x400000]
Registers
rax:
rbx:
rcx:
rdx:
rdi:
rsi:
r8 :
r9 :
r10:
r11:
r12:
r13:
r14:
r15:
rbp:
rsp:
rip:
IN [0x1000-0x1fff]
1000 | 00 00 00 00 00 00 00 00
|........|
1008 | 00 00 00 00 00 00 00 00
|........|
1010 | 00 00 00 00 00 00 00 00
|........|
1018 | 00 00 00 00 00 00 00 00
|........|
1020 | 00 00 00 00 00 00 00 00
|........|
1028 | 00 00 00 00 00 00 00 00
|........|
1030 | 00 00 00 00 00 00 00 00
|........|
1038 | 00 00 00 00 00 00 00 00
|........|
1040 | 00 00 00 00 00 00 00 00
|........|
1048 | 00 00 00 00 00 00 00 00
|........|
1050 | 00 00 00 00 00 00 00 00
|........|
1058 | 00 00 00 00 00 00 00 00
|........|
1060 | 00 00 00 00 00 00 00 00
|........|
1068 | 00 00 00 00 00 00 00 00
|........|
1070 | 00 00 00 00 00 00 00 00
|........|
1078 | 00 00 00 00 00 00 00 00
|........|
1080 | 00 00 00 00 00 00 00 00
|........|
1088 | 00 00 00 00 00 00 00 00
|........|
1090 | 00 00 00 00 00 00 00 00
|........|
1098 | 00 00 00 00 00 00 00 00
|........|
10a0 | 00 00 00 00 00 00 00 00
|........|
10a8 | 00 00 00 00 00 00 00 00
|........|
10b0 | 00 00 00 00 00 00 00 00
|........|
10b8 | 00 00 00 00 00 00 00 00
|........|
10c0 | 00 00 00 00 00 00 00 00
|........|
10c8 | 00 00 00 00 00 00 00 00
|........|
10d0 | 00 00 00 00 00 00 00 00
|........|
10d8 | 00 00 00 00 00 00 00 00
|........|
10e0 | 00 00 00 00 00 00 00 00
|........|
10e8 | 00 00 00 00 00 00 00 00
|........|
10f0 | 00 00 00 00 00 00 00 00
|........|
10f8 | 00 00 00 00 00 00 00 00
|........|
OUT [0x2000-0x2fff]
2000 | 00 00 00 00 00 00 00 00
|........|
2008 | 00 00 00 00 00 00 00 00
|........|
2010 | 00 00 00 00 00 00 00 00
|........|
2018 | 00 00 00 00 00 00 00 00
|........|
2020 | 00 00 00 00 00 00 00 00
|........|
2028 | 00 00 00 00 00 00 00 00
|........|
2030 | 00 00 00 00 00 00 00 00
|........|
2038 | 00 00 00 00 00 00 00 00
|........|
2040 | 00 00 00 00 00 00 00 00
|........|
2048 | 00 00 00 00 00 00 00 00
|........|
2050 | 00 00 00 00 00 00 00 00
|........|
2058 | 00 00 00 00 00 00 00 00
|........|
2060 | 00 00 00 00 00 00 00 00
|........|
2068 | 00 00 00 00 00 00 00 00
|........|
2070 | 00 00 00 00 00 00 00 00
|........|
2078 | 00 00 00 00 00 00 00 00
|........|
2080 | 00 00 00 00 00 00 00 00
|........|
2088 | 00 00 00 00 00 00 00 00
|........|
2090 | 00 00 00 00 00 00 00 00
|........|
2098 | 00 00 00 00 00 00 00 00
|........|
20a0 | 00 00 00 00 00 00 00 00
|........|
20a8 | 00 00 00 00 00 00 00 00
|........|
20b0 | 00 00 00 00 00 00 00 00
|........|
20b8 | 00 00 00 00 00 00 00 00
|........|
20c0 | 00 00 00 00 00 00 00 00
|........|
20c8 | 00 00 00 00 00 00 00 00
|........|
20d0 | 00 00 00 00 00 00 00 00
|........|
20d8 | 00 00 00 00 00 00 00 00
|........|
20e0 | 00 00 00 00 00 00 00 00
|........|
20e8 | 00 00 00 00 00 00 00 00
|........|
20f0 | 00 00 00 00 00 00 00 00
|........|
20f8 | 00 00 00 00 00 00 00 00
|........|
STACK [0xf000-0xffff]
ff00 (+00) | 0x0000000000000000
ff08 (+08) | 0x0000000000000000
ff10 (+10) | 0x0000000000000000
ff18 (+18) | 0x0000000000000000
ff20 (+20) | 0x0000000000000000
ff28 (+28) | 0x0000000000000000
ff30 (+30) | 0x0000000000000000
ff38 (+38) | 0x0000000000000000
ff40 (+40) | 0x0000000000000000
ff48 (+48) | 0x0000000000000000
ff50 (+50) | 0x0000000000000000
ff58 (+58) | 0x0000000000000000
ff60 (+60) | 0x0000000000000000
ff68 (+68) | 0x0000000000000000
ff70 (+70) | 0x0000000000000000
ff78 (+78) | 0x0000000000000000
ff80 (+80) | 0x0000000000000000
ff88 (+88) | 0x0000000000000000
ff90 (+90) | 0x0000000000000000
ff98 (+98) | 0x0000000000000000
ffa0 (+a0) | 0x0000000000000000
ffa8 (+a8) | 0x0000000000000000
ffb0 (+b0) | 0x0000000000000000
ffb8 (+b8) | 0x0000000000000000
ffc0 (+c0) | 0x0000000000000000
ffc8 (+c8) | 0x0000000000000000
ffd0 (+d0) | 0x0000000000000000
ffd8 (+d8) | 0x0000000000000000
ffe0 (+e0) | 0x0000000000000000
ffe8 (+e8) | 0x0000000000000000
fff0 (+f0) | 0x0000000000000000
fff8 (+f8) | 0x0000000000000000