ssti 취약점을 이용한 문제라고 한다.
우선, 문제를 풀기 전에 ssti 취약점이 무엇인지 한번 짚고 넘어가도록 하자.
#!/usr/bin/python3
from flask import Flask, request, render_template, render_template_string, make_response, redirect, url_for
import socket
app = Flask(__name__)
try:
FLAG = open('./flag.txt', 'r').read()
except:
FLAG = '[**FLAG**]'
app.secret_key = FLAG
@app.route('/')
def index():
return render_template('index.html')
@app.errorhandler(404)
def Error404(e):
template = '''
<div class="center">
<h1>Page Not Found.</h1>
<h3>%s</h3>
</div>
''' % (request.path)
return render_template_string(template), 404
app.run(host='0.0.0.0', port=8000)
코드는 이거다.
app.secret_key를 얻어야 FLAG를 얻을 수 있을듯
지금 어느 페이지로 들어가도
….?
404 에러가 뜬다.
ssti 취약점을 이용해 보자. flask를 이용하므로 템플릿 변수는 {{}} 이다.
예를 들어, http://host3.dreamhack.games:17212/{{7*7}} 이렇게 입력해 보자.
그러면 {{7*7}}가 뜨는 게 아니라, 계산된 값이 뜨는 걸 볼 수 있다. 그러면 app.secret_key의 값을 얻기 위해서 뒤에 {{}}로 어떠한 구문을 작성하면, 플래그 값을 읽어올 수 있을 것 같다.
<aside> 💡 {{config[%27SECRET_KEY%27]}}
</aside>
이걸 url 뒤에 넣어보자