I'm beginner in exploits. So I had type simple program in C
#include <stdio.h>
void func(){
printf("asd");
}
main(){
char buf[100];
scanf("%s", &buf);
}
My goal is to run the func() and print asd. With 116 'A's I'm over writing the EIP but when I change the last 4 A's with the memory address of the function(in reverse order) and run the program again the EIP is something completely different. Here are details form GDB:
Starting program: /root/Documents/C/overflow/stack
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Program received signal SIGSEGV, Segmentation fault.
0x41414141 in ?? ()
(gdb) info registers
eax 0x1 1
ecx 0x1 1
edx 0xb7fbd354 -1208233132
ebx 0xb7fbbff4 -1208238092
esp 0xbffff4d0 0xbffff4d0
ebp 0x41414141 0x41414141
esi 0x0 0
edi 0x0 0
eip 0x41414141 0x41414141
With address of the func:
(gdb) disas func
Dump of assembler code for function func:
0x0804846c <+0>: push %ebp
0x0804846d <+1>: mov %esp,%ebp
0x0804846f <+3>: sub $0x18,%esp
0x08048472 <+6>: movl $0x8048530,(%esp)
0x08048479 <+13>: call 0x8048340 <printf@plt>
0x0804847e <+18>: leave
0x0804847f <+19>: ret
Starting program: /root/Documents/C/overflow/stack
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\x6c\x84\x04\x08
Program received signal SIGSEGV, Segmentation fault.
0x6336785c in ?? ()
If I add more A's to the string the EIP start overflowing with A's again I mean
Adding 1 A EIP = 0x36785c41
Adding 2 A's EIP = 0x785c4141
Adding 3 A's EIP = 0x78414141
Adding 4 A's EIP = 0x41414141
I'm running Linux, I didn't remove or edit anything in the kernel so there my be protections. Also I didn't disable any function on gcc, and the compiler is gcc =D.
Any help is welcome. Thanks in advance.