I have a code snippet which has the classic strcpy
vulnerability
int main(int argc, char argv[][]){
char buffer[8];
strcpy(buffer, argv[1]);
}
By disassembling the binary file, we can see rsp
is decreased by 0x10
bytes (=16
)
So we can actually overwrite the rbp
after 16 bytes and return address after 24 bytes. Before the function returns, rax
is pointing to the beginning of our shellcode.
Here is my approach to attacking the program. Our shellcode will be in the following format
"A"*16 + "B"*8 + "C"*8
As ASLR is enabled, I replaced return address to an address of jmpq *%rax
, so the payload will now become
"A"*16 + "B"*8 + "\x77\x04\x40"
and by stepping through in gdb, I can see execution is being directed to the beginning of "A"s. However, the buffer is too small to put in a (system(/bin/sh)
) shellcode. What am I supposed to do here?
Here is what I am thinking:
Use egghunter approach. However, I am not able to send more than 24 bytes data to the application, as the return address include null bytes, it terminates my shellcode.
Find a shellcode that is smaller than 24 bytes for 64 bits Linux. (I guess this is not possible)
ROP approach, however, ASLR is enabled, I can't figure out the base address of libc
I have read through many tutorials and most of them have a big buffer like char buffer[500]
instead char buffer[8]
. It will be great if someone can guide me to the right place.