© 2010 Quest Software, Inc. ALL RIGHTS RESERVED Understanding and Preventing SQL Injection Attacks Kevin Kline, Technical Strategy Manager

Slides:



Advertisements
Similar presentations
Module XIV SQL Injection
Advertisements

Creating Stronger, Safer, Web Facing Code JPL IT Security Mary Rivera June 17, 2011.
1 Chapter 8 Fundamentals of System Security. 2 Objectives In this chapter, you will: Understand the trade-offs among security, performance, and ease of.
Understand Database Security Concepts
How Did I Steal Your Database Mostafa
Introduction The concept of “SQL Injection”
It’s always better live. MSDN Events Security Best Practices Part 2 of 2 Reducing Vulnerabilities using Visual Studio 2008.
NAVY Research Group Department of Computer Science Faculty of Electrical Engineering and Computer Science VŠB-TUO 17. listopadu Ostrava-Poruba.
ASP.NET 2.0 Chapter 6 Securing the ASP.NET Application.
SQL Injection and Buffer overflow
Jonas Thomsen, Ph.d. student Computer Science University of Aarhus Best Practices and Techniques for Building Secure Microsoft.
Secure SQL Server configuration Pat Larkin Ward Solutions
Dec 13 th CS555 presentation1 Yiwen Wang --“Securing the DB may be the single biggest action an organization can take to protect its assets” David C. Knox.
Varun Sharma Security Engineer | ACE Team | Microsoft Information Security
Web Application Vulnerabilities Checklist. EC-Council Parameter Checklist  URL request  URL encoding  Query string  Header  Cookie  Form field 
Check That Input Preventing SQL Injection Attacks By Andrew Morton For CS 410.
1 Infrastructure Hardening. 2 Objectives Why hardening infrastructure is important? Hardening Operating Systems, Network and Applications.
MIS Week 11 Site:
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Introduction to SQL Server 2000 Security Dave Watts CTO, Fig Leaf Software
Hamdi Yesilyurt, MA Student in MSDF & PhD-Public Affaris SQL Riji Jacob MS Student in Computer Science.
(CPSC620) Sanjay Tibile Vinay Deore. Agenda  Database and SQL  What is SQL Injection?  Types  Example of attack  Prevention  References.
CSCI 6962: Server-side Design and Programming Secure Web Programming.
Web Application Access to Databases. Logistics Test 2: May 1 st (24 hours) Extra office hours: Friday 2:30 – 4:00 pm Tuesday May 5 th – you can review.
1-Vulnerabilities 2-Hackers 3-Categories of attacks 4-What a malicious hacker do? 5-Security mechanisms 6-HTTP Web Servers 7-Web applications attacks.
JavaScript, Fourth Edition
Lecture slides prepared for “Computer Security: Principles and Practice”, 3/e, by William Stallings and Lawrie Brown, Chapter 5 “Database and Cloud Security”.
Attacking Applications: SQL Injection & Buffer Overflows.
Sofia, Bulgaria | 9-10 October Writing Secure Code for ASP.NET Stephen Forte CTO, Corzen Inc Microsoft Regional Director NY/NJ (USA) Stephen Forte CTO,
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Web Application Security ECE ECE Internetwork Security What is a Web Application? An application generally comprised of a collection of scripts.
Top Five Web Application Vulnerabilities Vebjørn Moen Selmersenteret/NoWires.org Norsk Kryptoseminar Trondheim
ColdFusion Security Michael Smith President TeraTech, Inc ColdFusion, Database & VB custom development
1 IT420: Database Management and Organization Database Security 5 April 2006 Adina Crăiniceanu
Copyright © 2013 Curt Hill Database Security An Overview with some SQL.
SQL Injection Attack Overview. Step by step analysis of a SQL Injection attack Code Obfuscation a Definition IIS Log Entry Decoding the HEX Part 1 SQL.
 Chapter 14 – Security Engineering 1 Chapter 12 Dependability and Security Specification 1.
Effective Security in ASP.Net Applications Jatin Sharma: Summer 2005.
Analysis of SQL injection prevention using a filtering proxy server By: David Rowe Supervisor: Barry Irwin.
SQL Injection Jason Dunn. SQL Overview Structured Query Language For use with Databases Purpose is to retrieve information Main Statements Select Insert.
Security Attacks CS 795. Buffer Overflow Problem Buffer overflows can be triggered by inputs that are designed to execute code, or alter the way the program.
Sumanth M Ganesh B CPSC 620.  SQL Injection attacks allow a malicious individual to execute arbitrary SQL code on your server  The attack could involve.
Module 14: Securing Windows Server Overview Introduction to Securing Servers Implementing Core Server Security Hardening Servers Microsoft Baseline.
Vulnerability Scanning Vulnerability scanners are automated tools that scan hosts and networks for known vulnerabilities and weaknesses Credentialed vs.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
ADO.NET AND STORED PROCEDURES - Swetha Kulkarni. RDBMS ADO.NET Provider  SqlClient  OracleClient  OleDb  ODBC  SqlServerCE System.Data.SqlClient.
WEB SECURITY WEEK 2 Computer Security Group University of Texas at Dallas.
Database Security Cmpe 226 Fall 2015 By Akanksha Jain Jerry Mengyuan Zheng.
SQL Injection Anthony Brown March 4, 2008 IntroductionQuestionsBackgroundTechniquesPreventionDemoConclusions.
©2008 Gotham Digital Science SQL Injection Worms for Fun & Profit Justin Clarke, Andrew Carey Nairn.
Error-based SQL Injection
ASP.NET 2.0 Security Alex Mackman CM Group Ltd
ADVANCED SQL.  The SQL ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set by one or more columns.  The ORDER BY keyword sorts the.
Microsoft Advertising 16:9 Template Light Use the slides below to start the design of your presentation. Additional slides layouts (title slides, tile.
Unit 2 Personal Cyber Security and Social Engineering Part 2.
SQL Injection Attacks S Vinay Kumar, 07012D0506. Outline SQL Injection ? Classification of Attacks Attack Techniques Prevention Techniques Conclusion.
SQL INJECTION Diwakar Kumar Dinkar M.Tech, CS&E Roll Diwakar Kumar Dinkar M.Tech, CS&E Roll
Lecture 19 Page 1 CS 236 Online 6. Application Software Security Why it’s important: –Security flaws in applications are increasingly the attacker’s entry.
Defense In Depth: Minimizing the Risk of SQL Injection
Database and Cloud Security
Group 18: Chris Hood Brett Poche
SQL Server Security & Intrusion Prevention
# 66.
Chapter 7: Identifying Advanced Attacks
Unix System Administration
Introduction to SQL Server 2000 Security
Computer Security Fundamentals
Defense in Depth Web Server Custom HTTP Handler Input Validation
Lecture 2 - SQL Injection
6. Application Software Security
Presentation transcript:

© 2010 Quest Software, Inc. ALL RIGHTS RESERVED Understanding and Preventing SQL Injection Attacks Kevin Kline, Technical Strategy Manager Blog at

2 Your Speaker: Kevin Kline My first bookFounding PASSMVP Status

3 Agenda What is SQL Injection? An Attacker’s Approach SQL Injection Techniques Preventing SQL Injection Security Best Practices & Tips Useful Links and Resources

4 Context and Background

5 What is SQL Injection? SQL injection occurs when a malicious user controls the criteria of SQL statements and enters values that alter the original intention of the SQL statement

6 Who is Vulnerable? All SQL database platforms are susceptible Bypasses firewall protections Applications that build and send SQL strings are vulnerable –Coding techniques can be exploited –SQL statement itself is hacked –Formatting vulnerabilities

7 Like This… Courtesy of

8 Or This Webcode… string cmdStr order_id, order_date, qty FROM Production.Orders WHERE customer_name LIKE '%" + SearchText.Text + "%'"; using (SqlConnection conn = new SqlConnection(connStr)) using (SqlDataAdapter sda = new SqlDataAdapter(cmdStr, conn)) { DataTable dtOrders = new DataTable(); sda.Fill(dtOrders); return dtOrders.DefaultView; }

9 9 Injected Values Can Range from Bad… The “Good” search text: 'Hanso Foundation' The “Curious” search text: 'Widmore Industries' or 1=1 -- ‘ The “Exploratory” search text: …ZZZ' UNION SELECT COLUMN_NAME, DATA_TYPE, TABLE_SCHEMA FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Address' --

10 …To Worse The Ugly search text: …ZZZ'; DROP TABLE customer_credit_card -- The REALLY UGLY search text: …ZZZ'; xp_cmdshell(‘FTP …’)

11 Attack Methodology ReconnaissanceScan for Vulnerabilities / AccessGain AccessEscalate PrivilegesMaintain AccessCover Tracks

12 Attackers… …understand the concept of ‘surface area’ …use error messages to learn about the structure of the underlying SQL statements and database …exploit SQL formatting characters (single quotes, comment notation (--), semi-colons, etc)

13 Then Attackers… …manipulate the SQL statements to learn about the structure of the database and data …execute SQL statements at will …use built-in trap doors inside of the DBMS to go to the next level –Upload their own files, even replacing your own –Examine the rest of your infrastructure –Download data –Launch malware and bots

14 SQL Injection Techniques Probing databases Bypassing authorization Executing multiple SQL statements Calling built-in stored procedures Exiting to the OS for command-line access Inserting code to be used by the web app

15 Error Type: Microsoft OLE DB Provider for SQL Server (0x80040E14) Unclosed quotation mark before the character string ′ having 1 = 1--′. /Project1/Demo.asp, line 14 Probing Databases Web apps usually return connectivity error information – unless you trap the errors! Hackers can use this information and continually modify parameters to discover: –Table names, column names, data types, row values

16 Bypassing Authorization Good Guy, passes these values - UserID: administrator Password: GoodOne SELECT * FROM users WHERE username = ‘administrator’ AND password = ‘GoodOne’; Bad Guy, passes this value - UserID: ‘ OR 1=1 Password -- SELECT * FROM users WHERE username = ‘’ OR 1=1 – and password =

17 INSERT Statement Injections Good Guy INSERT INTO Authors (auName, Address) VALUES (‘Julian Isla’, Bad Guy INSER INTO Authors (auName, Address) VALUES (‘SELECT TOP 1 name FROM sys.sys_logins’, EXEC xp_regread HKEY… ; Very Bad Guy, uses scripting and text/xml fields

18 Blind SQL Injection Good apps trap default errors and show their own. Hackers flank this with: –Normal Blind: Get response data from error codes, severity levels, and HTTP status codes –Totally Blind: Gather data through IF…THEN testing, response times, logging, and system functions.

19 Blind Example URL query string: Decoded: NVARCHAR(4000); AS NVARCHAR(4000)); SELECT CAST('this could be some bad code' as varbinary(256)) SELECT CAST (0x F756C F6D F 6465 as varchar(256))

20 Blind Example Final SQL code being executed (hex value decoded): varchar(255) DECLARE Table_Cursor CURSOR FOR select a.name,b.name from sysobjects a,syscolumns b where a.id=b.id and a.xtype='u' and (b.xtype=99 or b.xtype=35 or b.xtype=231 or b.xtype=167) OPEN Table_Cursor FETCH NEXT FROM Table_Cursor INTO BEGIN exec('update set ']))+'' ''') FETCH NEXT FROM Table_Cursor INTO END CLOSE Table_Cursor DEALLOCATE Table_Cursor

21 SQL Injection as an Attack Vector Attackers have chosen not to go after data Targets have been legitimate web sites Plant links and redirects to malware sites Use of a blended attack (browser vulnerability) to infect the client computer Take control of client computers

22 Preventing SQL Injection Never let an app connect as sysadmin –Least privilege principle Building secure SQL statements and apps: –Input validation: check for valid input Don’t check for bad input, you will always miss a case –Use stored procedure to hide application logic – no default error messages; no direct access to tables –Use parameterized input, not string concatenation –Multi layered input checking: application, stored procedure, database schema Apply the latest security patches!

23 Best Practices, Service Accounts SQL Server may use the local system account. Set up a specific Windows login (not Admin!) with appropriate privileges for use by the MSSQLServer system service. Add a separate Windows login (not Admin!) for SQLServerAgent system service.

24 Best Practices, Security Settings Enable ‘Non-sysadmin job step proxy account’ on SQL Server Agent. Set security Audit Level at least to ‘Failure’. Monitor it! Make sure data and log files are on NTFS with proper ACLs applied. Restrict system stored proc’s and XP’s to sysadmins- only Remove guest from all but master and tempdb Disable anything unneeded and unused! (e.g. SQL Browser service, unneeded network protocols) Use Windows Authentication where feasible..

25 Best Practices, Security Checks Check for null and bad passwords frequently Check for non-SA permissions on all system SPs and XPs Monitor failed login attempts Three free scanner utils (HP Scrawlr, URLScan, and Microsoft Source Code Analyzer for SQL Injection ( html?Ad=1) html?Ad=1 Microsoft Assessment and Planning (MAP) is a great tool as well, available at us/library/bb aspxhttp://technet.microsoft.com/en- us/library/bb aspx Tip: Get Quest Discovery Wizard for free!

26 Best Practices, Security Practices Strong SA password –at least 6 digits long with at least 2 numbers –Add mixed case and symbols for more strength Use roles for provisioning, not users –More work, user must be assigned to a login and role –Easy to forget when user leaves Never hardcode passwords Never write apps for use by the SA account Change passwords frequently

27 Best Practices, Security for Developers Do Not Trust User Input Data Validation –Black list vs White list Run With Least Privilege Defense in Depth Fail Intelligently Test Security Remove unused stored procedures, views, and UDFs

28 Best Practices, Security for Developers (cont’d) Use Parameterized Queries or Stored Procedures –Do not use string concatenations to build SQL queries Use Views and Stored Procedures Demand security savvy third-party applications!

29 Resources – my favorite for broad security and tools on SQL Serverhttp:// Microsoft SQL Injection white paper at How-to: Prevent SQL Injection on ASP.Net SQL Injection via CAST: cast.html cast.html SQL Injection Cheat Sheet:

30 Quest Software Swag for SQL Server Free posters, guides, and other goodies. Free DVD Training: March 2010 July 2010

31 Quest Software Resources for SQL Server SQLServerPedia – SQL Server knowledge base, straight from the experts. SQL Server Community – Online discussion forums, customization library, and beta programs. SQL Server Backstage – All things SQL Server at Quest including our Pain of the Week Webcasts.

© 2010 Quest Software, Inc. ALL RIGHTS RESERVED Questions ? Send questions to me at: Blogs at SQLServerPedia.com, SQLblog.com, SQLMag.com, etc. Rate Me – Content at