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.

Below, GDB is used to show <strong>the</strong> state <strong>of</strong> <strong>the</strong> processor registers right before<br />

<strong>the</strong> program st<strong>art</strong>s.<br />

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

Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".<br />

(gdb) break main<br />

Breakpoint 1 at 0x804837a<br />

(gdb) run<br />

St<strong>art</strong>ing program: /home/reader/booksrc/a.out<br />

Breakpoint 1, 0x0804837a in main ()<br />

(gdb) info registers<br />

eax 0xbffff894 -1073743724<br />

ecx 0x48e0fe81 1222704769<br />

edx 0x1 1<br />

ebx 0xb7fd6ff4 -1208127500<br />

esp 0xbffff800 0xbffff800<br />

ebp 0xbffff808 0xbffff808<br />

esi 0xb8000ce0 -1207956256<br />

edi 0x0 0<br />

eip 0x804837a 0x804837a <br />

eflags 0x286 [ PF SF IF ]<br />

cs 0x73 115<br />

ss 0x7b 123<br />

ds 0x7b 123<br />

es 0x7b 123<br />

fs 0x0 0<br />

gs 0x33 51<br />

(gdb) quit<br />

The program is running. Exit anyway? (y or n) y<br />

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

A breakpoint is set on <strong>the</strong> main() function so execution will stop right<br />

before our code is executed. Then GDB runs <strong>the</strong> program, stops at <strong>the</strong><br />

breakpoint, and is told to display all <strong>the</strong> processor registers and <strong>the</strong>ir<br />

current states.<br />

The first four registers (EAX, ECX, EDX, and EBX) are known as generalpurpose<br />

registers. These are called <strong>the</strong> Accumulator, Counter, Data, and Base<br />

registers, respectively. They are used for a variety <strong>of</strong> purposes, but <strong>the</strong>y mainly<br />

act as temporary variables for <strong>the</strong> CPU when it is executing machine<br />

instructions.<br />

The second four registers (ESP, EBP, ESI, and EDI) are also generalpurpose<br />

registers, but <strong>the</strong>y are sometimes known as pointers and indexes.<br />

These stand for Stack Pointer, Base Pointer, Source Index, and Destination Index,<br />

respectively. The first two registers are called pointers because <strong>the</strong>y store 32-bit<br />

addresses, which essentially point to that location in memory. These registers<br />

are fairly important to program execution and memory management; we will<br />

discuss <strong>the</strong>m more later. The last two registers are also technically pointers,<br />

24 0x200

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

Saved successfully!

Ooh no, something went wrong!