-
Notifications
You must be signed in to change notification settings - Fork 86
Home
Process Overwriting is a process impersonation (PE injection) technique, closely related to Process Hollowing and Module Overloading.
With its help, you can replace the main executable (not a DLL) of the target process.
It works only for a newly created process - injection to existing processes is not supported with this technique.
WARNING: The size of the target image must be NOT SMALLER than the size of the payload image.
The payload is mapped as MEM_IMAGE, each of its section has appropriate rights set. The name of the image points to the original file of the target.

Yes. See the video: https://youtu.be/sZ8tMwKfvXw
Process Hollowing (aka RunPE) is an old and popular PE injection technique. It comes in has variety of flavors, but there are some steps in common:
- Start by creating a process in a suspended state
- Write our own PE module in its memory
- Redirect to the new module
- Resume the thread
Process Hollowing does not require manual loading of payload's imports. Thanks to the step 3 Windows loader treat our PE implant as the main module of the process, and will load imports automatically when its execution resumes.
To make our implant recognized by Windows loader, its Module Base must be set in the PEB. It is usually done by one of the two ways:
- in the most classic variant, the original PE is unmapped from memory, and the new PE is mapped on its place, at the same address.
- in another, yet common variant, the old module is left as is, and another PE is mapped in a new memory region. Then the new module's base address is manually written into the PEB (this variant was demonstrated here)
As a result of those classic implementations we get a payload running as main module, yet it is mapped as MEM_PRIVATE (not as MEM_IMAGE like typically loaded PEs).
To obtain payload mapped as MEM_IMAGE we can use some closely related techniques, such as Transacted Hollowing or its variant "Ghostly Hollowing".
Process Overwriting is yet another take on solving this problem.
In contrast to the classic Process Hollowing, we are not unmapping the original PE, but writing over it. No new memory is allocated: we are using the memory that was originally allocated for the main module of the process.
Pros:
- the implanted PE looks like if it was loaded by Windows loader:
- mapped as
MEM_IMAGE - divided into sections with specific access rights
- the image is named
- mapped as
- convenience of loading:
- no need to manually relocate the implant prior to injection: Windows loader will take care of this (in classic Process Hollowing we have to relocate the module)
- no need to fill imports (like in every variant of Process Hollowing)
- no need to allocate new memory in the process
Cons:
- It doesn't work if the target has GFG (Control Flow Guard) enabled (yet it is possible to disable it on process creation)
- The target's ImageSize must not be smaller than payload's ImageSize (remember we are using only the memory that was already allocated!) - this limitation does not occur in other flavors of Process Hollowing
- Can be detected by comparing of the module in memory with corresponding file (PE-sieve detects it) - just like every variant of Process Hollowing
Process Herpaderping is another process impersonation technique, that can be used as a replacement of Process Hollowing. Yet, its mechanics is very different than Process Overwriting.
Process Herpaderping can be grouped together with the techniques such as Process Doppleganging, and Process Ghosting. They all rely on first creating a section, and then creating a process from this section (using NtCreateProcessEx API). What differs between them is, how do they obfuscate the fact that the file the process was created from is in fact a malicious executable.
Process Herpaderping:
- creates a file, writes a malicious payload into it, keeps a handle open
- creates a section from the file
- creates an inactive process from the section (using
NtCreateProcessEx) - modifies the file, overwriting it with a benign content
- creates the first thread within the process (using
NtCreateThreadEx), making the payload run using the previous, cached content of the file
In case of Process Overwriting, the APIs used are more like in case of the original Process Hollowing. The process is created by the classic, higher-level API, and loaded from the target's file. The payload is never written into a file, but written over the already loaded image.
Process Overwriting:
- creates a suspended process from a benign file (with CFG disabled)
- maps the payload in memory, and writes it over the originally mapped image (without unmapping of the original image)
- updates the entry point of the process to the entry point of the payload
- resumes the process, executing the replaced PE
Both techniques allow to map a payload as MEM_IMAGE. Yet, only in case of Process Overwriting the payload is mapped as a named image - so, exactly as the normal PE would be mapped.