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.

int main(int argc, char *argv[ ]) {<br />

if (spc_check_int3(myfunc_nodebug)) printf("being debugged: int3!\n");<br />

return(0);<br />

}<br />

Checking for int3 opcodes is a crude and largely unreliable method. The comparison<br />

with the 0xCC byte is immediately obvious when examining the disassembly of<br />

the above source code:<br />

8048328 :<br />

8048328: push %ebp<br />

8048329: mov %esp, %ebp<br />

804832b: sub $4, %esp<br />

804832e: mov 8(%ebp), %eax<br />

8048331: mov (%eax), %al<br />

8048333: cmp $0xCC, %al<br />

8048335: jne 8048340<br />

8048337: movl $1, -4(%ebp)<br />

804833e: jmp 8048347<br />

8048340: movl $0, -4(%ebp)<br />

8048347: mov -4(%ebp), %eax<br />

804834a: leave<br />

804834b: ret<br />

The compare instruction at address 8048333 is obviously checking for an embedded<br />

int3 instruction. A software protection cracker can neutralize this check either by<br />

changing the 0xCC byte in the compare instruction to another value (such as 0x90, the<br />

nop instruction) or by changing the conditional jump instruction at address 8048335<br />

(opcode 0x75) to an unconditional jump instruction (opcode 0xEB). In addition, most<br />

modern debuggers support the use of the debug registers present in Intel x86 CPUs<br />

because the Pentium breakpoints set using these registers do not require the int3<br />

instruction and will not be detected with this method.<br />

See Also<br />

Recipes 12.13, 12.14, 12.15<br />

12.13 Detecting Unix Debuggers<br />

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

You need to prevent someone from debugging a Unix binary.<br />

Solution<br />

Single-stepping through code in a Unix environment causes a SIGTRAP to be sent to<br />

the process. The debugger captures this signal and allows the user to examine the<br />

state of the process before continuing execution. By installing a SIGTRAP handler and<br />

sending itself a SIGTRAP, the process can determine whether it is being debugged.<br />

682 | 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!