DOM XSS从javascript中输出数据到HTML页面
存储或反射型XSS是从服务端输出到HTML页面
常见位置
URL代入页面
定义:通过js直接获取url中的参数,然后输出到HTML页面
通过window.location.search获取页面url传递的参数
function GetQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = decodeURI(window.location.search.substr(1)).match(reg);
if (r != null)return unescape(r[2]);
return null;
}
var sname = GetQueryString("name");
if(sname!=null){
var sname_ = decodeURIComponent(sname);
alert(sname_);
} #获取具体参数
document.getElementById('foo').innerHTML = getUrlParam('foo') #dom型XSS问题
此时取值时,匹配的URL是location.href,这个值包含了 location.search 和 location.hash 的值,而 location.hash 的值是不被传到服务器,但并且能被前端JS通过 getUrlParam 函数成功取值
location.search:获取问号后面的参数
如:
http://www.runoob.com/[email protected] example.com
通过document.write(location.search);获取到的是
[email protected]
location.hash:获取url的锚部分,从“#”开始到最后,都是锚部分,不被传到服务器,但并且能被前端JS通过 getUrlParam 函数成功取值。
跳转类
在 javascript 语法中,使用如下代码可以将页面进行跳转操作
location.href = urlparams.redirecturl;
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<script>
function jump(){
window.location.href="javascript:alert(1)";
}
</script>
<button type="button" onclick="jump()">test</button>
</body>
</html>
附:
//顶层窗口跳转
//top.location.href='http://www.baidu.com';
//父层窗口跳转
//parent.location.href='http://www.baidu.com';
//以下均为本页面跳转
//window.location.href="http://www.baidu.com";
//location.href="http://www.baidu.com";
//self.location.href="http://www.baidu.com";
//this.location.href="http://www.baidu.com";
//location.href="http://www.baidu.com";
document.location.href
这样的跳转通常会出现在登录页、退出页、中间页。
如果开发者让用户可以控制 redirecturl 参数,就可以使用 javascript:alert(1) 的形式进行XSS攻击。
最近几年的APP开发比较热门,通过web唤起APP的操作也是越来越多,跳转的协议也是多种多样,例如 webview:// , myappbridge:// 等等。 仅仅使用 http 和 https 来判断URL是否合法已经不适用了,于是由跳转所产生的DOM-XSS漏洞也逐渐增多。
测试关注点 输入点
document.location
document.URL
document.URLUnencoded
document.referrer
window.location(href hash)
所有的inputs
window.name
document.cookie
XMLhttpRequest返回的数据
localstorage
·····
以下几个地方是js输出到HTML的必经之路 输出点
document.write()
document.writeln()
xxx.innerHTML=
xxx.outerHTML=
innerHTML.replace=
document.attachEvent()
window.attachEvent()
document.location.replace()
document.location.assign()
缓存类
开发者在缓存前端数据的时候,通常会存在 sessionStorage , localStorage , cookie 中,因为 sessionStorage 在页面刷新时就失效的特性,利用方式相对简单的只有后面两种。
参考学习
https://code.google.com/archive/p/domxsswiki/ domxss 备忘单
https://cstcamaro.github.io/post/2018-ISC-%E6%BC%94%E8%AE%B2%E7%A8%BF?tdsourcetag=s_pctim_aiomsg
http://blog.nsfocus.net/xss-advance/#23_DOM