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.

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

int spc_detect_ptrace(void) {<br />

int status, waitrc;<br />

pid_t child, parent;<br />

parent = getpid();<br />

if (!(child = fork())) {<br />

/* this is the child process */<br />

if (ptrace(PT_ATTACH, parent, 0, 0)) exit(1);<br />

do {<br />

waitrc = waitpid(parent, &status, 0);<br />

} while (waitrc == -1 && errno == EINTR);<br />

ptrace(PT_DETACH, parent, (caddr_t)1, SIGCONT);<br />

exit(0);<br />

}<br />

if (child == -1) return -1;<br />

do {<br />

waitrc = waitpid(child, &status, 0);<br />

} while (waitrc == -1 && errno == EINTR);<br />

return WEXITSTATUS(status);<br />

}<br />

The state of the art in anti-debugging on Unix is not very advanced, because all<br />

widely used Unix debuggers are based on ptrace and do not require any special tricks<br />

to detect; generally speaking, any method that detects or counters ptrace should succeed.<br />

It is important to realize, however, that calls to ptrace( ) can be replaced with<br />

nop instructions in the binary to defeat the debugger detection, so take care to disguise<br />

them. For example, by using the system call interface instead of the C interface,<br />

the ptrace( ) system call can also be hooked at the kernel level to force a<br />

successful return.<br />

See Also<br />

“Linux Anti-Debugging Techniques” by Silvio Cesare (the techniques listed here<br />

were published in that 1999 paper, http://vx.netlux.org/lib/vsc04.html.<br />

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