burpsuite靶场----XSS----DOM型XSS4----hashchange

发布时间 2023-08-19 15:32:33作者: BattleofZhongDinghe

burpsuite靶场----XSS----DOM型XSS4----hashchange

靶场地址

https://portswigger.net/web-security/cross-site-scripting/dom-based/lab-jquery-selector-hash-change-event

XSS字典

链接:https://pan.baidu.com/s/1XAJbEc4o824zAAmvV85TOA
提取码:1234

正式开始

1.查看html源码,找到可能存在xss的地方

                        $(window).on('hashchange', function(){
                            var post = $('section.blog-list h2:contains(' + decodeURIComponent(window.location.hash.slice(1)) + ')');
                            if (post) post.get(0).scrollIntoView();
                        });

这段代码使用了jQuery的$(window).on('hashchange', function(){})语法,表示在浏览器窗口的URL哈希部分发生变化时执行其中的代码
执行的代码是什么呢,
section.blog-list h2是选中section标签内的所有h2元素,
contains是过滤器,用来选定包含指定文本的元素,这里要选定decodeURIComponent(window.location.hash.slice(1))的返回值,为URL的hash部分,然后进行URL解码
如果满足了条件,就会滑动到第一个匹配元素
2.现在点击Go to exploit server


3.分析官方给的payload

<iframe src="https://YOUR-LAB-ID.web-security-academy.net/#" onload="this.src+='<img src=x onerror=print()>'"></iframe>

我这里是

<iframe src="https://0ad2006f04b6be0480423abb00b00051.web-security-academy.net/#" onload="this.src+='<img src=x onerror=print()>'"></iframe>

如果攻击者将这串代码保存在一段恶意链接发送给受害者,因为在https://0ad2006f04b6be0480423abb00b00051.web-security-academy.net/最后面多了'#',URL的hash值发生改变
满足了if(post)的条件,加载了恶意代码
<img src=x onerror=print()>
完成了任务
4.这里是点击deliver exploit to victim模拟将exp发送给受害者,显示生活中可以将恶意代码保存在自己的云服务器上,再使用和主站很像的域名,完成XSS攻击