CTF/Web Hacking
Dreamhack - ex-reg-ex
햄친구베이컨
2024. 7. 18. 22:50
코드
#!/usr/bin/python3
from flask import Flask, request, render_template
import re
app = Flask(__name__)
try:
FLAG = open("./flag.txt", "r").read() # flag is here!
except:
FLAG = "[**FLAG**]"
@app.route("/", methods = ["GET", "POST"])
def index():
input_val = ""
if request.method == "POST":
input_val = request.form.get("input_val", "")
m = re.match(r'dr\w{5,7}e\d+am@[a-z]{3,7}\.\w+', input_val)
if m:
return render_template("index.html", pre_txt=input_val, flag=FLAG)
return render_template("index.html", pre_txt=input_val, flag='?')
app.run(host="0.0.0.0", port=8000)
정규표현식에 맞는 문자열을 쓰면 flag가 출력된다.
dr\w{5,7}e\d+am@[a-z]{3,7}\.\w+r
- dr
- \w{5,7} : 5~7자의 영문 또는 숫자 (그런데 6자 이상이여야 하는 것 같다..)
- e
- \d : 숫자
- am@
- [a-z] 중 3~7자
- .
- \w : 영문자 또는 숫자
- r