c - buffer overflow problem -


after reference this website, want simulate simple buffer overflow bug
environment ubuntu 10.10
gcc version 4.4.5
download execstack enable executable stack of file.
following code

char code[] = "\x90\x90\x90\x6a\x00\xe8\x39\x07\x00\x00\x90\x90\x90";< char msg[] = "run !!\n"; int main() {           int *ptr;           int i;        for(i=1;i<128;i++){                ptr = (int *)&ptr + i;           (*ptr) = (int)code;         }           return 0; } 

i use gcc -fno-stack-protector -g -static -o main.out main.c compile source code.
when use gdb debug executable file,
weird happened.
here gdb output looks like:

(gdb) x/i 0x8048492    0x8048492 <__libc_start_main+402>:   call   0x8048bd0 <exit> (gdb) x/5b 0x8048492 0x8048492 <__libc_start_main+402>:  0xe8    0x39    0x07    0x00    0x00 (gdb) x/i 0x80ce02e    0x80ce02e <code+6>:  call   0x80ce76c <_dlfcn_hooks+44> (gdb) x/5b 0x80ce02e 0x80ce02e <code+6>: 0xe8    0x39    0x07    0x00    0x00 

it seems the pattern of these 2 address same, instructions different.
can me , explain why happen.
lot!

you have buffer overflow sure, line

 (*ptr) = (int)code; 

stores address of code in each location, not content of code array.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -