Description
nc 45.32.157.65 65022
200.bin
TL;DR
- Overflow the length variable.
- Overflow the return address to the built-in get shell function (Only overflow least two bytes to bypass ASLR).
Exploit
-------------------------------------------- |
The binary let us input our name and a message. The memory layout looks like:
Stack: |
The vulnerability is that when reading a name of 40 bytes, the correct for loop should be:
for(int i = 0; i < 40; i++) |
instead of
for(int i = 0; i <= 40; i++) |
which causes a one byte overflow, and let us further overflow the return address when reading the SMS content. The target of the return is a built-in get shell function frontdoor
. However, this program is PIE enabled, so we don’t know the exact address of frontdoor
. We can overcome it by only overriding the least two bytes of the return address. Since the least 12 bits are fixed, we are only guessing 4 bits of the address.
The complete script is as follows.
1 | from pwn import * |
Flag:
DCTF{35c60be438186d13fdd2c9db9d3e33b7}