pathtraversal

2024. 9. 11. 15:55·DreamHack/WEB

 

 

 

디렉터리 조작 취약점이 있다고 한다.

 

 

 

 

 

 

 

 

 

 

#!/usr/bin/python3
from flask import Flask, request, render_template, abort
from functools import wraps
import requests
import os, json

users = {
    '0': {
        'userid': 'guest',
        'level': 1,
        'password': 'guest'
    },
    '1': {
        'userid': 'admin',
        'level': 9999,
        'password': 'admin'
    }
}

def internal_api(func):
    @wraps(func)
    def decorated_view(*args, **kwargs):
        if request.remote_addr == '127.0.0.1':
            return func(*args, **kwargs)
        else:
            abort(401)
    return decorated_view

app = Flask(__name__)
app.secret_key = os.urandom(32)
API_HOST = 'http://127.0.0.1:8000'

try:
    FLAG = open('./flag.txt', 'r').read() # Flag is here!!
except:
    FLAG = '[**FLAG**]'

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/get_info', methods=['GET', 'POST'])
def get_info():
    if request.method == 'GET':
        return render_template('get_info.html')
    elif request.method == 'POST':
        userid = request.form.get('userid', '')
        info = requests.get(f'{API_HOST}/api/user/{userid}').text #../../flag
        return render_template('get_info.html', info=info)

@app.route('/api')
@internal_api
def api():
    return '/user/<uid>, /flag'

@app.route('/api/user/<uid>')
@internal_api
def get_flag(uid):
    try:
        info = users[uid]
    except:
        info = {}
    return json.dumps(info)

@app.route('/api/flag')
@internal_api
def flag():
    return FLAG

application = app # app.run(host='0.0.0.0', port=8000)
# Dockerfile
#     ENTRYPOINT ["uwsgi", "--socket", "0.0.0.0:8000", "--protocol=http", "--threads", "4", "--wsgi-file", "app.py"]

 

전체 코드이다.

 

먼저 flag 위치를 파악해 보면 /api 디렉터리 안에 담겨 있는 걸 볼 수 있다.

 

좀 더 중요한 코드를 보자면 ...

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

@app.route('/get_info', methods=['GET', 'POST'])
def get_info():
    if request.method == 'GET':
        return render_template('get_info.html')
    elif request.method == 'POST':
        userid = request.form.get('userid', '')
        info = requests.get(f'{API_HOST}/api/user/{userid}').text #../../flag
        return render_template('get_info.html', info=info)

 

이 부분인데

 

request.method == 'POST'

> 사용자가 폼에 입력을 하면 POST 요청이 발생한다.

 

userid = request.form.get('userid', '')

> userid 값에 아무것도 없을 경우에는 빈 문자열로 반환시킨다.

 

info = request.get(f'{API_HOST}/api/user/{userid}'). text [View button]

> requests.get을 이용하여 API로 GET 요청을 보낸다 응답은 text 속성으로 온다.

 

여기서 보면 'view'를 눌렀을 때 GET 요청으로 인해 api를 호출한다 

 

그렇다면 view를 이용해서 경로를 조작하여 플래그를 출력시킬 수 있을 거 같다.

 

플래그에 위치는 이미 알고 있으니...

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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

proxy-1  (0) 2024.10.16
web-misconf-1  (1) 2024.10.10
blind-command  (0) 2024.10.10
session  (1) 2024.10.08
web-ssrf  (2) 2024.09.26
'DreamHack/WEB' 카테고리의 다른 글
  • web-misconf-1
  • blind-command
  • session
  • web-ssrf
G_OM
G_OM
최대한 설명 열심히 하려고 합니다. 궁금한 거 있으면 언제든지 물어보셔도 좋습니다.
  • G_OM
    끄적끄적
    G_OM
  • 전체
    오늘
    어제
    • 분류 전체보기 (142) N
      • 모의해킹 (9) N
      • Wargame (69)
        • Linux_bandit (33)
        • Webhacking.kr (36)
      • DreamHack (52)
        • WEB (14)
        • Reverising (9)
        • System (0)
        • CTF (22)
      • Android_security (7) N
        • Drozer_Android (4)
        • Frida_Android (1) N
      • 정보보안기사 (2)
      • IT? (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

    • DreamHack 에 대한 문제들...
  • 인기 글

  • 태그

    wargame
    drozer
    안드로이드
    webhacking
    union
    정보보안기사
    bandit
    sql injection
    CTF
    Linux wargame
    리눅스 워게임
    php wrapper
    bandit17
    bandit18
    난독화
    php
    Dreamhack
    webhacking.kr
    insecurebankv2
    Cookie
    bandit30
    워게임
    cookies
    lfi
    url encode
    bandit20
    Linux
    Android
    리눅스
    overthewire
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
G_OM
pathtraversal
상단으로

티스토리툴바