ProcessGhosting π»
A Rust implementation of the Process Ghosting technique by BlackTechX
Process Ghosting is an advanced code execution technique that allows running executable code without leaving traces on the filesystem. This library provides a safe, easy-to-use Rust API for implementing this technique.
π Table of Contents
- What is Process Ghosting?
- How It Works
- Technical Deep Dive
- Installation
- Quick Start
- API Reference
- Examples
- Hex Utilities
- Architecture Support
- Building
- Security Considerations
- Credits
- License
π» What is Process Ghosting?
Process Ghosting is a technique discovered by Gabriel Landau at Elastic Security. It exploits the Windows file system and process creation mechanisms to execute code from a file that no longer exists on disk.
Key Features
| Feature | Description |
|---|---|
| π Fileless Execution | Payload file is deleted before process starts |
| π΅οΈ Anti-Forensics | No file remains on disk for security tools to scan |
| π‘οΈ Evasion | Bypasses many file-based security products |
| π€ Stealth | Process appears to run from a legitimate path |
| π¦ Pure Rust | Safe, fast, and memory-efficient implementation |
| π¦ Easy API | Simple builder pattern for configuration |
π¬ How It Works
Process Ghosting exploits the Windows NT kernel's handling of delete-pending files:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PROCESS GHOSTING FLOW β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββ
β START β
ββββββββ¬ββββββββ
β
βΌ
βββββββββββββββββββββββββ
β 1. Create temp file β
βββββββββββββ¬ββββββββββββ
β
βΌ
ββββββββββββββββββββββββββ
β 2. Set delete-pending β
β (NtSetInformationFile) β
βββββββββββββ¬βββββββββββββ
β
βΌ
βββββββββββββββββββββββββ
β 3. Write PE payload β
β to the file β
βββββββββββββ¬ββββββββββββ
β
βΌ
βββββββββββββββββββββββββ
β 4. Create SEC_IMAGE β
β section from file β
βββββββββββββ¬ββββββββββββ
β
βΌ
βββββββββββββββββββββββββ
β 5. Close file handle β
β β οΈ FILE DELETED! β οΈ β
βββββββββββββ¬ββββββββββββ
β
βΌ
βββββββββββββββββββββββββ
β 6. Create process β
β from the section β
βββββββββββββ¬ββββββββββββ
β
βΌ
βββββββββββββββββββββββββ
β 7. Setup PEB and β
β process parameters β
βββββββββββββ¬ββββββββββββ
β
βΌ
βββββββββββββββββββββββββ
β 8. Create thread at β
β entry point β
βββββββββββββ¬ββββββββββββ
β
βΌ
RUNNING
(No file! π»)
The Magic Explained
- Delete-Pending State: When a file is marked for deletion but still has an open handle, it enters a "delete-pending" state
- Section Creation: Windows allows creating an image section from a delete-pending file
- File Deletion: Once we close the file handle, the file is deleted from disk
- Process Creation: The section (now without a backing file) can still be used to create a process
π§ Technical Deep Dive
NT API Functions Used
| Function | Purpose |
|---|---|
NtOpenFile |
Open temp file with DELETE permission |
NtSetInformationFile |
Mark file as delete-pending |
NtCreateSection |
Create SEC_IMAGE section |
NtCreateProcessEx |
Create process from section |
NtQueryInformationProcess |
Get PEB address |
RtlCreateProcessParametersEx |
Create process parameters |
NtAllocateVirtualMemory |
Allocate memory in target |
NtWriteVirtualMemory |
Write parameters to target |
NtCreateThreadEx |
Start execution |
RtlImageNtHeader |
Parse PE headers |
Memory Layout
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β TARGET PROCESS MEMORY β
βββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββ β
β β MAPPED PE IMAGE β β
β ββββββββββββββββββββββββββββββββββββββββββββββββ€ β
β β DOS Header (MZ) β β
β β NT Headers β β
β β ββ OptionalHeader.AddressOfEntryPoint βββββΌββΌβββΊ Entry Point
β β Section Headers β β
β ββββββββββββββββββββββββββββββββββββββββββββββββ€ β
β β .text (Code) βββ Execution starts β β
β β .rdata (Read-only data) β β
β β .data (Initialized data) β β
β β .rsrc (Resources) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββ β
β β PEB β β
β β ββ ImageBaseAddress β β
β β ββ ProcessParameters | |
β ββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βββββββββββββββββββββββββββββββββββββΌβββββββββββ β
β β RTL_USER_PROCESS_PARAMETERS β β
β β ImagePathName: C:\Windows\System32\svchost β β
β β CommandLine: svchost.exe β β
β β Environment: ... β β
β ββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
Comparison with Other Techniques
| Technique | File on Disk During Execution | Detectable by File Scan | Complexity |
|---|---|---|---|
| Process Ghosting | β No | β No | βββ |
| Process Hollowing | β Yes (legitimate) | β οΈ Maybe | ββ |
| Process DoppelgΓ€nging | β No | β No | ββββ |
| DLL Injection | β Yes | β Yes | ββ |
| Reflective Loading | β No | β οΈ Memory scan | βββ |
π¦ Installation
Add to your Cargo.toml:
[]
= "0.1"
Or using cargo:
π Quick Start
Method 1: From File
use ;
Method 2: From Bytes
use GhostingBuilder;
Method 3: From Hex String
use GhostingBuilder;
Method 4: Embedded at Compile Time
use GhostingBuilder;
const PAYLOAD: & = include_bytes!;
Method 5: Quick Functions
use ;
π API Reference
GhostingBuilder
Main builder for configuring process ghosting operations.
// Creation methods
new // Configuration methods
.x64 // Target x64 (default)
.x86 // Target x86
.architecture // Set architecture
.with_logging // Enable verbose output
.silent // Disable all output
.verbose // Set verbosity
// Execution
.build // Get configuration
.execute // Execute ghosting
Quick Functions
// Execute with defaults (x64, verbose)
ghost_payload // Execute from file
ghost_payload_file // Execute from hex string
ghost_payload_hex // Execute with architecture
ghost_payload_arch
Architecture Enum
π’ Hex Utilities
Convert EXE to Hex
use ;
// Get as string: "0x4D, 0x5A, 0x90, ..."
let hex = exe_to_hex_string?;
// Print formatted for Rust code
print_exe_hex?;
// Output:
// const PAYLOAD: &[u8] = &[
// 0x4D, 0x5A, 0x90, 0x00, ...
// ];
Parse Hex Strings
All formats supported:
use parse_hex_string;
// Continuous
parse_hex_string?;
// Space-separated
parse_hex_string?;
// C-style
parse_hex_string?;
// Escaped
parse_hex_string?;
Utility Functions
// Read file as bytes
read_exe_bytes // Convert bytes to hex string
bytes_to_hex_string // Convert file to formatted array
exe_to_hex_array
π Examples
Run Examples
# Basic usage
# From file with path argument
# Convert EXE to hex
# Full demo
Example: Basic Usage
use ;
Example: Silent Execution
use GhostingBuilder;
Example: Error Handling
use GhostingBuilder;
ποΈ Architecture Support
| Architecture | Status | Method |
|---|---|---|
| x64 (AMD64) | β Supported | .x64() (default) |
| x86 (i386) | β Supported | .x86() |
| ARM64 | β Not yet | - |
π¨ Building
# Debug build
# Release build
# Build for 32-bit
# Build for 64-bit
# Run tests
# Build docs
β οΈ Security Considerations
Intended Use Cases
- β Security research
- β Red team operations
- β Penetration testing (authorized)
- β Malware analysis
- β Educational purposes
Prohibited Uses
- β Unauthorized system access
- β Malware deployment
- β Any illegal activities
Legal Disclaimer
This software is provided for educational and authorized security research purposes only. The author is not responsible for any misuse. Users must ensure compliance with all applicable laws.
π Credits
- Gabriel Landau (Elastic Security) - Original Process Ghosting research.
- Offensive Panda (Github: @offensive-panda) - Process Ghosting in c.
- BlackTechX - Rust implementation
π License
MIT License - See LICENSE file.