09 Auth Session MGMT
09 Auth Session MGMT
Spring 2013
high level
scheme://domain:port/path?params
HTTP Header: Set-cookie: NAME=VALUE ; domain = (when to send) ; scope if expires=NULL: path = (when to send) this session only secure = (only send over SSL); expires = (when expires) ; HttpOnly
Server
Delete cookie by setting expires to date in past Default scope is domain and path of setting URL
(write SOP)
domain: any domain-suffix of URL-hostname, except TLD example: host = login.site.com allowed domains login.site.com .site.com disallowed domains user.site.com othersite.com .com
login.site.com can set cookies for all of .site.com but not for another site or TLD Problematic for sites like .stanford.edu path: can be set to anything
distinct cookies
(read SOP)
Server
cookie-domain is domain-suffix of URL-domain, and cookie-path is prefix of URL-path, and [protocol=HTTPS if cookie is secure]
Goal: server only sees cookies in its scope
Examples
both set by login.site.com
cookie 1 name = userid value = u1 domain = login.site.com path = / secure http://checkout.site.com/ http://login.site.com/ https://login.site.com/
document.cookie
Javascript URL
javascript: alert(document.cookie)
Cookie: NAME=VALUE
Problem: cs155 expects session-id from login.site.com; cannot tell that session-id cookie was overwritten
http://www.google.com (cleartext) Network attacker can inject into response Set-Cookie: LSID=badguy; secure and overwrite secure cookie
Not a security measure: DOM SOP: x.com/A has access to DOM of x.com/B Path separation is done for efficiency not security: x.com/A is only sent the cookies it needs <iframe src=x.com/B"></iframe> alert(frames[0].document.cookie);
Edit cookie file (FF3: cookies.sqlite) Modify Cookie header (FF: TamperData extension)
Historical problems
" " " " " " " " " " " " " "
Source:
(circa 2000)
D3.COM Pty Ltd: ShopFactory 5.8 @Retail Corporation: @Retail Adgrafix: Check It Out Baron Consulting Group: WebSite Tool ComCity Corporation: SalesCart Crested Butte Software: EasyCart Dansie.net: Dansie Shopping Cart Intelligent Vending Systems: Intellivend Make-a-Store: Make-a-Store OrderPage McMurtrey/Whitaker & Associates: Cart32 3.0 pknutsen@nethut.no: CartMan 1.04 Rich Media Technologies: JustAddCommerce 5.0 SmartCart: SmartCart Web Express: Shoptron 1.2
http://xforce.iss.net/xforce/xfdb/4621
17
Server
Verify tag: T = F(k, value) value should also contain data to prevent cookie replay and swap
Example:
n n
.NET 2.0
System.Web.Configuration.MachineKey
Secret web server key intended for cookie protection Stored on all web servers in site Creating an encrypted cookie with integrity:
HttpSecureCookie.Decode (cookie);
19
Session managemnt
Sessions
" A sequence of requests and responses from
one browser to one (or more) sites n Session can be long (Gmail) or short
n
Browsers sends hashed password on all subsequent HTTP requests: Authorization: Basic ZGFddfibzsdfgkjheczI1NXRleHQ=
User cannot log out other than by closing browser w What if user has multiple accounts? w What if multiple users on same computer? Site cannot customize password dialog Confusing dialog to users Easily spoofed Defeated using a TRACE HTTP request
(on old browsers)
n n
Session tokens
Browser GET /index.html set anonymous session token GET /books.html anonymous session token POST /do-login Username & password elevate to a logged-in session token POST /checkout logged-in session token check credentials (later) Web Site
Validate token
name=sessionid
SESSION HIJACKING
Attacker waits for user to login; then attacker obtains users Session Token and hijacks session
1.
Predictable tokens
" Example:
counter (Verizon Wireless) user logs in, gets counter value, can view sessions of other users weak MAC (WSJ) token = {userid, MACk(userid) } Weak MAC exposes k from few cookies.
" Example:
n n
Use underlying MD5(PRG) framework. but weak PRG [GM05]. n Predictable SessionID s Rails: token = MD5( current time, random nonce )
2. Cookie theft
" Example 1:
n n
What happens at wireless Caf ? (e.g. Firesheep) Other reasons why session token sent in the clear: w HTTPS/HTTP mixed content pages at site w Man-in-the-middle attacks on SSL Cross Site Scripting (XSS) exploits
" Example 2:
For URL tokens, trick user into clicking on URL For cookie tokens, set using XSS exploits (say, using URL tokens)
" Attack:
1. 2. 3.
Attacker gets anonymous session token for site.com Sends URL to user with attackers session token User clicks on URL and logs into site.com w this elevates attackers token to logged-in token Attacker uses elevated token to hijack users session.
4.
Once user logs in, token changes and is unknown to attacker Attackers token is not elevated.
Server stores all data associated to SessionToken: userid, login-status, login-time, etc.
When multiple web servers at site, lots of database lookups to retrieve user state.
e.g.
logout status
Will make it harder to use token at another machine But honest client may change IP addr during session w client will be logged out for no reason.
THE END