This is a mirror of official site: http://jasper-net.blogspot.com/

Retrieving Kernel32's Base Address

| Wednesday, March 10, 2010
For shellcode, a common method to resolve the addresses of library functions needed, is to get the base address of the kernel32.dll image in memory and retrieve the addresses of GetProcAddress and LoadLibraryA by parsing the kernel32 images Export Address Table (EAT). These two functions can then be used to resolve the remaining functions needed by the shellcode. To retrieve the kernel32.dll base address most shellcodes use the Process Environment Block (PEB) structure to retrieve a list of modules currently loaded in the processes address space. The InInitializationOrder module list pointed to by the PEB's Ldr structure holds a linked list of modules. Typically the second entry in this list has always been that of kernel32.dll. The code used to retrieve the kernel32 base address based on this method is shown below:

xor ebx, ebx             // clear ebx
mov ebx, fs:[ 0x30 ]     // get a pointer to the PEB
mov ebx, [ ebx + 0x0C ]  // get PEB->Ldr
mov ebx, [ ebx + 0x1C ]  // get PEB->Ldr.InInitializationOrderModuleList.Flink (1st entry)
mov ebx, [ ebx ]         // get the next entry (2nd entry)
mov ebx, [ ebx + 0x08 ]  // get the 2nd entries base address (kernel32.dll)

This method has worked for all versions of Windows from Windows 2000 up to and including Windows Vista. The introduction of Windows 7 (rc1) has broken this method of retrieving the kernel32 base address due to the new MinWin kernel structure employed by Windows 7. A new module kernelbase.dll is loaded before kernel32.dll and as such appears in the second entry of the InInitializationOrder module list.

Read more: Harmony security

Posted via email from jasper22's posterous

0 comments: