Attack Patterns |
|
xxxiii | |
Foreword |
|
xxv | |
Preface |
|
xxix | |
|
|
xxx | |
|
|
xxxi | |
|
But Isn't This Too Dangerous? |
|
|
xxxii | |
Acknowledgments |
|
xxxiii | |
1 Software-The Root of the Problem |
|
1 | (36) |
|
A Brief History of Software |
|
|
2 | (8) |
|
Software and the Information Warrior |
|
|
5 | (1) |
|
|
6 | (4) |
|
Bad Software Is Ubiquitous |
|
|
10 | (4) |
|
|
11 | (1) |
|
|
11 | (1) |
|
|
11 | (1) |
|
|
12 | (1) |
|
Microsoft and the Love Bug |
|
|
12 | (2) |
|
|
14 | (9) |
|
|
14 | (2) |
|
|
16 | (2) |
|
|
18 | (3) |
|
|
21 | (2) |
|
|
23 | (1) |
|
|
23 | (10) |
|
Short-Term Future: 2003-2004 |
|
|
24 | (4) |
|
Medium-Term Future: 2005-2007 |
|
|
28 | (2) |
|
Long-Term Future: 2008-2010 |
|
|
30 | (2) |
|
|
32 | (1) |
|
What Is Software Security? |
|
|
33 | (1) |
|
|
34 | (3) |
2 Attack Patterns |
|
37 | (34) |
|
|
38 | (4) |
|
|
39 | (1) |
|
|
39 | (1) |
|
|
39 | (2) |
|
|
41 | (1) |
|
|
42 | (6) |
|
|
44 | (1) |
|
|
45 | (1) |
|
|
46 | (1) |
|
|
47 | (1) |
|
|
48 | (7) |
|
|
48 | (1) |
|
Why Trusting Users Is Bad |
|
|
49 | (1) |
|
|
50 | (1) |
|
|
51 | (4) |
|
Attack Patterns: Blueprints for Disaster |
|
|
55 | (2) |
|
Exploit, Attack, and Attacker |
|
|
55 | (1) |
|
|
56 | (1) |
|
|
56 | (1) |
|
|
57 | (1) |
|
|
57 | (1) |
|
|
57 | (1) |
|
An Example Exploit: Microsoft's Broken C++ Compiler |
|
|
57 | (8) |
|
Technical Details of the Attack |
|
|
59 | (2) |
|
An Overview of Microsoft's Port of StackGuard |
|
|
61 | (1) |
|
Bypassing the Microsoft Feature |
|
|
61 | (2) |
|
|
63 | (1) |
|
|
64 | (1) |
|
|
65 | (5) |
|
|
65 | (1) |
|
|
66 | (1) |
|
|
67 | (1) |
|
Traceroute and Zone Transfers |
|
|
67 | (1) |
|
|
67 | (1) |
|
|
68 | (1) |
|
Leveraging Faults in the Environment |
|
|
68 | (1) |
|
|
68 | (1) |
|
|
69 | (1) |
|
|
70 | (1) |
|
Attack Pattern: Target Programs That Write to Privileged OS Resources |
|
|
70 | (1) |
|
|
70 | (1) |
3 Reverse Engineering and Program Understanding |
|
71 | (76) |
|
|
72 | (3) |
|
|
72 | (1) |
|
|
73 | (2) |
|
Should Reverse Engineering Be Illegal? |
|
|
75 | (2) |
|
Reverse Engineering Tools and Concepts |
|
|
77 | (2) |
|
|
77 | (1) |
|
|
78 | (1) |
|
|
78 | (1) |
|
The Reverse Compiler or Decompiler |
|
|
79 | (1) |
|
Approaches to Reverse Engineering |
|
|
79 | (5) |
|
|
79 | (1) |
|
|
80 | (1) |
|
|
81 | (1) |
|
Using Gray Box Techniques to Find Vulnerabilities in Microsoft SQL Server 7 |
|
|
82 | (2) |
|
|
84 | (8) |
|
|
84 | (2) |
|
Exploiting Version Differences |
|
|
86 | (1) |
|
Making Use of Code Coverage |
|
|
87 | (1) |
|
|
88 | (2) |
|
Leaking Data in Shared Buffers |
|
|
|
Auditing for Access Requirement Screwups |
|
|
90 | (1) |
|
|
90 | (2) |
|
Writing Interactive Disassembler (IDA) Plugins |
|
|
92 | (12) |
|
Decompiling and Disassembling Software |
|
|
104 | (1) |
|
Decompilation in Practice: Reversing helpctr.exe |
|
|
105 | (6) |
|
|
106 | (1) |
|
|
107 | (4) |
|
Automatic, Bulk Auditing for Vulnerabilities |
|
|
111 | (10) |
|
Batch Analysis with IDA-Pro |
|
|
114 | (7) |
|
Writing Your Own Cracking Tools |
|
|
121 | (18) |
|
|
121 | (1) |
|
|
121 | (2) |
|
|
123 | (3) |
|
Reading and Writing Memory |
|
|
126 | (1) |
|
Debugging Multithreaded Programs |
|
|
127 | (2) |
|
Enumerate Threads or Processes |
|
|
129 | (1) |
|
|
130 | (2) |
|
|
132 | (1) |
|
|
132 | (1) |
|
|
133 | (5) |
|
Disassembling Machine Code |
|
|
138 | (1) |
|
Building a Basic Code Coverage Tool |
|
|
139 | (6) |
|
|
144 | (1) |
|
|
145 | (2) |
4 Exploiting Server Software |
|
147 | (54) |
|
The Trusted Input Problem |
|
|
149 | (2) |
|
Attack Pattern: Make the Client Invisible |
|
|
150 | (1) |
|
The Privilege Escalation Problem |
|
|
151 | (3) |
|
Process-Permissions Equal Trust |
|
|
151 | (1) |
|
If We Don't Run as Administrator, Everything Breaks! |
|
|
152 | (1) |
|
Attack Pattern: Target Programs That Write to Privileged OS Resources |
|
|
152 | (1) |
|
Elevated Processes That Read Data from Untrusted Sources |
|
|
153 | (1) |
|
Attack Pattern: Use a User-Supplied Configuration File to Run Commands That Elevate Privilege |
|
|
153 | (1) |
|
Processes That Use Elevated Components |
|
|
153 | (1) |
|
|
154 | (2) |
|
|
155 | (1) |
|
Attack Pattern: Make Use of Configuration File Search Paths |
|
|
156 | (1) |
|
|
156 | (5) |
|
Using GDB and IDA-Pro Together on a Solaris SPARC Binary |
|
|
156 | (1) |
|
Setting Breakpoints and Expressions |
|
|
156 | (1) |
|
Mapping Runtime Memory Addresses from IDA |
|
|
157 | (1) |
|
Attaching to a Running Process |
|
|
158 | (1) |
|
Using Truss to Model the Target on Solaris |
|
|
159 | (2) |
|
Exploiting Trust through Configuration |
|
|
161 | (6) |
|
Attack Pattern: Direct Access to Executable Files |
|
|
162 | (1) |
|
Auditing for Directly Executable Files |
|
|
162 | (1) |
|
Know the Current Working Directory (CWD) |
|
|
163 | (1) |
|
What If the Web Server Won't Execute cgi Programs? |
|
|
163 | (1) |
|
Attack Pattern: Embedding Scripts within Scripts |
|
|
164 | (1) |
|
What About Nonexecutable Files? |
|
|
165 | (1) |
|
Attack Pattern: Leverage Executable Code in Nonexecutable Files |
|
|
165 | (1) |
|
|
166 | (1) |
|
Specific Techniques and Attacks for Server Software |
|
|
167 | (32) |
|
Technique: Shell Command Injection |
|
|
167 | (2) |
|
Attack Pattern: Argument Injection |
|
|
169 | (3) |
|
Attack Pattern: Command Delimiters |
|
|
172 | (1) |
|
Attack Pattern: Multiple Parsers and Double Escapes |
|
|
173 | (8) |
|
Technique: Plumbing Pipes, Ports, and Permissions |
|
|
181 | (3) |
|
Technique: Exploring the File System |
|
|
184 | (1) |
|
Attack Pattern: User-Supplied Variable Passed to File System Calls |
|
|
185 | (1) |
|
Attack Pattern: Postfix NULL Terminator |
|
|
186 | (1) |
|
Attack Pattern: Postfix, Null Terminate, and Backslash |
|
|
186 | (1) |
|
Attack Pattern: Relative Path Traversal |
|
|
187 | (2) |
|
Technique: Manipulating Environment Variables |
|
|
189 | (1) |
|
Attack Pattern: Client-Controlled Environment Variables |
|
|
189 | (1) |
|
Technique: Leveraging Extraneous Variables |
|
|
190 | (1) |
|
Attack Pattern: User-Supplied Global Variables (DEBUG=1, PHP Globals, and So Forth) |
|
|
190 | (2) |
|
Technique: Leveraging Poor Session Authentication |
|
|
192 | (1) |
|
Attack Pattern: Session ID, Resource ID, and Blind Trust |
|
|
192 | (1) |
|
Technique: Brute Forcing Session IDs |
|
|
193 | (5) |
|
Technique: Multiple Paths of Authentication |
|
|
198 | (1) |
|
Technique: Failure to Ckeck Error Codes |
|
|
199 | (1) |
|
|
199 | (2) |
5 Exploiting Client Software |
|
201 | (32) |
|
Client-side Programs as Attack Targets |
|
|
201 | (3) |
|
The Server Controls the Client |
|
|
202 | (1) |
|
|
203 | (1) |
|
|
204 | (8) |
|
Ancient (But Relevant) History |
|
|
204 | (1) |
|
Attack Pattern: Analog In-Band Switching Signals (aka "Blue Boxing") |
|
|
205 | (2) |
|
|
207 | (1) |
|
In-band Fun with Printers |
|
|
208 | (1) |
|
In-band Terminal Character Injection in Linux |
|
|
209 | (1) |
|
Attack Pattern Fragment: Manipulating Terminal Devices |
|
|
210 | (1) |
|
|
211 | (1) |
|
Cross-site Scripting (XSS) |
|
|
212 | (5) |
|
Using Reflection against Trusted Sites |
|
|
213 | (1) |
|
Attack Pattern: Simple Script Injection |
|
|
214 | (1) |
|
Attack Pattern: Embedding Script in Nonscript Elements |
|
|
215 | (1) |
|
Attack Pattern: XSS in HTTP Headers |
|
|
216 | (1) |
|
Attack Pattern: HTTP Query Strings |
|
|
216 | (1) |
|
Attack Pattern: User-Controlled Filename |
|
|
217 | (1) |
|
Clients Scripts and Malicious Code |
|
|
217 | (12) |
|
Auditing for Weak Local Calls |
|
|
219 | (5) |
|
|
224 | (1) |
|
Attack Pattern: Passing Local Filenames to Functions That Expect a URL |
|
|
225 | (1) |
|
|
226 | (1) |
|
Attack Pattern: Meta-characters in E-mail Header |
|
|
226 | (3) |
|
|
229 | (1) |
|
Attack Pattern: File System Function Injection, Content Based |
|
|
229 | (1) |
|
Backwash Attacks: Leveraging Client-side Buffer Overflows |
|
|
230 | (2) |
|
Attack Pattern: Client-side Injection, Buffer Overflow |
|
|
231 | (1) |
|
|
232 | (1) |
6 Crafting (Malicious) Input |
|
233 | (44) |
|
|
235 | (2) |
|
|
236 | (1) |
|
|
237 | (1) |
|
Intrusion Detection (Not) |
|
|
237 | (5) |
|
Signature-Based versus Anomaly-Based IDSs |
|
|
238 | (1) |
|
IDSs as a Reactive Subscription Service |
|
|
239 | (1) |
|
The Effect of Alternate Encoding on IDSs |
|
|
240 | (2) |
|
|
242 | (2) |
|
APISPY for Windows Revisited |
|
|
243 | (1) |
|
|
243 | (1) |
|
|
244 | (10) |
|
Backtracing from Vulnerable Locations |
|
|
245 | (2) |
|
|
247 | (1) |
|
|
247 | (3) |
|
|
250 | (1) |
|
|
251 | (1) |
|
|
251 | (2) |
|
|
253 | (1) |
|
|
253 | (1) |
|
|
254 | (4) |
|
|
255 | (1) |
|
|
255 | (1) |
|
|
256 | (1) |
|
|
257 | (1) |
|
Example: Reversing I-Planet Server 6.0 through the Front Door |
|
|
258 | (5) |
|
|
263 | (1) |
|
Attack Pattern: Cause Web Server Misclassification |
|
|
263 | (1) |
|
Building "Equivalent" Requests |
|
|
264 | (11) |
|
|
264 | (2) |
|
|
266 | (1) |
|
Attack Pattern: Alternate Encoding the Leading Ghost Characters |
|
|
267 | (1) |
|
Equivalent Meta-characters |
|
|
268 | (1) |
|
Attack Pattern: Using Slashes in Alternate Encoding |
|
|
268 | (1) |
|
|
269 | (1) |
|
Attack Pattern: Using Escaped Slashes in Alternate Encoding |
|
|
270 | (1) |
|
|
271 | (1) |
|
Attack Pattern: Unicode Encoding |
|
|
271 | (2) |
|
Attack Pattern: UTF-8 Encoding |
|
|
273 | (1) |
|
Attack Pattern: URL Encoding |
|
|
273 | (1) |
|
Attack Pattern: Alternative IP Addresses |
|
|
274 | (1) |
|
|
274 | (1) |
|
Attack Pattern: Slashes and URL Encoding Combined |
|
|
274 | (1) |
|
|
275 | (1) |
|
|
275 | (1) |
|
|
276 | (1) |
7 Buffer Overflow |
|
277 | (90) |
|
|
277 | (3) |
|
Smashing the Stack (for Fun and Profit) |
|
|
279 | (1) |
|
|
279 | (1) |
|
Injection Vectors: Input Rides Again |
|
|
280 | (6) |
|
Where Injection Stops and Payload Begins |
|
|
282 | (1) |
|
Choosing the Correct Code Address to Target |
|
|
282 | (1) |
|
Highland and Lowland Addresses |
|
|
283 | (1) |
|
Big Endian and Little Endian Representation |
|
|
284 | (1) |
|
|
285 | (1) |
|
Using Existing Code or Data Blocks in Memory |
|
|
286 | (1) |
|
Buffer Overflows and Embedded Systems |
|
|
286 | (3) |
|
Embedded Systems in Military and Commercial Use |
|
|
287 | (2) |
|
Database Buffer Overflows |
|
|
289 | (2) |
|
|
290 | (1) |
|
Command-Line Applications |
|
|
290 | (1) |
|
|
290 | (1) |
|
Buffer Overflows and Java?! |
|
|
291 | (2) |
|
sing Java and C/C++ Together |
|
|
292 | (1) |
|
Stored Procedures and DLLs |
|
|
293 | (1) |
|
Content-Based Buffer Overflow |
|
|
293 | (3) |
|
Attack Pattern: Overflow Binary Resource File |
|
|
293 | (1) |
|
Attack Pattern: Overflow Variables and Tags |
|
|
294 | (1) |
|
Attack Pattern: Overflow Symbolic Links |
|
|
294 | (1) |
|
Attack Pattern: MIME Conversion |
|
|
295 | (1) |
|
Attack Pattern: HTTP Cookies |
|
|
295 | (1) |
|
Audit Truncation and Filters with Buffer Overflow |
|
|
296 | (1) |
|
Attack Pattern: Filter Failure through Buffer Overflow |
|
|
296 | (1) |
|
Causing Overflow and Environment Variables |
|
|
296 | (2) |
|
Attack Pattern: Buffer Overflow with Environment Variables |
|
|
297 | (1) |
|
Attack Pattern: Buffer Overflow in an API Call |
|
|
297 | (1) |
|
Attack Pattern: Buffer Overflow in Local Command-Line Utilities |
|
|
297 | (1) |
|
The Multiple Operation Problem |
|
|
298 | (1) |
|
Attack Pattern: Parameter Expansion |
|
|
298 | (1) |
|
Finding Potential Buffer Overflows |
|
|
298 | (2) |
|
Exception Handling Hides Errors |
|
|
299 | (1) |
|
|
299 | (1) |
|
|
300 | (9) |
|
|
301 | (1) |
|
Functions That Do Not Automatically NULL Terminate |
|
|
302 | (2) |
|
Functions with Off-By-One NULL Termination |
|
|
304 | (4) |
|
Overwriting Exception Handler Frames |
|
|
308 | (1) |
|
Arithmetic Errors in Memory Management |
|
|
309 | (8) |
|
Negative Values Equal Large Values |
|
|
309 | (1) |
|
|
310 | (5) |
|
Signed Values and Memory Management |
|
|
315 | (2) |
|
Format String Vulnerabilities |
|
|
317 | (7) |
|
Printing Data from Anywhere in Memory |
|
|
319 | (5) |
|
Detecting the Problem in Code |
|
|
324 | (1) |
|
Attack Pattern: String Format Overflow in syslog() |
|
|
324 | (1) |
|
|
324 | (5) |
|
|
327 | (2) |
|
|
329 | (1) |
|
|
329 | (1) |
|
|
329 | (7) |
|
|
331 | (1) |
|
|
332 | (1) |
|
Using Hard-Coded Function Calls |
|
|
332 | (1) |
|
Using a Dynamic Jump Table |
|
|
333 | (1) |
|
Locating the Data Section |
|
|
334 | (1) |
|
|
335 | (1) |
|
|
335 | (1) |
|
Payloads on RISC Architectures |
|
|
336 | (22) |
|
"Branch Delay" or "Delay Slot" |
|
|
337 | (1) |
|
MIPS-Based Payload Construction |
|
|
337 | (1) |
|
|
337 | (1) |
|
|
338 | (1) |
|
Avoiding NULL Bytes in MIPS Opcodes |
|
|
339 | (1) |
|
|
340 | (1) |
|
SPARC Payload Construction |
|
|
340 | (1) |
|
|
341 | (1) |
|
Walking the Stack on SPARC |
|
|
342 | (2) |
|
Function Call Nesting in SPARC |
|
|
344 | (1) |
|
PA-RISC Payload Construction |
|
|
345 | (2) |
|
Walking the Stack on PA-RISC |
|
|
347 | (2) |
|
Stack Overflow on HPUX PA-RISC |
|
|
349 | (1) |
|
Inter-space Branching on the PA-RISC |
|
|
349 | (2) |
|
|
351 | (1) |
|
|
351 | (2) |
|
Self-Decrypting Payload on HPUX |
|
|
353 | (3) |
|
AIX/PowerPC Payload Construction |
|
|
356 | (1) |
|
|
356 | (1) |
|
Active Armor for the PowerPC Shell Code |
|
|
356 | (2) |
|
Removing the NULL Characters |
|
|
358 | (1) |
|
|
358 | (2) |
|
|
360 | (1) |
|
Prolog/Epilog Code to Protect Functions |
|
|
360 | (6) |
|
Defeating Canary Values (aka Stack Guard) |
|
|
361 | (3) |
|
Defeating Nonexecutable Stacks |
|
|
364 | (2) |
|
|
366 | (1) |
8 Rootkits |
|
367 | (82) |
|
|
367 | (2) |
|
|
368 | (1) |
|
What Is a Kernel Rootkit? |
|
|
368 | (1) |
|
Kernel Rootkits and the Trusted Computing Base |
|
|
369 | (1) |
|
A Simple Windows XP Kernel Rootkit |
|
|
369 | (11) |
|
|
369 | (1) |
|
The Checked Build Environment |
|
|
369 | (1) |
|
Files in the Rootkit Source |
|
|
370 | (1) |
|
|
370 | (1) |
|
|
370 | (1) |
|
The Basic Structure of a Driver |
|
|
371 | (1) |
|
When Programs Use a Driver |
|
|
372 | (1) |
|
Allowing the Driver to Be Unloaded |
|
|
373 | (2) |
|
|
375 | (2) |
|
Using SysystemLoadAndCallImage |
|
|
377 | (3) |
|
|
380 | (6) |
|
|
381 | (1) |
|
|
381 | (1) |
|
Structure of Our Basic Call Hook |
|
|
381 | (1) |
|
Removing a Process Record |
|
|
382 | (4) |
|
Process Injection Alternative |
|
|
386 | (1) |
|
Trojan Executable Redirection |
|
|
386 | (6) |
|
Redirection and the Problem with Tripwire |
|
|
386 | (1) |
|
|
387 | (5) |
|
Hiding Files and Directories |
|
|
392 | (2) |
|
|
394 | (14) |
|
|
395 | (2) |
|
Patching the NT Kernel to Remove All Security |
|
|
397 | (11) |
|
|
408 | (21) |
|
Reading and Writing Hardware Memory |
|
|
410 | (1) |
|
Example: Read/Write to the Keyboard Hardware |
|
|
411 | (6) |
|
Enable Read/Write from EEPROM |
|
|
417 | (1) |
|
|
417 | (4) |
|
|
421 | (1) |
|
|
421 | (3) |
|
Serial EEPROM versus Parallel EEPROM |
|
|
424 | (1) |
|
|
425 | (1) |
|
|
425 | (1) |
|
Detecting Chips via Common Flash Interface (CFI) |
|
|
426 | (1) |
|
Example: Detect a Flash RAM Chip |
|
|
427 | (1) |
|
Detecting Chips via ID Mode or JEDEC ID |
|
|
427 | (2) |
|
|
429 | (1) |
|
Reading/Writing the Master Boot Record (MBR) |
|
|
429 | (1) |
|
|
429 | (1) |
|
Adding Network Support to a Driver |
|
|
430 | (9) |
|
|
430 | (2) |
|
Putting the Interface in Promiscuous Mode |
|
|
432 | (1) |
|
Finding the Correct Network Card |
|
|
433 | (5) |
|
Using boron Tags for Security |
|
|
438 | (1) |
|
Adding an Interactive Shell |
|
|
438 | (1) |
|
|
439 | (4) |
|
Intel Interrupt Request (IRQ) Architecture |
|
|
439 | (2) |
|
Hooking the Interrupt Descriptor Table (IDT) |
|
|
441 | (1) |
|
The Mystery of the Programmable Interrupt Controller (PIC) |
|
|
441 | (2) |
|
|
443 | (1) |
|
|
443 | (1) |
|
Windows NT/2000/XP Key Logger |
|
|
443 | (1) |
|
The Keyboard Controller Chip |
|
|
444 | (1) |
|
|
444 | (2) |
|
Using a Rootkit as a Debugger |
|
|
445 | (1) |
|
Disabling Windows System File Protection |
|
|
445 | (1) |
|
Writing Directly to Physical Memory |
|
|
445 | (1) |
|
|
445 | (1) |
|
Infecting the Kernel Image |
|
|
446 | (1) |
|
Execute Redirection 446 Detecting Rootkits |
|
|
446 | (1) |
|
|
446 | (3) |
References |
|
449 | (4) |
Index |
|
453 | |