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.

ine the instruction making the reference, in this case push edx at address 08048366,<br />

to realize that the return address is being overwritten.<br />

A disassembler that does not follow the control flow will be not be affected by the<br />

false return trick, as the following output from objdump demonstrates:<br />

8048357: 51 push %ecx<br />

8048359: 52 push %edx<br />

8048358: 53 push %ebx<br />

804835a: 89 e3 mov %esp,%ebx<br />

804835c: 89 ec mov %ebp,%esp<br />

804835e: 5d pop %ebp<br />

804835f: 59 pop %ecx<br />

8048360: 8D 15 69 83 04 08 lea 0x8048369,%edx<br />

8048366: 52 push %edx<br />

8048367: c3 ret<br />

8048368: 0f 51 55 89 sqrtps 0xffffff89(%ebp),%xmm2<br />

804836c: e5 89 in $0x89,%eax<br />

804836e: dc 5a 5b fcompl 0x5b(%edx)<br />

8048371: 59 pop %ecx<br />

8048372: c9 leave<br />

8048373: c3 ret<br />

The false return at address 08048367 does not affect the subsequent disassembly,<br />

although the misalignment trick at address 08048368 does cause the next three<br />

instructions to be disassembled incorrectly. This provides an example of how two<br />

simple techniques can be combined to create an inaccurate disassembly in different<br />

types of disassemblers.<br />

12.17 Using Self-Modifying Code<br />

<strong>Problem</strong><br />

You want to hide portions of your binary using self-modifying code without rewriting<br />

existing code in assembler.<br />

Solution<br />

The most effective use of self-modifying code is to overwrite a section of vital code<br />

with another section of vital code, such that both vital sections do not exist at the<br />

same time. This can be time-consuming and costly to develop; a more expedient<br />

technique can be achieved with C macros that decrypt garbage bytes in the code section<br />

to proper executable code at runtime. The process involves encrypting the protected<br />

code after the binary has been compiled, then decrypting it only after it has<br />

been executed.<br />

The code presented in this recipe applies to FreeBSD, Linux, NetBSD, OpenBSD,<br />

and Solaris. The concepts apply to Unix and Windows in general.<br />

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

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

Using Self-Modifying Code | 693

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

Saved successfully!

Ooh no, something went wrong!