21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

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.

08048388 83 db 83h ; â<br />

08048389 7D db 7Dh ; }<br />

0804838A FC db 0FCh ; n<br />

The GNU objdump disassembler does not follow the jump at all and encounters the<br />

same problem:<br />

08048374 :<br />

8048374: 55 push %ebp<br />

8048375: 89 e5 mov %esp,%ebp<br />

8048377: 83 ec 08 sub $0x8,%esp<br />

804837a: 50 push %eax<br />

804837b: 39 c0 cmp %eax,%eax<br />

804837d: 74 01 je 8048380 <br />

804837f: 0f 58 c7 addps %xmm7,%xmm0<br />

8048382: 45 inc %ebp<br />

8048383: fc cld<br />

8048384: 00 00 add %al,(%eax)<br />

8048386: 00 00 add %al,(%eax)<br />

8048388: 83 7d fc 09 cmpl $0x9,0xfffffffc(%ebp)<br />

Sophisticated disassemblers attempt to reconstruct as much as possible of the original<br />

source code of the binary. One of the tasks they perform towards this goal is the<br />

recognition of functions within the binary. Because the end of a function is generally<br />

assumed to be the first return instruction encountered, it is possible to truncate a<br />

function within the disassembler by providing a false return. The following macro<br />

will return to a byte after the ret instruction, causing the definition of the function to<br />

end prematurely:<br />

#define DISASM_FALSERET asm volatile ( \<br />

" pushl %ecx /* save registers */\n" \<br />

" pushl %ebx \n" \<br />

" pushl %edx \n" \<br />

" movl %esp, %ebx /* save ebp, esp */\n" \<br />

" movl %ebp, %esp \n" \<br />

" popl %ebp /* save old %ebp */\n" \<br />

" popl %ecx /* save return addr */\n" \<br />

" lea 0f, %edx /* edx = addr of 0: */\n" \<br />

" pushl %edx /* return addr = edx */\n" \<br />

" ret \n" \<br />

" .byte 0x0F /* off-by-one byte */\n" \<br />

"0: \n" \<br />

" pushl %ecx /* restore ret addr */\n" \<br />

" pushl %ebp /* restore old &ebp */\n" \<br />

" movl %esp, %ebp /* restore ebp, esp */\n" \<br />

" movl %ebx, %esp \n" \<br />

" popl %ebx \n" \<br />

" popl %ecx \n")<br />

The first three pushl instructions and the last three popl instructions save and restore<br />

the registers that will be used in the course of the false return. The current stack<br />

pointer is saved in the ebx register, and the current stack pointer is set to the frame<br />

pointer (ebp) of the current function—this places the frame pointer of the calling<br />

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

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.<br />

Countering Disassembly | 691

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

Saved successfully!

Ooh no, something went wrong!