This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
直接来自 django 项目
(我在 google 上搜索 会话独立随机数。)
Directly from the django project
(I googled for session independent nonce.)
这是非常详细的描述 此类 MitM 攻击。下面是一个删节和简化的改编:
假设:
获取有效的 CSRF 令牌,
MitM 使用该令牌强制攻击者控制的 POST 到 HTTPS 页面:
修改 HTTP 提供的页面(例如,http:/ /foo.com/browse)拥有一个自动提交表单,提交到 HTTPS POST 端点(例如,http://foo.com/check_out)。还设置他们的 CSRF cookie 以匹配您的令牌:
Here's a very detailed description of one-such MitM attack. Below is an abridged and simplified adaptation:
Assume that:
Grab a valid CSRF token
MitM to force attacker-controlled POST to HTTPS page with that token:
Modify an HTTP-served page (e.g., http://foo.com/browse) to have an auto-submitting form that submits to an HTTPS POST end-point (e.g., http://foo.com/check_out). Also set their CSRF cookie to match your token:
中间人攻击的解释非常简单。想象一下两个人正在互相交谈,在他们开始互相交谈之前,他们在发起双向通信之前先握手。当第三个人开始分析两个人如何沟通时(他们的习惯是什么?,他们在互相交谈之前是否做了特殊的握手?,他们喜欢什么时间互相交谈,等等) ,第三人可以塑造他/她的沟通,使他/她可以将自己嵌入到对话中,并充当调解人,让原来的两个人认为他们正在互相交谈。
现在把这个概念带到极客的水平。当电脑、路由器、程序等与网络上的另一个节点进行通信时,会通过身份验证、确认或两者进行双向通信。如果第三方可以确定所需的事件序列(会话 ID、会话 cookie、流量中的下一个确认/传输/终止序列等),则恶意第三方可以将其自己的流量镜像为合法节点,并将流量淹没到合法节点之一,如果它们得到正确的事件序列,则恶意的第三个节点将被接受为合法节点。
The Man-In-The-Middle attack explained in very simplistic terms. Imagine two people are talking to each other and before they start talking to each other, they do a handshake before they initiate a two way communication. When a third person starts to analyze how the two individuals how the two people communicate (What are their mannerisms?, Do they do a special handshake before they speak to each other?, What time do they like to talk to each other, etc), the third person can mold his/her communication to the point the he/she can embed themselves into a conversation and act as a mediator with the original two people thinking that they are speaking with each other.
Now take the concept and bring down to the geek level. When a pc, router, programs etc. communicates with another node unto the network, there is two-way communication occurs either by authentication, acknowledgement, or both. If a third party can determine the sequence of events that is required (session id, session cookie, the next sequence of acknowledge/transfer/termination in the traffic, etc), a malicious third party can mirror its own traffic as a legit node and flood the traffic to one of the legit nodes and if they get the right sequence of events down, the malicious third becomes accepted as a legit node.
假设我们有一个由 Django 驱动的网站和一个恶意中间人。在一般情况下,网站甚至根本不需要提供
http://
页面,攻击就会成功。就 Django 而言,它可能需要通过普通的http://
提供至少一个受 CSRF 保护的页面(请参阅下面的解释)。攻击者首先需要获取语法上有效的 CSRF 令牌。对于某些类型的令牌(例如简单的随机字符串),她可能可以编造一个。对于 Django 的加扰令牌,她可能必须从包含 CSRF 的
http://
页面获取一个(例如,在隐藏的表单字段中)。关键点是 Django 的 CSRF 令牌不与用户的会话或任何其他保存的状态绑定。 Django 将简单地查看 cookie 和表单值(或 AJAX 中的标头)之间是否匹配。因此任何有效的令牌都可以。
用户通过
http://
请求页面。由于响应未加密,攻击者可以自由修改响应。她使用恶意 CSRF 令牌执行Set-Cookie
,并更改页面以包含隐藏表单 - 以及提交该表单的 Javascript -POST
到https://
端点。当然,该表单包含具有 CSRF 值的字段。当用户的浏览器加载响应时,它会存储由
Set-Cookie
标头指定的 CSRF cookie,然后运行 Javascript 来提交表单。它将POST
连同恶意 CSRF cookie 一起发送到https://
端点。(通过
http://
设置的 cookie 将被发送到https://
端点的“不幸”事实在 相关 RFC:“主动网络攻击者还可以将 cookie 注入发送到https://example.com/
通过模拟来自http://example.com/
的响应并注入Set-Cookie
HTTPS 标头。example.com
的服务器将无法区分这些 cookie 和它在 HTTPS 响应中设置的 cookie,活跃的网络攻击者可能能够利用此功能对example 发起攻击。 .com
,即使example.com
仅使用 HTTPS。”)最后,Django 服务器收到恶意
POST
请求。它将 CSRF cookie(由攻击者设置)与表单中的值(由攻击者设置)进行比较,发现它们是相同的。它允许恶意请求。因此,为了避免这种结果,Django 还会针对
Host
Referer 标头(预计始终在https://
请求中设置)进行检查代码>标题。在上面的示例中,该检查将失败,因为攻击者无法伪造Referer
标头。浏览器会将其设置为攻击者用来托管恶意表单的http://
页面,Django 将检测该页面与https://
之间的不匹配它正在服务的端点。Let's say we have a Django-powered site and a malicious Man-In-the-Middle. In the general case the site wouldn't even have to serve
http://
pages at all for the attack to succeed. In Django's case, it probably needs to serve at least one CSRF-protected page over plainhttp://
(see below for the explanation).The attacker first needs to get a syntactically-valid CSRF token. For some types of token (like a simple random string) she might be able to just make one up. For Django's scrambled tokens she will probably have to get one from an
http://
page that includes CSRF (e.g. in a hidden form field).The key point is that Django's CSRF tokens aren't tied to the user's session or any other saved state. Django will simply look to see if there is a match between the cookie and the form value (or header in the case of AJAX). So any valid token will do.
The user requests a page over
http://
. The attacker is free to modify the response since it's unencrypted. She does aSet-Cookie
with her malicious CSRF token, and alters the page to include a hidden form—and the Javascript to submit it—whichPOSTs
to anhttps://
endpoint. That form, of course, includes the field with the CSRF value.When the user's browser load the response, it stores the CSRF cookie specified by the
Set-Cookie
header and then runs the Javascript to submit the form. It sends thePOST
to thehttps://
endpoint along with the malicious CSRF cookie.(The "unfortunate" fact that cookies set over
http://
will be sent tohttps://
endpoints is discussed in the relevant RFC: "An active network attacker can also inject cookies into the Cookie header sent tohttps://example.com/
by impersonating a response fromhttp://example.com/
and injecting aSet-Cookie
header. The HTTPS server atexample.com
will be unable to distinguish these cookies from cookies that it set itself in an HTTPS response. An active network attacker might be able to leverage this ability to mount an attack againstexample.com
even ifexample.com
uses HTTPS exclusively.")Finally, the Django server receives the malicious
POST
request. It compares the CSRF cookie (set by the attacker) to the value in the form (set by the attacker) and sees that they are the same. It allows the malicious request.So, to avoid that result, Django also checks the
Referer
header (which is expected to always be set inhttps://
requests) against theHost
header. That check will fail in the example above because the attacker can't forge theReferer
header. The browser will set it to thehttp://
page that the attacker used to host her malicious form, and Django will detect the mismatch between that and thehttps://
endpoint that it's serving.