| Introduction |
|
1 | (1) |
|
|
|
1 | (1) |
|
What does This Book Cover? |
|
|
2 | (1) |
|
|
|
2 | (3) |
|
|
|
5 | (20) |
|
|
|
5 | (2) |
|
Why Should I Care about Security? |
|
|
7 | (1) |
|
What do we Mean by Security? |
|
|
8 | (7) |
|
|
|
8 | (1) |
|
Surely They Would Not Attack Me! |
|
|
9 | (1) |
|
|
|
9 | (1) |
|
Trust, Safety, and Intent |
|
|
10 | (1) |
|
|
|
11 | (1) |
|
|
|
11 | (1) |
|
|
|
12 | (1) |
|
|
|
13 | (2) |
|
|
|
15 | (3) |
|
Vulnerabilities and Exploits |
|
|
15 | (1) |
|
Combined Attacks: ILOVEYOU Redux |
|
|
15 | (2) |
|
|
|
17 | (1) |
|
|
|
18 | (5) |
|
Mission: Moderately Difficult versus Mission: Impossible |
|
|
19 | (2) |
|
|
|
21 | (1) |
|
You Do Not Have to be a Cryptologist |
|
|
21 | (1) |
|
|
|
22 | (1) |
|
|
|
23 | (2) |
|
.NET and Security: An Overview |
|
|
25 | (58) |
|
|
|
25 | (6) |
|
|
|
26 | (2) |
|
Security in Windows 95/98/ME |
|
|
28 | (1) |
|
Security in Internet Explorer |
|
|
29 | (2) |
|
|
|
31 | (10) |
|
|
|
31 | (1) |
|
The Managed Intermediate Language |
|
|
32 | (1) |
|
|
|
32 | (2) |
|
|
|
34 | (3) |
|
|
|
37 | (1) |
|
|
|
37 | (1) |
|
Security Namespaces in the .NET Framework |
|
|
38 | (1) |
|
|
|
38 | (1) |
|
The Web Security Namespace |
|
|
39 | (1) |
|
The Cryptography Namespace |
|
|
39 | (1) |
|
|
|
40 | (1) |
|
The Policy and Permissions Namespaces |
|
|
41 | (16) |
|
Code Security (From Ten Thousand Feet) |
|
|
41 | (1) |
|
|
|
41 | (1) |
|
|
|
42 | (1) |
|
|
|
43 | (1) |
|
|
|
44 | (1) |
|
Host Evidence: The Zone, URL, and Site |
|
|
44 | (1) |
|
|
|
45 | (2) |
|
|
|
47 | (1) |
|
|
|
47 | (2) |
|
|
|
49 | (1) |
|
|
|
49 | (1) |
|
|
|
50 | (1) |
|
|
|
51 | (1) |
|
Out-of-the-Box Permission Sets |
|
|
52 | (4) |
|
|
|
56 | (1) |
|
.NET Code Security in Practice |
|
|
57 | (22) |
|
A First Attempt at a Security Violation |
|
|
57 | (2) |
|
|
|
59 | (1) |
|
|
|
59 | (3) |
|
Forcing a Stack Walk with ``Demand'' |
|
|
62 | (1) |
|
Why Would You Ever Force a Stack Walk? |
|
|
63 | (3) |
|
Restricting Permissions with ``Deny'' and ``PermitOnly'' |
|
|
66 | (1) |
|
|
|
67 | (1) |
|
|
|
68 | (1) |
|
|
|
68 | (1) |
|
Overriding Stack Walks with Assert |
|
|
69 | (1) |
|
Using Asserts and Demands Together |
|
|
70 | (4) |
|
|
|
74 | (1) |
|
Why Use Declarative Security? |
|
|
74 | (2) |
|
|
|
76 | (1) |
|
Refusing Specific Permissions |
|
|
77 | (1) |
|
|
|
77 | (1) |
|
Requesting Optional Permissions |
|
|
78 | (1) |
|
Declarative Security with Permission Sets |
|
|
79 | (1) |
|
Assembly Attributes Overview |
|
|
79 | (1) |
|
|
|
79 | (4) |
|
|
|
83 | (32) |
|
|
|
83 | (13) |
|
|
|
84 | (1) |
|
Making Demands at ``Link Time'' |
|
|
85 | (1) |
|
|
|
85 | (1) |
|
|
|
86 | (6) |
|
Responsibilities of the Caller |
|
|
92 | (1) |
|
|
|
92 | (1) |
|
Calling Methods that have Link Demands |
|
|
93 | (1) |
|
|
|
94 | (1) |
|
|
|
94 | (1) |
|
Suppressing Unmanaged Code Demands |
|
|
95 | (1) |
|
|
|
96 | (1) |
|
|
|
96 | (1) |
|
|
|
97 | (3) |
|
Reflection and Link Demands |
|
|
97 | (1) |
|
|
|
98 | (2) |
|
Reflection and Deny/PermitOnly |
|
|
100 | (1) |
|
Role-Based Security in .NET |
|
|
100 | (12) |
|
|
|
101 | (1) |
|
|
|
101 | (1) |
|
|
|
102 | (1) |
|
|
|
103 | (1) |
|
|
|
103 | (1) |
|
|
|
104 | (5) |
|
Impersonation with WindowsIdentity Objects |
|
|
109 | (3) |
|
|
|
112 | (3) |
|
Security and Customizable Applications |
|
|
115 | (16) |
|
What are the Security Challenges? |
|
|
115 | (1) |
|
If It's Broke then Fix It |
|
|
116 | (13) |
|
Attempt One: Ask the User |
|
|
116 | (3) |
|
Attempt Two: Use PermitOnly |
|
|
119 | (1) |
|
Attempt Three: Lock down the Directory |
|
|
120 | (1) |
|
Attempt Four: Say it is from the Internet |
|
|
120 | (2) |
|
Why is Attempt Four a Bad Idea? |
|
|
122 | (1) |
|
Attempt Five: Custom Policy |
|
|
122 | (1) |
|
|
|
122 | (1) |
|
Custom Membership Condition |
|
|
123 | (2) |
|
|
|
125 | (1) |
|
|
|
125 | (4) |
|
Pros and Cons of Custom Policies |
|
|
129 | (1) |
|
|
|
129 | (2) |
|
How to Write Insecure Code |
|
|
131 | (74) |
|
How to Write Insecure Object Oriented Code |
|
|
132 | (5) |
|
Worst Practice: Fail to Restrict Access |
|
|
132 | (1) |
|
A Brief Refresher on Access Modifiers |
|
|
132 | (1) |
|
Worst Practice: Make too much Public |
|
|
133 | (2) |
|
Worst Practice: Allow Subclassing by Untrusted Assemblies |
|
|
135 | (2) |
|
How to Write Bad Link Demands |
|
|
137 | (4) |
|
Worst Practice: Inconsistent Link Demands in Class Hierarchies |
|
|
137 | (2) |
|
Worst Practice: Inconsistent Class and Method Link Demands |
|
|
139 | (1) |
|
Worst Practice: Structure Constructors |
|
|
140 | (1) |
|
How to Implement Insecure Exception Handling Code |
|
|
141 | (19) |
|
Worst Practice: Leaking Privileged Information |
|
|
141 | (3) |
|
Problem 1: Path Discovery |
|
|
144 | (1) |
|
Problem 2: Denial of Service |
|
|
145 | (1) |
|
Problem 3: The Assert Lives on |
|
|
146 | (1) |
|
Problem 4: Unintended Side Effects |
|
|
146 | (1) |
|
Problem 5: Fit and Finish |
|
|
147 | (1) |
|
Worst Practice: Fail to a Non-Secure Mode |
|
|
147 | (1) |
|
|
|
148 | (4) |
|
Worst Practice: Change State without Handling Exceptions |
|
|
152 | (1) |
|
Worst Practice: Make your State Inconsistent |
|
|
152 | (1) |
|
Worst Practice: Use Bad Defaults |
|
|
153 | (1) |
|
Vulnerabilities Involving Exception Filters |
|
|
154 | (6) |
|
Summing up Exception Handling |
|
|
160 | (1) |
|
|
|
160 | (9) |
|
Worst Practice: Fail to Demand on Cached Data |
|
|
161 | (1) |
|
Worst Practice: Write your own Encryption |
|
|
162 | (1) |
|
Worst Practice: Use XOR ``Encryption'' |
|
|
163 | (1) |
|
Worst Practice: Try to Keep Secrets from the User |
|
|
164 | (1) |
|
Worst Practice: Embed Secret Strings |
|
|
165 | (1) |
|
Worst Practice: Construct or Encrypt Secret Strings |
|
|
166 | (2) |
|
Security through Obscurity |
|
|
168 | (1) |
|
How to Write Insecure Server-Side Code |
|
|
169 | (12) |
|
Denial of Service Attacks |
|
|
170 | (1) |
|
|
|
170 | (1) |
|
|
|
170 | (1) |
|
Worst Practice: Trust the Client |
|
|
171 | (1) |
|
The SQL Injection Vulnerability |
|
|
171 | (5) |
|
The Cross Site Scripting (CSS) Vulnerability |
|
|
176 | (5) |
|
|
|
181 | (21) |
|
|
|
181 | (1) |
|
A Brief Refresher on Threading |
|
|
181 | (2) |
|
So where is the Vulnerability? |
|
|
183 | (1) |
|
|
|
184 | (1) |
|
|
|
184 | (3) |
|
How to Write Bad Serialization Code |
|
|
187 | (1) |
|
A Brief Refresher on Serialization |
|
|
187 | (2) |
|
Worst Practice: Write to Predictable Locations |
|
|
189 | (2) |
|
Worst Practice: Allow Untrusted Code to Serialize Sensitive State |
|
|
191 | (1) |
|
Worst Practice: Allow Untrusted Code to Deserialize Sensitive State |
|
|
192 | (1) |
|
A Brief Note about the Default Serializer |
|
|
192 | (1) |
|
Err On the Side of Caution |
|
|
193 | (1) |
|
How to Write Bad Event Handlers and other Delegates |
|
|
193 | (1) |
|
A Brief Refresher on Delegates |
|
|
193 | (2) |
|
Security Issues with Delegates |
|
|
195 | (6) |
|
|
|
201 | (1) |
|
|
|
201 | (1) |
|
|
|
202 | (3) |
|
|
|
205 | (34) |
|
Secure Code is Solid Code |
|
|
205 | (8) |
|
|
|
205 | (1) |
|
|
|
206 | (1) |
|
|
|
206 | (2) |
|
|
|
208 | (1) |
|
Manage the Risk by Planning for Mistakes |
|
|
208 | (1) |
|
|
|
208 | (1) |
|
Things to Look for When Testing Security |
|
|
209 | (1) |
|
|
|
210 | (1) |
|
|
|
211 | (2) |
|
|
|
213 | (1) |
|
|
|
213 | (12) |
|
|
|
214 | (1) |
|
Public Key Cryptography in a Nutshell |
|
|
215 | (1) |
|
How to Sign an Assembly with a Strong Name |
|
|
215 | (5) |
|
Authenticode and Strong Names |
|
|
220 | (4) |
|
Assembly Security Attributes |
|
|
224 | (1) |
|
Summing Up Assembly Security |
|
|
225 | (1) |
|
|
|
225 | (2) |
|
|
|
227 | (6) |
|
Even Good Software Security is Not Enough |
|
|
233 | (2) |
|
|
|
234 | (1) |
|
|
|
234 | (1) |
|
|
|
235 | (4) |
|
|
|
239 | (22) |
|
Spot the Security Flaw #1: Calling Unmanaged Code |
|
|
240 | (7) |
|
Spot the Security flaw #2: Playing Games |
|
|
247 | (3) |
|
Spot the Security Flaw #3: Server Code |
|
|
250 | (8) |
|
Now Spot the Security Flaws in Your Code |
|
|
258 | (3) |
| Appendix A: A Brief Explanation of Public Key Cryptography |
|
261 | (10) |
|
|
|
261 | (1) |
|
|
|
262 | (1) |
|
|
|
263 | (8) |
|
Performance Considerations |
|
|
268 | (1) |
|
Combining Symmetric and Asymmetric Cryptosystems |
|
|
268 | (1) |
|
Public Key Cryptography and Strong Names |
|
|
269 | (1) |
|
Secure Transmission is Not Important |
|
|
269 | (2) |
| Appendix B: Using ILDASM to View IL |
|
271 | (4) |
| Appendix C: Support, Errata, and Code Download |
|
275 | (4) |
|
How to Download the Sample Code for the Book |
|
|
275 | (1) |
|
|
|
276 | (1) |
|
|
|
276 | (1) |
|
|
|
277 | (2) |
| Index |
|
279 | |