Search code examples
c++clinuxinject

Linux inject C/C++ dll


Ire any solutions available to inject in process own C/C++ dll and start from entrypoint, i need hook process socket send functions and paste my own code there. Is it available on linux?

Thanks!


Solution

  • The typical way to do it is to set the LD_PRELOAD environment variable before launching the program. See for example tsocks. Note though that some programs will disable this due to security reasons (it can snoop a passwords etc), e.g. gnupg prevents LD_PRELOAD from working.

    If you want to inject into a running program it's much more difficult. It can be done with ptrace (e.g. attach with gdb and call dlopen). But it's unreliable because you don't know what state the program is when you attach.