Gray Hat Python: Python Programming for Hackers and Reverse Engineers [1 ed.] 9781593271923, 1-59327-192-1, 1-59327-192-1

Python is fast becoming the programming language of choice for hackers, reverse engineers, and software testers because

299 62 3MB

English Pages 220 Year 2009

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
Foreword......Page 15
Acknowledgments......Page 19
Introduction......Page 21
1: Setting Up Your Development Environment ......Page 23
1.2.1 Installing Python on Windows......Page 24
1.2.2 Installing Python for Linux......Page 25
1.3 Setting Up Eclipse and PyDev......Page 26
1.3.1 The Hacker’s Best Friend: ctypes......Page 27
1.3.2 Using Dynamic Libraries......Page 28
1.3.3 Constructing C Datatypes......Page 30
1.3.5 Defining Structures and Unions......Page 31
2: Debuggers and Debugger Design ......Page 35
2.1 General-Purpose CPU Registers......Page 36
2.2 The Stack......Page 38
2.4 Breakpoints......Page 40
2.4.1 Soft Breakpoints......Page 41
2.4.2 Hardware Breakpoints......Page 43
2.4.3 Memory Breakpoints......Page 45
3.1 Debuggee, Where Art Thou?......Page 47
3.2.1 Thread Enumeration......Page 55
3.2.2 Putting It All Together......Page 57
3.3 Implementing Debug Event Handlers......Page 61
3.4.1 Soft Breakpoints......Page 65
3.4.2 Hardware Breakpoints......Page 69
3.4.3 Memory Breakpoints......Page 74
3.5 Conclusion......Page 77
4: PyDbg -- A Pure Python Windows Debugger ......Page 79
4.1 Extending Breakpoint Handlers......Page 80
4.2 Access Violation Handlers......Page 82
4.3.1 Obtaining Process Snapshots......Page 85
4.3.2 Putting It All Together......Page 87
5: Immunity Debugger -- The Best of Both Worlds ......Page 91
5.2 Immunity Debugger 101......Page 92
5.2.2 PyHooks......Page 93
5.3.1 Finding Exploit-Friendly Instructions......Page 95
5.3.2 Bad-Character Filtering......Page 97
5.3.3 Bypassing DEP on Windows......Page 99
5.4.1 IsDebuggerPresent......Page 103
5.4.2 Defeating Process Iteration......Page 104
6: Hooking ......Page 107
6.1 Soft Hooking with PyDbg......Page 108
6.2 Hard Hooking with Immunity Debugger......Page 112
7: DLL and Code Injection ......Page 119
7.1 Remote Thread Creation......Page 120
7.1.1 DLL Injection......Page 121
7.1.2 Code Injection......Page 123
7.2.1 File Hiding......Page 126
7.2.2 Coding the Backdoor......Page 127
7.2.3 Compiling with py2exe......Page 130
8: Fuzzing ......Page 133
8.1.1 Buffer Overflows......Page 134
8.1.2 Integer Overflows......Page 135
8.1.3 Format String Attacks......Page 136
8.2 File Fuzzer......Page 137
8.3.2 Automated Static Analysis......Page 144
9: Sulley ......Page 145
9.1 Sulley Installation......Page 146
9.2.2 Delimiters......Page 147
9.2.5 Integers......Page 148
9.2.6 Blocks and Groups......Page 149
9.3.1 FTP 101......Page 151
9.3.2 Creating the FTP Protocol Skeleton......Page 152
9.3.3 Sulley Sessions......Page 153
9.3.4 Network and Process Monitoring......Page 154
9.3.5 Fuzzing and the Sulley Web Interface......Page 155
10: Fuzzing Windows Drivers ......Page 159
10.1 Driver Communication......Page 160
10.2 Driver Fuzzing with Immunity Debugger......Page 161
10.3 Driverlib-The Static Analysis Tool for Drivers......Page 164
10.3.1 Discovering Device Names......Page 165
10.3.2 Finding the IOCTL Dispatch Routine......Page 166
10.3.3 Determining Supported IOCTL Codes......Page 167
10.4 Building a Driver Fuzzer......Page 169
11: IDAPython -- Scripting IDA Pro ......Page 175
11.1 IDAPython Installation......Page 176
11.2.2 Segments......Page 177
11.2.4 Cross-References......Page 178
11.2.5 Debugger Hooks......Page 179
11.3.1 Finding Dangerous Function Cross-References......Page 180
11.3.2 Function Code Coverage......Page 182
11.3.3 Calculating Stack Size......Page 183
12: PyEmu -- The Scriptable Emulator ......Page 185
12.2.1 PyCPU......Page 186
12.2.5 Memory and Register Modifiers......Page 187
12.2.6 Handlers......Page 188
12.3 IDAPyEmu......Page 193
12.3.1 Function Emulation......Page 194
12.3.2 PEPyEmu......Page 197
12.3.4 UPX Packer......Page 198
12.3.5 Unpacking UPX with PEPyEmu......Page 199
Index ......Page 205
Updates ......Page 218

Gray Hat Python: Python Programming for Hackers and Reverse Engineers [1 ed.]
 9781593271923, 1-59327-192-1, 1-59327-192-1

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Recommend Papers