This article is part 5 of a 5 parts series on process injection on Linux.
Injection facilities¶
ptrace/proc/<pid>/mem,/proc/self/memprocess_vm_writev(does not have "punch through" capability)
Related facilities:
brk/sbrkexecve/fexecvememfd_createmlockmmapmprotectprocess_vm_readvshm_open
Persistence¶
cloneforksetitimersigactionsignaltimer_create- GOT/PLT hooking
- vDSO
Memory destinations¶
- allocated memory;
- code caves;
- overwritten code/data.
Prevention¶
kernel.yama.ptrace_scope- SELinux:
execmem,execheap,execstack,deny_ptrace - AppArmor
- Secure Computing (seccomp)
prctl/PR_SET_DUMPABLERELROandBINDOWlinking flags
Detection¶
auditdusing a ruleset with good coverage and, ideally, a filtering/search tool.
Forensics¶
Indicators¶
/proc/<pid>/statusto inspect signals and tracee status/proc/<pid>/exepointing to memory-backed file/proc/<pid>/fd/for memory-backed files/proc/<pid>/mapsfor non-file-backed executable memory regions/proc/<pid>/tasks/to list threads/proc/<pid>/tasks/childrento list children processes/dev/shmand other in-memory file systems (mount -t tmpfs)
Analysis¶
ptraceto dump the process or trace its behavior/proc/<pid>/memto dump a process's memory/proc/<pid>/exeto get a process's original program