21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

function at the top of the stack. The saved frame pointer is moved into the ebp register,<br />

and the return address is moved into the ecx register so that these values can be<br />

preserved across the return. The instruction movl0f, %edx stores the address of the<br />

local code label 0: in the edx register. This address is then pushed onto the stack,<br />

where it becomes the new return address. The following ret instruction causes the<br />

program to jump to code label 0:, where the execution context of the function (the<br />

stack and frame pointers, saved frame pointer, and return address) is restored to its<br />

original state.<br />

When a disassembler follows the control flow of the program, rather than blindly<br />

disassembling instructions from the start of the code segment, it will encounter the<br />

false return statement and will stop disassembly of the current function. As a result,<br />

any instructions after the false return will not be disassembled, and they will appear<br />

as data located in the code segment.<br />

void my_func(void) {<br />

int x;<br />

for (x = 0; x < 10; x++) printf("%x\n", x);<br />

DISASM_FALSERET;<br />

/* other stuff can be done here that won't be disassembled */<br />

}<br />

This produces the following disassembly in IDA Pro:<br />

08048357 51 push ecx<br />

08048358 53 push ebx<br />

08048359 52 push edx<br />

0804835A 89 E3 mov ebx, esp<br />

0804835C 89 EC mov esp, ebp<br />

0804835E 5D pop ebp<br />

0804835F 59 pop ecx<br />

08048360 8D 15 69 83 04 08 lea edx, ds:dword_8048369<br />

08048366 52 push edx<br />

08048367 C3 retn<br />

08048367 my_func endp ; sp = -0Ch<br />

08048367<br />

08048367 ;----------------------------------------------------------------<br />

08048368 0F db 0Fh ;<br />

08048369 51 55 89 E5 dword_8048369 dd 0E5895551h<br />

08048369 ; DATA XREF: my_func+38#r<br />

0804836D 89 db 89h ; ë<br />

0804836E DC db 0DCh ; ?<br />

0804836F 5A db 5Ah ; Z<br />

08048370 5B db 5Bh ; [<br />

08048371 59 db 59h ; Y<br />

08048372 C9 db 0C9h ; +<br />

08048373 C3 db 0C3h ; +<br />

The false return at address 08048367 ends the function, with the subsequent code<br />

not being disassembled. The XREF at address 08048369, however, clearly indicates<br />

that something strange is going on, even though the disassembly is incorrect. There<br />

is also an indication of a stack error at the endp directive. A cracker can simply exam-<br />

692 | Chapter 12: Anti-Tampering<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

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

Saved successfully!

Ooh no, something went wrong!