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.

(gdb) x/6cb 0x8048484<br />

0x8048484: 72 'H' 101 'e' 108 'l' 108 'l' 111 'o' 32 ' '<br />

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

0x8048484: "Hello, world!\n"<br />

(gdb)<br />

These commands reveal that <strong>the</strong> data string "Hello, world!\n" is stored at<br />

memory address 0x8048484. This string is <strong>the</strong> argument for <strong>the</strong> printf() function,<br />

which indicates that moving <strong>the</strong> address <strong>of</strong> this string to <strong>the</strong> address<br />

stored in ESP (0x8048484) has something to do with this function. The following<br />

output shows <strong>the</strong> data string’s address being moved into <strong>the</strong> address ESP is<br />

pointing to.<br />

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

0x8048393 : mov DWORD PTR [esp],0x8048484<br />

0x804839a : call 0x80482a0 <br />

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

0xbffff800: 0xb8000ce0<br />

(gdb) nexti<br />

0x0804839a 8 printf("Hello, world!\n");<br />

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

0xbffff800: 0x08048484<br />

(gdb)<br />

The next instruction is actually called <strong>the</strong> printf() function; it prints <strong>the</strong><br />

data string. The previous instruction was setting up for <strong>the</strong> function call, and<br />

<strong>the</strong> results <strong>of</strong> <strong>the</strong> function call can be seen in <strong>the</strong> output below in bold.<br />

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

0x804839a : call 0x80482a0 <br />

(gdb) nexti<br />

Hello, world!<br />

6 for(i=0; i < 10; i++)<br />

(gdb)<br />

Continuing to use GDB to debug, let’s examine <strong>the</strong> next two instructions.<br />

Once again, <strong>the</strong>y make more sense to look at in a group.<br />

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

0x804839f : lea eax,[ebp-4]<br />

0x80483a2 : inc DWORD PTR [eax]<br />

(gdb)<br />

These two instructions basically just increment <strong>the</strong> variable i by 1. The<br />

lea instruction is an acronym for Load Effective Address, which will load <strong>the</strong><br />

Programming 35

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

Saved successfully!

Ooh no, something went wrong!