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.

When run through strace, <strong>the</strong> notetaker binary’s suid-bit isn’t used, so it<br />

doesn’t have permission to open <strong>the</strong> data file. That doesn’t matter, though;<br />

we just want to make sure <strong>the</strong> arguments to <strong>the</strong> open() system call match <strong>the</strong><br />

arguments to <strong>the</strong> open() call in C. Since <strong>the</strong>y match, we can safely use <strong>the</strong> values<br />

passed to <strong>the</strong> open() function in <strong>the</strong> notetaker binary as <strong>the</strong> arguments for <strong>the</strong><br />

open() system call in our shellcode. The compiler has already done all <strong>the</strong> work<br />

<strong>of</strong> looking up <strong>the</strong> defines and mashing <strong>the</strong>m toge<strong>the</strong>r with a bitwise OR operation;<br />

we just need to find <strong>the</strong> call arguments in <strong>the</strong> disassembly <strong>of</strong> <strong>the</strong> notetaker<br />

binary.<br />

reader@<strong>hacking</strong>:~/booksrc $ gdb -q ./notetaker<br />

Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".<br />

(gdb) set dis intel<br />

(gdb) disass main<br />

Dump <strong>of</strong> assembler code for function main:<br />

0x0804875f : push ebp<br />

0x08048760 : mov ebp,esp<br />

0x08048762 : sub esp,0x28<br />

0x08048765 : and esp,0xfffffff0<br />

0x08048768 : mov eax,0x0<br />

0x0804876d : sub esp,eax<br />

0x0804876f : mov DWORD PTR [esp],0x64<br />

0x08048776 : call 0x8048601 <br />

0x0804877b : mov DWORD PTR [ebp-12],eax<br />

0x0804877e : mov DWORD PTR [esp],0x14<br />

0x08048785 : call 0x8048601 <br />

0x0804878a : mov DWORD PTR [ebp-16],eax<br />

0x0804878d : mov DWORD PTR [esp+4],0x8048a9f<br />

0x08048795 : mov eax,DWORD PTR [ebp-16]<br />

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

0x0804879b : call 0x8048480 <br />

0x080487a0 : cmp DWORD PTR [ebp+8],0x1<br />

0x080487a4 : jg 0x80487ba <br />

0x080487a6 : mov eax,DWORD PTR [ebp-16]<br />

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

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

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

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

0x080487b5 : call 0x8048733 <br />

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

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

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

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

0x080487c6 : mov eax,DWORD PTR [ebp-12]<br />

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

0x080487cc : call 0x8048480 <br />

0x080487d1 : mov eax,DWORD PTR [ebp-12]<br />

0x080487d4 : mov DWORD PTR [esp+8],eax<br />

0x080487d8 : mov eax,DWORD PTR [ebp-12]<br />

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

0x080487df : mov DWORD PTR [esp],0x8048aaa<br />

0x080487e6 : call 0x8048490 <br />

0x080487eb : mov eax,DWORD PTR [ebp-16]<br />

338 0x600

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

Saved successfully!

Ooh no, something went wrong!