먼저 축하를 하고 시작해야겠다
(경) 풀이 없이 문제를 혼자 풀었다~~~(축)
다만 정확히 코드를 이해하고 푼게 아니라...
풀이법은 정확히 보는게 좋다~~
param=매개변수 뜻이다
f(x) x =2x+1 에서 x가 바로 f함수의 매개변수다
a친구 b친구 c친구가 있는데
b친구가 a친구에게 c친구를 소개시켜주면
b는 a친구와 c친구의 매개체가 된다
여기서 3이라는 외부값(파라미터)를 넣어주면 f(3)이 되는데 f(3) = 7이라는 리턴값이 나온다
참고로 함수는 ()괄호가 뒤에 있는 친구들을 보통 얘기한다
파일 폴더를 확인해봤더니
flag 메모장 파일이 있다(!)
다시 문제로 돌아와 소스코드를 보자
#!/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)
쭉 읽다보면 prm1 ==, prm2 == 하는 코드가 있길래 넣어줬더니..
step1 prm1 == "getget" prm2 == "rerequest"
step2 prm1 = "pooost" prm2 == "requeeest"
문제를 풀어버렸다(!)
하지만
소스코드를 정확히 이해하고 가는게 좋을 것 같아 풀이법 블로그글을 추가 첨부한다!
https://2jw2534.tistory.com/94
드림핵 simple-web-request Write Up
문제 설명 STEP 1과 2를 거쳐서 FLAG 페이지에 도달하면 플래그를 출력할 수 있다. 일단 먼저 / 페이지를 보면 index.html 을 렌더링 하고있다. index.html 페이지를 보면 STEP1, STEP2, FLAG 페이지가 존재한다.
2jw2534.tistory.com
소스코드를 읽다가 문제가 다른걸 발견했다...
멍청이...
찾다보니 이 문제 소스코드를 정확히 해석해주는 블로그는 안보였다..
이 블로그가 비슷한 유형 문제 소스코드를 해석해줘서 참고하면 될뜻하다
의도치않게 문제 스포 당해버렸다(!)
그리고 직접웹앱을 사용해보고싶어서 열심히 따라했는데 파이썬 flask 설치 과정에서 또 문제 발생했다 ㅡㅡ
하고싶은데!! 왜 할 수가 없니!!!
'Dreamhack > Dreamhack Wargame (Challenge)' 카테고리의 다른 글
[20] IT 비전공자 [dreamhack] Exercise: SSH문제 풀기 (0) | 2024.09.29 |
---|---|
[19] IT 비전공자 [dreamhack] web-misconf-1문제 풀기 (0) | 2024.09.28 |
[17] IT 비전공자 [dreamhack] session 문제 풀기 (0) | 2024.09.26 |
[16] IT 비전공자 [dreamhack] Flying Chars 문제 풀기 (0) | 2024.09.25 |
[14] IT 비전공자 [dreamhack] ex-reg-ex 문제 풀기 (0) | 2024.09.24 |