2011年6月17日 星期五

Blind Sql Injection with Regular Expressions Attack

這是一篇前幾天 SimoneMarco 所發表的一篇 Paper ,內容是針對 Blind Sql Injection 攻擊測試提高效率的方法,而他們所提出的方法就是透過正規表達式  Regular Expressions



簡單說明一下傳統 Sql Injection  和 Blind Sql Injection 的差異
已一個例子為例(dump data) :

傳統 Sql Injection :仰賴網頁回應的錯誤訊息,所有想要知道的欄位內容(帳號密碼、資料庫資訊)都是輸出在網頁上

Blind Sql Injection:可以不需仰賴網頁回應的錯誤訊息,所以即使網站關閉了錯誤訊息,但網頁仍然有 Sql Injection 的問題,這個時候 Blind Sql Injection 這個方法就派上用場了,不需依賴錯誤訊息,只需藉由網頁的回應來判斷 True & Flase 就可以達到目的。

Blind Sql Injection 有幾種類型:
1.Error-based blind SQL Injection
2.Classical blind SQL Injection
3.Time-based ( Chema Alonso & José Parada Defcon 16 所發表

實際上不管是 Sql Injection 還是 Blind Sql Injection 在這些漏洞測試的方法或是進階 Evasion 繞過技巧有太多種了,有興趣的同鞋在 Google 看看,我們先拉回來主題,典型 Blind Sql Injection 所使用語法如下
  

 [...] >1 and 300 >(select top 1 ascii(substring(name,1,1)) from sysusers) → TRUE

  [...] >1 and 0 >(select top 1 ascii(substring(name,1,1)) from sysusers) FALSE

透過正規表達式  Regular Expressions 的方法如下: 

index.php?id=1 and 1=(SELECT 1 FROM information_schema.tables WHERE
TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^[a-n]' LIMIT 0,1)
True


index.php?id=1 and 1=(SELECT 1 FROM information_schema.tables WHERE
TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^[a-g]' LIMIT 0,1)
False



 文章作者做了幾個實驗相關數據如下:
1.取得一組 MD5 Hash 32 位 ( 內容中包含數字跟小寫英文共 16 個字符1234567890abcdef) 

在最好情況下透過 Regular Expressions 和一般 Blind Sql Injection 要花 32 次查詢才能完成
在最壞的情況下透過 Regular Expressions 需要花 128 次查詢 
一般 Blind Sql Injection 要花 512 查詢才能完成

 

2.取得一組密碼長度為 15 位 ( 內容中包含了英文大小寫、數字及符號共 76 個字符abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=);) 

在最好的情況下透過 Regular Expressions  要花 15 次查詢才能完成
在最壞的情況下透過 Regular Expressions 需要花 94 次查詢 
一般 Blind Sql Injection 要花 1140 查詢才能完成


文章來源:
Blind Sql Injection with Regular Expressions Attack
PHP example code

新聞事件:
Hackers use blind SQL injection attack to crack Oracle-Sun, MySQL.com