Detect Ptrace System Calls in Elastic Security
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.
MITRE ATT&CK
- Technique
- T1055 Process Injection
- Sub-technique
- T1055.008 Ptrace System Calls
- Canonical reference
- https://attack.mitre.org/techniques/T1055/008/
Elastic Detection Query
process where host.os.type == "linux"
and event.module == "auditd"
and auditd.data.syscall == "ptrace"
and auditd.data.a0 in ("4", "5", "d", "10", "13", "16", "19", "25")
and not process.name in ("gdb", "strace", "ltrace", "valgrind", "perf", "dockerd", "containerd", "runc", "java", "py-spy") Detects ptrace system calls on Linux with write/modify-capable request types (PTRACE_POKETEXT=0x4, PTRACE_POKEDATA=0x5, PTRACE_SETREGS=0xd/0x13, PTRACE_ATTACH=0x10/0x16, PTRACE_SEIZE=0x19/0x25) from non-legitimate debugger processes. Uses Elastic Auditd integration which resolves syscall numbers and captures the a0 argument in hex. Covers the primary injection primitives that allow an attacker to write shellcode into or redirect execution within a target process.
Data Sources
Required Tables
False Positives & Tuning
- Legitimate debuggers or IDE debug adapters installed to non-standard paths not matched by name exclusions (e.g., lldb, delve, rr, code-server debug shims)
- JVM-based APM agents using the Attach API (com.sun.tools.attach) which internally uses ptrace on older kernel versions
- Third-party EDR or AV agents that use ptrace for process introspection, memory scanning, or behavioral monitoring
Other platforms for T1055.008
Testing Methodology
Validate this detection against 3 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are available with Pro.
- Test 1Ptrace Attachment via strace
Expected signal: auditd: SYSCALL type with syscall=101, a0=16 (PTRACE_ATTACH), a1=<target_pid>, exe=/usr/bin/strace. /proc/<target_pid>/status will show TracerPid=<strace_pid> while attached.
- Test 2Ptrace Memory Read via /proc/pid/mem
Expected signal: auditd: open() syscall on /proc/<pid>/maps. If ptrace is used: SYSCALL with syscall=101. The /proc/pid/maps read itself may be logged by auditd file access rules.
- Test 3Check ptrace_scope Kernel Setting
Expected signal: No security telemetry — this is a configuration check. The output shows the current ptrace restriction level.
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.