Skip to content

Instantly share code, notes, and snippets.

@ts0818
Last active November 5, 2015 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ts0818/4964d19f89daa9902ef7 to your computer and use it in GitHub Desktop.
Save ts0818/4964d19f89daa9902ef7 to your computer and use it in GitHub Desktop.
パーフェクトPHP インクルード攻撃対応方法 basename( )関数を使って読み込みファイルを特定のディレクトリ内に制限
<?php
// basename()関数はバイナリセーフではないため、nullバイト対応を行う
if (strpos($_GET['design'], "\0") !== false) {
exit();
}
// 指定されたファイルをインクルード
// basename()関数で不正文字列を除去してインクルードを行う
include '/var/www/html/design/' . basename($_GET['design']) . '.html';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment