27.06.2013 Views

Hack Security Pro.pdf - Index of

Hack Security Pro.pdf - Index of

Hack Security Pro.pdf - Index of

SHOW MORE
SHOW LESS

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

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

A few assembler notions<br />

Let us see several essential assembler instruction:<br />

call 0x8048344 : When a routine calls a subroutine, it does an instruction call, which then<br />

jumps onto the address <strong>of</strong> the jump function in the .text section.<br />

ret : When all the instructions <strong>of</strong> a subroutine have been executed, the program returns to the<br />

address following the call on this subroutine. In this example, the call to the RET instruction at the<br />

0x8048357 address will make the program jump to the address following the func call, that is<br />

0x804836d. This instruction present at the end <strong>of</strong> eacj subroutine is actually a macro that successively<br />

executed<br />

pop %eip<br />

jmp %eip<br />

Registers<br />

Registers, (eax, ebx, ecx, edx, eip, ebp, esp ...) have a size <strong>of</strong> 32 bits or 4 bytes on Linux/X86<br />

platforms. Three <strong>of</strong> these are <strong>of</strong> a particular interest to us.<br />

EIP (Instruction Pointer): In this register is saved the address where the program<br />

must jump to in the .text at the output <strong>of</strong> a subroutine, that is during the call to<br />

ret.<br />

ESP (Stack pointer): This register always points to the end <strong>of</strong> the stack (we will talk<br />

about this soon).<br />

EBP When a new subroutine is called, new elements will be piled on top <strong>of</strong> the stack<br />

and so the ESP will be modified. So we save the old value <strong>of</strong> ESP in EBP, in<br />

order to re-attribute its previous value to the Stack Pointer during the call to RET.<br />

Let us check the state <strong>of</strong> registers during the call to the func function in our previous example:<br />

Stack level 0, frame at 0xb64950e8:<br />

eip = 0x804834a in func; saved eip 0x804836d<br />

called by frame at 0xb64950f8<br />

Arglist at 0xb64950e8, args:<br />

Locals at 0xb64950e8, Previous frame's sp in esp<br />

Saved registers:<br />

ebp at 0xb64950e8, eip at 0xb64950ec<br />

We can see that the EIP saved is: saved eip 0x804836d, which is the expected address.<br />

The <strong>Hack</strong>ademy DMP -141/209- SYSDREAM

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

Saved successfully!

Ooh no, something went wrong!