Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting PEB from remote process in Win 7

Specs: Windows 7 x64, Visual C++

Objective: I'm trying to get the remote PEB from a sample program (calc.exe e.g.). I've found the proc ID and I've opened a handle to the process with all the good rights. I've now moved on to writing a class to retrieve the location of the PEB from the process using PROCESS_BASIC_INFORMATION.

Problem: I've found several posts elsewhere that seem to indicate that the NtQueryInformationProcess turned to shit at MS. One post suggests a method of dynamic-runtime-linking NtQueryInformationProcess out of ntdll.dll. However, I think this would be unstable in the long-run (MS could remove NtQueryInformationProcess tomorrow) without extensive error handling.

This idea is realized later in this thread, and it is then suggested by Mike2343 that one should "use other methods."

Questions: What would be another method to locate the PEB of a remote process that doesn't involve NtQueryInformationProcess?

Thanks to anyone who spends any time looking at this.

like image 487
user850275 Avatar asked Nov 04 '22 19:11

user850275


1 Answers

Method I ended up using:

I stole pretty much all of this code and fixed it up for 64-bit. I spent a ton of time wrapping my head around various documents related to all of the different headers and structs. I also ran into an issue regarding the PE32+ format, where jcopenha was kind enough to enlighten me on a few problems I might be facing. After accounting for these problems I had a functioning program that is capable of obtaining a list of all the DLL's and their respective functions loaded in by an executable along with their relative addresses.

In retrospect, I don't think I had a good handle on what I was attempting to do. I think that I thought I was going to read in a process out of memory and find the PEB related structs or something (Later I found out that image headers and the like account for the information in the PEB). Albeit that may be possible, but what I have now is an offline example that reads in exe files and works for me.

like image 104
user850275 Avatar answered Nov 12 '22 13:11

user850275