Didier Stevens

Sunday 22 November 2009

Quickpost: SelectMyParent or Playing With the Windows Process Tree

Filed under: Forensics,My Software,Windows 7,Windows Vista — Didier Stevens @ 20:36

I read something very interesting in “Windows via C/C++” today: starting with Windows Vista, CreateProcess can start a program where you specify the parent process! This is something forensic investigators must be aware of when they analyse processes running on a Windows machine.

Normally the parent process of a new process is the process that created the new process (via CreateProcess). But when using STARTUPINFOEX with the right LPPROC_THREAD_ATTRIBUTE_LIST to create a process, you can arbitrarely specify the parent process, provided you have the rights (i.e. it’s your process or you have debug rights).

I developed a small tool to start a program while specifying its parent process: SelectMyParent. Here I use it to start notepad as a child of lsass.exe:

2 remarks about this example:

  1. to make lsass.exe a parent process, you need to use SelectMyParent with admin rights and elevate its rights (Run as administrator)
  2. the notepad process takes over the parent process’ account: NT AUTHORITY\SYSTEM

I don’t know how one can detect that a process’ parent is not the process that created it, because a process has no access to its extended startup info (only to its startup info). And it is the extended startup info that contains the attribute list with the handle to the parent process.

SelectMyParent version 0.0.0.1 is available here.


Quickpost info

 


8 Comments »

  1. I’d like to expand on my questions that I asked via Twitter. Those being:
    1. Are you able to move a currently running process under another one?
    2. Are there any privileges applied to the parent/child relationship of processes?

    You said that a child access the “inheritable handles”. I don’t know what exactly ‘handles’ are, but if you were able to migrate a running process under one that you created you might get some interesting permissions to it. Or say, Process A has handles H that Process B uses, if you were some how to hijack Process B or put yourself in between process A and process B, you might be able to alter the state of those handles.

    But getting back to the ability of your app, for software that starts an “update” process, there might be some inheritable handles that you could get a hold of by impersonating the update process that it starts since most coders wont think about the security of child processes… yet.

    Just thinking out loud.

    Sweet program! ;-)

    Comment by mubix — Sunday 22 November 2009 @ 21:27

  2. A handle is a pointer to a pointer to a kernel object.

    And I too believe that this feature merits further investigation ;-). That’s why I posted my program so soon, so that others can play with it too.

    FYI: my tool will not allow the new process to inherit handles. If you want this, change the code like this:
    CreateProcess(NULL, argv[1], NULL, NULL, FALSE, …
    ->
    CreateProcess(NULL, argv[1], NULL, NULL, TRUE, …

    Comment by Didier Stevens — Sunday 22 November 2009 @ 21:49

  3. [...] process is. This creates a problem. Read Didier’s post to find out what that problem is. Quickpost: SelectMyParent or Playing With the Windows Process Tree << Didier Stevens Tags: ( windows [...]

    Pingback by Interesting Information Security Bits for 11/23/2009 | Infosec Ramblings — Monday 23 November 2009 @ 23:04

  4. Cool :)

    I’ve ported the tool to Python and included it in my WinAppDbg debugger: http://sourceforge.net/apps/trac/winappdbg/browser/trunk/tools/SelectMyParent.py

    This trick could also be used to thwart an antidebugging trick, as some packers check if their parent is explorer.exe or not.

    Comment by Mario Vilas — Wednesday 25 November 2009 @ 0:57

  5. This has always been the case on NT, actually. The underlying system call has always allowed you to specify an inherit from process handle (provided you have PROCESS_CREATE_PROCESS access to said processs — a sensitive access level).

    It just so happens that the Win32 wrapper typically always uses the creator’s process handle as the inherit from process handle.

    The link between a creator process and a ‘child’ process has always been extremely tenuous in NT.

    Comment by Skywing — Thursday 3 December 2009 @ 19:11

  6. @Skywing

    Interesting. So the NtCreateProcess* functions exported by ntdll.dll have always allowed this, but it’s only starting with Vista that CreateProcess exported from kernel32.dll also allows this?

    Comment by Didier Stevens — Thursday 3 December 2009 @ 19:22

  7. Yes, that’s correct. Someone could have just as easily thunked down to the raw system call however and bypassed CreateProcess, so this is something that has required handling from the get-go and not just on Vista or later. It’s entirely possible to do exactly the same thing on earlier systems, and

    Note that there is no security implication here as privileged access (PROCESS_CREATE_PROCESS) to a process is required to inherit from it. This access right is typically only given to the object owner, system, and administrators.

    Comment by Skywing — Thursday 3 December 2009 @ 21:45

  8. @Skywing Thanks for the clarification. And I agree there is no security issue.

    Comment by Didier Stevens — Thursday 3 December 2009 @ 21:50


RSS feed for comments on this post. TrackBack URI

Leave a Reply (comments are moderated)

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Rubric Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 199 other followers

%d bloggers like this: