Skip to content

Instantly share code, notes, and snippets.

View ts0818's full-sized avatar

ts0818 ts0818

View GitHub Profile
@ts0818
ts0818 / command_injection_02.php
Created November 5, 2015 08:31
パーフェクトPHP コマンド実行攻撃(Command Injection)対応方法
<?php
// 一覧を出力するディレクトリを$dir変数にセット
if (isset($_GET['dir']) === true) {
// nullバイトを削除
$dir = str_replace("\0", '', $_GET['dir']);
} else {
$dir = '/';
}
// ディレクトリ内のファイル一覧を出力
@ts0818
ts0818 / mail_header_injection.php
Created November 5, 2015 08:44
PEAR::Mail_RFC822から抜き出したメールアドレスの正規表現による判定
<?php
function isValidInetAddress($data, $strict = false){
// 次の行は、表示改行されていますが実際は一行です
$regex = $strict ? ' /^([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i ' :
' /^([*+!.&#$|\'\\%\/0-9a-z^_`{ }=?~:-]+])@(([0-9a-z-]+\.)+[0-9a-z]{2,})$/i ';
if(preg_match($regex, trim($data),$matches)){
return array($matches[1], $matches[2]);
}else{
return false;
}