Created
November 5, 2015 07:55
-
-
Save ts0818/4691d688a79773166d11 to your computer and use it in GitHub Desktop.
パーフェクトPHP ディレクトリトラバーサル対応方法 不正文字列除去方式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (isset($_GET['file']) === true && $_GET['file'] !== '') { | |
$file = str_replace("\0", "", $_GET['file']); // nullバイトを削除 | |
$file = '/var/www/html/' . basename($file); // ファイル名以外の部分を削除 | |
// GET変数で指定されたファイルが /var/www/html に存在すれば内容を出力 | |
if (file_exists($file) === true) { | |
readfile($file); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment