SlowTurtle_

천천히 그러나 끝까지 완주

Webhacking-Write-Up/Dreamhack

[Dreamhack] Cookie

SlowTurtle_ 2022. 12. 20. 13:58
728x90

[Dreamhack] Wargame - Cookie

admin 계정으로 로그인에 성공하여 플래그 얻기!

유저에 guest가 있는 것을 알 수 있다.

users = {
    'guest': 'guest',
    'admin': FLAG
}

guest로 로그인 했을 때이다.

index를 구성하는 코드

@app.route('/')
def index():
    username = request.cookies.get('username', None)
    if username:
        return render_template('index.html', text=f'Hello {username}, {"flag is " + FLAG if username == "admin" else "you are not admin"}')
    return render_template('index.html')

로그인을 구성하는 코드

@app.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'GET':
        return render_template('login.html')
    elif request.method == 'POST':
        username = request.form.get('username')
        password = request.form.get('password')
        try:
            pw = users[username]
        except:
            return '<script>alert("not found user");history.go(-1);</script>'
        if pw == password:
            resp = make_response(redirect(url_for('index')) )
            resp.set_cookie('username', username)
            return resp 
        return '<script>alert("wrong password");history.go(-1);</script>'

 

index를 구성하는 코드를 보면 username변수가 이용자의 요청에 포함되는 쿠키로 결정된다는 것을 알 수 있다. 이것은 이용자가 쿠키를 보내기에 이용자 뜻대로 조작할 수 있다는 것이다. 서버에서 검증없이 이용자의 요청과 쿠키를 신뢰하기에 공격자는 쿠키에 타 계정 정보를 삽입하여 계정을 탈취할 수 있다.

 

그럼 이 취약점을 이용해 admin 계정을 탈취해보자.

guest의 value 쿠키 값을 확인.

value값을 admin으로 변경 후 새로고침 하여 계정을 탈취했다. 

 

728x90

'Webhacking-Write-Up > Dreamhack' 카테고리의 다른 글

[Dreamhack] csrf-1  (0) 2023.01.09
[Dreamhack] XSS-2  (0) 2023.01.09
[Dreamhack] XSS-1  (0) 2023.01.09
[Dreamhack] Same Origin Policy (SOP)  (0) 2022.12.20
[Dreamhack] session-basic  (0) 2022.12.20