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) c<br />

Continuing.<br />

Breakpoint 2, check_au<strong>the</strong>ntication (password=0xbffff9b7 'A' ) at<br />

auth_overflow2.c:9<br />

9 strcpy(password_buffer, password);<br />

(gdb) i r esp<br />

esp 0xbffff7a0 0xbffff7a0<br />

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

0xbffff7a0: 0x00000000 0x08049744 0xbffff7b8 0x080482d9<br />

0xbffff7b0: 0xb7f9f729 0xb7fd6ff4 0xbffff7e8 0x00000000<br />

0xbffff7c0: 0xb7fd6ff4 0xbffff880 0xbffff7e8 0xb7fd6ff4<br />

0xbffff7d0: 0xb7ff47b0 0x08048510 0xbffff7e8 0x080484bb<br />

0xbffff7e0: 0xbffff9b7 0x08048510 0xbffff848 0xb7eafebc<br />

0xbffff7f0: 0x00000002 0xbffff874 0xbffff880 0xb8001898<br />

0xbffff800: 0x00000000 0x00000001 0x00000001 0x00000000<br />

0xbffff810: 0xb7fd6ff4 0xb8000ce0 0x00000000 0xbffff848<br />

(gdb) p 0xbffff7e0 - 0xbffff7a0<br />

$1 = 64<br />

(gdb) x/s password_buffer<br />

0xbffff7c0: "?o??\200????????o???G??\020\205\004\b?????\204\004\b????\020\205\004\<br />

bH???????\002"<br />

(gdb) x/x &auth_flag<br />

0xbffff7bc: 0x00000000<br />

(gdb)<br />

Continuing to <strong>the</strong> second breakpoint in check_au<strong>the</strong>ntication(), a stack<br />

frame (shown in bold) is pushed onto <strong>the</strong> stack when <strong>the</strong> function is called.<br />

Since <strong>the</strong> stack grows upward toward lower memory addresses, <strong>the</strong> stack<br />

pointer is now 64 bytes less at 0xbffff7a0. The size and structure <strong>of</strong> a stack<br />

frame can vary greatly, depending on <strong>the</strong> function and certain compiler<br />

optimizations. For example, <strong>the</strong> first 24 bytes <strong>of</strong> this stack frame are just<br />

padding put <strong>the</strong>re by <strong>the</strong> compiler. The local stack variables, auth_flag and<br />

password_buffer, are shown at <strong>the</strong>ir respective memory locations in <strong>the</strong> stack<br />

frame. The auth_flag () is shown at 0xbffff7bc, and <strong>the</strong> 16 bytes <strong>of</strong> <strong>the</strong><br />

password buffer () are shown at 0xbffff7c0.<br />

The stack frame contains more than just <strong>the</strong> local variables and padding.<br />

Elements <strong>of</strong> <strong>the</strong> check_au<strong>the</strong>ntication() stack frame are shown below.<br />

First, <strong>the</strong> memory saved for <strong>the</strong> local variables is shown in italic. This st<strong>art</strong>s<br />

at <strong>the</strong> auth_flag variable at 0xbffff7bc and continues through <strong>the</strong> end <strong>of</strong> <strong>the</strong><br />

16-byte password_buffer variable. The next few values on <strong>the</strong> stack are just<br />

padding <strong>the</strong> compiler threw in, plus something called <strong>the</strong> saved frame pointer.<br />

If <strong>the</strong> program is compiled with <strong>the</strong> flag -fomit-frame-pointer for optimization,<br />

<strong>the</strong> frame pointer won’t be used in <strong>the</strong> stack frame. At <strong>the</strong> value<br />

0x080484bb is <strong>the</strong> return address <strong>of</strong> <strong>the</strong> stack frame, and at <strong>the</strong> address<br />

0xbffffe9b7 is a pointer to a string containing 30 As. This must be <strong>the</strong> argument<br />

to <strong>the</strong> check_au<strong>the</strong>ntication() function.<br />

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

0xbffff7a0: 0x00000000 0x08049744 0xbffff7b8 0x080482d9<br />

0xbffff7b0: 0xb7f9f729 0xb7fd6ff4 0xbffff7e8 0x00000000<br />

0xbffff7c0: 0xb7fd6ff4 0xbffff880 0xbffff7e8 0xb7fd6ff4<br />

130 0x300

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

Saved successfully!

Ooh no, something went wrong!