This is an experiment, to create a test tool for a client in security
business…
OS, Win 7 x86 (or others as well, but lets stick to this) all service packs
installed (doesnt matter)
what I am trying to do:
inject memory into another process, in this case always notepad.exe
Logic used:
- OpenProcess API used to open a running notepad.exe (we are admin)
- once we get HPROCESS use that to do a virtualAllocEx inside notepad’s
address space.
VirtualAllocEx is called with the lpAddress = NULL. - Using getprocaddress grab the address of NtWriteVirtualMemory and then
write to the memory returned by VirtualAllocEx.
All work fine. I am able to over write the memory I created. However
something isnt right, hence this thread.
After a successful over write (this is what the security software is
supposed to stop, in this case it is disabled and hence the overwrite is
possible) we use TerminateProcess api to kill notepad. It should have died,
but it doesnt. TerminateProcess is async, so it returns immidiately (after
scheduling an APC) so we wait on it.
What we see is that notepad stays alive a long time, like a real long time
(10 mins).
I did some initial debugging, my hunch was the apc isnt being dleivered to
notepad, probably because the process is corrupted or it is waiting for
something (lock? event?) in the kernel.
Win7 x86 (this is why i said lets stick to this os for the time) notepad
proces is a single threaded app (I dont know why a GUI app will be single
threaded, looks like notepad is really rudimentary), if my assumption that
we corrupted the thread in the injection process was rght then the process
should have crashed, thrown an exception or some thing of hte sort, but the
process is fine, in fact if I press the close icon (X) it shuts down
immediately, but TerminateProcess doesnt respond. that leads to the second
assumption is it waiting in the kernel? if so on what?
i havent debugged this entirely yet, but before i dig into it wanted to
know if we are doing something obviously wrong, it shouldnt be as this is a
simple enough case.
the other question is, when calling virtualallocex with the second param as
null, does it allocate memory pages i na region which is somehow
unstabelizing the process? If so I do not understand how the (X) icon
closes it, because that will post a WM_QUIT and if the main thread is
themessage processor (since tehre is one thread) and that is hung/corrupt
then it doesnt explain that…
any ideas?
-Al