zoukankan      html  css  js  c++  java
  • DVWA-13.4 CSP Bypass(绕过浏览器的安全策略)-Impossible

    Impossible Level

    查看源码

    impossible.php

    <?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>
    ';

    impossible.js

    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();
        });
    }

    jsonp_impossible.php

    <?php
    header("Content-Type: application/json; charset=UTF-8");
    
    $outp = array ("answer" => "15");
    
    echo "solveSum (".json_encode($outp).")";
    ?>

    该级别主要还是修复了 callback 参数可被控制问题,无法进行攻击。

    参考:https://zhuanlan.zhihu.com/p/110012962

  • 相关阅读:
    svnserve 配置
    JDBC与JTA的区别
    Redhat E5上安装Subversion 1.6详解
    CentOS5.3 编译 mod_jk 1.2.15 链接器 整合apache httpd 和 tomcat
    Linux对逻辑卷的创建与管理
    spring 包的解释
    vue.js之router详解(一)
    Ubuntu12.10 高速全自动配置bash脚本
    PHP execl导出/展示
    有关Linux下的一些配置
  • 原文地址:https://www.cnblogs.com/zhengna/p/12782067.html
Copyright © 2011-2022 走看看