T1055.008 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 is a method of executing arbitrary code in the address space of a separate live process.
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.1 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 (ex: the current address of the next instruction). 12
Ptrace system call injection may not be possible targeting processes that are non-child processes and/or have higher-privileges.3
Running code in the context of another process may allow access to the process’s memory, system/network resources, and possibly elevated privileges. Execution via ptrace system call injection may also evade detection from security products since the execution is masked under a legitimate process.
Item | Value |
---|---|
ID | T1055.008 |
Sub-techniques | T1055.001, T1055.002, T1055.003, T1055.004, T1055.005, T1055.008, T1055.009, T1055.011, T1055.012, T1055.013, T1055.014, T1055.015 |
Tactics | TA0005, TA0004 |
Platforms | Linux |
Version | 1.1 |
Created | 14 January 2020 |
Last Modified | 18 October 2021 |
Mitigations
ID | Mitigation | Description |
---|---|---|
M1040 | Behavior Prevention on Endpoint | Some endpoint security solutions can be configured to block some types of process injection based on common sequences of behavior that occur during the injection process. |
M1026 | Privileged Account Management | Utilize Yama (ex: /proc/sys/kernel/yama/ptrace_scope) to mitigate ptrace based process injection by restricting the use of ptrace to privileged users only. Other mitigation controls involve the deployment of security kernel modules that provide advanced access control and process restrictions such as SELinux, grsecurity, and AppArmor. |
Detection
ID | Data Source | Data Component |
---|---|---|
DS0009 | Process | OS API Execution |
References
-
Kerrisk, M. (2020, February 9). PTRACE(2) - Linux Programmer’s Manual. Retrieved February 21, 2020. ↩↩
-
Jain, S. (2018, July 25). Code injection in running process using ptrace. Retrieved February 21, 2020. ↩
-
Colgan, T. (2015, August 15). Linux-Inject. Retrieved February 21, 2020. ↩
-
Ligh, M.H. et al.. (2014, July). The Art of Memory Forensics: Detecting Malware and Threats in Windows, Linux, and Mac Memory. Retrieved December 20, 2017. ↩
-
GNU. (2010, February 5). The GNU Accounting Utilities. Retrieved December 20, 2017. ↩
-
Jahoda, M. et al.. (2017, March 14). redhat Security Guide - Chapter 7 - System Auditing. Retrieved December 20, 2017. ↩
-
stderr. (2014, February 14). Detecting Userland Preload Rootkits. Retrieved December 20, 2017. ↩