
A collection of samples and material related to process injection
A comprehensive collection of process injection techniques for Linux, demonstrating various methods of injecting code into running processes. These examples are intended for educational purposes, security research, and understanding low-level Linux process manipulation.
Process injection is a technique used to run code in the context of another process. While often associated with malware, these techniques are also valuable for:
Directory: ptrace/
The classic process injection method using the ptrace() system call to directly write shellcode into a process's memory and redirect execution.
Key Features:
Use Case: Understanding low-level process control and direct code injection
Directory: ld_preload/
Function interposition using the LD_PRELOAD environment variable to load a malicious library before any other libraries.
Key Features:
Use Case: Function hooking, API monitoring, behavior modification
Directory: proc_mem/
Direct memory writing through the /proc/<pid>/mem filesystem interface, combined with ptrace for process control.
Key Features:
Use Case: Fast bulk memory injection, bypassing traditional ptrace limitations
Directory: dlopen_inject/
Sophisticated technique that forces a running process to load a shared library by hijacking execution to call dlopen().
Key Features:
Use Case: Advanced persistent injection, runtime library manipulation
# Build ptrace injection
cd ptrace && make all
# Build LD_PRELOAD injection
cd ../ld_preload && make all
# Build /proc/mem injection
cd ../proc_mem && make all
# Build dlopen injection
cd ../dlopen_inject && make all
Each technique follows a similar pattern:
Start the victim process:
cd <technique>/victim-process
./sample
Note the PID displayed
Perform injection:
cd <technique>
sudo ./<injector> <PID> [additional args]
Observe results: Check victim process output for injected code execution
See individual README files for technique-specific instructions.
Yama ptrace_scope: Restrict ptrace to privileged users
echo 1 | sudo tee /proc/sys/kernel/yama/ptrace_scope
SELinux/AppArmor: Mandatory access controls
Monitoring: Use auditd to log ptrace and process injection attempts
auditctl -a exit,always -F arch=b64 -S ptrace
Runtime Integrity Checking: Periodically verify process memory
Code Signing: Verify library signatures
/proc/<pid>/maps for unexpected memory regions or librarieslsof, pmap, and process monitoring utilitiesIMPORTANT: These techniques should only be used in authorized contexts:
This repository is for educational and research purposes only. The authors are not responsible for misuse of these techniques. Always obtain proper authorization before testing on any system.
Permission denied errors:
sudo/proc/sys/kernel/yama/ptrace_scopeInjection fails silently:
Segmentation faults:
See individual technique READMEs for specific troubleshooting guidance.
Contributions are welcome! Potential additions:
man 2 ptrace - Process tracing system callman 5 proc - /proc filesystem documentationman 3 dlopen - Dynamic library loadingSee LICENSE.txt for details.
This software is provided "as is" for educational purposes. Use responsibly and ethically. Always obtain proper authorization before testing security techniques on any system you do not own.
| Technique | Complexity | Stealth | Persistence | Speed | Works on Running Process |
|---|
| ptrace | Medium | Low | No | Medium | Yes |
| LD_PRELOAD | Low | Very Low | No | Fast | No |
| /proc/mem | Medium | Low | No | Fast | Yes |
| dlopen | High | Medium | Yes | Medium | Yes |