https://dreamhack.io/wargame/challenges/24
simple_sqli
로그인 서비스입니다. SQL INJECTION 취약점을 통해 플래그를 획득하세요. 플래그는 flag.txt, FLAG 변수에 있습니다. Reference Server-side Basic
dreamhack.io
정말 심플하게 로그인 창만 구현되어 있다.
코드를 보자
@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>'
1. GET 방식일 땐 login.html 반환
2. 입력 받은 userid, userpassword가 데이터베이스에 존재하는지 확인
3. userid가 admin인 경우 플래그 출력
userid, userpassword를 검사하는 과정이 없기 때문에 임의의 쿼리문을 입력할 수 있다.
userid에 admin"--을 입력하고 password엔 아무거나 써서 제출해 보면
이렇게 바로 플래그가 뜬다.
sqli 문제를 풀 땐 코드에서 큰 따옴표를 쓰는지, 작은 따옴표를 쓰는지 꼼꼼하게 확인하는 게 좋을 것 같다.
'드림핵 워게임' 카테고리의 다른 글
[드림핵/워게임] Carve Party (0) | 2023.08.03 |
---|---|
[드림핵/워게임] command-injection-1 (0) | 2023.08.03 |
[드림핵/워게임] basic_exploitation_001 (0) | 2023.07.30 |
[드림핵/워게임] basic_exploitation_000 (0) | 2023.07.30 |
[드림핵/워게임] Return Address Overwrite (0) | 2023.07.30 |