A forum for reverse engineering, OS internals and malware analysis 

Ask your beginner questions here.
 #10076  by EP_X0FF
 Fri Dec 02, 2011 1:50 pm
Post your code. Use ZwOpenProcess instead.
 #10081  by utsav.0202
 Sat Dec 03, 2011 7:01 am
I don't get one thing.
Why do we need to KeAttachProcess(csrss process)?

I changed my code and tried to hook Shadow SSDT without KeAttachProcess(csrss process) and it worked absolutely fine.
Is it okay?
 #10087  by EP_X0FF
 Sat Dec 03, 2011 10:05 am
I do not understand how does your posts related each other.
 #10088  by utsav.0202
 Sat Dec 03, 2011 10:18 am
First I tried as given in the file sssdt.h and NtOpenProcess in getCsrPid() failed for all process.
Then I posted my problem here.
Today I just tried to Hook Shadow table without attaching csrss.exe and it worked
I mean if it can work without attaching shadow table then why do we need it or do we actually need it?
 #10090  by EP_X0FF
 Sat Dec 03, 2011 10:30 am
Depends on where you use this getCsrPid(). Obviously it is kind of trick to get pointer to Shadow SSDT when running in context of non-GUI thread. However code you maybe referring (posted by Alex I guess) is Chinese bad example of programming.
 #10099  by Vrtule
 Sat Dec 03, 2011 12:09 pm
First I tried as given in the file sssdt.h and NtOpenProcess in getCsrPid() failed for all process.
I did not find this routine in that file. However, if you call NtOpenProcess from kernel driver and the previous mode is UserMode, the routine will usually fail, because it accepts only parameters pointing to memory adresses accesible from usermode (address of OBJECT_ATTRIBUTES and CLIENT_ID structures). ZwOpenProcess can be understood as the following sequence of commands:
Code: Select all
PreviousMode = KernelMode;
NtOpenProcess(...);

It sets previous mode to KernelMode, so the operation will not fail even with addresses of OBJECT_ATTRIBUTES and CLIENT_ID structures pointing to kernel space.
Today I just tried to Hook Shadow table without attaching csrss.exe and it worked
I mean if it can work without attaching shadow table then why do we need it or do we actually need it?
As EP had already said, everything depends on the context of the process in which you perform Shadow hooking. Win32k.sys driver, where the most important parts of the shadow table are located, is not mapped in non-GUI processes because they don't need it; they use no system calls that redirects to shadow table.

----
Hope I understood your problem well enough and that I was not much mistaken.
 #10146  by utsav.0202
 Mon Dec 05, 2011 10:34 am
and Vrtule, I am sorry, by mistake I posted the wrong link to file that contains GetCsrPid().
As EP_X0FF rightly guessed it was the one posted by Alex.