문제 설명
웹 서버에 접속하니 위와 같이 총 세 가지의 사이트에 접속할 수 있게끔 표시가 된다.
문제 설명에 나와 있듯이 STEP 1과 STEP 2을 거쳐야 Flag를 획득할 수 있다.
아직 STEP 1을 수행하지 못했기 때문에 STEP 2 페이지는 접속조차 되지 않는다.
파이썬 코드를 열어서 살펴 보면 아래와 같다.
#!/usr/bin/python3
import os
from flask import Flask, request, render_template, redirect, url_for
import sys
app = Flask(__name__)
try:
# flag is here!
FLAG = open("./flag.txt", "r").read()
except:
FLAG = "[**FLAG**]"
@app.route("/")
def index():
return render_template("index.html")
@app.route("/step1", methods=["GET", "POST"])
def step1():
#### 풀이와 관계없는 치팅 방지 코드
global step1_num
step1_num = int.from_bytes(os.urandom(16), sys.byteorder)
####
if request.method == "GET":
prm1 = request.args.get("param", "")
prm2 = request.args.get("param2", "")
step1_text = "param : " + prm1 + "\nparam2 : " + prm2 + "\n"
if prm1 == "getget" and prm2 == "rerequest":
return redirect(url_for("step2", prev_step_num = step1_num))
return render_template("step1.html", text = step1_text)
else:
return render_template("step1.html", text = "Not POST")
@app.route("/step2", methods=["GET", "POST"])
def step2():
if request.method == "GET":
#### 풀이와 관계없는 치팅 방지 코드
if request.args.get("prev_step_num"):
try:
prev_step_num = request.args.get("prev_step_num")
if prev_step_num == str(step1_num):
global step2_num
step2_num = int.from_bytes(os.urandom(16), sys.byteorder)
return render_template("step2.html", prev_step_num = step1_num, hidden_num = step2_num)
except:
return render_template("step2.html", text="Not yet")
return render_template("step2.html", text="Not yet")
####
else:
return render_template("step2.html", text="Not POST")
@app.route("/flag", methods=["GET", "POST"])
def flag():
if request.method == "GET":
return render_template("flag.html", flag_txt="Not yet")
else:
#### 풀이와 관계없는 치팅 방지 코드
prev_step_num = request.form.get("check", "")
try:
if prev_step_num == str(step2_num):
####
prm1 = request.form.get("param", "")
prm2 = request.form.get("param2", "")
if prm1 == "pooost" and prm2 == "requeeest":
return render_template("flag.html", flag_txt=FLAG)
else:
return redirect(url_for("step2", prev_step_num = str(step1_num)))
return render_template("flag.html", flag_txt="Not yet")
except:
return render_template("flag.html", flag_txt="Not yet")
app.run(host="0.0.0.0", port=8000)
코드 내용을 읽다 보니 param과 param2를 직접적으로 알려주는 부분이 있다.
if prm1 == "getget" and prm2 == "rerequest":
이 내용 그대로 키워드를 입력해 보니, 해결이 된 듯 STEP 2로 추정되는 화면이 나타난다.
위의 코드를 다시 살펴보면 앞선 STEP 1의 답이 아닌, 또 다시 param과 param2를 언급하는 코드가 나온다.
if prm1 == "pooost" and prm2 == "requeeest":
이 내용 그대로 키워드를 입력해 보면,
플래그를 알려 준다. 이 내용 그대로 드림핵 문제 페이지에 입력하면 해결 완료
'SWUFORCE > 워게임 풀이' 카테고리의 다른 글
[Dreamhack] php7cmp4re (web) (0) | 2024.05.07 |
---|---|
[Dreamhack] Carve Party (web) (0) | 2024.05.01 |
[Dreamhack] Flying Chars (0) | 2024.04.02 |
[Dreamhack] ex-reg-ex(web) (0) | 2024.04.02 |
[Dreamhack] file-download-1(web) (0) | 2024.03.26 |