IT/Secure Coding

Open Redirect

바바옄 2015. 4. 23. 15:49
반응형

중간에 URL을 catch해서 자신이 원하는 url로 값을 변경할 수 있다.

 

이를 막기 위한 방법

whiteList를 이용해서 url을 숨겨준다.

OpenRedirectController 수정

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package kr.co.hucloud.security.code.example.attack.openredirect;
 
import java.util.HashMap;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
 
@Controller
public class OpenRedirectController {
 
    @RequestMapping("/attack/openredirect")
    public String openRedirect(HttpServletResponse response) {
        return "attack/openredirect/openredirect";
    }
    
    @RequestMapping("/attack/openredirect/url")
    public ModelAndView redirect(HttpServletRequest request, HttpServletResponse response) {
        
        //FIXME Paros / WireShark / Internet Explorer 에서 변조 가능.
        // Redirect 값은 모두 상수로 변환하고
        // 서버에서 허용하는 URL값을 가지고 있어야 한다.
        String url = request.getParameter("redirectURL");
        
        /* 
         * whiteList
         * 내가 사용할 것만 적어서 해킹을 방지한다
         * 내가 실행된 파일명을 외부로 보여주지 말자.
         */
        Map<StringString> whiteList = new HashMap<StringString>();
        whiteList.put("1""http://www.naver.com");
        whiteList.put("2""http://www.daum.net");
        whiteList.put("3""http://www.google.com");
        
        if(StringUtils.isEmpty(url)) {
            url = "";
        }
        // whiteList에 있는 key와 같은 값이 있으면 value(주소)를 받아와서 넘겨준다.
        else if(whiteList.containsKey(url)){
            return new ModelAndView("redirect:" + whiteList.get(url));
        }
        // whiteList에 있는 key와 같은 값이 없으면 현재 페이지 redirect
        return new ModelAndView("redirect:");
    }
    
}
 
 
 
cs

 

openredirect.jsp 수정

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c"   uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${initParam.TITLE}</title>
<link rel="stylesheet" href="/HuCloud/resources/css/menu.css" />
<link rel="stylesheet" href="/HuCloud/resources/css/common.css" />
<script type="text/javascript" src="/HuCloud/resources/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/HuCloud/resources/js/menu.js"></script>
<script type="text/javascript" src="/HuCloud/resources/js/tip.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    
});
    
</script>
</head>
<body>
<c:import url="/common/loginTop" />
<div class="wrapper">
    <div class="vNav" style="float:left;">
        <ul>
            <li class="openRedirect">Open Redirect</li>
        </ul>
    </div>
    <div class="w-spacer"> </div>
    <div class="content" style="float:left;">
        <form name="redirectURLForm" id="redirectURLForm" method="post" action="<c:url value='/attack/openredirect/url' />">
            <select    id="redirectURL" name="redirectURL" class="tip" data-tip="아래 선택된 URL 들은 모두 주소값을 Value로 가진다. paros, WireShark 등을 통해 전달되는 파라미터가 변경될 수 있다.">
                <!-- value에 있는 주소(www.naver.com..)를 사용자가 알 수 없는 번호로 바꿔 준다. -->
                <option value="1">Naver</option>
                <option value="2">DAUM</option>
                <option value="3">Google</option>
            </select>
            <input type="submit" value="Redirect" />
        </form>
    </div>
    <div class="clear"></div>
</div>
<c:import url="/common/bottom" />
</body>
</html>
cs
반응형

'IT > Secure Coding' 카테고리의 다른 글

잘못된 접근 제한(사용자의 행동 기록)  (0) 2015.04.24
로그인 제한  (0) 2015.04.24
Encrypt Password  (0) 2015.04.23
File Upload, File DownLoad  (0) 2015.04.23
XSS  (0) 2015.04.23