Landon Fuller (http://landonf.bikemonkey.org/code/macosx) created a kernel module to bypass the PTRACE_DENY_ATTACH “anti-debug” feature of Mac OS X. For the Tiger version he used a deprecated API, removed on Leopard. For Leopard he re-routes the ptrace syscall to his own version by patching the syscall table. Since the Leopard version is much more interesting because we can use it to re-route other interesting syscalls (for cases where DYLD_INSERT_LIBRARIES trick isn’t interesting to use), I fixed his great code to be used for Tiger.
I added the open() syscall, and if you want to use it you should uncomment the code for it (check the source code, it’s there.
If you are using other version than 10.4.11, you should edit the Info.plist file and replace the com.apple.kernel string for the correct one (hint: use uname -a to get it).
Grab the code here:
pt_deny_attach-201-tiger.tar.gz
As usual, have fun
-
That’s interesting stuff! Such a few line of code to do this kind of tricks… I must study XNU (in particular, the Mach and it’s IPC)!
-
I’ll read that for sure! I love this kind of stuff!

For now I’m too sleepy… I go bed… -
Hi, congrats for your site. It’s a great source of learning, I’ve been interested in ASM since I was 15 and programmed a motorola 68k microontroler for the first time.
I’ve a question about this anti-anti-debug method, this solves the problem with programs like itunes exiting on gdb with 055 status, but I’m now looking at others programs that call sysctl() and they exit with status 146 when they’re run in gdb.
I’ve found an article at apple talking about detecting the debugger using sysctl(), but I don’t know if it’s safe to NOP every call or how to detect the “bad one”.
Got any hints?
Thanks for sharing the knowledge and keep up the good work.
-
Well, the Apple tech note explaining how to detect if you are being run under the debugger:
http://developer.apple.com/qa/qa2004/qa1361.htmlThe program I’m exploring now is Remote Buddy by IOSpirit.
-
Yes, I found that really large series of _rand strange too, maybe they’re trying to put a delay or just writing random values in the registers to distract your attention.
Comments are now closed.
11 comments