Open SvarunSoda opened 1 month ago
Personally, I don't see how this is a phnt issue. Either way add suspended flag and debug the cloned process?
However, it appears that the example above, and other examples present in the cloning tutorial linked above, do not work properly in any x86 configuration. Attempting to run the example above in any x86 configuration results in only the parent process printing it's output:
Windows processes/subsystem shares objects and addresses with win32k, csrss, drivers and the kernel and caches addresses for these objects but the ntdll 'clone' functions are only duplicating kernel objects - they don't duplicate win32k, csrss etc... especially these days with ASLR
The wow64 subsystem introduces another layer of address/object caching used for thunking calls and other objects into 64bit types and structures.
The C and C++ runtimes also cache addresses and other objects...
There are only two supported cases for cloning on Windows:
1) The clone functions can only be used for creating snapshots while debugging: https://github.com/winsiderss/systeminformer/blob/44917dc744d8f3cc848341bc80cd250df469d663/phlib/util.c#L8403-L8590
2) The clone functions can only safely execute processes when used with an image compiled with the Native subsystem as they doesn't have dependencies on components like win32k and csrss:
I'm attempting to clone a process in C++ on Windows. All shown examples were compiled & ran with Visual Studio 2022 on a Windows 10 system.
The minimal example below (adapted from the following tutorial on process cloning in Windows) uses the
NtCreateUserProcess
function from thisphnt
library in order to perform the process clone, smillar to the Unixfork
function:The example above can successfully clone a process in the
x64
configuration in my VS instance:However, it appears that the example above, and other examples present in the cloning tutorial linked above, do not work properly in any
x86
configuration. Attempting to run the example above in anyx86
configuration results in only the parent process printing it's output:The child process appears to terminate & return successfully, but it fails to print it's output.
The same behaviour is exhibited with the following slightly different example using the
RtlCloneUserProcess
function, also from this library:Also only printing the parent process's output when running in the
x86
configuration.I'm assuming that I'm missing some include files specifically for building these examples in the
x86
configuration. The only additional include directory I have setup in these VS example projects is thephnt
library, and below is the list of libraries included by the Linker (copied from the official examples):Has anyone else encountered simillar issues with the
NtCreateUserProcess
andRtlCloneUserProcess
functions from this library when attempting to clone a Windows process in thex86
configuration?Thanks for reading my post, any guidance is appreciated.