On cross-domain hijacking

This article explain the main cross-domain attacks:

  • Jsonp hijacking
  • Flash cross-domain hijacking
  • CORS cross-domain access to resources

Jsonp hijacking

Jsonp appeared in 2016, mostly due cause harm that disclosure of sensitive information, such as user information, token, etc., is far better than SQL injection, command execution of these vulnerabilities to complete, so always overlooked. Jsonp hijacking attacks, also known as "JSON Hijacking", the process is similar to csrf attack, but csrf just send http request, but the purpose is to obtain Json-hijack sensitive data.

The Jsonp (JSON with Padding) is a json "Use mode" that allows it to obtain information from other web domain name (website), that cross-domain data is read.

Jsonp hijacking and explain the specific use

Year-know:  JSONP security attack and defense technology

Jsonp hijacking vulnerability mining

There are a lot of programmers when writing interface will easily write jsonp interface, you can open burp look at the function point, to see if there are places with the jsonp

Quick Find Jsonp interface

Bp open walk around, general data transmission jsonp will appear as script in mimetype, you can quickly have to find by sorting

The value of callback is jsonp return back function name

Then just to see if there is data transfer sensitive information on it

Json looking for sensitive data

If jsonp interface does not transmit sensitive information, json packet exactly so, we can try to see if programmers have developed jsonp format, most programmers like to return parameters jsonp named callback

Of course, there are other possible paste a dictionary, directly Intruder Fuzz about to try:

 
callback=attack cb=attack call=attack jsonp=attack jsonpcallback=attack jsonpcb=attack json=attack jsoncallback=attack jcb=attack
 

Vulnerability to prove

If the last successful blasting interface

http://www.xxx.com/interface?callback=attack

The data returned is

attack({"value":1})

Use the following poc:

 
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jsonp劫持</title> <script src="js/jquery.min.js"></script> </head> <body> <script type="text/javascript"> $.ajax({ url:"http://xxx.com/interface", dataType:"jsonp", jsonp:"callback", jsonpCallback:"attack", success:function (data) { alert(data.value) } }) </script> </body> </html>
 

jsonp fill in the callback parameter name

jsonpcallback is the value of callback parameters

alert local values ​​change as needed

If you can get to the normal value, it shows vulnerabilities exist

Exploit:

Here a view request:

The results of this request to return the mobile phone number (here I test account not bound phone), if we want an interactive way CSRF attacks get the phone number of the how to do?

Take a look at this request have callback, but the result is not a function in Javascript is similar?

Javascript primitive is defined as follows:

function funName(){}

这里是缺少了函数定义的关键词function和花括号的函数主体部分,只有函数名和函数传参,聪明人已经想到了,这不就相当于是自定义函数被引用了么,而中间那段传参就相当于是一个数组,所以我们可以先用JS自定义好这个函数,然后再引用这个请求,自然就可以获取到数据了。

这时候我们可以来构建一下PoC:

<!-- 引用一段如上请求为JS --> <script>function jsonp2(data){alert(JSON.stringify(data));}</script> <script src="http://gh0st.cn/user/center?callback=jsonp2"></script>

使用正常的账号(绑定过手机号)来测试下:

其他漏洞案例参照乌云:苏宁易购多接口问题可泄露用户姓名、地址、订单商品(jsonp案例)

-------------------------------------------

Flash跨域劫持

首先分享三个参考资料:

1.还有flash跨域漏洞吗?

2.flash跨域数据劫持漏洞

3.flash安全总结

尽管flash宣布不再维护,但是还有许多视频站正在使用flash作为播放器,本为主要来学习flash跨域读取漏洞

flash(swf)以宿主域出发(而不是使用域)判断 是否为跨域请求。

A站上的flash文件 http://www.a.com/vul.swf,被B站 http://www.b.com/exp.htm 拿去使用。此时 vul.swf 请求a站上的资源是不需要提前获取 http://www.a.com/crossdomain.xml 判断是否有权限,反而vul.swf请求b站上的资源却需要提前判断是否有权限。这一点与js不同。
          Flash跨域比较经典了,在做web目录资产整理的时候有时候会发现这样的文件 crossdomain.xml ,文件内容如果是如下的,那么就存在Flash跨域问题,如下内容的意思是支持所有域:

<?xml version="1.0"?> <cross-domain-policy> <allow-access-from domain="*" /> </cross-domain-policy>

为什么会如此?具体流程是这样的:

gh0st.cn 有一个SWF文件,这个文件是想要获取 vulkey.cn 的 userinfo 的返回响应主体,SWF首先会看在 vulkey.cn 的服务器目录下有没有 crossdoamin.xml 文件,如果没有就会访问不成功,如果有 crossdoamin.xml ,则会看crossdomain.xml 文件的内容里面是否设置了允许 gh0st.cn 域访问,如果设置允许了,那么 gh0st.cn 的SWF文件就可以成功获取到内容。所以要使Flash可以跨域传输数据,其关键就是crossdomain.xml 文件。

当你发现 crossdomain.xml 文件的内容为我如上所示的内容,那么就是存在Flash跨域劫持的。

漏洞案例

在对一个厂商进行测试的时候正好发现了这样的文件:

在这里我需要做两件事:

1.找到一个能获取敏感信息的接口

2.构建PoC

在这里敏感的信息接口以个人中心为例子,PoC使用的是 :

https://github.com/nccgroup/CrossSiteContentHijacking/raw/master/ContentHijacking/objects/ContentHijacking.swf

 

其他漏洞案例:

wooyun----搜狐焦点旗下搜狐家居可劫持任意账号

------------------------------------------------

CORS跨域资源获取

强烈建议先看一下 : 跨域资源共享CORS学习笔记

漏洞案例

如上图中我在请求的时候加上了请求头 Origin: http://gh0st.cn,而对应的响应包中出现了 Access-Control-Allow-Origin: http://gh0st.cn 这个响应头其实就是访问控制允许,在这里是允许http://gh0st.cn的请求的,所以http://gh0st.cn是可以跨域读取此网址的内容的~在这里我介绍下Origin

OriginReferer很相似,就是将当前的请求参数删除,仅剩下三元组(协议 主机 端口),标准的浏览器,会在每次请求中都带上Origin,至少在跨域操作时肯定携带(例如ajax的操作)。

所以要测试是否存在CORS这个问题就可以参考我上面的操作手法了。

怎么利用呢?在这里我使用了github上的开源项目:https://github.com/nccgroup/CrossSiteContentHijacking,readme.md中有具体的说明,这里我就不一一讲解了,那么已经确认问题了,那就需要进一步的验证。

在这里我找到了一处接口,其响应主体内容是获取用户的真实姓名、身份证、手机号等内容:

/daren/author/query (要注意的是这个请求在抓取的时候是POST请求方式,但并没有请求正文,经过测试请求正文为任意内容即可)

响应报文正文内容:

这里CrossSiteContentHijacking项目我搭建在了本地(127.0.0.1) http://127.0.0.1/CrossSiteContentHijacking/ContentHijackingLoader.html

根据项目所说的操作去进行参数的配置,然后点击 Retrieve Contents 按钮:

测试如下,测试结果是可以跨域读取的:

 

案例总结

这个问题其实就是对Origin的验证没有控制好,对其进行加强即可。

Guess you like

Origin www.cnblogs.com/nul1/p/10986640.html