Skip to content

Latest commit

 

History

History
117 lines (83 loc) · 6.42 KB

T1055.md

File metadata and controls

117 lines (83 loc) · 6.42 KB

T1055 - Process Injection

Process injection is a method of executing arbitrary code in the address space of a separate live process. 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 process injection may also evade detection from security products since the execution is masked under a legitimate process.

Windows

There are multiple approaches to injecting code into a live process. Windows implementations include: (Citation: Endgame Process Injection July 2017)

  • Dynamic-link library (DLL) injection involves writing the path to a malicious DLL inside a process then invoking execution by creating a remote thread.
  • Portable executable injection involves writing malicious code directly into the process (without a file on disk) then invoking execution with either additional code or by creating a remote thread. The displacement of the injected code introduces the additional requirement for functionality to remap memory references. Variations of this method such as reflective DLL injection (writing a self-mapping DLL into a process) and memory module (map DLL when writing into process) overcome the address relocation issue. (Citation: Endgame HuntingNMemory June 2017)
  • Thread execution hijacking involves injecting malicious code or the path to a DLL into a thread of a process. Similar to Process Hollowing, the thread must first be suspended.
  • Asynchronous Procedure Call (APC) injection involves attaching malicious code to the APC Queue (Citation: Microsoft APC) of a process's thread. Queued APC functions are executed when the thread enters an alterable state. A variation of APC injection, dubbed "Early Bird injection", involves creating a suspended process in which malicious code can be written and executed before the process' entry point (and potentially subsequent anti-malware hooks) via an APC. (Citation: CyberBit Early Bird Apr 2018) AtomBombing (Citation: ENSIL AtomBombing Oct 2016) is another variation that utilizes APCs to invoke malicious code previously written to the global atom table. (Citation: Microsoft Atom Table)
  • Thread Local Storage (TLS) callback injection involves manipulating pointers inside a portable executable (PE) to redirect a process to malicious code before reaching the code's legitimate entry point. (Citation: FireEye TLS Nov 2017)

Mac and Linux

Implementations for Linux and OS X/macOS systems include: (Citation: Datawire Code Injection) (Citation: Uninformed Needle)

  • LD_PRELOAD, LD_LIBRARY_PATH (Linux), DYLD_INSERT_LIBRARIES (Mac OS X) environment variables, or the dlfcn application programming interface (API) can be used to dynamically load a library (shared object) in a process which can be used to intercept API calls from the running process. (Citation: Phrack halfdead 1997)
  • Ptrace system calls can be used to attach to a running process and modify it in runtime. (Citation: Uninformed Needle)
  • /proc/[pid]/mem provides access to the memory of the process and can be used to read/write arbitrary data to it. This technique is very rare due to its complexity. (Citation: Uninformed Needle)
  • VDSO hijacking performs runtime injection on ELF binaries by manipulating code stubs mapped in from the linux-vdso.so shared object. (Citation: VDSO hijack 2009)

Malware commonly utilizes process injection to access system resources through which Persistence and other environment modifications can be made. More sophisticated samples may perform multiple process injections to segment modules and further evade detection, utilizing named pipes or other inter-process communication (IPC) mechanisms as a communication channel.

Atomic Tests


Atomic Test #1 - Process Injection via mavinject.exe

Windows 10 Utility To Inject DLLS

Supported Platforms: Windows

Inputs

Name Description Type Default Value
dll_payload DLL to Inject Path C:\AtomicRedTeam\atomics\T1055\src\x64\T1055.dll
process_id PID of input_arguments Int $pid

Run it with powershell!

mavinject $pid /INJECTRUNNING #{dll_payload}


Atomic Test #2 - Process Injection via PowerSploit

PowerShell Injection using PowerSploit Invoke-DLLInjection

Supported Platforms: Windows

Inputs

Name Description Type Default Value
dll_payload DLL to Inject Path T1055.dll
process_id PID of input_arguments Int $pid

Run it with powershell!

Invoke-DllInjection.ps1 -ProcessID #{process_id} -Dll #{dll_payload}


Atomic Test #3 - Shared Library Injection via /etc/ld.so.preload

This test adds a shared library to the ld.so.preload list to execute and intercept API calls. This technique was used by threat actor Rocke during the exploitation of Linux web servers. This requires the glibc package.

Supported Platforms: Linux

Inputs

Name Description Type Default Value
path_to_shared_library Path to a shared library object Path /tmp/evil_module.so

Run it with bash!

echo #{path_to_shared_library} > /etc/ld.so.preload


Atomic Test #4 - Process Injection via C#

Process Injection using C# reference: https://github.com/pwndizzle/c-sharp-memory-injection Excercises Five Techniques

  1. Process injection
  2. ApcInjectionAnyProcess
  3. ApcInjectionNewProcess
  4. IatInjection
  5. ThreadHijack

Supported Platforms: Windows

Inputs

Name Description Type Default Value
exe_binary Output Binary Path T1055.exe

Run it with command_prompt!

.\bin\#{exe_binary}