top of page

[DownUnderCTF 2023 Writeup][pwn] one byte

  • shinkhong97
  • Sep 4, 2023
  • 2 min read

Updated: Nov 4, 2023


ree

This is one of the challenges for beginner pwn players.

First of all, we inspect the given binary file. It is a 32-bit ELF.

ree

checksec:

ree

PIE is enabled, so if we want to get the real address of a function used in the program, we need to calculate the base address of the file.

ree

Look at the source code, the game turns easy when the program gives us the address of function init. The aim is to execute function win. We can utilize the given address to calculate the address of function win.

Paying more attention to lines 20 and 21, we see that buf is assigned with 0x10 bytes, but the program reads 0x11 bytes (we have one byte extra).

Let's take a look at asm code of the program:

ree

Looking at the last snippet, we realize that if we can control the value of ecx register, then we can control esp value, and finally, we can change the return address of the program.

With only 1 byte extra, we can totally achieve that. Let's debug the program to take a deeper look.

First, we get the address of init: 0x565561bd

ree

buf is 0x18 bytes far from ebp

ree

After receiving the buffer, it will pop the value which is located in address ebp -8 (0xffffcd00) to ecx.

ree

If we enter 0x11 bytes, we can control the last byte of ecx.

ree

If we send a payload with the first 12 junk bytes, plus the address of function win and the last byte is a null byte, we can change the flow of the program to win (based on the last snippet of asm code of the main function)

This is the result of exploiting with local binary:

ree

And finally, exploit the remote server and got the flag:

ree

solve.py

ree

For more challenges in the contest, please visit this GitHub repo: https://github.com/DownUnderCTF/Challenges_2023_Public/


Recent Posts

See All

Comments


Drop Me a Line, Let Me Know What You Think

Thanks for submitting!

© 2035 by n33r9. Powered and secured by me.

bottom of page