Last active
November 5, 2015 07:58
-
-
Save ts0818/fc8b23f9b73d4e936a0f 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'] !== '') { | |
// 指定されたファイル名に「..」が含まれていたら処理終了 | |
if (strpos($_GET['file'], '..') !== false) { | |
exit(); | |
} | |
// GET変数で指定されたファイルが /var/www/html に存在すれば内容を出力 | |
$file = '/var/www/html/' . $_GET['file']; | |
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