SQL Injection Part 1 - BASICSWasimHalani(WaSHaL)
./whoamiStudentFallibleNOT a SQL expert“Do not take anything I say as fact. I have been wrong before and I will be wrong again.” - Nullthreat
OWASP Top 10A1 – Injection FlawsInjection flaws, such as SQL, OS, and LDAP injection, occur when untrusted data is sent to an interpreter as part of a command or query. The attacker’s hostile data can trick the interpreter into executing unintended commands or accessing unauthorized data.Simpler definition, anyone? 
SQL InjectionSQL = Structured Query LanguageExecute a SQL query/statement or syntax by injecting it in an user input field on the web application
Why study it?BarracudaHBGary/ HBGary FederalAppinonlineAppinlabsNIITMysql.com
Our Sample DBuser_db
Generic SQL - SelectSQL> select * from userdb where username=‘xxxx’ and password=‘yyyy’;returns all columns from table ‘userdb’ and every row which have given username and passwordSQL> select role from userdb where username=‘zzzz’;returns only column ‘role’ where username matches
UNION OperatorCombine results of two or more SELECT statementsSELECT username,password from user_db UNION SELECT username,password from admin_dbSELECT username,password from user_db UNION ALL SELECT username,password from admin_db
ORDER BY ClauseSort results of SELECT query by a specific columnnumber column name
Misc.INSERTUPDATEDELETEALTERDROP
Categories of SQL InjectionIn-bandErrorUnionOut-bandDnsPingInferential (Blind)SleepWaitforRef: www.toorcon.org/tcx/9_McCray.pdf
SQL Injection Attacks
Vulnerable Code
Vanilla Injection‘ or 1=1 --a‘ or ‘a’=‘a
Finding # of Columns1234....100
Finding # of Columns - 2
Injecting Queries (UNION)Ref: http://ferruh.mavituna.com/sql-injection-cheatsheet-oku/
ToolsNetsparker (Pro/Community)HavijSQLMapSQLNinja
Coming Up…Blind SQLManual Extraction of Data using SQLi+BurpPreventing SQL Injections
Questions?*wasimhalani@gmail.com@washalsechttp://securitythoughts.wordpress.com/*Conditions Apply

SQL Injections (Part 1)