120 likes | 287 Views
Aniket Joshi Justin Thomas. Agenda. Introduction to SQL Injection SQL Injection Attack SQL Injection Prevention Summary. What is SQL Injection?. It is a kind of web application attack where user supplied input coming from: URL : www.abc.com?id=1 Login forms: username=John Doe
E N D
AniketJoshi Justin Thomas
Agenda • Introduction to SQL Injection • SQL Injection Attack • SQL Injection Prevention • Summary
What is SQL Injection? • It is a kind of web application attack where user supplied input coming from: • URL: www.abc.com?id=1 • Login forms: username=John Doe • Other elements such as cookie, HTTP headers is manipulated so that vulnerable application executes SQL commands injected by attacker.
Methods of Injection • Injection into source code of website • Injection into the URL
SQL Injection cont.… • The injection process works by prematurely terminating a text string and appending a new command. • Because the inserted command may have additional strings appended to it before it is executed, the attacker terminates the injected string with a comment mark "--". • Subsequent text is ignored at execution time.
Example: Statement=“SELECT * FROM users WHERE uname=‘ ”+username+” ’;” username=‘ or ‘1’=‘1’- -’ SELECT * FROM users WHERE uname=‘ ‘ OR ‘1’=‘1’ - -’;
How to avoid SQL Injection • As long as injected SQL code is syntactically correct, tampering cannot be detected programmatically. • Therefore, you must validate all user input and carefully review code that executes constructed SQL commands in the server that you are using.
Some tips: • Filter and validate all input data • Separating code from data by making use of prepared and stored procedures • Making use of escape characters
Filter out character like single quote, double quote, slash, back slash, semi colon, extended character like NULL, carry return, new line a. input from users b. parameters from URL c. values from cookies 2. Convert all numeric values into integer before parsing into SQL statement.
Summary • Considered top 10 web application vulnerabilities of 2007 and 2010 by the Open Web Application Security Project • SQLIA’s has • Many sources • Many Goals • Many Types • Prevention should not be developer dependent