Detect Ptrace System Calls in Splunk
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/
SPL Detection Query
index=linux sourcetype="linux:audit" type=SYSCALL syscall=101
| eval exe_name=mvindex(split(exe, "/"), -1)
| search NOT exe_name IN ("gdb", "strace", "ltrace", "valgrind", "perf", "dockerd", "containerd", "runc")
| eval ptrace_request=case(
a0="0", "PTRACE_TRACEME",
a0="1", "PTRACE_PEEKTEXT",
a0="2", "PTRACE_PEEKDATA",
a0="4", "PTRACE_POKETEXT",
a0="5", "PTRACE_POKEDATA",
a0="6", "PTRACE_CONT",
a0="10" OR a0="16", "PTRACE_ATTACH",
a0="11" OR a0="17", "PTRACE_DETACH",
a0="d" OR a0="13", "PTRACE_SETREGS",
a0="19" OR a0="25", "PTRACE_SEIZE",
1=1, "PTRACE_OTHER_" . a0
)
| eval InjectionIndicator=if(match(ptrace_request, "(POKETEXT|POKEDATA|SETREGS|ATTACH|SEIZE)"), "High - Write/Modify capability", "Low - Read-only operation")
| table _time, host, auid, uid, exe, pid, ptrace_request, a1, InjectionIndicator
| sort - _time Detects ptrace system calls via Linux auditd logs. Decodes the ptrace request type from the first argument (a0) to identify injection-relevant operations: PTRACE_ATTACH (attaching to a process), PTRACE_POKETEXT/POKEDATA (writing memory), and PTRACE_SETREGS (modifying register values including instruction pointer). Filters out legitimate debuggers and container runtimes.
Data Sources
Required Sourcetypes
False Positives & Tuning
- Developers using gdb/strace/ltrace for debugging
- Container runtimes using ptrace for namespace operations
- Performance profiling tools (perf, valgrind) using ptrace
- Security scanning tools performing process analysis via ptrace
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.