Ptrace System Calls
Adversaries may inject malicious code into processes via ptrace (process trace) system calls in order to evade process-based defenses as well as possibly elevate privileges. Ptrace system call injection involves attaching to and modifying a running process. The ptrace system call enables a debugging process to observe and control another process (and each individual thread), including changing memory and register values. Ptrace system call injection is commonly performed by writing arbitrary code into a running process (ex: malloc) then invoking that memory with PTRACE_SETREGS to set the register containing the next instruction to execute. Ptrace system call injection can also be done with PTRACE_POKETEXT/PTRACE_POKEDATA, which copy data to a specific address in the target processes' memory.
// Detect ptrace-based process injection on Linux endpoints
// Monitor for ptrace system calls from non-debugger processes
Syslog
| where TimeGenerated > ago(24h)
| where Facility == "authpriv" or Facility == "auth" or Facility == "kern"
| where SyslogMessage has "ptrace" or SyslogMessage has "PTRACE"
| where SyslogMessage !has "gdb" and SyslogMessage !has "strace" and SyslogMessage !has "ltrace"
| project TimeGenerated, Computer, SyslogMessage, Facility, SeverityLevel
| sort by TimeGenerated desc Data Sources
Required Tables
False Positives
- Software developers using gdb, strace, or ltrace for legitimate debugging
- Container runtime tools (Docker, containerd) using ptrace for process namespace management
- System administration tools performing ptrace for diagnostic purposes
- Security scanners and vulnerability assessment tools that ptrace processes for analysis
References (5)
- https://attack.mitre.org/techniques/T1055/008/
- http://man7.org/linux/man-pages/man2/ptrace.2.html
- https://medium.com/@jain.sm/code-injection-in-running-process-using-ptrace-d3ea7191a4be
- https://github.com/gaffe23/linux-inject/blob/master/slides_BHArsenal2015.pdf
- https://github.com/redcanaryco/atomic-red-team/blob/master/atomics/T1055.008/T1055.008.md
Unlock Pro Content
Get the full detection package for T1055.008 including response playbook, investigation guide, and atomic red team tests.