https://dreamhack.io/wargame/challenges/24
simple_sqli
로그인 서비스입니다. SQL INJECTION 취약점을 통해 플래그를 획득하세요. 플래그는 flag.txt, FLAG 변수에 있습니다. Reference Server-side Basic
dreamhack.io
문제 설명
로그인 서비스입니다.
SQL INJECTION 취약점을 통해 플래그를 획득하세요. 플래그는 flag.txt, FLAG 변수에 있습니다.
문제 풀이
기본적인 SQL Injection 문제이다.
어드민 계정으로 로그인을 우회하는 것이 첫 단계이다.

@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'GET':
return render_template('login.html')
else:
userid = request.form.get('userid')
userpassword = request.form.get('userpassword')
res = query_db(f'select * from users where userid="{userid}" and userpassword="{userpassword}"')
if res:
userid = res[0]
if userid == 'admin':
return f'hello {userid} flag is {FLAG}'
return f'<script>alert("hello {userid}");history.go(-1);</script>'
return '<script>alert("wrong");history.go(-1);</script>'
코드를 열어보면 userid를 admin인 것이 확인되어야 flag가 나온다는 것을 확인할 수 있다.
따라서 SQL문이 select * from user where userid='admin'에서 잘리도록 인풋값을 설정했다.
password 부분은 어차피 주석 처리되므로 아무 값이나 넣어준다.
admin" --
결과
flag가 잘 나온다.
'Security > War Games' 카테고리의 다른 글
[Dreamhack Lv.1] XSS-1 (0) | 2024.12.20 |
---|---|
[Dreamhack Lv.1] csrf-2 (0) | 2024.12.20 |
[Dreamhack Lv.1] csrf-1 (0) | 2024.12.20 |