Without a Break

[Dreamhack] pathtraversal 본문

Web/Wargame

[Dreamhack] pathtraversal

와븨 2022. 10. 5. 17:40

 

[문제 파일]

users = {
    '0': {
        'userid': 'guest',
        'level': 1,
        'password': 'guest'
    },
    '1': {
        'userid': 'admin',
        'level': 9999,
        'password': 'admin'
    }
}
  • 존재하는 계정들의 정보
@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
        return render_template('get_info.html', info=info)
  • get_info 페이지는 유저의 아이디를 보여주는 렌더링 페이지
@app.route('/api/user/<uid>')
@internal_api
def get_flag(uid):
    try:
        info = users[uid]
    except:
        info = {}
    return json.dumps(info)
  • user의 정보를 info 변수에 넣고 json 형식으로 반환
  • user 변수에 없는 값을 요청 시, info 변수는 {}가 넣어지고 빈 값이 json 형식으로 반환
@app.route('/api/flag')
@internal_api
def flag():
    return FLAG
  • /api/flag에 flag가 출력됨

 


[풀이]

 

Get User Info 페이지는 입력한 userid의 정보를 보여준다

 

 

개발자 도구를 살펴보면 userid에 넣은 값이 users에 있는 값으로 변경되어 서버에 넘어가는 것을 알 수 있다.

따라서, userid를 사용해 공격을 할 것이다.

 

버프스위트에서 브라우저를 열고 문제 페이지로 들어가 view 버튼을 눌러서 패킷을 가로챈 후 리피터로 보낸다.

 

현재 디렉토리의 위치를 모르기 때문에 상위 디렉토리로 이동 후 flag페이지로 이동하도록 경로를 조작해야 한다.

따라서, 요청의 userid를 ../flag로 수정해 send 버튼을 눌러 전송하면

응답 페이지에 플래그가 뜨게 된다.

 

답 : DH{8a33bb6fe0a37522bdc8adb65116b2d4}

'Web > Wargame' 카테고리의 다른 글

[Dreamhack] file-download-1  (0) 2022.11.01
[Dreamhack] image-storage  (0) 2022.11.01
[Dreamhack] carve party  (0) 2022.10.05
[Dreamhack] command-injection-1  (0) 2022.10.05
[Dreamhack] Mango  (0) 2022.10.01