目录

1、级别:Low

2、级别:Medium

3、级别:High

4、级别:Impossible


CSP(Content Security Policy):即内容安全策略。

开发者通过约束指定可信的信息来源,告诉客户端哪些外部资源可以被加载和执行,相当于提供了个白名单,来保障web运行环境的安全。例如,只允许本站的资源、限制可以使用的插件格式、限制外部资源只能从当前域名加载等等。可以很大程度上防止XSS攻击。

1、级别:Low


<?php$headerCSP = "Content-Security-Policy: script-src 'self' https://pastebin.com hastebin.com www.toptal.com example.com code.jquery.com https://ssl.google-analytics.com ;"; // allows js from self, pastebin.com, hastebin.com, jquery and google analytics.header($headerCSP);# These might work if you can't create your own for some reason
# https://pastebin.com/raw/R570EE00
# https://www.toptal.com/developers/hastebin/raw/cezaruzeka?>
<?php
if (isset ($_POST['include'])) {
$page[ 'body' ] .= "<script src='" . $_POST['include'] . "'></script>
";
}
$page[ 'body' ] .= '
<form name="csp" method="POST"><p>You can include scripts from external sources, examine the Content Security Policy and enter a URL to include here:</p><input size="50" type="text" name="include" value="" id="include" /><input type="submit" value="Include" />
</form>
';
$headerCSP = "Content-Security-Policy: script-src 'self' https://pastebin.com hastebin.com example.com code.jquery.com https://ssl.google-analytics.com ;";

Content-Security-Policy:允许站点管理者控制用户代理能够为指定的页面加载哪些资源。

这句代码说明了以下的外部资源可以被执行

https://pastebin.com
hastebin.com
example.com
code.jquery.com
https://ssl.google-analytics.com

这里通过bp抓包也可以看出来

我们打开https://pastebin.com,pastebin 是个快速分享文本内容的网站,假如文本的内容是一段 JavaScript 代码,网页就会把该代码包含进来。(需要先注册登录)

点击Create New Paste

点击raw

url:https://pastebin.com/raw/GLi165q9https://pastebin.com/raw/GLi165q9

我们将url粘贴至dvwa中,然后include一下

按照道理是能够出现弹窗的,但是我一直没弹窗,查了一下原因可能是因为 pastebin是国外的网站,访问比较慢,可能不会出现弹窗

白名单里其他的网站也是可以利用的

这里就借用一下别人成功弹窗的图吧

2、级别:Medium


<?php$headerCSP = "Content-Security-Policy: script-src 'self' 'unsafe-inline' 'nonce-TmV2ZXIgZ29pbmcgdG8gZ2l2ZSB5b3UgdXA=';";header($headerCSP);// Disable XSS protections so that inline alert boxes will work
header ("X-XSS-Protection: 0");# <script nonce="TmV2ZXIgZ29pbmcgdG8gZ2l2ZSB5b3UgdXA=">alert(1)</script>?>
<?php
if (isset ($_POST['include'])) {
$page[ 'body' ] .= "" . $_POST['include'] . "
";
}
$page[ 'body' ] .= '
<form name="csp" method="POST"><p>Whatever you enter here gets dropped directly into the page, see if you can get an alert box to pop up.</p><input size="50" type="text" name="include" value="" id="include" /><input type="submit" value="Include" />
</form>
';

unsafe-inline:当csp有Unsafe-inline时, 并且受限于csp无法直接引入外部js, 不过当frame-src为self, 或者能引入当前域的资源的时候, 即有一定可能能够引入外部js。

nonce-source,仅允许特定的内联脚本块。如源码中:nonce-TmV2ZXIgZ29pbmcgdG8gZ2l2ZSB5b3UgdXA='

所以我们直接输入源码中注释的内容就可以了

<script nonce="TmV2ZXIgZ29pbmcgdG8gZ2l2ZSB5b3UgdXA=">alert(1)</script>

3、级别:High

source/high.php:没有了白名单,可以通过POST传递include参数


<?php
$headerCSP = "Content-Security-Policy: script-src 'self';";header($headerCSP);?>
<?php
if (isset ($_POST['include'])) {
$page[ 'body' ] .= "" . $_POST['include'] . "
";
}
$page[ 'body' ] .= '
<form name="csp" method="POST"><p>The page makes a call to ' . DVWA_WEB_PAGE_TO_ROOT . '/vulnerabilities/csp/source/jsonp.php to load some code. Modify that page to run your own code.</p><p>1+2+3+4+5=<span id="answer"></span></p><input type="button" id="solve" value="Solve the sum" />
</form><script src="source/high.js"></script>
';

source/high.js:代码的主要逻辑还是在这一段,大致的意思就是,点击一个按钮会生成一个script的标签,该标签的src指向source/jsonp.php?callback=solveNum,然后把这个标签加入到DOM中。solveSum()函数传入参数obj,如果obj包含“answer”,远程加载的 solveSum({"answer":"15"}) 当作 js 代码执行,然后这个函数就会在界面适当的位置写入答案。


function clickButton() {var s = document.createElement("script");s.src = "source/jsonp.php?callback=solveSum";document.body.appendChild(s);
}function solveSum(obj) {if ("answer" in obj) {document.getElementById("answer").innerHTML = obj['answer'];}
}var solve_button = document.getElementById ("solve");if (solve_button) {solve_button.addEventListener("click", function() {clickButton();});
}

可以看到src指向的source/jsonp.php?callback=solveNum未做任何XSS的过滤,直接F12修改high.js的源代码,可以看到也能成功获取cookie

s.src = "source/jsonp.php?callback=alert(document.cookie)";

利用include参数构造payload:

include=<script src="source/jsonp.php?callback=alert('hacked');"></script>

4、级别:Impossible

impossible.js :可以看到修复了callback参数可控的问题


function clickButton() {var s = document.createElement("script");s.src = "source/jsonp_impossible.php";document.body.appendChild(s);
}function solveSum(obj) {if ("answer" in obj) {document.getElementById("answer").innerHTML = obj['answer'];}
}var solve_button = document.getElementById ("solve");if (solve_button) {solve_button.addEventListener("click", function() {clickButton();});
}

DVWA 之 CSP Bypass相关推荐

  1. DVWA指点迷津-CSP Bypass

    CSP 介绍 内容安全策略,实质上是白名单策略,通过限定允许加载哪些外部资源而保证网站的安全性. CSP规定的指令: CSP规定的值 在实际使用中,CSP策略在Content-Security-Pol ...

  2. 一步一步学习DVWA渗透测试(CSP Bypass绕过内容安全策略)-第十二次课

    小伙伴们,今天我们继续学习. Content-Security-Policy是指HTTP返回报文头中的标签,浏览器会根据标签中的内容,判断哪些资源可以加载或执行.翻译为中文就是绕过内容安全策略.是为了 ...

  3. PHP代码审计DVWA[CSP Bypass]

    CSP Bypass 靶场搭建可用蓝易云服务器

  4. DVWA 黑客攻防实战(十五) 绕过内容安全策略 Content Security Policy (CSP) Bypass

    看到标题,是否有点疑惑 CPS 是什么东东.简单介绍一下就是浏览器的安全策略,如果 标签,或者是服务器中返回 HTTP 头中有 Content-Security-Policy 标签 ,浏览器会根据标签 ...

  5. 【工具-DVWA】DVWA的安装和使用

    1 Wamp安装 Wamp:Apache+Mysql/MariaDB+Perl/PHP/Python 下载地址:http://www.wampserver.com/en/#download-wrapp ...

  6. DVWA靶场通关教程

    目录 Burt Force(爆破) (low) (medium) ​(high) (impossible) Command Injection(命令执行) (low) (medium) (high) ...

  7. DVWA全关教程手册

    搭建 使用phpstudy 放入根目录下 C:\phpstudy\PHPTutorial\WWW 修改两个配置文件 C:\phpstudy\PHPTutorial\WWW\DVWA\php.ini m ...

  8. 【WEB安全】PHP靶场实战分析——DVWA

    文章目录 前言 一.实战前的准备: 1.dvwa靶场安装 2.代码审计工具介绍 2.1.seay代码审计工具的介绍 2.2.rips 审计工具介绍 二.DVWA通关讲解 1. brute force ...

  9. 【CSRF02】跨站请求伪造——DVWA靶场实操(含CSRF+XSS协同攻击实验)

    目录 1 实验简介 1.1 实验目的 1.2 实验环境 2 Low难度 2.1 前戏 2.2 实验步骤 2.3 代码审计 3 Medium难度 3.1 前戏 3.2 实验思路 3.3 方法一:诱导点击 ...

最新文章

  1. 英特尔也决定了!正式退出5G智能型手机
  2. ios 中的小技巧 - 总有你想要的 一
  3. 获取某个时间开始 之后的 N次[周几,周几]
  4. axios 跨域代理
  5. 微信小程序——极点日历使用方法
  6. 如何在Ubuntu-16.04 / 18.04上为 RTX 2080 Ti GPU 安装Nvidia驱动和cuda-10.0
  7. ./configure --prefix --with解释
  8. 海康威视网络摄像头SDK中Demo的二次开发(运行)
  9. GEE开发之Landsat8计算NDWI和数据分析
  10. MFC调用RDP实现远程桌面共享实例
  11. 年长车友的单车游记:骑单车游崇明岛(转)
  12. H5接入微信SDK 实现微信支付
  13. 信用卡上了“灰名单”怎么办?如何解除?
  14. mysql8.013安装_关于mysql 8.0.13zip包安装
  15. Sharding JDBC-读写分离
  16. 树莓派安装NOOBS失败
  17. Libor利率查询_图表加数据Libor伦敦银行同业拆借利率
  18. 一梦江湖卡在服务器信息100,一梦江湖卡69、89、129到底有什么区别?这一篇讲的很清楚了...
  19. Flash拖拽元件的元件+元件的元件随鼠标移动:目的让元件的元件随着鼠标移动
  20. 标注工具—labelme, label-studio

热门文章

  1. 零售行业常见数据分析简介
  2. 用python 实现数据反序列化处理 以及 算法的学习
  3. GNU Radio入门之旅
  4. vs2010 c语言 如何编译器,如何在Visual Studio中选择C++和C#的编译器版本
  5. 利用RAW格式处理大光比照片
  6. 【Metal2剖析(七):抗锯齿之基于Imageblock特性的增强MSAA】
  7. 淘宝买家谈阿里质量意识
  8. Conan软件包管理器的Qt 6.2.4软件包
  9. 【Python】使用CDS API下载ECMWF气候数据
  10. 支付清结算之账户和账务处理