Detect Ptrace System Calls in Google Chronicle
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/
YARA-L Detection Query
rule linux_ptrace_injection_t1055_008 {
meta:
author = "Detection Engineering"
description = "Detects ptrace syscalls with write or attach capability on Linux endpoints indicating process injection - T1055.008"
mitre_attack_technique = "T1055.008"
mitre_attack_tactic = "Defense Evasion, Privilege Escalation"
severity = "HIGH"
confidence = "MEDIUM"
reference = "https://attack.mitre.org/techniques/T1055/008/"
events:
// Chronicle normalizes Linux auditd PTRACE_ATTACH and PTRACE_SEIZE events
// to PROCESS_OPEN in UDM when the Linux forwarder parses auditd SYSCALL records
$e.metadata.event_type = "PROCESS_OPEN"
$e.principal.process.pid > 0
$e.target.process.pid > 0
$e.principal.process.pid != $e.target.process.pid
$e.principal.asset.platform_software.platform = "LINUX"
$e.principal.process.file.full_path != ""
not re.regex(
$e.principal.process.file.full_path,
`/(gdb|strace|ltrace|valgrind|perf|dockerd|containerd|runc|lldb|py-spy|rbspy)$`
)
condition:
$e
} Chronicle YARA-L 2.0 rule detecting ptrace-based process injection on Linux by matching PROCESS_OPEN UDM events where a non-debugger principal process opens or attaches to a distinct target process. Chronicle's Linux auditd parser normalizes PTRACE_ATTACH and PTRACE_SEIZE syscall records from auditd SYSCALL type events into PROCESS_OPEN UDM event type, populating principal.process (attacker) and target.process (victim) fields. Name-based exclusions filter known legitimate debuggers via regex on the full executable path.
Data Sources
Required Tables
False Positives & Tuning
- Legitimate profiling tools (e.g., py-spy, rbspy, async-profiler) that attach to running processes for performance analysis and are installed under unexpected paths
- Service mesh sidecar or observability agents (e.g., eBPF-based tools with ptrace fallback) performing process enumeration or metric collection
- Kubernetes ephemeral debug containers or kubectl debug sessions that invoke ptrace-based attach operations against pods on the same node
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.