SQL Injection
SQL Injection
TOPICS
1. 2. 3. WHAT IS SQL? WHAT IS SQL INJECTION? HOW COMMON IS IT? & ITS VULNERABLE APPLICATIONS.. 4. SQL INJECTION SCANNER 5. SQL INJECTION CHARACTERS 6. EVASION TECHNIQUE 7. DEFENDING AGAINST SQL INJECTION 8. CODE VERIFICATION 9. CONCLUSION 10. REFERENCES
What is SQL?
SQL stands for Structured Query Language Allows us to access a database ANSI and ISO standard computer language The most current standard is SQL99 SQL can: insert new records in a database execute queries against a database delete records from a database retrieve data from a database update records in a database
3
SQL injection
SQL injection
SQL injection
Vulnerable Applications
Almost all SQL databases and programming languages are potentially vulnerable
MS SQL Server, Oracle, MySQL, Postgres, DB2, MS Access, Sybase, Informix, etc Perl and CGI scripts that access databases ASP, JSP, PHP XML, XSL and XSQL Javascript VB, MFC, and other ODBC-based tools and APIs DB specific Web-based applications and APIs Reports and DB Applications 3 and 4GL-based languages (C, OCI, Pro*C, and COBOL) many more
7
SQL injection
SQL INJECTION
SCANNER
SQL injection
Why is it possible to pass SQL queries directly to a database that is hidden behind a firewall and any other security mechanism?
SQL is, in fact, the only way that a web application (and users) can interact with the database.
web application is hard coded with specific SQL queries If any input field of the web application is not properly sanitised, a hacker may inject additional SQL commands that broaden the range of SQL commands that the web application will execute, thus going beyond the original intended design and function. A hacker will thus have a clear channel of communication
10
11
Finally, every input vector of every page is bombarded with a variety of attack patterns often referred to as input fuzzing and the resulting pages are scanned for indications of vulnerability.
12
(If it returns something then login!) ASP/MS SQL Server login syntax
var sql = "SELECT * FROM users WHERE login = '" + formusr + "' AND password = '" + formpwd + "'";
13
SQL injection
SQL injection
15
EVASION TECHNIQUES
16
SQL injection
Evasion Techniques
Input validation circumvention and Signature Evasion techniques are very similar Snort based detection of SQL Injection is partially possible but relies on "signatures" Signatures can be evaded easily
17
SQL injection
Signature Evasions
Evading ' OR 1=1 signature ' OR 'unusual' = 'unusual' ' OR 'something' = 'some'+'thing' ' OR 'text' = N'text' ' OR 'something' like 'some%' ' OR 2 > 1 ' OR 'text' > 't' ' OR 'whatever' IN ('whatever') ' OR 2 BETWEEN 1 AND 3
18
SQL injection
Input validation
Some people use PHP addslashes() function to escape characters
single quote (') double quote (") backslash (\) NUL (the NULL byte)
This can be easily evaded by using replacements for any of the previous characters in a numeric field
19
20
SQL injection
SQL injection
1.Input Validation
Define data types for each field
Implement stringent "allow only good" filters
If the input is supposed to be numeric, use a numeric variable in your script to store it
Reject bad input rather than attempting to escape or modify it Implement stringent "known bad" filters
For example: reject "select", "insert", "update", "shutdown", "delete", "drop", "--", "'"
22
SQL injection
2.Strong Design
Define an easy "secure" path to querying data
Use stored procedures for interacting with database Call stored procedures through a parameterized API Validate all input through generic routines Use the principle of "least privilege"
Define several roles, one for each kind of query
23
SQL injection
CODE VERIFICATION
25
SQL injection
26
SQL injection
27
SQL injection
28
Conclusion
SQL Injection is a fascinating and dangerous vulnerability All programming languages and all SQL databases are potentially vulnerable Protecting against it requires
strong design correct input validation hardening
29
THANK YOU!!
30
REFERENCES
1. http://www.securityfocus.com/infocus/1768 2.http://www.extropia.com/tutorials/sql/toc.html 3.http://www.google.com/sqlinjection 4.http://www.owasp.org 5. http://www.sqlsecurity.com
31
Questions ?
32