Web Security, Part 1
(as usual, thanks to Dave Wagner and Vern Paxson)
1
Web Security, Part 1 (as usual, thanks to Dave Wagner and Vern - - PowerPoint PPT Presentation
Web Security, Part 1 (as usual, thanks to Dave Wagner and Vern Paxson) 1 Web Server Threats What can happen? Compromise Defacement Gateway to attacking clients Disclosure (not mutually exclusive) And what makes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
http://user:pass@berkeley.edu:81/class?name=cs161#homework
Protocol Username Password Host Port Path Query Fragment 17
18
– and returns stdout to the user
19
– and returns stdout to the user
20
21
22
23
processed
– E.g. …regex=foo%27; mail … – E.g. …regex=foo%25%32%37; mail …
» Double-escaping bug
24
25
26
27
Browser Web server URL / Form Web page built from database command.php? arg1=x&arg2=y Database server
28
29
30
31
32
Victim Server Victim SQL DB Attacker post malicious form unintended query receive valuable data 1 2 3
33
Victim Server Victim SQL DB Attacker post malicious form unintended command Database modified 1 2 3
34
Defenses (work-in-progress)
35
(seen every day)
36
37
38
GET /index.html HTTP/1.1 Accept: image/gif, image/x-bitmap, image/jpeg, */* Accept-Language: en Connection: Keep-Alive User-Agent: Mozilla/1.22 (compatible; MSIE 2.0; Windows 95) Host: www.example.com Referer: http://www.google.com?q=dingbats
Method Resource HTTP version Headers Data (if POST; none for GET) Blank line
39
HTTP/1.0 200 OK Date: Sun, 19 Apr 2009 02:20:42 GMT Server: Microsoft-Internet-Information-Server/5.0 Connection: keep-alive Content-Type: text/html Last-Modified: Sat, 18 Apr 2009 17:39:05 GMT Set-Cookie: session=44eb; path=/servlets Content-Length: 2543 <HTML> Some data... blah, blah, blah </HTML>
HTTP version Status code Reason phrase Headers Data
Cookies
40
41
42
43
44
45
46
n frames, tabs, sequential visits
47
48
49
n (protocol, domain, port (in some browsers))
50
n <script> tags: Javascript executes with full privileges
n <img> tags: may contain arbitrary HTML content
n More on this in a few minutes
51
– Domain = <server, protocol, port> from which the frame content was downloaded
Server = example.com, protocol = HTTP (maybe HTTPS)
– Access = read and modify values, including page contents
<script ¡type="text/javascript"> ¡// ¡Downloaded ¡from ¡foo.com ¡ ¡ ¡ ¡ ¡ ¡ ¡src="http://www.bar.com/scripts/script.js"> ¡ ¡ ¡ ¡ ¡// ¡Executes ¡as ¡if ¡it ¡were ¡from ¡foo.com ¡ </script>
52
Attack Server Victim client visit web site receive malicious page click on link echo user input 1 2 3 send valuable data 5 4 (A “reflected” XSS attack) Server Patsy/Victim
53
<HTML> <TITLE> Search Results </TITLE> <BODY> Results for <?php echo $_GET[term] ?> : . . . </BODY> </HTML>
54
<HTML> Results for <script> … </script> …
Sends badguy.com cookie for victim.com Or any other arbitrary execution / rewrite victim.com page !
55
Attack Server Server Patsy/Victim User Victim Inject malicious script request content receive malicious script 1 2 3 steal valuable data 4
(A “stored” XSS attack)
56
<script>, <body>, onclick, <a href=javascript://>
<div style="background:url('javascript:alert(1)')">
Run arbitrary code in full MySpace context Exfiltrate data to attacker and/or make arb. MySpace changes User Victim Server Patsy/Victim
57
HTTP/1.1 200 OK … Content-Type: image/jpeg <html> fooled ya </html>
58
victim site
web app, such as a database
59
– Ensure that your app validates all headers, cookies, query strings, form fields, and hidden fields (i.e., all parameters) against a rigorous specification of what should be allowed. – Do not attempt to identify active content and remove, filter, or sanitize it. There are too many types of active content and too many ways of encoding it to get around filters for such content. – We [= OWASP] strongly recommend a ‘positive’ security policy that specifies what is allowed. ‘Negative’ or attack signature based policies are difficult to maintain and are likely to be incomplete.
Use White- listing Beware Black- listing
60
61
n Must be a suffix of the actual domain n Must explicitly set document.domain even if the
62
63
64
n Example: allow users to enter text that includes
n Don’t use frames: content from different sources
n Analyze content before including in page:
w Don’t allow some features (HTML, Javascript) w Modify code to include additional run-time checks
65
n All identifiers get application-specific prefix to avoid
n Can’t access DOM directly: instead of n must invoke FBJS method that enforces isolation
66
n Password field on Citibank website contained within a
n Attacker could navigate this frame to an identical-
n Attack can come from any open window or tab
67
awglogin
window.open("https://attacker.com/", ¡"awglogin");
68
Child Sibling Descendant Frame Bust
69
n Older versions such as IE6 and Firefox 2 are more
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
Apparent browser is generated by script running in real browser!
85
86
87
88
89
90
91
92