Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

322
Views
Equivalent of VirtualProtectEx/CreateRemoteThread in Linux?

I was wondering if there was an equivalent version either in a library or as a syscall, of the windows APIs which allow a process to interact with other process' space, which would mean modifying the flow of that second process. This is to inject a .so in a running process without killing it.

Thanks!

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

maybe take a look here: CreateRemoteThread in Linux

I don't know of a simpler way than described there. On Windows you have this fancy API like VirtualProtectEx. On Linux you'd be writing a .so which e.g. executes pthread_create in a __attribute__((constructor)) function. Then you'd load that .so via the LD_PRELOAD mechanism.

The next best thing to CreateRemoteThread would be manipulating the main thread of the process with the ptrace API. But this would involve

  1. Holding a thread
  2. Saving its context
  3. Setting arguments for pthread_create
  4. Set IP to pthread_create and execute
  5. Restore the old context.

I think manipulating the memory access rights would also involve calling mprotect from a process context. As already mentioned above, the simplest way to do that would not be using ptrace but using a precompiled shared object.

over 4 years ago · Santiago Trujillo Report

0

On Linux, there is a standard mechanism of injecting your code to a program. You basically define an encironment variable LD_PRELOAD that specifies a .so library that is loaded before all other .so files. Functions in that .so will replace standard versions of the functions. There is no need to modify the assembly code of fuctions manually to insert hooks to your own code like on windows.

Here is a nice tutorial: https://rafalcieslak.wordpress.com/2013/04/02/dynamic-linker-tricks-using-ld_preload-to-cheat-inject-features-and-investigate-programs/

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!