0x01 WooYun-2014-51505
输入1',显示有waf。 输入and 1=1同样也显示有waf,尝试其他关键字均如此,使用大小写,双写等方式绕过判断,发现可以大小写绕过,并判断出是整形注入。 联合查询时1 uNIon sElect 1,2database()发现,被过滤,那么采用join来绕过。发现*也被过滤了。。。看来联合注入不太行了,只能使用盲注或者报错注入了,这里还是有报错回显的。 然后去看了下之间写的东西,发现各种报错注入不是有*就是有,同样也用不了,好像只能用盲注了。。。 1 aNd length(database())=4,数据库长度为4。 直接再试试user能不能查就算了,没啥意思。。。1 aNd ascii(substr((seLect user fRom users limit 1 offset 0) fRom 1 fOr 1))=97 正常回显了,说明确实可以注入,limit 1 offset 0替代的是limit 0,1,而substr(x from 1 for 1)替换的是substr(x,1,1)。后面就不搞了。
0x02 源码分析
WooYun
-2014-51505 Source
<?php
if(isset($_GET['Submit'])){
$id = inject_check($_GET['id']);
$getid = "SELECT first_name, last_name FROM users WHERE user_id = $id";
$result = mysql_query($getid) or die('<pre>' . mysql_error() . '</pre>' );
$num = mysql_numrows($result);
$i = 0;
while ($i < $num) {
$first = mysql_result($result,$i,"first_name");
$last = mysql_result($result,$i,"last_name");
echo '<pre>';
echo 'ID: ' . $id . '<br>First name: ' . $first . '<br>Surname: ' . $last;
echo '</pre>';
$i++;
}
}
function inject_check($str) {
$check=preg_match('/select|order|insert|update|eval|document|delete|injection|jection|link|\'|\%|\/\*|\*|\.\.\/|\.\/|\,|\.|--|\"|and|or|from|union|into|load_file|outfile|<script>/',$str);
if($check){
echo "<script>alert('Filtered!!!');window.history.go(-1);</script>";
exit();
}else{
return $str;
}
}
?>
这个比较简单,只使用了preg_match()函数过滤了大量的关键字,这些关键字可以用大小写绕过,主要还是特殊符号无法绕过去。