Berner Fachhochschule, Technik und Informatik
Advanced Web Technology 10) XSS, CSRF and SQL Injection
- Dr. E. Benoist
Fall Semester 2010/2011
Advanced Web Technology 10) XSS, CSRF and SQL Injection 1
Advanced Web Technology 10) XSS, CSRF and SQL Injection Dr. E. - - PowerPoint PPT Presentation
Berner Fachhochschule, Technik und Informatik Advanced Web Technology 10) XSS, CSRF and SQL Injection Dr. E. Benoist Fall Semester 2010/2011 Advanced Web Technology 10) XSS, CSRF and SQL Injection 1 Table of Contents Cross Site Request
Advanced Web Technology 10) XSS, CSRF and SQL Injection 1
Advanced Web Technology 10) XSS, CSRF and SQL Injection 2
◮ Not a new attack, but simple and devastating ◮ CSRF attack forces a logged-on victim’s browser to send
◮ Target: Perform the chosen action on behalf of the
Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF 3
◮ Insert an image in a HTML file
◮ An image can be generated by a PHP program (or any
Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: Presentation 4
◮ An image can be generated according to some
◮ An image tag can contain something else
→logout”>
Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: Presentation 5
◮ has no authorization checks for vulnerable actions ◮ will process an action if a default login is able to be
→pwd=123”>
◮ Authorizes requests based only on credentials that are
application
integrated logon with Active Directory.
Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: Presentation 6
◮ Most of web applications rely solely on automatically
◮ Vulnerability also known as
Forgery, Hostile Linking, and Automation Attack
Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: Presentation 7
◮ A typical CSRF attack directs the user to invoke some
◮ The following tag can be inserted in any page viewed by
◮ Example: Online banking transfer
→=3434.43”>
Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: Vulnerability 8
◮ Jeremiah Grossman1 Succeeded in making changes in
◮ Even if the user doesn’t know that he can configure his
◮ He used the router’s default account name to perform
→=143.23.45.1”>
◮ Once DNS changed, user will never be able to access a
1Talk in Blackhat 2006 : “Hacking Intranet Sites from the outside” Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: Vulnerability 9
◮ Web-site Owner embedded JavaScript malware ◮ Web page defaced with embedded JavaScript malware ◮ JavaScript Malware injected into a public area of a
◮ Clicked on, a specially-crafted link causing the website
Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: Vulnerability 10
◮ The attacker sends requests from inside the Intranet
◮ CSRF combined with javascript allows to send many
Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: CSRF allows to access the intranet 11
◮ Leaving hosts unpatched
◮ Using default passwords
◮ Do not putting a firewall in front of a host ◮ Everything seams OK because the perimeter firewalls
Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: CSRF allows to access the intranet 12
◮ User authorization credential is automatically included in
◮ The Attacker doesn’t need to supply that credential
◮ Success of CSRF belongs on the probability that the
Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: CSRF allows to access the intranet 13
◮ Combine CSRF and XSS
◮ Risk is increased by that combination
◮ CSRF does not require XSS
◮ Any application with XSS flaws is susceptible to CSRF
non-automatically submitted credential
◮ When building defenses against CSRF attacks, you must
Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: CSRF allows to access the intranet 14
◮ Application must ensure that they are not only relying
◮ Application should use a custom token that the browser
Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: Protection 15
◮ Ensure that there are no XSS vulnerabilities in your
access the hidden data.
◮ Insert custom random tokens into every form and URL
<form action=”/transfer.do” method=”POST”> <input type=”hidden” name=”383838” value=”ց
→1234323433”>
... </form>
the application is then much more complicated to write
Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: Protection 16
◮ For sensitive data or value transactions, re-authenticate
◮ Do not use GET requests for sensitive data or to
the user.
creates a unique URL, which makes CSRF almost impossible to perform
◮ POST alone is an insufficient protection
Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: Protection 17
◮ Goal: Verify that the application generates and requires
◮ Automated approaches:
CSRF vulnerabilities.
code
Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: Protection 18
◮ Cross Site Scripting - XSS
◮ Cross Site Request Forgery - CSRF
from a trusted user2
2wikipedia Advanced Web Technology 10) XSS, CSRF and SQL Injection Cross Site Request Forgery - CSRF: Conclusion 19
◮ Principle:
part of a command or a query.
◮ Injection Flows may be done on:
◮ This vulnerability is very common on Web Application
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Presentation 20
◮ Attacker tricks the interpreter into executing unintended
◮ Attacker supplies unexpected content to a site
◮ Attacker may take control of the interpreter, for
◮ For the Operating System interpreter
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Presentation 21
◮ Environments affected
◮ System is vulnerable when user input is passed without
→+”’”; Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Vulnerability 22
◮ Avoid the use of interpreter if possible ◮ Otherwise: Use safe APIs
◮ Validation is still recommended
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Protection 23
◮ Input Validation
◮ Use strongly typed parameterized query APIs
◮ Enforce least privilege
than what is expected
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Protection 24
◮ Avoid detailed error messages
◮ Use stored procedures
◮ Do not use dynamic query interfaces (such as
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Protection 25
◮ Do not use simple escaping functions
◮ Prefer following methods
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Protection 26
◮ Java EE
Hibernate or Spring
◮ PHP
bindParam()).
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Protection 27
◮ Such a site must access a DB
◮ If the site does not test its input
www.mysite.com/index.php?id=%2710
◮ If the site lets the user see error messages
◮ Examples
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Examples 28
◮ Suppose we have the following HTML Form
◮ and the following PHP line defining a SQL command:
→$user’”;
◮ For our examples, we disable a security feature from the
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Examples 29
◮ We want the select to work in any case ◮ Following expressions are always true
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Examples 30
◮ So we do not need a valid username and password
→AND \
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Examples 31
◮ We can specify the right username and change the
◮ The previous SQL statement becomes
→AND \
◮ So username is OK, but password is not checked!
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Examples 32
◮ Another great principle in SQL injection is Comments
◮ If we inject a #, the rest of the SQL expression is not
→password=’’
◮ If we use the comments /* comments */ we may escape
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Examples 33
◮ Suppose we have the following query, for displaying the
→$number”;
◮ We can copy the content in a file
$number="11 or 1=1 INTO OUTFILE ’/tmp/test.security.txt’"
◮ Suppose the Attacker has an account on the system
→OUTFILE\
◮ Attacker could create any php file inside the system!!
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Examples 34
◮ Since most of the server have magic quotes gpc = on
◮ Use MySQL char() function
◮ Previous attack becomes
UPDATE news SET votes=votes+1, score=score+$note ց
→WHERE\
newsID=’$id’ ,
$note=”3, title=char(104,111,112)
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Examples 35
◮ From SQL injection in PHP ◮ Configure PHP such that ’ and ” are automatically
◮ Always quote input before sending query to an
◮ Do not use any interpreter at all
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Examples 36
◮ SQL Injection allows attacker to
◮ Easy protection are already exploited
database layer is a must (also from the point of view of Design)
◮ Solution? test your inputs!
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Conclusion 37
◮ Infrastructure Security is Vital
◮ Application Security must not be forgotten
◮ Teach your users
◮ Security is expensive
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Conclusion 38
◮ OWASP Top 10 - 2007
◮ A Guide for Building Secure Web Applications and Web
◮ Advanced SQL Injection in SQL Server Applications - Chris
◮ L’injection (My)SQL via PHP - leseulfrog
◮ SQLMAP (a SQL Injection Tool)
Advanced Web Technology 10) XSS, CSRF and SQL Injection Injection Flows: Conclusion 39