xxxxx@valhallalegends.com wrote:
Well, what would you propose that CreateProcessAsUser is supposed to do
if it discovers that it can’t finish preparing the new process to run, but
access
to terminate it has been revoked silently (even though CreateProcessAsUser
itself expects that it has obtained terminate access)?
Hi Ken,
Yeah it’s a tricky one, as you say there’s no one-stop solution. I guess a
good start would be checking the return of TerminateProcess and not calling
waiting on the process handle. At least we’d only have a suspended process
and not a hung parent thread.
However one idea could be, assuming the terminate error was ACCESS_DENIED,
to hand off the terminate job to the system process. At least that would
give the OS a chance to clean up in this scenario. Anyone blocking system
from terminating processes would be clearly have a very bad design.
The other option is to add a big note to the sample code, saying “this code
will cause hangs”, or preferably just remove it entirely from the WDK
samples.
Incidentally, the hang can be fixed by resuming the hung processes, which
gives you a halfplemented processes, but one that is killable via the GUI.
At least this resolves the hang and zombie.
xxxxx@broadcom.com wrote:
The thing is, you’re not the first here to pop up with the question
“how do I make a process unkillable”
I didn’t pop up with that question. In fact, I didn’t ask any question at
all. You’re assuming I have a problem, and you’re assuming you have the
correct fix. Neither of those assumptions are correct. For the record,
you’ll be pleased to know that if I were trying to do what you suggest, I
would likely be using DACLs (and a mini-filter to block ownership changes).
This also prevents DLL injection and hook installation
Yep, amongst other things. Interestingly, you can also prevent these things
by stripping rights.
Handle duplication, VM read/write, remote thread termination,
getting/setting thread context, assigning/terminating job objects. They can
all be avoided with stripping handle rights. I’m not saying it’s the correct
solution, and I’m not asking for help or ratification, I’m just saying it’s
possible and Microsoft provide documented APIs to help you do it 
xxxxx@hotmail.com wrote:
> To be fair, you don’t know what problem I’m trying to solve,
Well, let me guess…probably, just writing malware, right.
No!. If I was writing malware, I’d just make the process undetectable, not
unkillable.
Search this list for more info and see how posters who ask
questions like that are generally treated here.
I’m well aware, I’ve been reading this list (well, I’m normally on ntfsd)
daily for the last 15 years… In fact from back in the day when Ken used
to work in open source 
Look, I haven’t turned up asking any questions. I haven’t requested hints or
pointers on how to stop processes from being killed. I’m certainly not a
malware writer, I write enterprise software for multi-billion dollar
industries, and have done for a looong time.
I just wrote a mail to point out an issue I found when doing some research.
An issue that hadn’t been documented before on this list, and an issue that
Microsoft themselves exhibit in their own sample code. It’s a bit of a sad
day when you try to post something helpful to the list and get shot down for
being a malware writer.
Ged.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Skywing
Sent: 09 October 2016 22:06
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Removing PROCESS_TERMINATE flag causes hang
Well, what would you propose that CreateProcessAsUser is supposed to do if
it discovers that it can’t finish preparing the new process to run, but
access to terminate it has been revoked silently (even though
CreateProcessAsUser itself expects that it has obtained terminate access)?
There are a number of reasons why this may happen, including (but not
limited to) elevation required. It is not necessarily reasonable to account
for them all up front, as some operations may need to be done on the new
process once it is created (and which could fail due to e.g. low resources).
This is a classic, fundamental problem with filters that decide to mess with
access rights, or otherwise alter the “ground rules” from their norm: You
can introduce failure modes that no program expects (or even worse, that
there is just no reasonable way to handle at all), because the behavior of
the system that programs may rightly expect to depend on has suddenly been
changed out from under them.
Filter capabilities like this are very much in a quite fragile “You break
it, you buy it” sort of category if broadly used. There are a whole bunch
of ways to break things in subtle cases (revoking access to terminate the
process from the creator being one example). Those filtering mechanisms are
best used sparingly and in very narrow circumstances, if at all.
- S (Msft)
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ged Murphy
Sent: Sunday, October 09, 2016 12:06 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Removing PROCESS_TERMINATE flag causes hang
> To make a process truly unkillable, it’s not enough to deny
TERMINATE_PROCESS right.
Yep, I’m well aware of that. I’ve currently listed 12 very different
‘attack’ methods, of which I’m sure there are more for anyone more
imaginative than I am.
> I’m afraid “the problem you’re trying to solve” is you’re trying to
> find
out how to implement a wrong solution for the feature the customers want.
To be fair, you don’t know what problem I’m trying to solve, and I wasn’t
asking for any suggestions on solving anything
The solution I listed previously is a commonly accepted solution to what is
a slightly controversial topic. There’s quite a few topics on ntdev pointing
to the use of ObRegisterCallbacks to modify handles. For example this
lengthy post:
https://www.osronline.com/showThread.CFM?link=261303
Microsoft themselves also provide sample code showing this exact solution to
restrict PROCESS_TERMINATE access on a particular target process
https://github.com/Microsoft/Windows-driver-samples/tree/master/general/obca
llback/driver
If you run the sample using a target process that requires elevation, you’ll
see that it exhibits this exact problem and causes a hang in the parent
thread and a zombie process.
I’m just documenting the issues I found when researching, in the hope it
might help someone else in the future. It’s surely worth pointing out that
following Microsoft’s lead on this topic will cause problems. The WDK sample
code should probably be removed, or CreateProcessInternalW should be ‘fixed’
to avoid the hangs.
Ged.
—
NTDEV is sponsored by OSR
Visit the list online at:
http:
MONTHLY seminars on crash dump analysis, WDF, Windows internals and software
drivers!
Details at http:
To unsubscribe, visit the List Server section of OSR Online at
http:
—
NTDEV is sponsored by OSR
Visit the list online at:
http:
MONTHLY seminars on crash dump analysis, WDF, Windows internals and software
drivers!
Details at http:
To unsubscribe, visit the List Server section of OSR Online at
http:</http:></http:></http:></http:></http:></http:>