exploit generator: Automated Exploit generation with WinDBG
exploit generator – autoexp
A script to automatically create a working exploit from crash PoCs.
The motivations behind creating this simple tool were to show how powerful is to script WinDBG and to simplify the typical BoF (buffer overflow) exploit development process. As the method is basically the same every time, a lot of manual work can be saved by automating the process. There are plenty of helper scripts (far the best and well known is mona.py), but none of them does the entire job for you.
The typical steps to create a BoF exploit are:
- Find EIP overwrite location (offset in the buffer)
- Examine memory layout, registers
- Somehow jump to the buffer with the help of registers
- Find bad characters
- Generate shellcode
- Put it all together
These are the classic steps, and although there are corner cases, most of them work this way. This is a heavily manual process especially the part, when you start the debugger, attach the process, run your PoC code, discover memory layout, or debug errors you made, and then start again. When it comes to discovering bad characters, that is especially time intense.
The goal of creating this script/tool was to automate as much as I can, so no manual interaction is needed to create a working exploit from a crash PoC.
The script is written entirely in Python and uses the pykd library to interact with WinDBG. The library is specific to this debugger, so others can’t be used.
It is still in very early development stage, so there might be bugs, especially if interaction with the application is needed, and not all cases are covered.
Setting up the environment
- Install Debugger Tools for Windows from http://msdn.microsoft.com/en-US/windows/hardware/hh852363
- Install an older version of Python (e.g.: 2.7.3), download from https://www.python.org/downloads/windows/
- Download latest 3.x version of pykd from https://pykd.codeplex.com/releases/view/614442
- Extract the zip file contents
- Copy the pykd.pyd file to “C:\Program Files (x86)\Windows Kits\8.0\Debuggers\x86\winext”
Verify Installation
- Launch a custom x86 application
- Attach the debugger
- Type: “.load pykd.pyd”, you shouldn’t get any errors showing up
- In case WinDBG terminates, try an older version of Python
- Type “r” to get the values stored in registers
- Start Python in WinDBG, type: “!py”
- Type: “hex(reg(‘eip’))”, you should get the same value for EIP, what you saw at step #4
Copyright (c) <2016> theevilbit