跳转至

IdekCTF 2023

Taskmanager

考点:Python 类原型链污染

添加 eval global

@app.before_first_request
def init():
    if app.env == 'yolo':
        app.add_template_global(eval)
跟进源码发现需要更改 _got_first_request 为 False。
if self._got_first_request:
    return
with self._before_request_lock:
    if self._got_first_request:
        return
    for func in self.before_first_request_funcs:
        self.ensure_sync(func)()
    self._got_first_request = True

  • app.env='yolo'
  • app._got_first_request=[None, False]

任意渲染文件

跟进 jinja2 渲染流程,当传入 template str name 时会在 loaders.py#get_source 方法中调用 split_template_path 获取 pieces,然后用 posixpath.join 拼接。

>>> import posixpath
>>> posixpath.join('sakura', '../2333') 
'sakura/../2333'
split_template_path 函数
pieces = []
for piece in template.split("/"):
    if (
        os.path.sep in piece # /
        or (os.path.altsep and os.path.altsep in piece) # \\
        or piece == os.path.pardir # ..
    ):
        raise TemplateNotFound(template)
    elif piece and piece != ".":
        pieces.append(piece)
return pieces
可以直接覆写 os.path.pardir,避开 ..

  • os.path.pardir=$ 接着可以更改模板标记:

  • app.jinja_env.comment_start_string = sth

  • app.jinja_env.comment_end_string = sth 找一个形如 eval(.*) 的文件包含就行 但挺可惜的是 pydash 的作者在几天前更新了 Fix 做了题,又像没有做题 :>

一些其他有趣思路:


最后更新: June 24, 2023 16:07:33
创建日期: February 8, 2023 05:36:24

评论