I'm trying to understand a program. This programm implements an antidebug technique.
From what I've understand so far, the father ptrace
a forked process.
An the child does something like that:
some code
Int 3
some code
Int 3
some code
Int 3
and so on
I think the father implements a kind of debugger because with strace -i
I see a lot of:
[77b7457c] waitpid(2468, [{WIFSTOPPED(s) && WSTOPSIG(s) == SIGTRAP}], __WALL) = 2468
[77b7457c] --- SIGCHLD (Child exited) @ 0 (0) ---
[77baf52c] ptrace(PTRACE_GETREGS, 2468, 0, 0x7fb68be4) = 0
[77baf52c] ptrace(PTRACE_SETREGS, 2468, 0, 0x7fb68be4) = 0
[77baf52c] ptrace(PTRACE_CONT, 2468, 0, SIG_0) = 0
It reminds me this document http://www.alexonlinux.com/how-debugger-works where we found the same ideas: a child process, sending TRAP, catched by the father via ptrace calls, setting registers to the right value, then continue.
My problem now: How can I debug this "debugger"?
- If I bypass the ptrace, the child will get its SIGTRAP and stop.
- If I leave the ptrace, I can't use gdb
- If I bypass ptrace and use gdb with
set follow-fork-mode child
, I can't follow how and where the TRAP is caught in father process because gdb handle it. And if I sendsignal SIGTRAP
the father detects it (how? that's one thing I want to understand) and terminates.
I know that gdb can't follow both father and child, so is there a way to debug this program?