生活 + 筆記

3.19.2010

PHP 防 SQL Injection

一定會用到 php avoid Sql Injection ...
只是方法有太多種,而且沒有一種是真正100%可以擋下來的啦
雖然我們專題就是研究這個 …
但目前還沒實做出來 ~ 只有理論。
方法我個人覺得不錯 ~ 但如果要把效能啊速度啊什麼的考慮進去我想還有很多要改進的 …



$input = '\'or 1=1--';
$pass = '123';

echo urlencode($input)."";
echo htmlentities($input)."";
echo addslashes($input)."";
echo mysql_escape_string($input)."";

$str_select = sprintf("select * from users where user='%s' and password='%d'", addslashes($input), addslashes($pass) );

echo $str_select;

?>

output:
%27or+1%3D1--
'or 1=1--
\'or 1=1--
\'or 1=1--
select * from users where user='\'or 1=1--' and password='123'


參考網站:
http://www.wretch.cc/blog/allan820312/21760356
http://plog.longwin.com.tw/programming/2008/08/27/php-sql-injection-xss-security-2008

沒有留言:

張貼留言