๐Ÿ”’ Cyber Security/Web Hacking (์›นํ•ดํ‚น)

[DreamHack] ๋“œ๋ฆผํ•ต ์›นํ•ดํ‚น : ex-reg-ex

์„ ๋‹ฌ 2023. 11. 6. 16:13
๋ฐ˜์‘ํ˜•

https://dreamhack.io/wargame/challenges/834

 

ex-reg-ex

Description ๋ฌธ์ œ์—์„œ ์š”๊ตฌํ•˜๋Š” ํ˜•์‹์˜ ๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•˜์—ฌ ํ”Œ๋ž˜๊ทธ๋ฅผ ํš๋“ํ•˜์„ธ์š”. ํ”Œ๋ž˜๊ทธ๋Š” flag.txt ํŒŒ์ผ๊ณผ FLAG ๋ณ€์ˆ˜์— ์žˆ์Šต๋‹ˆ๋‹ค. ํ”Œ๋ž˜๊ทธ ํ˜•์‹์€ DH{...} ์ž…๋‹ˆ๋‹ค.

dreamhack.io

 

๋ฌธ์ œ์„ค๋ช…

 

๋ฌธ์ œ์—์„œ ์š”๊ตฌํ•˜๋Š” ํ˜•์‹์˜ ๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•˜์—ฌ ํ”Œ๋ž˜๊ทธ๋ฅผ ํš๋“ํ•˜์„ธ์š”. ํ”Œ๋ž˜๊ทธ๋Š” flag.txt ํŒŒ์ผ๊ณผ FLAG ๋ณ€์ˆ˜์— ์žˆ์Šต๋‹ˆ๋‹ค.

ํ”Œ๋ž˜๊ทธ ํ˜•์‹์€ DH{…} ์ž…๋‹ˆ๋‹ค.

 

๋”๋ณด๊ธฐ
#!/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)

 

ํ’€์ด

        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='?')

 

dr\w{5,7}e\d+am@[a-z]{3,7}\.\w+

์ด ์ •๊ทœ์‹์— ๋งž๋Š” ๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•˜๋ฉด ํ”Œ๋ž˜๊ทธ๊ฐ€ ๋‚˜์˜ค๋Š” ๊ฐ„๋‹จํ•œ ์ƒˆ์‹น ๋ฌธ์ œ

 

- dr

- \w{5,7} : ์†Œ๋ฌธ์ž๋‚˜ ์ˆซ์ž 5~7๊ฐœ

- e

- \d : ์ˆซ์ž 1๊ฐœ

- am@

- [a-z]{3,7} : ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž 3~7๊ฐœ

- \. : ์˜จ์  . ์ž…๋ ฅ

- \w+ : ์†Œ๋ฌธ์ž๋‚˜ ์ˆซ์ž 1๊ฐœ ์ด์ƒ

 

๋Œ€์ถฉ dr12345e6am@hac.k ์œผ๋กœ ์ž…๋ ฅํ•ด์คฌ๋‹ค

๋ฐ˜์‘ํ˜•