Pentesting Tools

Process Ghosting In Rust : Crafting Evasive Applications On Windows

Process ghosting is a sophisticated technique used to evade detection by security tools on Windows systems.

It involves creating a temporary file, marking it for deletion, and then executing its contents from memory without leaving a persistent file on disk.

This method allows malicious code to run undetected, as traditional security software often relies on scanning files on disk.

How Process Ghosting Works

  1. File Creation and Deletion: A temporary file is created using Windows API functions like NtCreateFile. The file is immediately marked for deletion using NtSetInformationFile, placing it in a delete-pending state. This prevents external access to the file while it is being manipulated.
  2. Mapping to Memory: The file’s contents are mapped into memory as an image section. This step is crucial because it allows the file’s data to be executed without needing a physical file presence.
  3. Process Creation: A new process is created from the in-memory image section. Since the original file is deleted, the process appears without an associated executable file, making detection challenging.
  4. Execution: A thread is created within the new process to execute the mapped code. This execution happens after the file has been deleted, ensuring that security tools cannot scan the file.

Implementing Process Ghosting in Rust

Rust provides a robust environment for implementing process ghosting due to its low-level memory management capabilities and compatibility with Windows APIs.

The Whitecat18/Rust-for-Malware-Development repository includes a Rust implementation of process ghosting, demonstrating how to leverage Rust’s features for such advanced techniques.

To implement process ghosting in Rust, you would typically use the winapi crate to interact with Windows system calls. Here’s a simplified example of how you might start:

rustuse winapi::shared::minwindef::{DWORD, HANDLE};
use winapi::um::fileapi::{CreateFileA, DeleteFileA};
use winapi::um::memoryapi::{CreateFileMappingA, MapViewOfFile};
use winapi::um::processthreadsapi::{CreateProcessA, CreateThread};

fn main() {
    // Step 1: Create a file
    let file_handle = unsafe {
        CreateFileA(
            b"C:\\path\\to\\file.exe\0".as_ptr() as *const i8,
            0x40000000, // GENERIC_WRITE
            0,
            std::ptr::null_mut(),
            2, // CREATE_ALWAYS
            0,
            std::ptr::null_mut(),
        )
    };

    // Step 2: Mark for deletion
    // Use NtSetInformationFile to set delete-pending state

    // Step 3: Map file to memory
    let file_mapping_handle = unsafe { CreateFileMappingA(file_handle, std::ptr::null(), 0x04, 0, 0, std::ptr::null()) };
    let view = unsafe { MapViewOfFile(file_mapping_handle, 0x001F0001, 0, 0, 0) };

    // Step 4: Create process from mapped memory
    // Use CreateProcessA with STARTUPINFO and PROCESS_INFORMATION

    // Step 5: Execute the process
    // Use CreateThread to start execution
}

This example is simplified and focuses on key steps. For a complete implementation, you would need to handle errors, manage memory, and ensure proper cleanup.

Process ghosting in Rust demonstrates how advanced evasion techniques can be implemented using modern programming languages.

By leveraging Rust’s capabilities for low-level system interactions, developers can create sophisticated tools that challenge traditional security measures.

However, such techniques should be used responsibly and ethically, focusing on improving security rather than compromising it.

Varshini

Varshini is a Cyber Security expert in Threat Analysis, Vulnerability Assessment, and Research. Passionate about staying ahead of emerging Threats and Technologies.

Recent Posts

Playwright-MCP : A Powerful Tool For Browser Automation

Playwright-MCP (Model Context Protocol) is a cutting-edge tool designed to bridge the gap between AI…

2 weeks ago

JBDev : A Tool For Jailbreak And TrollStore Development

JBDev is a specialized development tool designed to streamline the creation and debugging of jailbreak…

2 weeks ago

Kereva LLM Code Scanner : A Revolutionary Tool For Python Applications Using LLMs

The Kereva LLM Code Scanner is an innovative static analysis tool tailored for Python applications…

2 weeks ago

Nuclei-Templates-Labs : A Hands-On Security Testing Playground

Nuclei-Templates-Labs is a dynamic and comprehensive repository designed for security researchers, learners, and organizations to…

2 weeks ago

SSH-Stealer : The Stealthy Threat Of Advanced Credential Theft

SSH-Stealer and RunAs-Stealer are malicious tools designed to stealthily harvest SSH credentials, enabling attackers to…

2 weeks ago

ollvm-unflattener : A Tool For Reversing Control Flow Flattening In OLLVM

Control flow flattening is a common obfuscation technique used by OLLVM (Obfuscator-LLVM) to transform executable…

2 weeks ago