Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- CodeEngn
- 순서도
- 모의해킹
- webhacking
- 소프트웨어
- network
- 시스템
- 해킹
- WarGame
- ftz
- 알고리즘
- 시스템해킹
- 리버싱
- Web
- reversing
- 드림핵
- 비박스
- 네트워크
- 워게임
- System
- 웹해킹
- 소프트웨어보안
- XSS
- hacking
- TCP
- Webhaking
- dreamhack
- 웹
- 네트워크보안
- bee-box
Archives
- Today
- Total
Without a Break
[Dreamhack] simple_sqli 본문
[문제 파일]
데이터베이스
DATABASE = "database.db"
if os.path.exists(DATABASE) == False:
db = sqlite3.connect(DATABASE)
db.execute('create table users(userid char(100), userpassword char(100));')
db.execute(f'insert into users(userid, userpassword) values ("guest", "guest"), ("admin", "{binascii.hexlify(os.urandom(16)).decode("utf8")}");')
db.commit()
db.close()
- 데이터베이스 파일이 존재하지 않는 경우 파일을 생성하고 연결한다.
- 유저 테이블을 설정한다. => db.execute(~)를 보아 아이디랑 비밀번호를 저장하는 테이블임을 알 수 있다.
- guest와 admin 계정이 존재함을 알 수 있다.
login()
@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>'
- GET method를 요청받은 경우, login.html 페이지를 보여준다.
- POST method(elif)를 요청받은 경우, 이용자가 입력한 아이디와 패스워드를 userid, userpassword 변수에 각각 저장한다.
- res(result) 변수에는 users 테이블에서 userid와 userpassword가 일치하는 모든 정보를 저장한다.
- userid가 admin일 경우 플래그를 출력한다.
[풀이]
로그인 페이지에서 우리가 아이디를 입력하면 "SELECT * FROM users WHERE userid="~"" 빨간색 물결 부분에 삽입이 된다.
userid가 admin일 경우 플래그가 출력되기 때문에
다음과 같이 입력하면 userid에는 admin이 입력되고, --를 통해 뒷부분은 주석처리가 된다.
패스워드는 내가 설정한 패스워드로 입력을 하고 로그인을 해주면
플래그가 출력된다.
답 : DH{1f136225e316add7bff3349ab1dd5400}
'Web > Wargame' 카테고리의 다른 글
[Dreamhack] command-injection-1 (0) | 2022.10.05 |
---|---|
[Dreamhack] Mango (0) | 2022.10.01 |
[Dreamhack] SQL Injection (0) | 2022.09.24 |
[Dreamhack] csrf-2 (0) | 2022.09.24 |
[Dreamhack] csrf-1 (0) | 2022.09.24 |