Even uploading a JPG file can lead to Cross-Site Content Hijacking (client-side attack)!
Introduction:
This post is going to introduce a new technique that has not been covered previously in other topics that are related to file upload attacks such as Unrestricted file upload and File in the hole.
Update 3 (01/11/2016)
Title was changed from “Cross Domain Data Hijacking” to “Cross-Site Content Hijacking” to reflect the issue better. This issue can also be called “Cross-Site Data Hijacking“. The recommendations section was updated as well.
The following posts were created based on this topic:
https://www.acunetix.com/vulnerabilities/web/cross-domain-data-hijacking
https://dunnesec.com/2014/05/26/cross-domain-hijack-flash-file-upload-vulnerability/
The following tool was created to exploit this issue as a proof of concept – this project covers multiple methods such as by using Flash, PDF, or Silverlight:
https://github.com/nccgroup/CrossSiteContentHijacking
Update 2 (21/05/2014)
Ok! People in twitter were very resourceful and reminded me that this was not in fact a new technique and some other bug bounty hunters are already using it in their advisories! I wish they had documented this properly before. The following links are related to this topic:
http://50.56.33.56/blog/?p=242 (Content-Type Blues)
https://bounty.github.com/researchers/adob.html (Flash content-type sniffing)
Update 1 (21/05/2014):
It seems @fransrosen and @avlidienbrunn were quicker than me in publishing this technique! Yesterday they have published a very good blog post about this issue: http://blog.detectify.com/post/86298380233/the-pitfalls-of-allowing-file-uploads-on-your-website
I highly recommend the readers to read the other blog post as well especially for its nice JSONP trick.
I wanted to wait until end of this week to publish mine but now that this technique is already published, I release my post too. The draft version of this post and PoCs were ready before but I was not sure when I am going to publish this as it would affect a lot of websites; this was a note for bug bounty hunters!
The only point of this blog post now is the way that I had looked at the issue initially.
How safe is the file uploader?
Imagine that there is a file uploader that properly validates the uploaded file’s extension by using a white-list method. This file uploader only allows a few non-dangerous extensions such as .jpg, .png, and .txt. Moreover, it checks the filename to not contain any non-alphanumeric characters!
This seems to be a simple and a safe method to protect the server and its users if risks of file processors’ bugs and file inclusion attacks have already been accepted.
What can possibly go wrong?
This file uploader does not have any validation for the file’s content and therefore it is possible to upload a malicious file with a safe name and extension on the server. However, when the server is properly configured, this file cannot be run on the server. Moreover, the file will be sent to the client with an appropriate content-type such a text/plain or image/jpeg; as a result, an attacker cannot exploit a cross-site scripting issue by opening the uploaded file directly in the browser.
Enforcing the content-type by using an OBJECT tag!
If we could change the file’s content-type for the browsers, we would be able to exploit this issue! But nowadays this is not simply possible directly as this counts as a security issue for the browser…
I knew straight away that the “OBJECT” tag has a “TYPE” attribute but I was not sure which content-types will force the browser to actually load the object instead of showing the contents (“OBJECT” tag can act as an IFrame). I have created a test file (located at http://0me.me/demo/SOP/ObjectMimeType.html) that loads the object tags with the different mime-types and the result is as follows (Java and Silverlight were not installed):
“application/futuresplash”: load the file as a Flash object
“application/x-shockwave-flash”: load the file as a Flash object
“text/x-component”: only works in IE to load .htc files(?)
“application/pdf” and a few others: load the file as a PDF object
The result can be different with having different plugins installed.
So I can load any uploaded file as a flash file. Now I can upload a malicious flash file into the victim’s server as a .JPG file, and then load it as flash file in my own website. Please note that there is no point for me to upload a flash file that is vulnerable to XSS as it would run under my website’s domain instead of the target.
Exploitation
I found out that the embedded flash can still communicate with its source domain without checking the cross-domain policy. This makes sense as the flash file belongs to the victim’s website actually.
As a result, the flash file that has been uploaded as a .JPG file in the victim’s website can load important files of the victim’s website by using current user’s cookies; then, it can send this information to a JavaScript that is in the attacker’s website which has embedded this JPG file as a Flash file.
The exploitation is like a CSRF attack, you need to send a malicious link to a user who is already logged-in in the victim’s website (it still counts as CSRF even if you are not logged-in but this is out the scope of this post). The malicious Flash should have already been uploaded in the victim’s website. If the uploader is vulnerable to a CSRF attack itself, an attacker can first upload a malicious Flash file and then use it to hijack the sensitive data of the user or perform further CSRF attacks.
As a result, an attacker can collect valuable information that are in the response of different pages of the victim’s website such as users’ data, CSRF tokens, etc.
The following demonstrates this issue:
A) 0me.me = attacker’s website
B) sdl.me = victim’s website
C) A JPG file that is actually a Flash file has already been uploaded in the victim’s website: http://sdl.me/PoCs/CrossDomainDataHijack.jpg
(Source code of this Flash file is accessible via the following link:
http://0me.me/demo/SOP/CrossDomainDataHijack.as.txt )
D) There is a secret file in the victim’s website (sdl.me) that we are going to read by using the attacker’s website (0me.me): http://sdl.me/PoCs/secret.asp?mysecret=original
E) Note that the victim’s website does not have any crossdomain.xml file: http://sdl.me/crossdomain.xml
F) Now an attacker sends the following malicious link to a user of sdl.me (the victim’s website):
http://0me.me/demo/SOP/CrossDomainDataHijackHelper.html
By pressing the “RUN” button, 0me.me (attacker’s website) website can read contents of the secret.asp file which was in sdl.me (victim’ website). This is just a demo file that could be completely automated in a real scenario.
Note: If another website such as Soroush.me has added sdl.me as trusted in its crossdomain.xml file, the attacker’s website can also now read the contents of Soroush.me by using this vulnerability.
Limitations
An attacker cannot read the cookies of the victim.com website.
An attacker cannot run a JavaScript code directly by using this issue.
Future works
Other client-side technologies such as PDF, Java applets, and Silverlight might be used instead of the Flash technology.
Bypassing the Flash security sandbox when a website uses “Content-Disposition: attachment;” can also be a research topic. If somebody bypasses this, many mail servers and file repositories will become vulnerable.
Recommendations
Please find the recommendations in the following project: https://github.com/nccgroup/CrossSiteContentHijacking
The paper referer:https://soroush.secproject.com/blog/2014/05/even-uploading-a-jpg-file-can-lead-to-cross-domain-data-hijacking-client-side-attack/
Even uploading a JPG file can lead to Cross-Site Content Hijacking (client-side attack)!的更多相关文章
- SPJS Upload for SharePoint: Custom upload page for uploading documents to various document libraries in a site collection
http://spjsblog.com/2013/12/08/spjs-upload-for-sharepoint-custom-upload-page-for-uploading-documents ...
- nodejs(四)file System模块 解决Cross device link错误 EXDEV
var fs = require('fs'); /*cross device link fs.rename('c:\\err.LOG','d:\\err.LOG',function(err){ con ...
- 各种WAF绕过手法学习
原文:https://mp.weixin.qq.com/s/aeRi1lRnKcs_N2JLcZZ0Gg 0X00 Fuzz/爆破 fuzz字典 1.Seclists/Fuzzing https ...
- Python Socket File Transfer
I have a RPi which I intented to use it to crawl data. The development environment in RPi is very ba ...
- File Input Features
文件输入功能 1.该插件将将一个简单的 HTML 文件输入转换为高级文件选取器控件.将有助于对不支持 JQuery 或 Javascript 的浏览器的正常 HTML 文件输入进行回退. 2.文件输入 ...
- HDFS分布式文件系统(The Hadoop Distributed File System)
The Hadoop Distributed File System (HDFS) is designed to store very large data sets reliably, and to ...
- mvc file控件无刷新异步上传操作
前言 上传文件应该是很常见必不可少的一个操作,网上也有很多提供的上传控件.今天遇到一个问题:input控件file无法进行异步无刷新上传.真真的感到别扭.所以就尝试这去处理了一下.主要分三个部分:上传 ...
- Error of "Please Check for Sufficient Write File Permissions"
The error message “Please check for sufficient write file permissions” is generated by the Web-based ...
- Introducing Microsoft Sync Framework: Sync Services for File Systems
https://msdn.microsoft.com/en-us/sync/bb887623 Introduction to Microsoft Sync Framework File Synchro ...
随机推荐
- Luogu-2495 [SDOI2011]消耗战
虚树第一题 对于每次询问的点建立一棵虚树,然后在树上DP,一个点的答案就是这个点的父边切断的代价与所有儿子切断的代价去最小值,当然如果这个节点是资源点则必须切父边 注意在虚树上一条边的代价应该是中间所 ...
- 【P2016】战略游戏(贪心||树状DP)
这个题真是...看了一会之后,发现有一丝丝的熟悉,再仔细看了看,R,这不是那个将军令么...然后果断调出来那个题,还真是,而且貌似还是简化版的...于是就直接改了改建树和输入输出直接交了..阿勒,就2 ...
- HBase学习2(HBase shell)
HBase 常用命令 查看当前用户:whoami 创建表:create '表名', '列族名1','列族名2','列族名N' 查看所有表:list 描述表: describe '表名' 判断表存在: ...
- 循环插入一条数据的sql写法
DECLARE @i INTSET @i = 1WHILE @i > 0 BEGIN DECLARE @TransportFormMstID BIGINT; DECLARE @TradeOrde ...
- UOJ12 猜数
这一天,小Y.小D.小C正在愉快地玩耍. 小Y是个数学家,他一拍脑袋冒出了一个神奇的完全平方数 nn. 小D是个机灵鬼,很快从小Y嘴里套出了 nn 的值.然后在脑内把 nn 写成了 a×ba×b的形式 ...
- Ceilometer Polling Performance Improvement
Ceilometer的数据采集agent会定期对nova/keystone/neutron/cinder等服务调用其API的获取信息,默认是20秒一次, # Polling interval for ...
- SQL Server集成服务最佳实践:语句优化
SQL Server集成服务(SQL Server Integration Services,SSIS)在其前辈DTS(Data Transformation Services,数据转换服务) ...
- 机器学习(二)—支持向量机SVM
1.SVM的原理是什么? SVM是一种二类分类模型.它的基本模型是在特征空间中寻找间隔最大化的分离超平面的线性分类器.(间隔最大是它有别于感知机) 试图寻找一个超平面来对样本分割,把样本中的正例和反例 ...
- 选择排序—简单选择排序(Simple Selection Sort)原理以及Java实现
基本思想: 在要排序的一组数中,选出最小(或者最大)的一个数与第1个位置的数交换:然后在剩下的数当中再找最小(或者最大)的与第2个位置的数交换,依次类推,直到第n-1个元素(倒数第二个数)和第n个元素 ...
- 关于js冒泡、捕获、以及阻止冒泡
有如下html <ul> <li> <p> <a href="javascript:;">click me</a> &l ...