XCS110 All Slides
XCS110 All Slides
TO WEB SECURITY
John Mitchell
Dan Boneh
MODULE 2
HTTP
Rendering the Content
Isolation
Navigation
Communication
Client State
Click-Jacking
Frame Busting
Introduction
Module 2: Web Background
and the Browser Security Model
Reported Web Vulnerabilities "In the Wild"
XSS peak
37%
49% 51%
63%
Web Applications (49%) Others (51%) Web Applications (49%) Others (51%)
Web Security Challenge
Good server
Enter password?
Browser
Network
User
Bad Server
How can honest users safely interact with
well-intentioned sites, while still freely
browsing the web (search, shopping, etc.) ?
Can also operate as
client to other servers
Goals of web security
Safely browse the web
§ Users should be able to visit a variety of web sites, without incurring harm:
› No stolen information (without user’s permission)
› Site A cannot compromise session at Site B
Support secure web applications
§ Applications delivered over the web should have the same security properties we
require for stand-alone applications
And
§ Since many mobile apps are interfaces to web sites,
§ Support security for mobile apps.
Web Threat Models
Web attacker
§ Control attacker.com
§ Can obtain SSL/TLS certificate for attacker.com
§ User visits attacker.com
› Or: runs attacker’s Facebook app
Network attacker
§ Passive: Wireless eavesdropper
§ Active: Evil router, DNS poisoning
Malware attacker
§ Attacker escapes browser isolation mechanisms and run
separately under control of OS
Outline
§ Web security goals and threat models
§ HTTP
§ Rendering: Html, DOM, embedded content, JavaScript
§ Isolation: frames, same-origin policy, HTML5 sandboxing
§ Communication: fragment, post-message, cross-origin request
§ Frame navigation: Same-origin policy, descendant policy
§ Client storage: Cookies, Local storage, Native Client
§ Click-jacking, tap-jacking, frame busting
HTTP
Module 2: Web Background
and the Browser Security Model
Uniform Resource Locator (URL)
Example:
http://stanford.edu:81/class?name=cs155#homework
Protocol
Fragment
Hostname
Port Path
Query
Blank line
Data – none for GET
HTTP/1.0 200 OK
Date: Sun, 21 Apr 1996 02:20:42 GMT
Server: Microsoft-Internet-Information-Server/5.0
Connection: keep-alive
Content-Type: text/html Data
Last-Modified: Thu, 18 Apr 1996 17:39:05 GMT
Set-Cookie: …
Content-Length: 2543
Cookies
Rendering Content
Module 2: Web Background
and the Browser Security Model
Rendering content
Browser execution model
Each browser window or frame
§ Loads content
§ Renders it
› Processes HTML and scripts to display page
› May involve images, subframes, etc.
§ Responds to events
Events can be
§ User actions: OnClick, OnMouseover
§ Rendering: OnLoad, OnBeforeUnload
§ Timing: setTimeout(), clearTimeout()
<head>
<title>Washington Post: Breaking News, World, US, DC News .. Analysis</title>
...
</head>
<body class="eidos homepage sectionfront">
<script type="text/javascript">
if(self!==top&&!(top.window.location.pathname).startsWith('/PortalEdito
r')){top.location=self.location;}
</script>
...
<h2 class="headline"><a href="/world/national-security/nsa-gathered-
thousands-of-americans-e-mails-before-court-struck-down-
program/2013/08/21/146ba4b6-0a90-11e3-b87c-476db8ac34cd_story.html">
Secret court: <br>NSA gathered thousands of domestic e-mails</a>
...
<p class="byline">Ellen Nakashima …</p>
<p class="">
The program unlawfully gathered as many as tens of thousands of e-mails,
according to a 2011 opinion.</p>
...
<div class="hide"><img class=""
src="http://ad.doubleclick.net/ad/N4359.washingtonpost.com/B7241351.19;sz=1x1
;ord=[timestamp]?" width="1" height="1" border="0" style="display: inline-
block; "></div>
...
Share this video:
...
<a class="facebook_static"
onclick="TWP.Module.SocialButtons.staticSocialPopup('http://www.facebook.com/
sharer.php?u=http://www.washingtonpost.com/posttv/video/thefold/tonight-on-
the-fold-august-21-2013/2013/08/21/36ed282c-0a98-11e3-9941-
6711ed662e71_video.html%3Ffb_ref%3Dsm_btn_fb')">
...
Document Object Model (DOM)
Object-oriented interface used to read and write docs
§ web page in HTML is structured data
§ DOM provides representation of this hierarchy
Examples
§ Properties: document.alinkColor, document.URL,
document.forms[ ], document.links[ ], document.anchors[ ]
§ Methods: document.write(document.referrer)
<html>
…
<p> … </p>
…
<img src=“http://example.com/sunset.gif” height="50" width="100">
…
</html>
<img src="image.gif"
§ Runs onError handler if image does not
onerror="alert('The existcould
image and cannot load
not be loaded.')“
>
http://www.w3schools.com/jsref/jsref_onError.asp
Basic web functionality
JavaScript timing
Sample code
<html><body><img id="test" style="display: none">
<script>
var test = document.getElementById(’test’);
var start = new Date();
test.onerror = function() {
var end = new Date();
alert("Total time: " + (end - start));
}
test.src = "http://www.example.com/page.html";
</script>
</body></html>
§ When response header indicates that page is not an image, the browser
stops and notifies JavaScript via the onerror handler.
Basic web functionality
Port scanning behind firewall
JavaScript can:
§ Request images from internal IP addresses
› Example: <img src=“192.168.0.4:8080”/>
§ Use timeout/onError to determine success/failure
§ Fingerprint webapps using known image names
Malicious
2) “check this out”
Web page
scan
3) port scan results Browser
scan
Firewall
Remote scripting
Goal
§ Exchange data between a client-side app running in a browser and server-side app, without reloading page
Methods
§ Java Applet/ActiveX control/Flash
› Can make HTTP requests and interact with client-side JavaScript code, but requires LiveConnect (not available on all browsers)
§ XML-RPC
› open, standards-based technology that requires XML-RPC libraries on server and in your client-side code.
§ Simple HTTP via a hidden IFRAME
› IFRAME with a script on your web server (or database of static HTML files) is by far the easiest of the three remote scripting options
See: http://developer.apple.com/internet/webcontent/iframe.html
Simple remote scripting example
client.html: RPC by passing arguments to server.html in query string
<script type="text/javascript">
function handleResponse() {
alert('this function is called from server.html') }
</script>
<iframe id="RSIFrame" name="RSIFrame"
style="width:0px; height:0px; border: 0px"
src="blank.html">
</iframe>
<a href="server.html" target="RSIFrame">make RPC call</a>
<script type="text/javascript">
window.parent.handleResponse()
</script>
32
Analogy
Operating system Web browser
Primitives Primitives
§ System calls § Document object model
§ Frames
§ Processes
§ Cookies / localStorage
§ Disk
Principals: “Origins”
Principals: Users § Mandatory access control
§ Discretionary access control
Vulnerabilities
Vulnerabilities § Cross-site scripting
§ Cross-site request forgery
§ Buffer overflow
§ Cache history attacks
§ Root exploit § …
Browser security mechanism
A B A
A
<script src=https://seal.verisign.com/getseal?
host_name=a.com></script>
VeriSign
www.facebook.com chat.facebook.com
www.facebook.com
www.facebook.com
facebook.com
facebook.com
chat.facebook.com
www.facebook.com
awglogin
window.open("https://attacker.com/", "awglogin");
What should the policy be?
Sibling
Frame Bust
Child
Descendant
43
Legacy Browser Behavior
Browser Policy
IE 6 (default) Permissive
IE 6 (option) Child
IE7 (no Flash) Descendant
IE7 (with Flash) Permissive
Firefox 2 Window
Safari 3 Permissive
Opera 9 Window
HTML 5 Child
Window Policy Anomaly
top.frames[1].location = "http://www.attacker.com/...";
top.frames[2].location = "http://www.attacker.com/...";
...
Legacy Browser Behavior
Browser Policy
IE 6 (default) Permissive
IE 6 (option) Child
IE7 (no Flash) Descendant
IE7 (with Flash) Permissive
Firefox 2 Window
Safari 3 Permissive
Opera 9 Window
HTML 5 Child
Adoption of Descendent Policy
Browser Policy
IE7 (no Flash) Descendant
IE7 (with Flash) Descendant
Firefox 3 Descendant
Safari 3 Descendant
Opera 9 (many policies)
HTML 5 Descendant
Communication
Module 2: Web Background
and the Browser Security Model
Fragment Identifier Messaging
Add a contact
Share contacts
postMessage syntax
frames[0].postMessage("Attack at dawn!",
"http://b.com/");
Attack at dawn!
Facebook
Anecdote
Why include “targetOrigin”?
What goes wrong?
frames[0].postMessage("Attack at dawn!");
52
Two-way communication
A method call is associated with a response
Can build this on top of postMessage
§ Messenger: Each time you call a method in the iframe, you pass a reply function that is
called with the results of that method call.
jQuery postMessage plugin
Wraps the postMessage API and simplifies its usage.
Works in browsers that do not support postMessage method by using fragment
navigation (hash portion of the url)
Network communication
Site A Site B
Browser GET …
Cookie: NAME = VALUE
Server
POST login.cgi
Username & pwd Validate user
GET restricted.html
Cookie: auth=val restricted.html
auth=val Check val
If YES, YES/NO
restricted.html
Cookie Security Policy
Uses:
§ User authentication
§ Personalization
§ User tracking: e.g. Doubleclick (3rd party cookies)
GET …
Browser
Server
HTTP Header:
Set-cookie: NAME=VALUE ;
Secure=true
• … but no integrity
• Can rewrite secure cookies over HTTP
Þ network attacker can rewrite secure cookies
Þ can log user into attacker’s account
httpOnly Cookies
GET …
Browser
Server
HTTP Header:
Set-cookie: NAME=VALUE ;
httpOnly
Retrieve it:
Clickjacking
Clicks meant for the visible page are hijacked and routed to
another, invisible page
slide 70
<iframe name=“myframe”
src=“http://www.google.com/”>
This text is ignored by most
browsers.
</iframe>
Frame Busting
Frame busting:
if (top != self)
top.location.href = location.href
Better Frame Busting
if (top != self)
top.location.href = location.href
else { … code of page here …}
• Web security goals and threat models
• HTTP
• Rendering: Html, DOM, embedded content,
JavaScript
• Isolation: frames, same-origin policy, HTML5
sandboxing Summary
• Communication: fragment, post-message, cross-
origin request
• Frame navigation: Same-origin policy, descendant
policy
• Client storage: Cookies, Local storage, Native Client
• Click-jacking, tap-jacking, frame busting
MODULE 3
TLS 1.3
Compression attacks
Password Breaches
Certificates on the Web
Abusing Mobile Sensors
Topics for this section
TLS attacks and defenses:
Compression attacks: CRIME and BREACH, TLS 1.3
k encrypt
hdr ciphertext
How?
POST /bank.com/buy?id=aapl
Cookie: uid=JhPL8g69684rksfsdg
POST /bank.com/buy?id=aapl
Cookie: uid=JhPL8g69684rksfsdg
POST /bank.com/buy?id=goog
Cookie: uid=JhPL8g69684rksfsdg
POST /bank.com/buy?id=aapl
Cookie: uid=JhPL8g69684rksfsdg
Host: bank.com
Javascript
Goal: steal user’s bank cookie
Javascript can issue requests to Bank,
but cannot read Cookie value
Even worse: the CRIME attack [RD’2012]
(simplified)
POST /bank.com/buy?uid=A11111…
16KB Cookie: uid=J hPL8g69684rksfsdg
Host: bank.com
POST /bank.com/buy?uid=B11111…
16KB Cookie: uid=J hPL8g69684rksfsdg
Host: bank.com
POST /bank.com/buy?uid=J11111…
16KB Cookie: uid=J hPL8g69684rksfsdg
Host: bank.com
POST /bank.com/buy?uid=Ja1111…
16KB Cookie: uid=Jh PL8g69684rksfsdg
Host: bank.com
POST /bank.com/buy?uid=Jh1111…
16KB Cookie: uid=Jh PL8g69684rksfsdg
Host: bank.com
POST /bank.com/buy?uid=Jh1111…
16KB Cookie: uid=Jh PL8g69684rksfsdg
Host: bank.com
A proposed defense:
A common occurrence
Fraction 2009 (6 most
Example: the5%
Rockyou password
1.1% list,0.9% 0.5% common pwds) 0.5%
0.5% 0.3%
of users:
123456, 12345, Password, iloveyou, princess, abc123
List of 360,000,000 words covers about 25% of user passwords Total: 8.8%
How to store passwords
First rule of password storage: never store passwords in the clear !
password database
Alice
Alice SA H(pwA , SA)
pwA
Bob SB H(pwB , SB)
… … …
id salt hash
To validate a given password server checks:
H(pwA , SA) ≟ StoredHash(Alice)
How to hash?
Linked-in: SHA-1 hashed (unsalted) passwords
⇒ 6 days, 90% of pwds. recovered by exhaustive search
The problem: SHA-1 is too fast …
attacker can try all words in dictionary
To hash passwords:
• Use a keyed hash function (e.g., HMAC) where key stored in HSM
3 mill
50x
3000
2 mill
2000
1 mill
1000
93
0
0
Intel x86 Antminer
Problems:
Biometrics are not generally secret
Cannot be changed, unlike passwords
Identification:
login page
pwd
data
user database
g e : m
confirm h a lle n Alice pkA
2FA c
k , m)
si g n ( s Bob pkB
o ns e :
Resp … …
sk
id pub-key
No secrets on server, simple user experience
Certificates
on the Web
Module 3: Attacks and Defenses
Certificate Issuance Woes
Wrong issuance:
2011: Comodo and DigiNotar RAs hacked, issue certs for Gmail, Yahoo! Mail
2013: TurkTrust issued cert. for gmail.com (discovered by pinning)
2014: Indian NIC (intermediate CA trusted by the root CA IndiaCCA) issue certs
for Google and Yahoo! domains
Result: (1) India CCA revoked NIC’s intermediate certificate
(2) Chrome restricts India CCA root to only seven Indian domains
2015: MCS (intermediate CA cert issued by CNNIC) issues certs for Google
domains
Result: current CNNIC root no longer recognized by Chrome
⇒ enables eavesdropping w/o a warning on user’s session
Man in the middle attack using rogue cert
GET https://bank.com BadguyCert BankCert
ClientHello attacker ClientHello bank
device-id
app
Example 2: Gyrophone [MBN’14]
Trouble:
› Gyroscope picks up air vibrations (a.k.a speech)
› Sample rate (apps.): 200Hz
› Machine learning ⇒ can recognize some speech
Example 3: Power usage sensor
Modern phones measure power drained from battery
Enables apps to optimize power use
Repeatedly read:
/sys/class/power_supply/battery/voltage_now
/sys/class/power_supply/battery/current_now
Unrestricted access.
Can this be abused?
Example 3: Power usage sensor
Prevention: