<문제>
<풀이>
1. 사이트 및 코드 확인
문제 사이트에 접속하면 처음에 뜨는 페이지이다.
아무 이름이나 입력해서 Sign in 한다.
Sign in 하면 나의 자산 내역을 확인할 수 있다.
자산의 종류에는 DHH, DHC, DHD가 있는 것을 알 수 있다.
산타 사설 거래소로 들어가본다.
DHH를 빌리고, 코인을 교환하고, FLAG를 구매할 수 있는 페이지이다.
@app.route("/santa/flag", methods=['GET'])
def santa_flag():
if session['DHH'] >= 1000.0:
if session['debt_DHH'] == 0.0:
return render_template("flag.html")
else:
return render_template("santa.html", session=session, message="빚을 먼저 값으세욧!")
return render_template("santa.html", session=session, message="드핵코인이 없어욧!")
FLAG 구매에 대한 코드를 살펴보았다.
DHH가 1000 이상이고 debt_DHH가 0이면 flag를 얻을 수 있다.
산타 사설 거래소에서 나와서 이번에는 드림 유동성 풀로 들어가본다.
DHC를 담보로 낼 수 있고, DHC, DHD를 예금할 수 있고, DHC를 담보로 DHD를 빌릴 수 있다.
@app.route("/dream/collateral", methods=['POST'])
def dream_col():
value = float(request.form['value'])
if value < 0:
if session['debt_DHD'] == 0.0:
session['DHC'] += session['col_DHC']
session['col_DHC'] = 0.0
return render_template("dream.html", session=session, message="담보 반환 완료!")
else:
return render_template("dream.html", session=session, message="빚을 먼저 값으세욧!")
if session['DHC'] - value < 0.0:
return render_template("dream.html", session=session, message="가지고 있는 드냥코인이 부족합니다!")
session['DHC'] -= value
session['col_DHC'] += value
return render_template("dream.html", session=session, message="담보 확인!")
DHC를 담보로 내는 부분에 대한 코드를 살펴보았다.
104, 105행을 보면 입력만 만큼의 DHC를 col_DHC로 변환하는 것을 확인할 수 있다.
@app.route("/dream/lend", methods=['POST'])
def dream_loan():
value = float(request.form['value'])
dhc_price = get_price('DHC')
dhd_price = get_price('DHD')
max_lend = session['col_DHC'] * dhc_price / dhd_price * 0.8
print(max_lend)
if session['DHD'] + value < 0.0:
return render_template("dream.html", session=session, message="더 갚으시게요...?")
if max_lend < value:
return render_template("dream.html", session=session, message="그만큼 빌리기에는 담보가 부족합니다!")
session['DHD'] += value
session['debt_DHD'] += value
return render_template("dream.html", session=session, message="대출 완료!")
DHD를 대출하는 기능을 하는 코드이다.
col_DHC 값을 기준으로 한번에 대출할 수 있는 최대 액수가 제한된다.
하지만 최대 액수 이내의 금액으로 여러번 대출하는 것이 가능하므로 결국 필요한 만큼 대출을 받을 수 있음을 알 수 있다.
2. 취약점 공략
1) DHH 대출
2) DHC로 전환
3) 전환한 DHC를 담보로 냄
4) DHD를 여러번 나눠 충분한 금액만큼 대출
담보가 1000DHC라서 한번에 대출할 수 있는 최대 금액 800DHD를 세번에 나눠 대출했다.
5) 대출한 DHD를 DHH로 전환
6) 대출한 DHH 상환
7) 남은 DHH로 FLAG 구매
3. FLAG 획득
플래그가 출력되었다.
<후기>
문제를 너무 어렵게 생각해서 간단한 취약점인데 이틀동안 찾지 못하고 결국 인터넷을 참고해서 풀었다.
내가 찾은 취약점이 왜 뚫리지 않았는지 아직도 의문이지만ㅠㅠ
다음부터는 좀더 유연하게 문제를 바라볼 필요가 있을 것 같다.
'드림핵' 카테고리의 다른 글
[드림핵 워게임] XSS Filtering Bypass (0) | 2023.08.15 |
---|---|
[드림핵 워게임] CSRF Advanced (0) | 2023.08.15 |
[드림핵 워게임] command-injection-chatgpt (0) | 2023.08.11 |
[드림핵 워게임] simple_sqli_chatgpt (0) | 2023.08.11 |
[드림핵 워게임] 🌱 simple-web-request (0) | 2023.08.09 |