0xf001
January 18th, 2005, 17:02
Hi SiNTAX,
this would of course be an option. but then you can not debug your binary anymore with gdb, since it wants to also use ptrace()
you have to code gdb detection into the ptrace function and there I think it gets more complicated, but it is another option.
I have a little example attached, just for fun
Code:
// ptrace.c -- Our little ptrace dummy --
int ptrace(int i, int j, int k, int l)
{
printf(" PTRACE CALLED!\n"

;
}
// antiptrace.c -- Our little ptrace test executable --
int main()
{
if (ptrace(0,0,1,0) < 0)
{
printf("DEBUGGER PRESENT!\n"

;
exit(1);
}
printf("Hello World!\n"

;
}
now if you run this it says Hello World!
Running in gdb it says DEBUGGER PRESENT! and Hello World
If we compile the above code with
Code:
gcc antiptrace.c -o antiptrace
gcc -shared ptrace.c -o ptrace.so
and set LD_PRELOAD=ptrace.so and run it in the debugger it says
Code:
# gdb antiptrace
GNU gdb 6.0-2
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i586-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".
gdb> bp _start
Breakpoint 1 at 0x8048300: file ../sysdeps/i386/elf/start.S, line 48.
gdb>
gdb> run
PTRACE CALLED!
PTRACE CALLED!
Hello World!
Program exited with code 010.
You can't do that without a process to debug.
_______________________________________________________________________________
Error while running hook_stop:
No registers.
gdb>
gdb> q
but of course the breakpoint did not work, therefore the program did not detect us
has anyone a good gdb detection method in his ptrace.c

?
cheers, 0xf001