Process Doppelgänging
Created the Saturday 23 March 2019. Updated 1 year, 2 months ago.
This technique leverages the Transactional NTFS
functionality in Windows. This functionality helps maintain data integrity during an unexpected error. For example, when an application needs to write or modify a file, if an error is triggered mid-write, the data can be corrupted. To avoid this kind of behavior, an application can open the file in a transactional mode to perform the modification, then commit the modification, avoiding any corruption. The modification either completes successfully or does not begin.
Process Doppelgänging abuses this functionality to overwrite a legitimate file with a malicious file, resulting in a process injection. The malicious file will be created inside a transaction then committed to the legitimate file, then executed.
Here are the detailed steps to reproduce the Process Doppelgänging technique:
-
Create a new transaction object using
NtCreateTransaction
and store the handle inhTransaction
. -
Open the target file for the transaction using
CreateFileTransacted
and store the handle inhTransactedFile
. -
Open the payload file using
CreateFile
and store the handle in hFile. -
Query the size of the payload file using
GetFileSizeEx
and store the result infsz
. -
Allocate a buffer for the payload file using
NtAllocateVirtualMemory
and store the pointer in Buffer. -
Read the payload file into the buffer using
ReadFile
. -
Close the handle to the payload file.
-
Set the size of the target file using
SetFileInformationByHandle
and theFileEndOfFileInfo
structure. -
Map the target file into memory using
NtMapViewOfSection
and store the result inMemoryPtr
. -
Copy the payload file from the buffer into the mapped memory using
RtlCopyMemory
. -
Unmap the target file from memory using
NtUnmapViewOfSection
. -
Commit the transaction using
NtCommitTransaction
. -
Create a new process using
NtCreateUserProcess
and store the handle inhProcess
. -
Allocate memory for the process parameters using
NtAllocateVirtualMemory
and store the result inProcessParameters
. -
Set the process parameters using
RtlCreateProcessParametersEx
. -
Create the process using
NtCreateSection
andNtMapViewOfSection
. -
Start the process using
NtCreateThreadEx
and store the handle inhThread
. -
Wait for the process to finish execution using
WaitForSingleObject
. -
Close the handle to the process and thread.
Technique Identifier
Featured Windows API's
Below, you will find a list of the most commonly used Windows API's that are currently utilized by malware authors for current evasion technique. This list is meant to provide an overview of the API's that are commonly used for this purpose. If there are any API's that you feel should be included on this list, please do not hesitate to contact us. We will be happy to update the list and provide any additional information or documentation that may be helpful.
Code Snippets
Additional Resources
External Links
The resources provided below are associated links that will give you even more detailed information and research on current evasion technique. It is important to note that, while these resources may be helpful, it is important to exercise caution when following external links. As always, be careful when clicking on links from unknown sources, as they may lead to malicious content.