crashme
Last updated
Was this helpful?
Last updated
Was this helpful?
to solve this challenge we are going to inject shellcode since the NX is disabled, often we jump to the esp to execute the shellcode but in this challenge there's not jmp esp gadgets this is why we are going to search for other registers and we will find rax as a way to execute the shellcode.
this file is a 64bit executable and all the protections are disabled so we can inject shellcode into the stack and execute it to get the flag
opening the crashme binary c code we can see that its vulnerable to buffer overflow since it reads 64 bytes and the buffer is only 32 bytes
i often calculate the offset using pwndbg and cyclic
the sequence that made it into the RIP is located in the RSP register which is 'faaaaaaa' , using cyclic -l we can determine at which offset that sequence happen and this way we get the offset to the RIP which is 40
normally when we build a shellcode injection script we first try to overflow the buffer and overwrite the EIP with the address of the gadget jmp esp
and from there we start to execute the shellcode but in this binary this gadget doesn't exist
so we need to find registers that are pointing to the stack and to do that we should find a call
gadget in our program. I've used objdump to disassemble full binary.
objdump -d crashme | grep call
so the plan is we are going to overflow the buffer and overwrite the RIP with the address 0x40066e to jump to the register rax where we will put our shellcode so when we return to the register rax our shellcode will start executing
The empty space (filled with NOPs, which stands for No Operation) before the shellcode is known as a "nop sled" or "slide." This technique is often used in buffer overflow exploits to increase the chances of successfully redirecting the program's control flow to the shellcode.
asm('nop') * 16
: This is an additional NOP sled of 16 bytes. NOP sleds act as a buffer in case the exact return address is not hit precisely. It provides some "wiggle room" for the program's execution flow to slide into the intended shellcode.
now let's run the exploit remotely