I am using CreateRemoteThread in Windows and would like to know if the same thing is possible in Linux. Is it possible to do this in Linux?
2 Answers
The traditional way of doing this on Linux would be to create a dynamic library (.so) with your code in it, then separately force the loading of your library into the running application. There is no one-stop shop as there is with CreateRemoteThread
on Windows.
So here are the basic steps:
- Create and link a
.so
dynamic library (.dylib
on macOS) that contains the code you wish to execute in the remote process. - Write some very simple code in assembly that loads the specified so file (mainly copy and paste from this link, part 1).
- Embed said loader ASM as a binary payload in a buffer in a 2nd code file/app. Here you will use
ptrace
to run the binary payload written in step 2, which will trigger the target app to call_dl_open()
on the .so created in step 1, which contains the actual code you wish to run. (Sample given in the same link, part 2.)
If you need your code to run in a separate thread from the main pump, then you should use pthread_create
in the code in step 1.
Hope this answers your question. Yes, it's more involved than on Windows; but it should work equally well. Plus, you can reuse just about the entire code from steps 2 and 3 for future remote code injection projects.

- 28,357
- 12
- 85
- 125
-
2Create remote thread of windows creates the thread in an already running process. If you modify the executable image while the process is running, the process will still see the old version of the ELF until terminating. – Apr 16 '18 at 11:53
-
1
-
1The content of the links have been archived on https://web.archive.org/web/20150717110958/http://www.ars-informatica.com/Root/Code/2010_04_18/LinuxPTrace.aspx – alecail Dec 20 '21 at 16:07
`#include pthread.h
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);` Compile and link with -pthread.
see man pthread_create for detail

- 80
- 2
-
5That's how to create a thread, not create a thread and inject it into a remote process. – Mahmoud Al-Qudsi Feb 20 '13 at 17:19