dvwa13——CSP Bypass
CSP(content security policy):
个人理解是类似于白名单的东西,通过http头部或者<meta>标签声明,来控制网页可以加载哪些外部资源
ps:Meta标签是html文档里的一种标签,用于提供网页的元信息
也就是说,CSP禁止所有未被明确允许的内容,只执行符合条件的资源
关键指令:script-src:
script-src指定哪些来源的JavaScript可以被浏览器加载和执行
LOW
先分析一下源码
通过这一行可以得到允许的来源
- 'self ':同源脚本 (和当前页面有相同协议,域名,端口的js文件)
- https://pastebin.com
- hastebin.com
- example.com
- code.jquery.com
- https://ssl.google-analytics.com
这里选用https://pastebin.com来进行攻击,在newpaste里写
alert("rerelee")
Creat New Paste ,在出现的页面里面点击download,然后右键复制下载连接
返回dvwa,在输入框里输入我们刚才复制的代码,然后Include提交!回显成功!
MEDIUM
观察源码,发现直接泄露了,那就稍作改动输入
回显成功!
HIGH
看到high的界面,我们发现输入框已经没了.....
打开high.js,直接在里面进行修改
试了好几种方法都改动不了,于是打开控制台
输入这一串把前面的js文件覆盖掉
solveSum = function(obj) {alert("rerelee"); // 强制弹窗if ("answer" in obj) {document.getElementById("answer").innerHTML = obj['answer'];}
};
回车后回显成功
IMPOSSIBLE
分析源码:
<?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>Unlike the high level, this does a JSONP call but does not use a callback, instead it hardcodes the function to call.</p><p>The CSP settings only allow external JavaScript on the local server and no inline 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/impossible.js"></script>
';
优化的地方:
- csp更加严格,只允许加载同源脚本self
- 通过document.createElement动态加载脚本确保来源是可信的