Win DLL’s
Finding the right return was for me one of the most difficult aspects of getting my overflows to work on win32. The examples in books like the shell coders handbook and The Art of Hacking were linux based and old for that matter. The examples didn’t take into account safe guards imposed by the OS. When starting out it was vexing to say the least.
My first successful Windows exploit was warftpd 1.65. It was straight forward and after I fixed a minor type-o in my code that was causing me to underrun the buffer, but overflow it later having the exception thrown somewhere in the middle of my shellcode I got it! It was late at night and I think I woke up my wife when I yelled in excitement.
The return I used was a jmp esp that I found in kernel32.dll, I found the address using findjmp which was written by Ryan Permeh from Eeye. Findjmp finds useful jump points in a dll.
A week later my co worker sent me some exploit code an activex overflow in bearshare. He was out doing a Vulnerability Assessment when the advisory came out. He noticed though that the offset and returns for xpsp2 and xpsp2 (vmware) were different so he sent it out to me and asked if I could get a quick return and check the offset for him. It took me a few minutes (mainly cause I did not have the binary for findjmp and had to find a visual C 6 compiler. This time I returned using a call esp, again into kernel32.dll.
Both times I have returned into kernel32.dll and it made me start to wonder, what’s the difference between all the .dll’s and is there any significant advantage to using one over the other. After asking my co worker the answer I received was in short No, its just dependent on if you can find the instruction you need and successfully call your shellcode. This still made me want to go out and discover more about which dll’s did what. So I set about to findout, but could not find a central definition of the most popular. So here is a run down:
These are the most popular dll’s people tend to return to, they are also the ones outlined in the MSF opcode DB. Per the MSF Wiki “Buffer Overflow exploits on windows often require precise knowledge of the position of certain machine language opcodes in the attacked program or included DLL’s. Here is what the DLL’s do:
Ntdll.dll – The ntdll has a description of “NT Layer DLL” and contains NT kernel functions. It can be located in the %systemroot%\system32, or I386 directory.
Kernel32.dll – Handles memory management, input/output operations, and interrupts. Kernel32.dll is loaded into a protected memory space so other applications do not take that space over.
User32.dll – Handles Windows functions related to user interface (window handling, basic UI, and so forth)
Gdi32.dll – gdi32.dll contains functions for the Windows GDI (Graphical Device Interface) which assists windows in creating simple 2-dimensional objects.
Ws2_32.dll – File that contains the Windows Sockets API used by most Internet and network applications to handle network connections.
Ws2help.dll – File that contains the functions used by the Windows Sockets API, which is used by Internet and network applications.
For more information on DLL’s, visit DLL Wikipedia
