• 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

  • 相关阅读:
    题解-AtCoder ARC-083F Collecting Balls
    题解-CTS2019氪金手游
    题解-CTS2019随机立方体
    题解-APIO2019路灯
    题解-APIO2019桥梁
    vue-property-decorator 源码阅读
    如何在Vue项目中使用TypeScript
    在 Vue+TypeScript 项目中,如何配置 ESLint 和 Prettier
    JavaScript 原型和原型链
    pre-commit + imagemin 实现图片自动压缩
  • 原文地址:https://www.cnblogs.com/zhengna/p/12782067.html
Copyright © 2020-2023  润新知