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
- XSS
- Web
- hacking
- Webhaking
- WarGame
- 알고리즘
- 소프트웨어보안
- reversing
- network
- 소프트웨어
- 모의해킹
- 워게임
- 웹
- TCP
- 비박스
- 리버싱
- dreamhack
- 네트워크
- bee-box
- 드림핵
- 해킹
- 순서도
- 네트워크보안
- CodeEngn
- System
- 웹해킹
- 시스템
- 시스템해킹
- ftz
- webhacking
Archives
- Today
- Total
Without a Break
[Dreamhack] xss-1 본문
[문제 파일]
vuln()
@app.route("/vuln")
def vuln():
param = request.args.get("param", "")
return param
- 이용자가 요청한 param의 값을 리턴한다.
flag()
@app.route("/flag", methods=["GET", "POST"])
def flag():
if request.method == "GET":
return render_template("flag.html")
elif request.method == "POST":
param = request.form.get("param")
if not check_xss(param, {"name": "flag", "value": FLAG.strip()}):
return '<script>alert("wrong??");history.go(-1);</script>'
return '<script>alert("good");history.go(-1);</script>'
- GET method일 경우 flag.html 페이지를 렌더링한다.
- POST method일 경우 flag를 포함하고 있는 check_xss 함수를 실행한다.
check_xss
def check_xss(param, cookie={"name": "name", "value": "value"}):
url = f"http://127.0.0.1:8000/vuln?param={urllib.parse.quote(param)}"
return read_url(url, cookie)
- name(=flag)과 value를 인자로 받은 cookie를 생성하여 /vuln에 접속 요청을 보낸다.
memo()
@app.route("/memo")
def memo():
global memo_text
text = request.args.get("memo", "")
memo_text += text + "\n"
return render_template("memo.html", memo=memo_text)
- memo 파라미터에 입력한 값이 text 변수에 저장되고, 줄바꿈을 적용한 문자열이 memo_text에 저장되어 memo.html에 출력된다.
[페이지]
vuln(xss) page 페이지
vuln(xss) page에 들어가게 되면 위와 같이 팝업창에 1이 뜨게 된다.
xss 파라미터 값이 스크립트에 삽입되어 뜨는 것을 알 수 있다.
memo 페이지
memo 파라미터의 값을 저장한 변수인 memo_text가 출력된 모습을 볼 수 있다.
flag 페이지
xss 파라미터에 test 입력 후 제출 시, good이라는 팝업창이 뜬다.
[풀이]
요청 시에 flag()에서 check_xss() 함수를 호출할 때 플래그를 인자로 받은 쿠키 값을 보낸다는 것을 주목하여 문제를 해결한다.
쿠키 값에 있는 플래그를 memo 페이지에 출력을 해야 우리가 볼 수 있기 때문에 memo 페이지에 쿠키 값을 뜰 수 있도록 코드를 작성해 준다.
따라서, <script>location.href="/memo?memo="+document.cookie; 를 입력한다. 입력 후에는 아까와 마찬가지로 팝업창에 good이 뜨게 된다.
memo 페이지로 이동하면
위와 같이 플래그가 뜨게 된다.
답 : DH{2c01577e9542ec24d68ba0ffb846508e}
'Web > Wargame' 카테고리의 다른 글
[Dreamhack] ClientSide: CSRF (0) | 2022.09.21 |
---|---|
[Dreamhack] xss-2 (0) | 2022.09.21 |
[Dreamhack] ClientSide: XSS (0) | 2022.09.19 |
[Dreamhack] Cookie (0) | 2022.09.17 |
[Dreamhack] session-basic (0) | 2022.09.17 |