Exploring SSTI in Flask/Jinja2
Flask는 파이썬 웹 프레임 워크이다. 그리고 Flask에는 Jinja라는 Template 엔진이 내장되어 있다.
Jinja의 구분자는 아래와 같다.
- {% ... %} : 제어문 ( for / if / elif / else )
- {{ ... }} : 표현식
- {# ... #} : 주석
- # ... ## : 1번 구분자 한줄 표현
<title>{% block title %}{% endblock %}</title>
<ul>
{% for user in users %}
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
{% endfor %}
</ul>
https://jinja.palletsprojects.com/en/2.10.x/templates/
Template Designer Documentation — Jinja Documentation (2.11.x)
This document describes the syntax and semantics of the template engine and will be most useful as reference to those creating Jinja templates. As the template engine is very flexible, the configuration from the application can be slightly different from t
jinja.palletsprojects.com
Flask에서 어떤 문자열이나 파일을 렌더링할 때, 임의의 문자를 포함시킬 수 있다면 위에 나온 구분자를 이용하여 Template Injection을 시도할 수 있다.
Flask에는 config 글로벌 객체가 존재한다.
config 객체는 어플리케이션의 모든 구성값을 포함하는 딕셔너리 형태의 객체이다.
여기에는 SECRET_KEY 같은 민감한 데이터도 포함한다.
위 코드는 search 파라미터에 Template Injection이 가능하다.
?search={{ config.items() }} 이렇게 쿼리를 보내면 아래와 같이 SECRET_KEY 탈취가 가능하다.
https://medium.com/@nyomanpradipta120/ssti-in-flask-jinja2-20b068fdaeee
SSTI in Flask/Jinja2
What is SSTI ( Server-Side Template Injection)
medium.com