Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep list of threads inside Linux Target #65

Open
fabiim opened this issue Jul 31, 2020 · 7 comments
Open

Keep list of threads inside Linux Target #65

fabiim opened this issue Jul 31, 2020 · 7 comments
Labels
enhancement New feature or request linux

Comments

@fabiim
Copy link
Contributor

fabiim commented Jul 31, 2020

From #47 discussion it is my understanding that we need to keep a list of threads inside target that is continuously updated as threads come and go

To do this we need to:

  • Update all ptrace calls to use PTRACE_O_TRACECLONE
  • Listen on all waitpids calls inside the target code so that we register new/dead threads.
@bjorn3 bjorn3 added enhancement New feature or request linux labels Jul 31, 2020
@fabiim
Copy link
Contributor Author

fabiim commented Jul 31, 2020

Does that plan looks right @bjorn3 ?

@bjorn3
Copy link
Contributor

bjorn3 commented Jul 31, 2020

Yes

@Stupremee
Copy link
Contributor

Stupremee commented Aug 5, 2020

I threw together a little sketch to play around with PTRACE_O_TRACECLONE.
I think this is almost exactly what we want in headcrab.

The important part in the snippet is the waitpid call

waitpid(None, None)?;

It uses None as the pid, which means that it actually uses -1 in the libc call, and the manpage says:

If pid is less than (pid_t)−1, status is requested for any child process whose process group ID is equal to the absolute value of pid.

Thus, it also gets the status for all child processes (threads) and can be used to track threads.

@bjorn3
Copy link
Contributor

bjorn3 commented Aug 5, 2020

That will likely cause interference between multiple headcrab sessions. Does the parent thread itself get suspended too?

@Stupremee
Copy link
Contributor

Stupremee commented Aug 5, 2020

Does the parent thread itself get suspended too?

I don't think so unless waitpid returns a status for the parent.

@bjorn3
Copy link
Contributor

bjorn3 commented Aug 5, 2020

PTRACE_O_TRACECLONE (since Linux 2.5.46)
    Stop the tracee at the next clone(2) and automatically start tracing the newly cloned process [...]
    [...]
    The PID of the new process can be retrieved with PTRACE_GETEVENTMSG.

I think it actually does get suspended.

@Stupremee
Copy link
Contributor

Ah yes, you right. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request linux
Projects
None yet
Development

No branches or pull requests

3 participants