欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php跨站攻擊實(shí)例分析

 更新時(shí)間:2014年10月28日 12:12:27   投稿:shichen2014  
這篇文章主要介紹了php跨站攻擊的原理與防范技巧,以具體實(shí)例對(duì)php跨站攻擊進(jìn)行了較為詳細(xì)的分析,是非常實(shí)用的技巧,需要的朋友可以參考下

本文實(shí)例講述了php跨站攻擊的原理與防范技巧。分享給大家供大家參考。具體方法分析如下:

跨站攻擊就是利用程序上的一些細(xì)節(jié)或bug問(wèn)題進(jìn)行的,那么我們要如何耿防止跨站攻擊呢?下面就以一個(gè)防止跨站攻擊例子來(lái)說(shuō)明,希望對(duì)各位有幫助。

復(fù)制代碼 代碼如下:
<?php
#demo for prevent csrf
/**
* enc
*/
function encrypt($token_time) {
return md5('!@##$@$$#%43' . $token_time);
}
$token_time = time();
$token = encrypt($token_time);
$expire_time = 10;
if ($_POST) {
$_token_time = $_POST['token_time'];
$_token = $_POST['token'];
if ((time() – $_token_time) > $expire_time) {
echo “expired token”;
echo “<br />”;
}
echo $_token;
echo “<br />”;
$_token_real = encrypt($_token_time);
echo $_token_real;
//compare $_token and $_token_real
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=utf-8″ />
<title>test for csrf</title>
<meta http-equiv=”" content=”" />
</head>
<body>
<form method=”post” action=”">
<input type=”text” name=”text” id=”" value=”hello” />
<input type=”hidden” name=”token” id=”" value=”<?php echo $token ?>” />
<input type=”hidden” name=”token_time” id=”" value=”<?php echo $token_time ?>” />
<input type=”submit” name=”submit” id=”" value=”submit” />
</form>
</body>
</html>

 
通過(guò)在你的表單中包括驗(yàn)證碼,你事實(shí)上已經(jīng)消除了跨站請(qǐng)求偽造攻擊的風(fēng)險(xiǎn)??梢栽谌魏涡枰獔?zhí)行操作的任何表單中使用這個(gè)流程
當(dāng)然,將token 存儲(chǔ)到session更好,這里只是簡(jiǎn)單示例下

簡(jiǎn)單分析:

token防攻擊也叫作令牌,我們?cè)谟脩粼L問(wèn)頁(yè)面時(shí)就生成了一個(gè)隨機(jī)的token保存session與表單了,用戶提交時(shí)如果我們獲取到的token與session不一樣就可以提交重新輸入提交數(shù)據(jù)了

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論