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

    Medium Level

    查看代码

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

    http头信息中的script-src的合法来源发生了变化,说明如下

    • unsafe-inline,允许使用内联资源,如内联< script>元素,javascript:URL,内联事件处理程序(如onclick)和内联< style>元素。必须包括单引号。
    • nonce-source,仅允许特定的内联脚本块,nonce="TmV2ZXIgZ29pbmcgdG8gZ2l2ZSB5b3UgdXA="

    现在更加简单了,可以直接输入以下代码

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

    弹出如下信息框,表示注入成功。

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

  • 相关阅读:
    CentOS7.4安装Docker
    责任链模式
    策略模式
    状态模式
    解释器模式
    备忘录模式
    中介者模式
    观察者模式
    迭代器模式
    private、default、protected和public的作用域
  • 原文地址:https://www.cnblogs.com/zhengna/p/12782033.html
Copyright © 2011-2022 走看看