domxss的经典类型

admin 2026-01-01 05:26:02 网络安全文章 来源:ZONE.CI 全球网 0 阅读模式

文章总结: 文章介绍了DOMXSS中通过获取URL查询参数触发的经典类型,详细解析了使用split循环、正则表达式及URLSearchParams三种获取参数的方法。建议在代码审计或安全测试中重点关注getUrlParameter和getQueryParamByName等敏感函数,以便及时发现潜在的DOMXSS漏洞。 综合评分: 78 文章分类: WEB安全,漏洞分析,代码审计


cover_image

domxss的经典类型

原创

richardo1o1

迪哥讲事

2025年12月30日 09:00 江苏

domxss的经典类型

正文

domxss里面有一种非常经典的类型: 获取浏览器的URL查询参数

举个例子:

URL为’http://example.com?name=John&age=30′

写一个函数能够实现:获取参数’name’的值’John’,获取参数’age’的值’30’。 我这里实现了如下:

var getUrlParameter = function getUrlParameter(sParam) {
        var sPageURL = window.location.search.substring(1),
            sURLVariables = sPageURL.split('&'),
            sParameterName,
            i;
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(i = 0; i < sURLVariables.length; i++) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sParameterName = sURLVariables[i].split('=');

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(sParameterName[0] === sParam) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;sParameterName[1] === undefined ?&nbsp;true&nbsp;: decodeURIComponent(sParameterName[1]);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; };

这段代码中,’var sPageURL = window.location.search.substring(1),’获取了当前浏览器的URL地址,并将其存储在变量’sPageURL’中。然后,使用’var sURLVariables = sPageURL.split(‘&’)’将URL地址按照’&’进行分割,并将结果存储在变量’sURLVariables’中。

接下来,使用’for (i = 0; i < sURLVariables.length; i++)’循环遍历’sURLVariables’数组。在循环中,使用’var sParameterName = sURLVariables[i].split(‘=’)’将每个参数按照’=’进行分割,并将结果存储在变量’sParameterName’中。

最后,使用’if (sParameterName[0] === sParam)’判断当前参数是否是所需的参数。如果是,则使用’return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1])’返回参数的值,否则返回’undefined’。

看一个url:

https://s.weibo.com/weibo?q=%23%E8%A1%80%E6%B0%A7%E4%BB%AA%E5%AF%B9%E5%86%9C%E6%9D%91%E6%84%8F%E5%91%B3%E7%9D%80%E4%BB%80%E4%B9%88%23&t=31&band_rank=2&Refer=top

#就是:
https://s.weibo.com/weibo?q=#血氧仪对农村意味着什么#&t=31&band_rank=2&Refer=top

window.location.search.substring(1)获取的是:

q=%23%E8%A1%80%E6%B0%A7%E4%BB%AA%E5%AF%B9%E5%86%9C%E6%9D%91%E6%84%8F%E5%91%B3%E7%9D%80%E4%BB%80%E4%B9%88%23&t=31&band_rank=2&Refer=top
#其实就是
q=#血氧仪对农村意味着什么#&t=31&band_rank=2&Refer=top

而window.location.search/window.location.search.substring(0)获取的是

?q=%23%E8%A1%80%E6%B0%A7%E4%BB%AA%E5%AF%B9%E5%86%9C%E6%9D%91%E6%84%8F%E5%91%B3%E7%9D%80%E4%BB%80%E4%B9%88%23&t=31&band_rank=2&Refer=top

另外一种写法:

function&nbsp;getQueryParamByName(e) {
&nbsp; &nbsp; var t = window.location.href;
&nbsp; &nbsp; e = e.replace(/[\[\]]/g,&nbsp;"\\$&");
&nbsp; &nbsp; var a = new RegExp("[?&]"&nbsp;+ e +&nbsp;"(=([^&#]*)|&|#|$)").exec(t);
&nbsp; &nbsp;&nbsp;return&nbsp;a ? a[2] ? decodeURIComponent(a[2].replace(/\+/g,&nbsp;" ")) :&nbsp;""&nbsp;: null
}

其中 parameterName 是要检索的参数的名称。

第三种写法:

new URLSearchParams(window.location.search).get(‘ParamName’)

举个例子:

http://example.com?name=John&age=30

new URLSearchParams(window.location.search).get(‘age’)

结果为30

这三种写法都值得我们注意,在搜索js的时候,多注意getUrlParameter,getQueryParamByName,URLSearchParams这类敏感词

往往可能藏着dom类型的xss

如果你是一个长期主义者,欢迎加入我的知识星球,本星球日日更新,包含号主大量一线实战,全网独一无二,微信识别二维码付费即可加入,如不满意,72 小时内可在 App 内无条件自助退款

往期回顾

#

如何利用ai辅助挖漏洞

#

如何在移动端抓包-下

#

如何绕过签名校验

#

一款bp神器

挖掘有回显ssrf的隐藏payload

ssrf绕过新思路

一个辅助测试ssrf的工具

dom-xss精选文章

年度精选文章

Nuclei权威指南-如何躺赚

漏洞赏金猎人系列-如何测试设置功能IV

漏洞赏金猎人系列-如何测试注册功能以及相关Tips‍


免责声明:

本文所载程序、技术方法仅面向合法合规的安全研究与教学场景,旨在提升网络安全防护能力,具有明确的技术研究属性。

任何单位或个人未经授权,将本文内容用于攻击、破坏等非法用途的,由此引发的全部法律责任、民事赔偿及连带责任,均由行为人独立承担,本站不承担任何连带责任。

本站内容均为技术交流与知识分享目的发布,若存在版权侵权或其他异议,请通过邮件联系处理,具体联系方式可点击页面上方的联系我

本文转载自:迪哥讲事 richardo1o1《domxss的经典类型》

domxss的经典类型 网络安全文章

domxss的经典类型

文章总结: 文章介绍了DOMXSS中通过获取URL查询参数触发的经典类型,详细解析了使用split循环、正则表达式及URLSearchParams三种获取参数的
评论:0   参与:  0