简析CSRF

一、简介php

CSRF(Cross-site request forgery),中文名称:跨站请求伪造,也被称为:one click attack/session riding,缩写为:CSRF/XSRF;html

二、功能mysql

你这能够这么理解CSRF攻击:攻击者盗用了你的身份,以你的名义发送恶意请求。CSRF可以作的事情包括:以你名义发送邮件,发消息,盗取你的帐号,甚至于购买商品,虚拟货币转帐......形成的问题包括:我的隐私泄露以及财产安全;sql

三、原理安全

四、示例session

<!--  这个页面是用来进行登陆的 -->
<form action="#" method="post">
    username:<input type="text" name="username">
    password:<input type="text" name="password">
    <input type="submit" value="submit">
</form>

<?php
session_start();
include('conn.php');
if(isset($_POST["username"]) && isset($_POST["password"]))
{
    $user=$_POST["username"];
    $pass=$_POST["password"];
    $sql="select * from admin where username='$user' and password='$pass'";
    $res=mysql_query($sql);
    while($row=mysql_fetch_array($res)){
        $_SESSION['username']=$row["username"];
        header("Location:welcome.php");
    }
}
else{
    exit();
}

?>
<?php
//登录成功,若是id=1,就添加一个admin帐号
session_start();
include("conn.php");
if(isset($_SESSION['username']))
{
    if(isset($_GET['id']))
    {
        if($_GET['id']==1)
        {
            $sql="insert into admin values('admin','admin')";
            $res=mysql_query($sql);
        }
        else
        {
            exit();
        }
    }
}
else
{
    echo "please login ";
}
?>

这个时候若是黑客有这样的代码post

hack.php
<html>
<img src="http://localhost/csrf/welcome.php?id=1">
</html>

当用户登陆了之后,再去访问咱们的hack.php文件,这个时候,就会执行添加用户!其余的你们同理进行推论~~~~fetch

相关文章
相关标签/搜索