SQL Injection and XSS



Similar documents
ASP.NET MVC Secure Coding 4-Day hands on Course. Course Syllabus

Check list for web developers

Cracking the Perimeter via Web Application Hacking. Zach Grace, CISSP, CEH January 17, Mega Conference

Web Application Security

Gateway Apps - Security Summary SECURITY SUMMARY

Adobe Systems Incorporated

Columbia University Web Security Standards and Practices. Objective and Scope

Creating Stronger, Safer, Web Facing Code. JPL IT Security Mary Rivera June 17, 2011

WordPress Security Scan Configuration

Magento Security and Vulnerabilities. Roman Stepanov

Project 2: Web Security Pitfalls

WebCruiser Web Vulnerability Scanner User Guide

FINAL DoIT v.8 APPLICATION SECURITY PROCEDURE

Passing PCI Compliance How to Address the Application Security Mandates

05.0 Application Development

Web Application Guidelines

Advanced Web Technology 10) XSS, CSRF and SQL Injection 2

Intrusion detection for web applications

Sitefinity Security and Best Practices

Online Vulnerability Scanner Quick Start Guide

CSE598i - Web 2.0 Security OWASP Top 10: The Ten Most Critical Web Application Security Vulnerabilities

Cross Site Scripting (XSS) and PHP Security. Anthony Ferrara NYPHP and OWASP Security Series June 30, 2011

Thomas Röthlisberger IT Security Analyst

Criteria for web application security check. Version

Application security testing: Protecting your application and data

Detecting and Exploiting XSS with Xenotix XSS Exploit Framework

ArcGIS Server Security Threats & Best Practices David Cordes Michael Young

WHITE PAPER. FortiWeb and the OWASP Top 10 Mitigating the most dangerous application security threats

Still Aren't Doing. Frank Kim

Using Foundstone CookieDigger to Analyze Web Session Management

Application Layer Encryption: Protecting against Application Logic and Session Theft Attacks. Whitepaper

Web Application Vulnerability Testing with Nessus

The Top Web Application Attacks: Are you vulnerable?

Where every interaction matters.

Acunetix Website Audit. 5 November, Developer Report. Generated by Acunetix WVS Reporter (v8.0 Build )

QUANTIFY INSTALLATION GUIDE

Web Application Security. Vulnerabilities, Weakness and Countermeasures. Massimo Cotelli CISSP. Secure

Webapps Vulnerability Report

WEB SECURITY CONCERNS THAT WEB VULNERABILITY SCANNING CAN IDENTIFY

Finding and Preventing Cross- Site Request Forgery. Tom Gallagher Security Test Lead, Microsoft

QualysGuard WAS. Getting Started Guide Version 3.3. March 21, 2014

OWASP TOP 10 ILIA

External Vulnerability Assessment. -Technical Summary- ABC ORGANIZATION

WebCruiser User Guide

Recon and Mapping Tools and Exploitation Tools in SamuraiWTF Report section Nick Robbins

OWASP Top Ten Tools and Tactics

Chapter 1 Web Application (In)security 1

(WAPT) Web Application Penetration Testing

Application Security Testing

VIDEO intypedia007en LESSON 7: WEB APPLICATION SECURITY - INTRODUCTION TO SQL INJECTION TECHNIQUES. AUTHOR: Chema Alonso

Hacking Web Apps. Detecting and Preventing Web Application Security Problems. Jorge Blanco Alcover. Mike Shema. Technical Editor SYNGRESS

FINAL DoIT v.4 PAYMENT CARD INDUSTRY DATA SECURITY STANDARDS APPLICATION DEVELOPMENT AND MAINTENANCE PROCEDURES

Web Application Security

Guidelines for Web applications protection with dedicated Web Application Firewall

Web Application Security Guidelines for Hosting Dynamic Websites on NIC Servers

Columbia University Web Application Security Standards and Practices. Objective and Scope

JOOMLA SECURITY. ireland website design. by Oliver Hummel. ADDRESS Unit 12D, Six Cross Roads Business Park, Waterford City

External Network & Web Application Assessment. For The XXX Group LLC October 2012

MS Enterprise Library 5.0 (Logging Application Block)

Safewhere*Identify 3.4. Release Notes

Threat Modeling. Categorizing the nature and severity of system vulnerabilities. John B. Dickson, CISSP

Thick Client Application Security

Hacking the WordpressEcosystem

Ruby on Rails Secure Coding Recommendations

What is Web Security? Motivation

Hack Proof Your Webapps

JVA-122. Secure Java Web Development

Web Application Report

Contemporary Web Application Attacks. Ivan Pang Senior Consultant Edvance Limited

Security features of ZK Framework

Detecting Web Application Vulnerabilities Using Open Source Means. OWASP 3rd Free / Libre / Open Source Software (FLOSS) Conference 27/5/2008

Web Plus Security Features and Recommendations

Acunetix Web Vulnerability Scanner. Getting Started. By Acunetix Ltd.

Exploits: XSS, SQLI, Buffer Overflow

APPLICATION SECURITY AND ITS IMPORTANCE

Web Application Hacking (Penetration Testing) 5-day Hands-On Course

Web Application Security

Testing the OWASP Top 10 Security Issues

MS SQL Server Database Management

A Server and Browser-Transparent CSRF Defense for Web 2.0 Applications. Slides by Connor Schnaith

Advanced Security for Systems Engineering VO 01: Web Application Security

OWASP and OWASP Top 10 (2007 Update) OWASP. The OWASP Foundation. Dave Wichers. The OWASP Foundation. OWASP Conferences Chair

HTTPParameter Pollution. ChrysostomosDaniel

1. Introduction. 2. Web Application. 3. Components. 4. Common Vulnerabilities. 5. Improving security in Web applications

Agenda. SQL Injection Impact in the Real World Attack Scenario (1) CHAPTER 8 SQL Injection

SQL Injection 2.0: Bigger, Badder, Faster and More Dangerous Than Ever. Dana Tamir, Product Marketing Manager, Imperva

5 Simple Steps to Secure Database Development

THE OPEN UNIVERSITY OF TANZANIA

Secure Web Development Teaching Modules 1. Threat Assessment

Enterprise Application Security Workshop Series

Web Application Security Assessment and Vulnerability Mitigation Tests

Penetration Test Report

To install Multifront you need to have familiarity with Internet Information Services (IIS), Microsoft.NET Framework and SQL Server 2008.

MatriXay WEB Application Vulnerability Scanner V Overview. (DAS- WEBScan ) The best WEB application assessment tool

Top Ten Web Application Vulnerabilities in J2EE. Vincent Partington and Eelco Klaver Xebia

Input Validation Vulnerabilities, Encoded Attack Vectors and Mitigations OWASP. The OWASP Foundation. Marco Morana & Scott Nusbaum

Transcription:

SQL Injection and XSS How they work and how to stop them. Rob Kraft, Rob@RobKraft.org September 22, 2011 Rob Kraft www.kraftsoftware.com 1

What r hackers looking 4? Non-specific attacks Identifying vulnerable servers Turning the computer into a zombie (botnet) Hard disk space Specific attacks Info to exploit: Financial Data Doing damage September 22, 2011 Rob Kraft www.kraftsoftware.com 2

SQL Injection Prevention Overview Programmers Don t use Dynamic SQL Validate Inputs (on the server side) Don t provide detailed errors to users DBAs Restrict database permissions Review Logs Disable unneeded features Encrypt data, Strong Procedures September 22, 2011 Rob Kraft www.kraftsoftware.com 3

SQL Injection Prevention Overview Network Administrators Configure firewalls to watch for scans Windows Administrators Configure IIS to use URL Scanning Require strong passwords with expirations Use different accounts for SQL Services Auditing Review configurations and logs September 22, 2011 Rob Kraft www.kraftsoftware.com 4

Don t use dynamic SQL Do NOT build SQL Dynamically like this: sql = "select title from titles where id =" + id; September 22, 2011 Rob Kraft www.kraftsoftware.com 5

Do use Parameters DO use parameters (not just on strings) sql = select title from titles where id = @id"; mycmd.parameters.addwithvalue("@id",txt1.text); Or Write your own formatter sql = sql.replace( ', '' ); Tip: It is usually easier to review code that uses parameters for proper usage. Tip: Review code. September 22, 2011 Rob Kraft www.kraftsoftware.com 6

Comparison strcity = Lee's Summit ; sql = where city = ' + strcity + ' ; where city = 'Lee's Summit' - Error sql = where city = @city ; Parameters.Add( @city,strcity); where city = 'Lee''s Summit' No Error September 22, 2011 Rob Kraft www.kraftsoftware.com 7

Dangerous Stored Procedure CREATE PROCEDURE dbo.loginaccount ( @UserName nvarchar(20), @Password nvarchar(20)) AS EXECUTE ( SELECT USERNAME, USERID FROM USERS WHERE USERNAME = + @UserName + AND PASSWORD = + @Password + ) RETURN Don t build dynamic SQL in stored procedures. September 22, 2011 Rob Kraft www.kraftsoftware.com 8

Preventing SQL Injection IIS Sites: Set the mode of <customerrors> in web.config to On or RemoteOnly to minimize information returned to the client s browser that a hacker could use to learn about your databases. September 22, 2011 Rob Kraft www.kraftsoftware.com 9

Validate Input Validate data input Use javascript to provide a friendly and responsive UI to users, but don t rely on it for security Use ASP.Net Validators, but don t rely on them Check input lengths (and log rejections) Use a Regex Whitelist (and log rejections) September 22, 2011 Rob Kraft www.kraftsoftware.com 10

Regex Example Regex allowregex = new Regex(@ ^[a-za-z\s\ ]*$ ); // But we disallow common SQL functions Regex disallowregex = new Regex( (union select drop delete) ); if ((!allowregex.ismatch(textboxlastname.text)) (disallowregex.ismatch(textboxlastname.text))) { } labelerrormessage.text = Invalid name. ; return; September 22, 2011 Rob Kraft www.kraftsoftware.com 11

Restrict Database Permissions NEVER use sa for an application NEVER use an Admin account for an application Use a database logon, or logons with minimal database permissions required by the application. Use stored procedures don t give the dbms logon account permission to the underlying tables Turn off xp_cmdshell Use SQL 2008/2005 instead of SQL 2000 September 22, 2011 Rob Kraft www.kraftsoftware.com 12

Don t depend on front-end devices Internet Do NOT rely on signature based detection You can block --; but what about %2d%2d You can block union; but what about un + ion September 22, 2011 Rob Kraft www.kraftsoftware.com 13

Preventing SQL Injection Review logs: Failed SQL Logins URL Requests September 22, 2011 Rob Kraft www.kraftsoftware.com 14

Other technologies Web Services Web services are also at risk for SQL Injection LINQ to SQL is safe by default Dim q = From c in db.customers Where c.city = Lee s Summit Nhibernate is safe by default MS Entity Framework is safe by default September 22, 2011 Rob Kraft www.kraftsoftware.com 15

September 22, 2011 Rob Kraft www.kraftsoftware.com 16

Topic 2: Cross Site Scripting (XSS) XSS is also called 2 nd Order SQL Injection Data is injected into a database, and is used later to attack. HTML or Javascript stored in the database that executes when rendered on a web page. September 22, 2011 Rob Kraft www.kraftsoftware.com 17

A Script embedded in a web site sends data to the hacker s site. In this example, a hacker may have embedded a script in a book review on Amazon. When any user navigates to the page with the book review, information from their cookie is sent to the hacker s web site. September 22, 2011 Rob Kraft www.kraftsoftware.com 18

How to stop XSS Check that ASP.Net request validation is enabled ValidateRequest=true on ASP.Net web pages Check input lengths or use a Regex Whitelist HttpUtility.HTMLEncode and URLEncode (blacklist) Better: https://www.owasp.org/index.php/esapi Better: Microsoft Anti-XSS Libraries Use the innertext Property Instead of innerhtml Better: jquery: $( tagname ).html(value) September 22, 2011 Rob Kraft www.kraftsoftware.com 19

How to stop XSS - Dilemma To prevent XSS we must encode output. To render output correctly we must not double encode it. Therefore we need to know what encodings may be in the raw data: HTML, javascript, CSS, XML We need to know where to perform encoding (server side or client side) I haven t found a great solution for client-side yet. September 22, 2011 Rob Kraft www.kraftsoftware.com 20

Microsoft Resources A Microsoft tool for scanning for injection problems: www.pnpguidance.net/post/microsoftsourcecodeanalyzersqlinject iontoolfindsqlinjectionproblems.aspx Microsoft guidance in SQL 2008: msdn2.microsoft.com/en-us/library/ms161953.aspx How To: Protect From SQL Injection in ASP.NET msdn.microsoft.com/en-us/library/ms998271.aspx Microsoft Guidance on XSS msdn.microsoft.com/en-us/library/ms998274.aspx Microsoft Security Development Lifecycle (SDL)-- Microsoft Anti-Scripting library 4.0: http://www.microsoft.com/downloads/en/details.aspx?familyid=f4cd231b-7e06-445bbec7-343e5884e651 September 22, 2011 Rob Kraft www.kraftsoftware.com 21

Good resources OWASP https://www.owasp.org/index.php/template:cheatsheet_navigation Examples of using Regex against injection www.developerfusion.com/article/5855/beyond-stored-proceduresdefenseindepth-against-sql-injection Good examples of SQL Injection en.wikipedia.org/wiki/sql_injection www.unixwiz.net/techtips/sql-injection.html CSRF: en.wikipedia.org/wiki/cross-site_request_forgery www.freedom-to-tinker.com/sites/default/files/csrf.pdf September 22, 2011 Rob Kraft www.kraftsoftware.com 22

Tools to help Absinthe: blind injection attack and analysis tool www.0x90.org/releases/absinthe FXCop msdn.microsoft.com/enus/library/bb429476(vs.80).aspx Microsoft Security Runtime Engine blogs.msdn.com/cisg/archive/2008/10/24/asneak-peak-at-the-security-runtime-engine.aspx September 22, 2011 Rob Kraft www.kraftsoftware.com 23

Summation BAD: "select Title from titles where title like '%" + input + "%'" GOOD: mycmd = new SqlDataAdapter("select Title from titles where title like @query", m_sqlconn); parm = mycmd.selectcommand.parameters.add( "@query", SqlDbType.VarChar, 10); parm.value = "%" + input + "%"; September 22, 2011 Rob Kraft www.kraftsoftware.com 24

All the links and slides are at: www.kraftsoftware.com September 22, 2011 Rob Kraft www.kraftsoftware.com 25

Cross Site Request Forgeries (CSRF) 1. User goes to site 3. User navigates to injected site 2. Page goes to Paypal Server PayPal Server 4. Injected site performs action on still authenticated site. <img src="http://paypal.com/withdraw?account=rkraft&amount=1000000&for=hacker"> September 22, 2011 Rob Kraft www.kraftsoftware.com 26

How to stop CSRF Only use POST for modifications, not GET Require all requests to include pseudo-random value (session independent) include on POST form and cookie must match User s should Log Out of sites September 22, 2011 Rob Kraft www.kraftsoftware.com 27