Okay next, let's solve the 3rd challenge
Don't forget to run it first so we know how the program work
ok so the program greet us with some kind of hex value that I expect it was some memory address inside the program. When we enter some strings it doesn't give us anything.
let's load our binary to Ghidra and when I dump all the functions the only functions that caught my eyes are main and echo. The main function doesn't have any particularly interesting function so lets just to the echo function.
Notice that there is gets function again and we should have the ability to cause a buffer overflow in the program
before we start to do some fuzzing, load the binary to Ghidra so we have a more depth understanding of the code.
hmmm, notice that the printed address is the address of the variable that stored our input. I assume we should use that address to place our shellcode but we will get into that later.
create a pattern so we know how much buffer that we need to change the EIP register.
cool! we are able to know how much offset that we need to change the EIP, but let's have a quick look at the security in the binary
Damn! the PIE has enabled this means that the stack address is random and we cannot put our shellcode.
But take a look again at the program when it runs, it shows us the memory of the variable inside the stack and by knowing this location we can craft our program to put the shellcode in the address.
to generate the shellcode I use msfvenom because I'm too lazy to craft it by myself LOL. To craft the payload, I use this formula:
payload = buf+padding+eip
so in the simple term, we put our payload at the start of our variable since we already got the address where we have to jump. Run the program again with our python script and to mimic real-life CTF event I map the program to the port using a socat utility check my previous post on pwn1 on how to set this up.
ok just a little not from me, maybe many of you try to put the padding that contains "\x90" nop sled at the beginning of the payload but when I try to run with this kind of placement in my payload it didn't work.
yea we got the root shell!
hope you enjoy this write up
references:
https://www.youtube.com/watch?v=1S0aBV-Waeo&t=35s
https://github.com/zst123/tamuctf-2019-writeups/blob/master/Solved/Pwn3/solve.py
Comments
Post a Comment