Created
November 5, 2015 08:09
-
-
Save ts0818/9b90c05e0435c2bbf0ca 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 | |
/** | |
* このプログラムは脆弱性のサンプルです。 | |
* 公開サーバに設置しないでください | |
*/ | |
// アップロードされたファイルは、ドキュメントルート内のuploadsディレクトリに保存 | |
$upload_dir = '/var/www/html/uploads/'; | |
if (empty($_FILES) === false && empty($_FILES['upfile']) === false) { | |
if (is_uploaded_file($_FILES['upfile']['tmp_name']) === true) { | |
move_uploaded_file( | |
$_FILES['upfile']['tmp_name'], | |
$upload_dir . $_FILES['upfile']['name'] | |
); | |
// アップロード成功画面を出力 | |
echo <<<EOF | |
<html> | |
<head> | |
<title>アップロード成功</title> | |
<meta http-equiv="refresh" content="3; url=./upload_attack_01.php" /> | |
</head> | |
<body> | |
ファイルのアップロードに成功しました | |
</body> | |
</html> | |
EOF; | |
} else { | |
echo 'ファイルアップロード攻撃を受けた可能性があります。'; | |
echo 'ファイル名:' | |
. htmlspecialchars($_FILES['upfile']['name'], ENT_QUOTES, 'UTF-8') | |
. ' / '; | |
} | |
} | |
// ファイルアップロードフォームを出力 | |
echo <<<EOF | |
<html> | |
<head> | |
<title>ファイルアップロード</title> | |
</head> | |
<body> | |
<form action="" method="post" enctype="multipart/form-data"> | |
<!-- 最大サイズ --> | |
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" /> | |
<input type="file" name="upfile" /> | |
<input type="submit" value="アップロード" /> | |
</form> | |
</body> | |
</html> | |
EOF; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment