SQL深盲注入技术

点击放大图片
SQL深盲注入技术
Ferruh Mavituna www.portc ullis- sec urity.c om
翻译:daokers

        注:我把Deep Blind SQL Injection译为SQL深盲注入技术或者SQL高级盲注技术
  
     SQL深盲注入技术已在多篇文章中被描述.如果注入点是完全盲目的,那么提取数据库数据的唯一方法就是基于时间差的攻击,比如 WAITFOR DELAY , BENCHMARK等等.
现在已知有2种方法来读取数据,
1. 逐字节读取数据
2. 在字符模式下通过二进制搜索算法来读取数据

     这2种方法都有“一个请求-一个响应”的限制,并且平均每一个字符需要发送6个请求给服务器。
在深盲SQL注入中读取数据比传统盲注更加复杂,但是,它仍然是有可能获取数据的,而且发送给服务器的请求数有可能会减少66%,因为获取每个字符只需要发送2次请求而不是6次。

    深盲SQL注入在MS SQL服务器上工作良好,也可能可以工作在其它数据库上,比如ORACLE, PostgreSQL等等。

    这种一个请求收到多个响应的注入方式是基于时间差来完成的。例如,如果字符的前半字节是6,那么数据库将等待12秒,如果后半字节是1的话将等待2秒。攻击者应该储存服务器的响应次数并且把响应以每2次为单位进行分割来理解。结果,在2个请求中我们得到0x61,也就是'a'。很明显,根据情况使用比2更大或者更小的单位来分割响应信息也是可以的。

实例
对SQL服务器攻击的一个功能部分:

程序代码 程序代码
DECLARE @x as int; DECLARE @w as char(6);
SET @x=ASCII(SUBSTRING(master.dbo.fn_varbintohexstr(CAST({QUERY}  as varbinary(8000))),{POSITION},1));
IF @x>97 SET @x=@x-87 ELSE SET @x=@x-48; SET @w='0:0:'+CAST(@x*{SECONDS} as char); WAITFOR DELAY @w



{QUERY}是你想获得的数据这些数据可以使变量比如USER,函数比如db_name(2)或者是返回一行和一列的Select声明。
{POSITION} 是欲读取的半字节。你需要添加2来替换SQL服务器响应开始部分字串的“0x”。
{SECONDS}是等待时间的乘数。等待时能以毫秒计,但是也可以使用分数计算比如 等待延时'0:0:0.51 '。

相同的代码可以以不同的方式表达,有少许不同、更短但是更难读。

程序代码 程序代码
DECLARE @x as int; DECLARE @w as char(6);
SET @x=ASCII(SUBSTRING(master.dbo.fn_varbintohexstr(CAST({QUERY} as varbinary(8000))),{POSITION},1));
SET @w='0:0:'+CAST(((@x+((@x&79)/8)+(@x/64)&15)*2) as char);

WAITFOR DELAY @w



实际攻击

总的来说深盲SQL攻击还是不适合手动攻击,明智的做法是采用自动攻击,这些功能已经在“BSQL Hacker”得以实现。

限制

•    如果连接时间太慢或者其它的原因导致服务器不可预知的响应次数,软件将不稳定
•    大多数的服务器脚本和数据库连接都有大约30秒的连接超时限制(虽然对于使用2元2次乘法(?)来枚举一个半字节来说30秒钟已经足够,但是为了增加在其它环境中结果的稳定性,可能需要更长的超时限制,一般建议设置为60秒)

作者
Nico Leidecker -  http ://www. le ide cker. info/,
Thanks for shorter he x stri ng to i nte ger conversion algori thm.

参考文献

•    0 3/02/20 07 - I dea
•    01/05 /2007 – Priv ate Release
•    19/0 8/2007  – BSQL Hac ker implementatio n
•    10/0 9/ 2007 – Formatting etc .
•    26/10/ 2007 – Ready fo r Public    Release
•    26/0 2/ 200 8 – Hex Enco ding Improved


1    More Advanced SQL Injections, NGS Blind SQL Injecti on, SPI Dyna mics Blind SQL Server Injecti on, Im perva
2   No error is dis played a nd no indicators are visi ble in the response that a n error occ urred
3   Except outbound communica tion channels
4   At the time of writi ng BSQL Hacker is avai lable a t https://la bs.por tcullis. co.uk/

原文地址:https://labs.portcullis.co.uk/application/deep-blind-sql-injection/
下载地址:https://labs.portcullis.co.uk/download/Deep_Blind_SQL_Injection.pdf
BSQL Hacker英文版下载地址:https://labs.portcullis.co.uk/download/BSQLHackerSetup-0909.exe
BSQL Hacker中文版下载地址:http://www.daokers.com/attachments/month_0907/f2009719161313.rar
 
 

 

注:

关于Blind SQL Inject的例子可以参考OWASP的WebGot的例子和演示视频,另外,也可以用用JHijack这个Fuzz工具来做盲注

OWASP关于Blind SQL Injection的描述:

https://www.owasp.org/index.php/Blind_SQL_Injection

When an attacker executes SQL Injection attacks, sometimes the server responds with error messages from the database server complaining that the SQL Query's syntax is incorrect. Blind SQL injection is identical to normal SQL Injection except that when an attacker attempts to exploit an application, rather then getting a useful error message, they get a generic page specified by the developer instead. This makes exploiting a potential SQL Injection attack more difficult but not impossible. An attacker can still steal data by asking a series of True and False questions through SQL statements.

posted on 2011-05-10 22:44  hackchecker  阅读(6451)  评论(0编辑  收藏  举报

导航