Earlier quoted context omitted.
> It seems like it's mostly useful for cases where people are blocking the ptrace syscall (like Docker's default syscall filter, maybe?) and not loading an LSM. It’s a shot in the dark, but I’d guess this is designed to work with programs that neuter themselves or commit suicide if you ptrace them, as is common for mildly sophisticated malware or (less often) CTF challenges.
How do you detect that you're being ptraced? I see the link to https://www.aldeid.com/wiki/Ptrace-anti-debugging in the README, but a) the program has to actively run its check while being ptraced to notice. If you attach to the program (which pauses it), inject your code, run your code, and then detach, the program's own code will not notice it's being ptraced, no? b) if you want to run the program's own code while…
Show HN: dlinject.py – Inject a .so into a running Linux process, without ptrace
11–20 of 20 posts
Re: Show HN: dlinject.py – Inject a .so into a running Linux process, without ptrace
#12Earlier quoted context omitted.
How do you detect that you're being ptraced? I see the link to https://www.aldeid.com/wiki/Ptrace-anti-debugging in the README, but a) the program has to actively run its check while being ptraced to notice. If you attach to the program (which pauses it), inject your code, run your code, and then detach, the program's own code will not notice it's being ptraced, no? b) if you want to run the program's own code while…
> a) the program has to actively run its check while being ptraced to notice. If you attach to the program (which pauses it), inject your code, run your code, and then detach, the program's own code will not notice it's being ptraced, no? Depends on if all threads were put into a paused state. Also, the program that's being debugged might have spawned some additional processes that will be checking if the parent is b…
Re: Show HN: dlinject.py – Inject a .so into a running Linux process, without ptrace
#13Re: Show HN: dlinject.py – Inject a .so into a running Linux process, without ptrace
#14If you want to avoid the side effects of SIGSTOP, you can put the target process in a freezer cgroup instead.
Re: Show HN: dlinject.py – Inject a .so into a running Linux process, without ptrace
#15Earlier quoted context omitted.
How do you detect that you're being ptraced? I see the link to https://www.aldeid.com/wiki/Ptrace-anti-debugging in the README, but a) the program has to actively run its check while being ptraced to notice. If you attach to the program (which pauses it), inject your code, run your code, and then detach, the program's own code will not notice it's being ptraced, no? b) if you want to run the program's own code while…
Some of the detection methods methods were mentioned in a comment (here’s one more: timers), but I should also mention that some binaries try to resist ptrace attempts with ptrace(PTRACE_TRACEME, …) as well if you’re too slow to get in before that.
As such, I never truly understood the semantics behind PTRACE_TRACEME, and I'm not sure what bad things will happen if you use that when the parent isn't expecting to ptrace the child.
Re: Show HN: dlinject.py – Inject a .so into a running Linux process, without ptrace
#16Earlier quoted context omitted.
Some of the detection methods methods were mentioned in a comment (here’s one more: timers), but I should also mention that some binaries try to resist ptrace attempts with ptrace(PTRACE_TRACEME, …) as well if you’re too slow to get in before that.
This might be off topic but I never really understood the utility of PTRACE_TRACEME. The documentation suggests that the parent must be a cooperating process (the wording "probably shouldn't" in the documentation is very suspicious). But if the parent knows it will ptrace the child, it could very well set up a pipe and have the child be blocked on it, then PTRACE_ATTACH, then unblock the child with the pipe. As such,…
The problem with PTRACE_TRACEME is that if you do it to yourself and recieve a signal, you're put into ptrace stop there's and there's no way out of it unless the parent knows how to get you out of it (using ptrace, of course). Sending signals will not work, even SIGKILL; somewhat humorously, on iOS, if you attempt to do the equivalent (using the similar PT_TRACE_ME) and oops yourself, the entire system will slowly grind to a halt as it tries to (at least, I think…) SIGKILL your process for a variety of reasons and fails, at some point locking up waiting for process termination.
Re: Show HN: dlinject.py – Inject a .so into a running Linux process, without ptrace
#17Re: Show HN: dlinject.py – Inject a .so into a running Linux process, without ptrace
#18What are the circumstances in which someone would be doing something like this?
Re: Show HN: dlinject.py – Inject a .so into a running Linux process, without ptrace
#19What are the circumstances in which someone would be doing something like this?
Re: Show HN: dlinject.py – Inject a .so into a running Linux process, without ptrace
#20The tl;dr of the technique is to use /proc/$pid/mem to overwrite the stack. (Since you don't have direct control of the instruction pointer this way, there's some complexity in loading shellcode somewhere and having the process return to it to get it to usefully execute your code, much like an actual stack-corruption exploit.) On a normal Linux system, /proc/$pid/mem is protected by the same kernel permission check a…
It looks like the gVisor approach for containers (reimplementing parts of the kernel syscalls in userspace and disallowing the rest)