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

  • 相关阅读:
    (HDOJ 2503)a/b + c/d
    用VSTS进行网站压力测试
    .NET中IDisposable接口的基本使用
    创建ASP.Net自定义控件
    petshop4.0详解
    .net中SQL防注入代码
    petshop4 缓存机智在sql2005上的设置
    Asp.net自定义控件:概念
    .Net pet shop 4 和 MSMQ
    .net缓存自己总结的几条
  • 原文地址:https://www.cnblogs.com/zhengna/p/12782067.html
Copyright © 2011-2022 走看看