GRAY HAT PYTHON – INTRODUCTION

I learned Python specifically for hacking—and I’d venture to say that’s a true statement for a lot of other folks, too. I spent a great deal of time hunting around for a language that was well suited for hacking and reverse engineering, and a few years ago it became very apparent that Python was becoming the natural leader in the hacking-programming language department. The tricky part was the fact that there was no real manual on how to use Python for a variety of hacking tasks. You had to dig through forum posts and man pages and typically spend quite a bit of time stepping through code to get it to work right. This book aims to fill that gap by giving you a whirlwind tour of how to use Python for hacking and reverse engineering in a variety of ways.

The book is designed to allow you to learn some theory behind most hacking tools and techniques, including debuggers, backdoors, fuzzers, emulators, and code injection, while providing you some insight into how prebuilt Python tools can be harnessed when a custom solution isn’t needed. You’ll learn not only how to use Python-based tools but how to build tools in Python. But be forewarned, this is not an exhaustive reference! There are many, many infosec (information security) tools written in Python that I did not cover. However, this book will allow you to translate a lot of the same skills across applications so that you can use, debug, extend, and customize any Python tool of your choice.

There are a couple of ways you can progress through this book. If you are new to Python or to building hacking tools, then you should read the book front to back, in order. You’ll learn some necessary theory, program oodles of Python code, and have a solid grasp of how to tackle a myriad of hacking and reversing tasks by the time you get to the end. If you are familiar with Python already and have a good grasp on the Python library ctypes, then jump straight to Chapter 2. For those of you who have been around the block, it’s easy enough to jump around in the book and use code snippets or certain sections as you need them in your day-to-day tasks.

I spend a great deal of time on debuggers, beginning with debugger theory in Chapter 2, and progressing straight through to Immunity Debugger in Chapter 5. Debuggers are a crucial tool for any hacker, and I make no bones about covering them extensively. Moving forward, you’ll learn some hooking and injection techniques in Chapters 6 and 7, which you can add to some of the debugging concepts of program control and memory manipulation.

The next section of the book is aimed at breaking applications using fuzzers. In Chapter 8, you’ll begin learning about fuzzing, and we’ll construct our own basic file fuzzer. In Chapter 9, we’ll harness the powerful Sulley fuzzing framework to break a real-world FTP daemon, and in Chapter 10 you’ll learn how to build a fuzzer to destroy Windows drivers.

In Chapter 11, you’ll see how to automate static analysis tasks in IDA Pro, the popular binary static analysis tool. We’ll wrap up the book by covering PyEmu, the Python-based emulator, in Chapter 12.

I have tried to keep the code listings somewhat short, with detailed explanations of how the code works inserted at specific points. Part of learning a new language or mastering new libraries is spending the necessary sweat time to actually write out the code and debug your mistakes. I encourage you to type in the code! All source will be posted to http://www.nostarch.com/ ghpython.htm for your downloading pleasure.

Now let’s get coding!

Leave a comment