Created
November 5, 2015 07:39
-
-
Save ts0818/4c144fa721cdd25ca852 to your computer and use it in GitHub Desktop.
パーフェクトPHP nullバイト攻撃
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 | |
/** | |
* 文字列中のnullバイトを削除する関数 | |
* 引数が配列の場合は、配列の要素に対して再帰的に処理を行う | |
*/ | |
function delete_null_byte($value){ | |
if (is_string($value) === true) { | |
$value = str_replace("\0", "", $value); | |
} elseif (is_array($value) === true) { | |
$value = array_map('delete_null_byte', $value); | |
} | |
return $value; | |
} | |
// 変数内のnullバイトを削除 | |
$_GET = delete_null_byte($_GET); // $_GET内のnullバイトを削除 | |
$_POST = delete_null_byte($_POST); // $_POST内のnullバイトを削除 | |
$_COOKIE = delete_null_byte($_COOKIE); // $_COOKIE内のnullバイトを削除 | |
$_REQUEST = delete_null_byte($_REQUEST); // $_REQUEST内のnullバイトを削除 | |
if (isset($_GET['file']) === true && $_GET['file'] !== '') { | |
// GET変数で指定されたファイルが存在し、テキストファイルであれば内容を出力 | |
if (file_exists($_GET['file']) === true && | |
substr($_GET['file'], -4) === '.txt') { | |
readfile($_GET['file']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment