웹어플리케이션보안템플릿 -...

86
2006. 6 웹 어플리케이션 보안 템플릿

Transcript of 웹어플리케이션보안템플릿 -...

Page 1: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

2006.6

웹 어플리케이션 보안 템플릿

Page 2: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

본 템플릿은 최근 해킹에 주로 이용되고 있는 주요 웹 보안 취약점을 개발단계

에서부터 보완하기 위한 목적으로 한국정보보호진흥원 인터넷침해사고 응지원센터

해킹 응팀 연구원들과 국내 웹 보안 및 웹 어플리케이션 전문가들의 참여와 자문을

통해 제작되었습니다. 웹 개발자들이 보안을 고려한 웹 프로그램 제작에 활용

하시기 바랍니다.

2006년 6월

사업 책임자 : 본 부 장 김우한

연구 책임자 : 팀 장 성재모

참여 연구원 : 수석연구원 정현철

연 구 원 한단송

외부 전문가 : KCC시큐리티 가성호

프로그램 감수 : 패닉시큐리티 양정규

패닉시큐리티 윤달형

나우콤 김 호

Page 3: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

본 템플릿에서는 SQL Injection 취약점, 업로드 취약점, 다운로드 취약점,

Cross Site Script(XSS) 취약점, 접근통제 취약점 등 해킹에 가장 많이 이용되고

있는5가지웹보안취약점에 해안전한웹프로그래밍을위한템플릿을제공하고

있다.

각각의취약점에 한 간단한 설명과 해당 취약점으로 인해발생될수있는

해킹사례를소개하고, ASP, PHP, JSP 등 3가지웹개발언어별로 해당 취약점에

한 공격을 차단할 수 있는 보안 템플릿을 제공한다.

각기관에서 사용하는 웹 개발 언어의 보안 템플릿을 선택하여 웹 프로그램

개발시 또는 기존의 웹 프로그램의 수정시 적용시키기 바란다.

개발언어별 보안 템플릿은 가급적 일반적인 웹 개발 환경에서 적용 가능

하도록 작성하기 위해 노력하 다. 하지만, 각 기관의 웹 개발 환경 및 서비스가

매우 다양하므로, 정상적이 서비스에 지장이 없도록 충분한 최적화 작업 및

테스트 하기를 바란다.

Page 4: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

제 1장 SQL Injection 보안 템플릿…………………………………………… 1

제 2장 업로드 보안 템플릿 ………………………………………………… 27

제 3장 다운로드 보안 템플릿 ……………………………………………… 43

제 4장 Cross Site Script (XSS) 보안 템플릿 …………………………… 53

제 5장 접근통제 보안 템플릿………………………………………………… 69

참고문헌 ………………………………………………………………………… 80

Contents

Page 5: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Page 6: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

....................................................................................................................................................................................................................................................................................................................................................................................................................................

................................................................................................................................................................................................................

................................................................................................................................................................................................................

..............................................................................................................................................................................................................

.......................................................................................................

.......................................................................................................................................................................................................................................................................................................................

.........................................................................................................

.........................................................................................................

..................................................................................................................................................................................................................

..............................................................................................................................................................................................................

................................................................................................................................................................................................................

.....................................................................................................................................................................................................................................................................................................................

.......................................................................................................

...........................................................................................................................................................................................................................................................................................................................

..................................................................................................................................................................................................................

.......................................................................................................................................................................................................................................................................................................................

.......................................................................................................

..............................................................................................................................................................................................................

.......................................................................................................................................................................................................................................................................................................................

.........................................................................................................

SQL Injection 보안 템플릿

Page 7: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

2│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

SQL Injection이란?

SQL Injection은 정상적인 SQL 질의문을 변조하여 불법 로그인, DB 데이터 열람, 시스템 명령 실행

등을수행하는공격이다.

이 공격은 사용자 입력값 또는 URL 파라미터 값에 한 적절한 검증작업이 이루어지지 않아

발생된다.

사 례

1. 사용자인증을비정상적으로통과한사례

위의 그림에서 공격자는 신청인의 인터넷 접수번호를 알지 못하더라도 A’or ‘A’=’A 라는 악의적인

값을입력함으로써 로그인이가능하다.

이경우구문의WHERE 절은“True AND False OR True”로전체구문이“True”가되어사용자인증

모듈을우회하여로그인이가능하게된다.이는웹프로그램이사용자입력값을적절하게검증하지않

아발생한것이다.

제1장 SQL Injection 보안템플릿

SELECT 신청인명, 접수번호FROM user_table WHERE 신청인명=‘test’AND 접수번호=‘A’OR ‘A’=‘A’

<그림 1-1> 사용자인증 우회

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

Page 8: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │3

웹어플리케이션보안템플릿제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

제1장

SQ

L In

jectio

n 보

안템

플릿

2. URL 파라미터입력값의조작을통한공격사례

웹사이트의공지사항이나게시판등은게시 의번호를입력값으로받아해당게시 을DB에서찾

아 화면에 보여준다. 하지만 공격자는 게시 번호 입력 항목에 비정상적인 SQL 구문을 입력함으로

써, DB가해당SQL문을실행하게하여DB 조회및임의의명령실행이가능하다.

최근 중국발 해킹사고에서 이와 같은 방법을 주로 사용하고 있으며, 아래와 같은 자동화된 공격 툴

을이용하여다수의웹사이트들을공격하고있다.

위 그림은 공지사항의 게시 번호를 입력으로 받는“id”라는 파라미터가 입력값을 검증하지 않아,

SQL Injection 공격툴에의해관리자아이디와패스워드가노출되는것을볼수있다.

<그림 1-2> SQL Injection 공격 툴을 사용한 사례

웹어플리케이션보안템플릿

Page 9: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

4│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

각 언어별 보안 템플릿

1. 사용자인증을비정상적으로통과한경우

기존의 로그인 인증 방식은 아이디, 패스워드를 입력받아 해당 값들을 WHERE절 구문에 사용

하여 구문의 참/거짓으로 인증 확인을 수행한다. 이러한 방법을 사용할 경우 SQL Injection 공

격으로 인증을 우회할 수 있는 취약점이 존재한다. 이를 보완하기 위해서 기존의 처리 방식에

서 WHERE절에 아이디로 질의를 실행한 후 나온 질의 결과 패스워드를 입력된 패스워드와 비

교하여 구문의 결과와 입력 결과를 재확인하는 방식으로 작성하는 것이 바람직하다.

Page 10: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │5

제1장

웹어플리케이션보안템플릿

/login.asp

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

SQ

L In

jectio

n 보

안템

플릿

<!--#include virtual="/include/connection.inc.asp"--><% 'DB연결 헤더 %>

<!--#include virtual="/include/secure.inc.asp"--> <% '보안관련라이브러리 %>

<!--#include virtual="/include/config.inc.asp"--> <% '전역변수리스트 %>

<!--#include virtual="/head.asp"--><% '초기 설정 페이지(에러 메시지 미출력) %>

<%

' 사용되는 ID 값은 유일해야 한다.

' ID에 한 PW값을 가져와서 입력된 패스워드와 비교하는 방식으로 기존의 로그인 방식은 ID, PW를 모두

확인하는 방식으로 WHERE 구문의 조작으로 루틴을 우회할 수 있으나 해당 방식은 인젝션이 성공한다 하

더라도 임의의 인젝션된 값과 입력된 값을 비교하게 되어 공격의 성공율을 낮출 수 있다.

Dim strQuery, strSQL

Dim strID, strPW

strID = sqlFilter(Request("Name"))

strPW = sqlFilter(Request("Password"))

' 입력값 NULL 체크

If Len(strID) = 0 OR Len(strPW) = 0 then

'입력값 체크 실패

'Response.Write "입력 오류"

Else

'입력되는 ID값의 존재여부 파악

strSQL = "SELECT count(*) FROM userinfo WHERE strID = '" & strID & "'"

objRs.Open strSQL, objDBConn

'유일하게 존재하는 경우

If objRs(0) = 1 Then

objRs.close

'접근 ID와 일치하는 패스워드값을 SELECT 함으로써 SQL 구문으로 인증 체크를

하지 않도록 한다.

'오류를 이용한 SQL Injection 기법에는 기존의 SQL Injection 필터링 방법으로 통제

한다.

strSQL = "SELECT strPassword,strName FROM userinfo WHERE strID = '" & strID

& "'"

objRs.Open strSQL, objDBConn

<ASP 보안 템플릿>

Page 11: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

6│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

�'SELECT된 패스워드와 입력 패스워드 비교

If StrComp(trim(objRs(0)),strPW) = 0 Then

'로그인 성공 후 프로세스 작성

Response.Write objRs(1) & " Login OK"

Else

'입력된 패스워드와 SELECT한 패스워드가 다를 경우 로그인 실패

Response.Write strID & " Login Failed"

End If

End If

'ID가 복수개 또는 없을 경우 로그인 실패

Response.Write strID & " Login Failed"

objRs.Close

End If

%>

<HTML>

<HEAD>

<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">

</HEAD>

<BODY>

<H3><P>텍스트 상자 정보 입력하기</P></H3>

<form action="login.asp" name=postform method=post>

<table border=0>

<tr>

<td>아이디 : </td>

<td><input type=text name=Name size=20 value=""></td>

</tr>

<tr>

<td>패스워드 : </td>

<td><input type=password name=Password size=20 value=""></td>

</tr>

<tr>

<td colspan= 2 align=center><input type="submit" value= "로그인" id=submit1 name=submit1>

<input type="reset" value="취소하기" id=reset name=reset></td>

</tr>

</table>

</form>

</BODY>

</HTML>

Page 12: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │7

제1장

웹어플리케이션보안템플릿

/login.html

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

SQ

L In

jectio

n 보

안템

플릿

<HTML>

<HEAD>

<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">

</HEAD>

<BODY>

<H3><P>로그인</P></H3>

<form action="login.php" name=postform method=post>

<table border=0>

<tr>

<td>아이디 : </td>

<td><input type=text name=user_id size=20 value=""></td>

</tr>

<tr>

<td>패스워드 : </td>

<td><input type=password name=user_pw size=20 value=""></td>

</tr>

<tr>

<td colspan= 2 align=center><input type="submit" value= "로그인" id=submit1 name=submit1>

<input type="reset" value="취소하기" id=reset name=reset></td>

</tr>

</table>

</form>

</BODY>

</HTML>

<PHP 보안 템플릿>

Page 13: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

8│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

/login.php�

<?

require "include/connect.inc.php"; //DB 연결 헤더

require "include/config.inc.php"; //전역 변수 리스트

require "include/secure.inc.php"; //보안 라이브러리

require "include/lib.php"; //게시판 라이브러리

?>

<?

$connect=db_connect();

$mb_table = "userinfo";

$user_id = sqlfilter($user_id);

$user_pw = sqlfilter($user_pw);

if(trim($user_id)=="") print ("아이디를 입력하여 주십시요");

if(trim($user_pw)=="") print ("비 번호를 입력하여 주십시요");

// 회원 로그인 체크

$result = mysql_query("select id,user_id,password from $mb_table where user_id='$user_id'");

if ($mb_data = mysql_fetch_array($result)) {

if($mb_data[password] == $user_pw) {

// 회원로그인이 성공하 을 경우 세션을 생성하고 페이지를 이동함

//로그인 후 프로세스

print ("로그인 성공");

exit;

}

else {

// 회원로그인이 실패하 을 경우 에러 표시

print ("로그인 실패");

exit;

}

}

else {

print ("로그인 실패");

}

db_close($connect);

?>

Page 14: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │9

제1장

웹어플리케이션보안템플릿

/ login.html

/login.jsp

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

SQ

L In

jectio

n 보

안템

플릿

<HTML>

<HEAD>

<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">

</HEAD>

<BODY>

<H3><P>텍스트 상자 정보 입력하기</P></H3>

<form action="login.jsp" name=postform method=post>

<table border=0>

<tr>

<td>아이디 : </td>

<td><input type=text name=id size=20 value=""></td>

</tr>

<tr>

<td>패스워드 : </td>

<td><input type=password name=pw size=20 value=""></td>

</tr>

<tr>

<td colspan= 2 align=center><input type="submit" value= "로그인" id=submit1 name=submit1>

<input type="reset" value="취소하기" id=reset name=reset></td>

</tr>

</table>

</form>

</BODY>

</HTML>

<%@ page language="java" import="java.sql.*,java.util.*" contentType="text/html;charset=KSC5601" %>

<%@ include file="connection.inc.jsp" %>

<%@ include file="config.inc.jsp" %>

<%@ include file="secure.inc.jsp" %>

<%

String s_tablename = "user"; // 테이블 이름

<JSP 보안 템플릿>

Page 15: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

10│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

�String s_id, s_pw, s_name; //SQL 구문 실행 결과값 저장String g_id, g_pw; //입력값 저장String s_sql;

g_id = sqlFilter(request.getParameter("id"));g_pw = sqlFilter(request.getParameter("pw"));

try {//사용자 ID만으로 엔트리를 가져옴s_sql = "SELECT id,pw,name FROM " + s_tablename + " WHERE id='" + g_id + "'";

rs = stmt.executeQuery(s_sql); // 쿼리문 실행 결과 값을 담을 객체

if (rs.next()) {s_id = rs.getString(1);s_pw = rs.getString(2);s_name = rs.getString(3);

//DB에서 가져온 사용자 패스워드와 입력한 패스워드를 비교if (s_pw == g_pw) {

//로그인 후 처리 프로세스out.println("로그인 성공");

}else {

//로그인 실패 시 처리 프로세스out.println("로그인 실패:패스워드 오류");

}}else {

//로그인 실패 시 처리 프로세스//에러메시지를 출력하지 않기 위해 제거하는 편이 바람직함 - out.println("로그인 실

패: 사용자 없음");}

//DB 처리

stmt.close(); // 인클루드 파일(db_conn. jsp)에서 생성한 stmt 닫기

Conn.close(); // 인클루드 파일(db_conn.jsp)에서 생성한 Conn 닫기

} catch (Exception e) {

out.println(e);

}

%>

Page 16: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │11

제1장

웹어플리케이션보안템플릿

2. URL 파라미터입력값을조작한경우

각 언어별 보안 템플릿은 크게 위험성이 존재하는 문자(혹은 문자열)에 한 필터링, 입력값

을 사용하는데 있어 데이터 타입의 확인 방법, 공격 코드로 유출될 수 있는 문자(혹은 문자열)

에 한 필터링 항목으로 구성되어 있다.

/include/secure.inc.asp : SQL Injection 필터링 함수

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

SQ

L In

jectio

n 보

안템

플릿

<%

'공격 위험성이 존재하는 문자들을 필터링

'문자열 입력시에만 사용

Function sqlFilter(search)

Dim strSearch(5), strReplace(5), cnt, data

'SQL Injection 특수문자 필터링

'필수 필터링 문자 리스트

strSearch(0)="'"

strSearch(1)=""""

strSearch(2)="\"

strSearch(3)=null

strSearch(4)="#"

strSearch(5)="--"

strSearch(6)=";"

'변환될 필터 문자

strReplace(0)="''"

strReplace(1)=""""""

strReplace(2)="\\"

strReplace(3)="\"&null

strReplace(4)="\#"

strSearch(5)="\--"

strSearch(6)="\;"

<ASP 보안 템플릿>

Page 17: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

12│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

/head.asp : 오류 메시지 제거

에러 메시지를 출력하지 않기 위해 각 페이지 처음 부분에 사용한다.

/content.asp : 인덱스 번호를 입력받아 게시물을 표시

하단의 웹페이지는 게시물 번호(no) 값을 받아 SQL 구문에 입하여 게시물을 출력하는 웹페

이지의 일부이다.

이 중 sqlFilter 함수를 이용하여 페이지 시작부분에서 문자를 필터링하고 있으며 SQL 구문 수행시

발생할 수 있는 오류 메시지를 출력하지 않아 최 한 정보를 노출하지 않도록 하고 있다.

�data = search

For cnt = 0 to 6 '필터링 인덱스를 배열 크기와 맞춰준다.

data = replace(data, LCASE(strSearch(cnt)), strReplace(cnt))

Next

sqlFilter = data

End Function

%>

<%

'페이지에서 에러가 발생하여도 페이지 오류를 외부로 출력하지 않기위해 사용

On Error Resume Next

'On Error GoTo 0도 가능하나 2003에서는 실행되지 않음

if err.number <> 0 then

'Response.Write err.description & "<BR>" & err.source & "<BR>"

err.clear

End if

%>

<!--#include virtual="/include/connection.inc.asp"--> <% 'DB연결 헤더 %>

<!--#include virtual="/include/secure.inc.asp"--> <% '보안관련라이브러리 %>

<!--#include virtual="/include/config.inc.asp"--> <% '전역변수리스트 %>

<!--#include virtual="/head.asp"--> <% '초기 설정 페이지(에러 메시지 미출력) %>

<%

Dim strSQL

Dim intSeq, strName, strEmail, strSubject, strContent, intCount, dtmReg_Date, intExist

Dim blnTag, strUserIP

Page 18: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │13

제1장

웹어플리케이션보안템플릿제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

SQ

L In

jectio

n 보

안템

플릿

Dim atag

'입력값이 숫자형인 경우 IsNumeric 함수를 사용한다.

If IsNumeric(seq) Then

intSeq = Request.QueryString("seq")

Else

Response.Write "허용하지 않는 입력값입니다."

Reponse.End

End If

'문자(열)인 경우sqlFilter 사용

'intSeq = sqlFilter(Request.QueryString("seq")) 'SQL Injection 필터링

'읽은 횟수 검색

strSQL = "SELECT count(*) FROM board WHERE intSeq='" & intSeq & "'"

objRs.Open strSQL, objDBConn

intExist = objRs(0)

objRs.Close

If intExist <> 1 Then

Response.Write "해당 이 없습니다."

Else

'읽은 횟수 증가

strSQL = "UPDATE board SET intCount=intCount+1 WHERE intSeq='" & intSeq & "'"

objRs.Open strSQL, objDBConn

'게시물 SELECTZ

strSQL = "SELECT

strName,strEmail,strSubject,strContent,intCount,strUserIP,blnTag,dtmReg_Date FROM board WHERE

intSeq='" & intSeq & "'"

objRs.Open strSQL, objDBConn

strName = objRs(0)

strEmail = objRs(1)

Page 19: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

14│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

�strSubject = objRs(2)

strContent = objRs(3)

intCount = objRs(4)

strUserIP = objRs(5)

blnTag = objRs(6)

dtmReg_Date = objRs(7)

objRs.Close

Set objRs = Nothing

objDBConn.Close

Set objDBConn = Nothing

'게시물 출력값에 XSS 필터링

'사용자가 입력하는 출력되는 값은 strName, strEmail, strSubject, strContent으로 이 부분은

XSS 공격이 가능한 부분들이다.

'일반적으로 본문만 선택적으로 HTML 태그 사용을 허용하며 나머지 부분들은 사용할 수 없도록

하는것이 바람직하다.

strName = clearXSS(strName, atag)

strEmail = clearXSS(strEmail, atag)

strSubject = clearXSS(strSubject, atag)

strContent = clearXSS(strContent, atag)

'줄넘김 처리

strContent = replace(strContent, vbLf, vbLf & "<br>")

%>

<html>

<head>

<meta name="GENERATOR" content="Microsoft FrontPage 5.0">

<meta name="ProgId" content="FrontPage.Editor.Document">

<meta http-equiv="Content-Type" content="text/html; charset=ks_c_5601-1987">

<title>내용보기</title>

</head>

<body>

Page 20: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │15

제1장

웹어플리케이션보안템플릿제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

SQ

L In

jectio

n 보

안템

플릿

<div align=center>

<table border=1>

<tr>

<td>이름</td>

<td><%=strName%></td>

<td>등록일</td>

<td><%=dtmReg_Date%></td>

</tr>

<tr>

<td>이메일</td>

<td><%=strEmail%></td>

<td>조회</td>

<td><%=intCount%></td>

</tr>

<tr>

<td>제목</td>

<td colspan=3><%=strSubject%></td>

</tr>

<tr>

<td>내용</td>

<td colspan=3><%=strContent%></td>

</tr>

<tr>

<td colspan=4>

<a href="list.asp">목록으로</a> <a href="edit.asp?seq=<%=intSeq%>">수정하기</a> <a

href="delete.asp?seq=<%=intSeq%>">삭제하기</a>

</td>

</tr>

</table>

</div>

</body>

</html>

<%

End If

%>

Page 21: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

16│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

/include/secure.inc.php : SQL Injection 필터링 함수

/view.php : 인덱스 번호를 입력받아 게시물을 표시

<?

//SQL 입력값 문자열 필터

//$str = 입력 문자열

function sqlfilter($str) {

//1단계 ? ',",NULL 문자 필터링. 각 문자들에 백슬래쉬(\) 삽입됨. 필수 항목

//출력시 stripslashes()함수를 이용하여 백슬래쉬(\)를 제거

if (!get_magic_quotes_gpc()) $str = addslashes($str);

//3단계 ? 특수 문자 및 문자열 필터링

//WHERE 구문에서 쓰여지는 데이터만 사용하는 것이 바람직하다.

$search = array("--","#",";");

$replace = array("\--","\#","\;");

$str = str_replace($search, $replace, $str);

return $str;

}

?>

<?

require "include/connect.inc.php"; //DB 연결 헤더

require "include/config.inc.php"; //전역 변수 리스트

require "include/secure.inc.php"; //보안 라이브러리

require "include/lib.php"; //게시판 라이브러리

?>

<?

if (is_numeric($no)) {

$no = ($_REQUEST[no]); // SQL Injection 필터

<PHP 보안 템플릿>

Page 22: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │17

제1장

웹어플리케이션보안템플릿제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

SQ

L In

jectio

n 보

안템

플릿

}

else {

echo "허용하지 않는 입력값";

exit;

}

$board = sqlfilter($_REQUEST[board]); // SQL Injection 필터

//읽기 횟수 저장

$updok = mysql_query("UPDATE $board SET hit = hit + 1 WHERE no=$no", $connect);

$query = sprintf("SELECT * FROM %s WHERE no='%d'",$board,$no);

$result = mysql_query($query);

$view = @mysql_fetch_array($result); //@를 이용하여 에러 메세지 출력을 하지 않는다.

//XSS 필터링

$view[usrname] = clearxss($view[usrname],$avatag);

$view[usremail] = clearxss($view[usremail],$avatag);

$view[usrtitle] = clearxss($view[usrtitle],$avatag);

$view[contents] = clearxss($view[contents],$avatag);

$dates = date ("Y-m-d, h:i:s", $view[filluptime]);

$perpage = 10;

$tlpn = get_pagenum();

$nowpage = get_page($view[idx]);

if ($view[usremail] != "") {

$name = "<a href=\"mailto:$view[usremail]\">$view[usrname]</a>";

}

else {

$name = "$view[usrname]";

}

if ($view[usrhomepage] != "") {

$homeurl = "<a href=\"$view[usrhomepage]\" target=\"_blank\">[Homepage]</a>";

Page 23: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

18│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

�}

else {

$homeurl = "";

}

echo "

<html>

<head>

<title> 내용 보기</title>

</head>

<body>

<center>

<table width=\"550\" cellspacing=\"1\"

border=\"0\" cellpadding=\"2\">

<tr>

<td align=\"left\"><font size=\"2\"><b>|<a href=\"list.php?board=$board&page=$nowpage\">게시물 목

록 </a>|<a href=\"edit.php?board=$board&no=$no\">수 정 </a>|<a

href=\"delete.php?board=$board&no=$no\">삭제</a>|</b></font></td>

</tr>

</table>

<table width=\"550\" cellspacing=\"1\" border=\"0\" cellpadding=\"2\">

<tr>

<td colspan=\"2\" bgcolor=\"#A5A595\"><font color=\"white\" size=\"2\">$view[num] 번 :

<b>$view[usrtitle]</b></font></td>

</tr>

<tr>

<td align=\"left\" bgcolor=\"#E5E5D5\"><font size=\"2\">조회수: $view[hit]</font></td>

<td align=\"right\" bgcolor=\"#E5E5D5\"><font size=\"2\">$name 님이 $homeurl $dates 에 작성해주셨습

니다.</font></td></tr>

</table>";

Page 24: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │19

제1장

웹어플리케이션보안템플릿제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

SQ

L In

jectio

n 보

안템

플릿

if ($view[filesize] > 0) {

$view[contents] .= "<p align=\"right\">";

$view[contents] .= "<a href=\"dn.php?board=$board&no=$view[no]\">";

$view[contents] .= $view[filename];

$view[contents] .= "</a>";

}

echo "

<table width=\"550\" cellspacing=\"1\" border=\"0\" cellpadding=\"2\">

<tr>

<td><font size=\"2\">$view[contents]</font>

</td>

</tr>

</table>

<table width=\"550\" cellspacing=\"1\" border=\"0\" cellpadding=\"2\">

<tr>

<td align=\"right\"><font size=\"2\"><b>|<a href=\"list.php?board=$board&page=$nowpage\">게시물 목

록</a>|<a href=\"edit.php?board=$board&no=$no\">수정</a>|<a

href=\"delete.php?board=$board&no=$no\">삭제</a>|</b></font></td>

</tr>

</table>

</center>

</body>

</html>

";

?>

Page 25: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

20│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

JSP의 경우 별도의 라이브러리로 작성하려면 클래스를 생성해야 하므로 코드 내에서 할 수 있는

방법을 기술한다. JSP의 경우 에러 노출을 막기 위한 특별한 방법은 찾을 수 없었으나

PreparedStatement 방식이나 클래스 함수 중 형 검사를 할 수 있는 방법이 존재하므로 고려하

도록 한다.

/secure.inc.jsp : SQL Injection 필터링 함수

gFilter : SQL 구문중 SELECT 구문에서 입력값을 필터링 할 때 사용

pFilter : SQL 구문중 INSERT/UPDATE 구문에서 입력값을 필터링 할 때 사용

사용예)

/view.jsp : 인덱스 번호를 입력받아 게시물을 표시

<%!

//공격 위험성이 존재하는 문자들을 필터링

//입력값: SQL 입력값

String sqlFilter(String str) {

str = str.replaceAll("'","''");

str = str.replaceAll("\"","\"\"");

str = str.replaceAll("\\","\\\\");

str = str.replaceAll(";","");

str = str.replaceAll("#","");

str = str.replaceAll("--","");

str = str.replaceAll(" ","");

return (str);

}

<!--

www.itmembers.net의 JSP게시판 만들기 강좌에서 손병목님이 작성하신 view.jsp파일을 strip Tokonizer

사용을 위해 인용하 습니다.

-->

<%@ page language="java" import="java.sql.*,java.util.*" contentType="text/html;charset=KSC5601" %>

<%@ include file="connection.inc.jsp" %>

<JSP 보안 템플릿>

Page 26: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │21

제1장

웹어플리케이션보안템플릿제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

SQ

L In

jectio

n 보

안템

플릿

<%@ include file="config.inc.jsp" %>

<%@ include file="secure.inc.jsp" %>

<%

String s_tablename = "bbs"; // 테이블 이름

String s_sql, s_number, s_name="", s_email="", s_homepage="", s_subject="", s_memo="" ;

String s_mail_addr="";

String s_page ;

int i_number, i_count=0, i_page ;

StringTokenizer st = null; // <br> 처리를 위해서

String s_temp = "";

s_number = request.getParameter("number"); // view.jsp?number=10 과 같이 넘어온 값 "10"을 받음.

try {

i_number = Integer.parseInt(s_number); //Integer형인 경우 숫자형으로 형 변환

//i_number = Long.parseLong(s_number); //Long형인 경우 Long

} catch (Exception e) {

stmt.close();

Conn.close();

return;

//out.println(e);}

s_page = request.getParameter("page"); // view.jsp?page=3 과 같이 넘어온 값 "3"을 넘겨받음.

try {

if(s_page==null) s_page="1";

i_page = Integer.parseInt(s_page);

} catch (Exception e) {

stmt.close();

Conn.close();

return;

//out.println(e);

}

//s_number = sqlFilter(s_number); //SQL Injection 필터

//s_page = sqlFilter(s_page); //SQL Injection 필터

Page 27: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

22│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

try {

s_sql = "select name,count,email,homepage,subject,memo from "+s_tablename+" where

number='"+s_number+"'";

rs = stmt.executeQuery(s_sql); // 쿼리문 실행 결과 값을 담을 객체

if(rs.next()) {

//XSS 필터

s_name = clearXSS(rs.getString(1),avatag);

i_count = rs.getInt(2);

s_email = clearXSS(rs.getString(3),avatag);

s_homepage = clearXSS(rs.getString(4),avatag);

s_subject = clearXSS(rs.getString(5),avatag);

s_memo = clearXSS(rs.getString(6),avatag);

}

if(!s_email.equals("")) {

s_mail_addr="<a href=mailto:"+s_email+">"+s_email+"</a>";

} else {

s_mail_addr=s_email;

}

// Enter를 <br>로 처리

st = new StringTokenizer(s_memo,"\n");

while(st.hasMoreTokens()) {

s_temp = s_temp + st.nextToken()+"<br>";

}

s_memo = s_temp;

s_sql = "update "+s_tablename+" set count = count + 1 where number = "+s_number;

stmt.executeUpdate(s_sql);

stmt.close(); // 인클루드 파일(db_conn.jsp)에서 생성한 stmt 닫기

Page 28: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │23

제1장

웹어플리케이션보안템플릿제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

SQ

L In

jectio

n 보

안템

플릿

Conn.close(); // 인클루드 파일(db_conn.jsp)에서 생성한 Conn 닫기

} catch (Exception e) {

//out.println(e);

}

%>

<html>

<head>

<title>JSP 게시판 프로젝트 - 보기</title>

<STYLE TYPE="text/css">

BODY,TD,SELECT,input,DIV,form,TEXTAREA,center,option,pre,blockquote {font-family:굴림font-

size:9pt;color:#555555;}

A:link {color:black;text-decoration:none;}

A:visited {color:black;text-decoration:none;}

A:active {color:black;text-decoration:none;}

A:hover {color:gray;text-decoration:none;}

</STYLE>

</head>

<body bgcolor=white background=./images/body_bg.gif>

<img src=./images/maintitle.gif>

<table border=0 cellspacing=1 cellpadding="3" width=670>

<tr>

<td align=center>

<font color=green><b>내용 보기 화면입니다.</b></font>

</td>

</tr>

<tr>

<td bgcolor="#EAC3EA">

<table border=0 cellspacing=1 cellpadding=0 width=670 bgcolor="white">

<tr>

<td width="100">

<p align="right"><b>이름 &nbsp;</b></p>

Page 29: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

24│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

�</td>

<td width="400">

<p><%= s_name %></p>

</td>

<td width="100">

<p align="right"><b>조회수 &nbsp;</b></p>

</td>

<td>

<p><%= i_count %></p>

</td>

</tr>

<tr>

<td width="100">

<p align="right"><b>전자우편 &nbsp;</b></p>

</td>

<td colspan="3">

<p><%= s_mail_addr %></p>

</td>

</tr>

<tr>

<td width="100">

<p align="right"><b>홈페이지 &nbsp;</b></p>

</td>

<td colspan="3">

<p><%= s_homepage %></p>

</td>

</tr>

<tr>

<td width="100">

<p align="right"><b>제목 &nbsp;</b></p>

</td>

<td colspan="3">

<p><%= s_subject %></p>

</td>

</tr>

Page 30: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │25

제1장

웹어플리케이션보안템플릿제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

SQ

L In

jectio

n 보

안템

플릿

<tr>

<td width="100">

<p align="right"><b>내용 &nbsp;</b></p>

</td>

<td colspan="3">

<p><%= s_memo %></p>

</td>

</tr>

</table>

<p align="center"><a href="list.jsp?page=<%= s_page %>">[목록]</a> &nbsp;<a

href="write.html">[쓰기]</a> &nbsp;<a href="modify.jsp?number=<%= s_number %>&page=<%=

s_page %>">[수정]</a> &nbsp;<a href="delete.jsp?number=<%= s_number %>&page=<%= s_page

%>">[삭제]</a></p>

</td>

</tr>

</table>

</body>

</html>

Page 31: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Page 32: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

................................................................................................................................................................................................................................................................................................................................................................................................................................

..............................................................................................................................................................................................................

..............................................................................................................................................................................................................

............................................................................................................................................................................................................

......................................................................................................

....................................................................................................................................................................................................................................................................................................................

........................................................................................................

........................................................................................................

................................................................................................................................................................................................................

............................................................................................................................................................................................................

..............................................................................................................................................................................................................

..................................................................................................................................................................................................................................................................................................................

......................................................................................................

........................................................................................................................................................................................................................................................................................................................

................................................................................................................................................................................................................

....................................................................................................................................................................................................................................................................................................................

......................................................................................................

............................................................................................................................................................................................................

....................................................................................................................................................................................................................................................................................................................

........................................................................................................

업로드 보안 템플릿

Page 33: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

28│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

제 2 장 업로드 보안 템플릿

업로드 취약점이란?

첨부파일 업로드 기능을 악용하여 웹 쉘(WebShell)과 같은 해킹 프로그램을 업로드한 후, 이를

실행하여 웹서버 권한을 획득하는 공격방법이다.

파일 업로드 취약점은 크게 두 가지의 취약점이 발견되면 공격이 가능하다.

- 서버상에서 실행할 수 있는 스크립트 파일을 업로드할 수 있어야 함

- 업로드된 파일의 위치를 알아낼 수 있어야 하며, 그 위치가 웹상에서 실행 가능해야 함

사 례

아래 예는 그림파일을 업로드하기 위한 게시판에서 업로드 취약점으로 인해 공격을 받은

사례이다.

위의 좌측 그림에서 악의적인 스크립트 파일이 업로드되는 것을 볼 수 있다. 또한, 업로드된 파일

의 위치가 아래 상태 표시줄에 노출되고 있다.

우측 그림은 업로드한 스크립트를 웹 브라우져를 통해 실행한 것이다. 이 스크립트를 통해 해

커는 시스템내의 파일과 폴더의 편집/삭제/복사/ 이동, 임의의 명령 실행, DB 생성 및 조회 등

의 작업을 할 수 있다.

<그림 2-1> 스크립트 업로드 <그림 2-2> 스크립트 실행

Page 34: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │29

웹어플리케이션보안템플릿

각 언어별 보안 템플릿

/include/secure.inc.asp : 업로드 파일 확장자 검사 함수

제2장

업로

드보

안템

플릿

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

<%'확장자 검사'$filename: 파일명'$avaext: 허용할 확장자 예) $avaext = "jpg,gif,pdf"'리턴값: true-"ok", false-"error"Function Check_Ext(filename,avaext)

Dim bad_file, FileStartName, FileEndName

if instr(filename,"\0") ThenResponse.End

End if

'업로드 금지 확장자 체크bad_file = "asp,html,htm,asa,hta"

filename = Replace(filename, " ", "")filename = Replace(filename, "%", "")

FileStartName = Left(filename,InstrRev(filename,".")-1)FileEndName = Mid(filename, InstrRev(filename, ".")+1)

bad_file = split(bad_file, ",")

for each p in bad_fileif instr(FileEndName, p)>0 then

Check_Ext = "error"Exit Function

end ifnext

'허용할 확장자 체크

<ASP 보안 템플릿>

Page 35: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

30│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

/upload.html : 업로드 입력 폼 웹페이지

/upload.asp : 파일 업로드 실행 페이지

�if avaext <> "" Then

ok_file = split(avaext, ",")

for each p in ok_file

if instr(FileEndName, p)>0 then

Check_Ext = "ok"

Exit FunctionEnd If

nextEnd If

Check_Ext = "error"

End Function

%>

<HTML>

<HEAD>

<TITLE>Upload Test</TITLE>

</HEAD>

<BODY>

<form name="frmUp" method="post" action="upload.asp" enctype="multipart/form-data">

<p>파일 : <input type="file" name="attachFile" style="border:1 solid slategray"></p>

<p>전송 : <input type="submit" style="width:150; border:1 solid slategray"></p>

</BODY>

</HTML>

<!--#include virtual="/include/connection.inc.asp"--> <% 'DB연결 헤더 %>

<!--#include virtual="/include/secure.inc.asp"--> <% '보안관련라이브러리 %>

<!--#include virtual="/include/config.inc.asp"--> <% '전역변수리스트 %>

<!--#include virtual="/head.asp"--> <% '초기 설정 페이지(에러 메시지 미출력) %>

<%

Dim DirectoryPath

DirectoryPath = Server.MapPath("Uploaded_Files") '파일이 저장될 로컬폴더 경로

Page 36: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │31

제2장

웹어플리케이션보안템플릿

업로

드보

안템

플릿

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

Dim abc, oFile, fileext

Set abc = Server.CreateObject("ABCUpload4.XForm")

abc.AbsolutePath = True

Set oFile = abc("attachFile")(1)

Dim strFileName, FileSize, FileType, strFileWholePath

If oFile.FileExists Then

strFileName = oFile.SafeFileName

FileSize = oFile.Length

FileType = oFile.FileType

'-- 업로드 금지파일 체크---

If Check_Ext(strFileName,fileext) = "error" Then

Response.Write "<script language=javascript>"

Response.Write "alert(""파일 업로드 실패1 "");"

Response.Write "history.back();"

Response.Write "</script>"

Else

If oFile.Length > 4096000 then

Response.Write "<script language=javascript>"

Response.Write "alert(""4M 이상의 사이즈인 파일은 업로드하실 수 없습

니다"");"

Response.Write "history.back();"

Response.Write "</script>"

Response.end

else

strFileWholePath = GetUniqueName(strFileName, DirectoryPath)

oFile.Save strFileWholePath

Response.Write "파일 업로드 성공"

End if

End If

Else

Page 37: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

32│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

�Response.Write "파일 업로드 실패 1"

End If

'유니크한 파일경로및 파일이름을 얻어내는 함수

Function GetUniqueName(byRef strFileName, DirectoryPath)

Dim strName, strExt

' 확장자를 제외한 파일명을 얻는다.

strName = Mid(strFileName, 1, InstrRev(strFileName, ".") - 1)

strExt = Mid(strFileName, InstrRev(strFileName, ".") + 1) '확장자를 얻는다

Dim fso

Set fso = Server.CreateObject("Scripting.FileSystemObject")

Dim bExist : bExist = True

'우선 같은 이름의 파일이 존재한다고 가정

Dim strFileWholePath : strFileWholePath = DirectoryPath & "\" & strName & "." & strExt

'저장할 파일의 완전한 이름(완전한 물리적인 경로) 구성

Dim countFileName : countFileName = 0

'파일이 존재할 경우, 이름 뒤에 붙일 숫자를 세팅함.

Do While bExist ' 우선 있다고 생각함.

If (fso.FileExists(strFileWholePath)) Then ' 같은 이름의 파일이 있을 때

countFileName = countFileName + 1 '파일명에 숫자를 붙인 새로운 파일

이름 생성

strFileName = strName & "(" & countFileName & ")." & strExt

strFileWholePath = DirectoryPath & "\" & strFileName

Else

bExist = False

End If

Loop

GetUniqueName = strFileWholePath

End Function

%>

Page 38: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │33

제2장

웹어플리케이션보안템플릿

/include/config.inc.php : 허용할 확장자 변수

/include/secure.inc.php : 업로드 확장자 체크 함수

업로

드보

안템

플릿

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

<?

$exts = "jpg,gif,swf"; //허용할 확장자 리스트

?>

<?

//확장자 검사

//$filename: 파일명

//$avaext: 허용할 확장자 예) $avaext = "jpg,gif,pdf"

//리턴값: true-"ok", false-"error"

function checkext($filename,$avaext) {

if(eregi("\\0",$filename)) { return "error"; }

//업로드 금지 확장자 체크

if(eregi('\.inc|\.htm|\.shtm|\.ztx|\.dot|\.cgi|\.pl|\.phtm|\.php|\.ph',$filename))

return "error";

//허용 확장자가 설정된 경우

if ($avaext != "") {

$extfile = str_replace(",","|\\.", $avaext);

$extfile = "\\." . $extfile;

if(eregi($extfile,$filename))

return "ok";

}

return "error";

}

?>

<PHP 보안 템플릿>

Page 39: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

34│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

/process.php : 게시판 쓰기 처리 웹페이지�

<?

require "include/connect.inc.php"; //DB 연결 헤더

require "include/config.inc.php"; //전역 변수 리스트

require "include/secure.inc.php"; //보안 라이브러리

require "include/lib.php"; //게시판 라이브러리

?>

<?

$connect = db_connect();

//입력 변수 처리

$board = sqlfilter($_POST[board]);

$name = sqlfilter($_POST[name]);

$title = sqlfilter($_POST[title]);

$email = sqlfilter($_POST[email]);

$homepage = sqlfilter($_POST[homepage]);

$content = sqlfilter($_POST[content]);

$passwd = sqlfilter(trim($_POST[passwd]));

$result = mysql_query("SELECT MAX(num) AS num, MAX(idx) AS idx,MAX(no) AS no FROM $board",

$connect);

$ist[num] = mysql_result($result, 0, "num");

$ist[num] += 1;

$ist[idx] = mysql_result($result, 0, "idx");

$ist[idx] += 1;

mysql_free_result($result);

$intime = time();

//$passwd = crypt($passwd);

Page 40: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │35

제2장

웹어플리케이션보안템플릿

/write.html : 업로드가 가능한 게시판 쓰기 웹페이지

업로

드보

안템

플릿

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

if ($userfile_size > 0) {

if (checkext($userfile_name,$exts) == "error") {

echo "파일 확장자 에러";

exit;

}

mkdir("upload/$board/$intime", 0755);

exec("move \"$userfile\" \"upload/$board/$intime/$userfile_name\"");

//chmod("upload/$board/$intime/$userfile_name", 0644);

}

$query = "INSERT INTO $board VALUES('',$ist[num], $ist[idx], '$title', '$content',0, 0, 0, 0,0, '',

'$userfile_name', $userfile_size,' $name', '$passwd', '$email', '$homepage', $intime)";

$result = mysql_query($query, $connect);

}

?>

<html>

<head>

<title> 입력</title>

</head>

<body>

<center>

<form method="post" action="process.php" enctype="multipart/form-data">

<input type="hidden" name="board" value="<?php=$board?>">

<table width="550" cellspacing="1" border="0" cellpadding="2">

<tr>

<td align="left"><font size="2"><b>|<a href="list.php?board=<?php=$board?>">|게시물 목록

Page 41: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

36│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

�</a></b></font></td>

</tr>

</table>

<table width="400" cellspacing="1" bgcolor="#A5A595" border="0" cellpadding="5">

<tr>

<td width="30%" bgcolor="#A5A595" align="center">

<font size="2" color="white"><b>작성자명</b></font></td>

<td width="70%" bgcolor="white" align="left"><font color="white"><input type="text" name="name"

size="10" maxlength="10"></font></td>

</tr>

<tr>

<td width="30%" bgcolor="#A5A595" align="center"><font size="2" color="white"><b>E-

mail</b></font></td>

<td width="70%" bgcolor="white" align="left"><font color="white"><input type="text" name="email"

size="20" maxlength="256"></font></td>

</tr>

<tr>

<td width="30%" bgcolor="#A5A595" align="center"><font size="2"

color="white"><b>Homepage</b></font></td>

<td width="70%" bgcolor="white" align="left"><font color="white"><input type="text"

name="homepage" size="20" maxlength="256"></font></td>

</tr>

<tr>

<td width="30%" bgcolor="#A5A595" align="center"><font size="2" color="white"><b>비 번호

</b></font></td>

<td width="70%" bgcolor="white" align="left"><font color="white"><input type="password"

name="passwd" size="10" maxlength="20"></font></td>

</tr>

<tr>

<td width="30%" bgcolor="#A5A595" align="center"><font size="2" color="white"><b> 제목

</b></font></td>

Page 42: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │37

제2장

웹어플리케이션보안템플릿

업로

드보

안템

플릿

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

<td width="70%" bgcolor="white" align="left"><font color="white"><input type="text" name="title"

size="30" maxlength="256"></font></td>

</tr>

<!-- 파일 업로드 -->

<tr>

<td width="30%" bgcolor="#A5A595" align="center"><font size="2" color="white"><b>파 일

</b></font></td>

<td width="70%" bgcolor="white" align="left"><font color="white"><input type="file" name="userfile"

size="20" maxlength="256"></font></td>

</tr>

<tr>

<td width="30%" bgcolor="#C5C5B5" align="center"><font size="2" color="white"><b>본 문

</b></font></td>

<td width="70%" bgcolor="white" align="left"><font color="white"><textarea name="content"

wrap="hard" rows="10" cols="36"></textarea></font></td>

</tr>

</table>

<input type="submit" value="저장하자">

<input type="reset" value="재작성">

</form>

<table width="550" cellspacing="1" border="0" cellpadding="2">

<tr>

<td align="right"><font size="2"><b>|<a href="list.php?board=<?php=$board?>">|게시물 목록

</a></b></font></td>

</tr>

</table>

</center>

</body>

</html>

Page 43: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

38│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

별도의 파일 업로드 모듈이 없어 일반적으로 별도의 외장 클래스를 사용하여 작성한다.

/config.inc.jsp : 업로드 파일 저장 위치 변수

/secure.inc.jsp : 확장자 체크 함수

<%

//확장자 검사

//$filename: 파일명

//$avaext: 허용할 확장자 예) $avaext = "jpg,gif,pdf"

//리턴값: true-"ok", false-"error"

String checkext(String fileName, String avaExt) {

String chkExt = "false";

if (fileName.indexOf("\0") > -1) { chkExt = "false"; }

//업로드 금지 확장자 체크

String file_ext = fileName.substring(fileName.lastIndexOf('.') + 1);

if(( file_ext.equalsIgnoreCase("jsp") || file_ext.equalsIgnoreCase("htm") ||

file_ext.equalsIgnoreCase("html")) ) {

//out.println("업로드 금지 확장자");

chkExt = "false";

}

//허용 확장자가 설정된 경우

<JSP 보안 템플릿>

<%

String savePath="C:/TforWindows/Tomcat5/webapps/ROOT/upload/"; // 저장할 디렉토리 (절 경로)

%>

Page 44: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │39

제2장

웹어플리케이션보안템플릿

/upload.html : 파일 업로드용 웹페이지

업로

드보

안템

플릿

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

<html>

<body>

<form action="upload.jsp" enctype="multipart/form-data" method="post">

이름 : <input type="text" name="userName"> <BR>

파일 : <input type="file" name="upfile">

<input type="submit" value="Upload">

</form>

</body>

</html>

if (!avaExt.equals("")) {

//공백 제거

avaExt.replaceAll(" ","");

String compStr[] = avaExt.split(",");

for (int i = 0;i < compStr.length; i++) {

if (file_ext.equalsIgnoreCase(compStr[i])) {

chkExt = "true";

}

}

}

else {

chkExt = "true";

}

return chkExt;

}

%>

Page 45: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

40│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

/upload.jsp : 파일 업로드 처리 페이지�

<%@ page contentType="text/html;charset=euc-kr" %>

<%@ page

import="com.oreilly.servlet.MultipartRequest,com.oreilly.servlet.multipart.DefaultFileRenamePolicy,java.uti

l.*,java.io.*" %>

<%@ include file="connection.inc.jsp" %>

<%@ include file="config.inc.jsp" %>

<%@ include file="secure.inc.jsp" %>

<%

String chkExt="false";

int i, sizeLimit = 5 * 1024 * 1024 ; // 5메가까지 제한 넘어서면 예외발생

try {

MultipartRequest multi=new MultipartRequest(request, savePath, sizeLimit, new

DefaultFileRenamePolicy());

Enumeration formNames=multi.getFileNames(); // 폼의 이름 반환

String formName=(String)formNames.nextElement(); // 자료가 많을 경우엔 while 문을 사용

String fileName=multi.getFilesystemName(formName); // 파일의 이름 얻기

chkExt = checkext(fileName, avaExt);

if(fileName == null) { // 파일이 업로드 되지 않았을때

out.println("파일 업로드 되지 않았음");

}

else { // 파일이 업로드 되었을때

if (chkExt.equals("true")) {

fileName=new String(fileName.getBytes("8859_1"),"euc-kr");

// 한 인코딩 - 브라우져에 출력

out.println("User Name : " + multi.getParameter("userName") + "<BR>");

out.println("Form Name : " + formName + "<BR>");

out.println("File Name : " + fileName);

}

else {

Page 46: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │41

제2장

웹어플리케이션보안템플릿

업로

드보

안템

플릿

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

out.println(avaExt+"만 가능");

File tmp = new File(savePath+"\\"+fileName);

if (tmp.exists()) {

tmp.delete();

}

}

} // end if

} catch(Exception e) {

out.print("예외 상황 발생..! ");

}

%>

Page 47: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Page 48: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

................................................................................................................................................................................................................................................................................................................................................................................................................................

..............................................................................................................................................................................................................

..............................................................................................................................................................................................................

............................................................................................................................................................................................................

......................................................................................................

....................................................................................................................................................................................................................................................................................................................

........................................................................................................

........................................................................................................

................................................................................................................................................................................................................

............................................................................................................................................................................................................

..............................................................................................................................................................................................................

..................................................................................................................................................................................................................................................................................................................

......................................................................................................

........................................................................................................................................................................................................................................................................................................................

................................................................................................................................................................................................................

....................................................................................................................................................................................................................................................................................................................

......................................................................................................

............................................................................................................................................................................................................

....................................................................................................................................................................................................................................................................................................................

........................................................................................................

다운로드 보안 템플릿

Page 49: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

44│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

제 3 장 다운로드 보안 템플릿

다운로드 취약점이란?

홈페이지 상에서 파일 열람 또는 다운로드를 위해 입력되는 경로를 체크하지 않을 때 웹 서

버의 홈 디렉토리를 벗어나서 임의의 위치에 있는 파일(/etc/passwd 파일 등)을 열람하거나

다운로드받는 공격이다.

이 공격은 입력되는 URL 경로에서 임의의 문자(../.. 등)나 주요 파일명(passwd 등)에 한

필터링을 하지 않아 발생된다.

사 례

아래와 같이 파일을 다운로드 받아야 하는 URL의 경우 공격자는 filename 변수 값을

../../../../../../../winnt/win.ini와 같이 상 경로를 이용해서 시스템 내부의 파일을 불법으로

획득할 수 있다.

http://test.site.com/board/download.jsp?num=203&filename=upload/azip.exe ← 다운로드 파일 위치 및

파일 이름

<그림 3-1> 시스템 내부파일을 획득한 사례

Page 50: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │45

웹어플리케이션보안템플릿

각 언어별 보안 템플릿

/include/config.inc.asp : 다운로드 위치 변수

/include/secure.inc.asp : 다운로드 경로 입력값 검사

제3장

다운

로드

보안

템플

릿

<%

UploadedPath = "/Uploaded_Files/" '업로드 기본 경로

%>

<%

'다운로드 경로 체크 함수

'$dn_dir - 다운로드 디렉토리 경로(path)

'$fname - 다운로드 파일명

'리턴 - true:파운로드 파일 경로, false: "error"

Function Check_Path(dn_dir, fname)

dn_dir = Replace(dn_dir, "/", "\")

fname = Replace(fname, "/", "\")

strFile = Server.MapPath(dn_dir) & "\" & fname '서버 절 경로

strFname = Mid(fname,InstrRev(fname,"\")+1) '파일 이름 추출, ..\ 등의 하위 경로 탐색은 제거 됨

Response.Write strFname

strFPath = Server.MapPath(dn_dir) & "\" & strFname '웹서버의 파일 다운로드 절 경로

If strFPath = strFile Then

Check_Path = strFile '정상일 경우 파일 경로 리턴

Else

Check_Path = "error"

<ASP 보안 템플릿>

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

Page 51: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

46│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

/download.asp : 다운로드 페이지

�End If

End Function

%>

<!--#include virtual="/include/connection.inc.asp"--> <% 'DB연결 헤더 %>

<!--#include virtual="/include/secure.inc.asp"--> <% '보안관련라이브러리 %>

<!--#include virtual="/include/config.inc.asp"--> <% '전역변수리스트 %>

<!--#include virtual="/head.asp"--> <% '초기 설정 페이지(에러 메세지 미출력) %>

<%

Dim dn_dir, fname, val_ok

Dim UploadedPath

dn_dir = Request("dir")

fname = Request("fname") '파일 이름

' IE 5.01에서는 이 방식을 사용할때 메모리 관련 문제가 발생할 수 있다.

strUA = Request.ServerVariables("HTTP_USER_AGENT")

If Instr(strUA, "MSIE") Then

intVersion = CDbl(mid(strUA, Instr(strUA, "MSIE")+5, 3))

If intVersion < 5.01 Then

Response.Write "error"

End If

End If

if fname = "" Then

Response.Write "<script language=javascript>"

Response.Write "alert(""파일명을 입력해 주세요"");"

Response.Write "history.back();"

Response.Write "</script>"

End If

dn_dir = UploadedPath & dn_dir

val_ok = Check_Path(dn_dir, fname)

If val_ok <> "error" Then '사용자가 다운 받는 파일과 웹서버의 파일 다운로드 경로가 맞는지 비교

Set objStream = Server.CreateObject("ADODB.Stream") 'Stream 이용

Response.ContentType = "application/unknown" 'ContentType 선언

Response.AddHeader "Content-Disposition","attachment; filename=" & fname

objStream.Open

Page 52: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │47

제3장

웹어플리케이션보안템플릿

/include/config.inc.php : 다운로드 경로

/include/secure.inc.php - 경로 입력값 체크 함수

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

다운

로드

보안

템플

릿

objStream.Type = 1objStream.LoadFromFile val_ok

download = objStream.ReadResponse.BinaryWrite download

End If

Set objstream = nothing '객체 초기화

%>

<PHP 보안 템플릿>

<?

$UploadedPath = "c:/apm_setup/php/upload"; // 기본 다운로드 디렉토리

?>

<?

//다운로드 경로 체크 함수

//$dn_dir - 다운로드 디렉토리 경로(path)

//$fname - 다운로드 파일명

//리턴 - true:다운로드 파일 경로, false: "error"

function checkpath($dn_dir,$fname) {

$dn_dir = str_replace("\\","/",$dn_dir);

//다운로드 경로에 공격 문자 필터링

if (eregi("\.\./",$dn_dir)) {

print "허용하지 않는 입력값입니다.";

return "error";

}

//사용자 입력값으로 다운로드 파일 경로 생성

$dn_file = $dn_dir . "/" . $fname;

//$fname에서 파일명만 분리 - 파일명에 공격 위험성 문자 필터링

//$filename = substr($dn_file, strrpos($dn_file, '/') + 1);

Page 53: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

48│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

/download.php : 다운로드 페이지

�$filename=basename($fname);

//분리한 파일명과 절 경로를 재구성

$strfname = $dn_dir . "/" . $filename;

//사용자 입력값과 재구성한 입력값을 비교하여 공격 위험성이 존재하는지 확인

if ($strfname == $dn_file)

return $strfname;

else

return "error";

}

?>

<?

require "include/connect.inc.php"; //DB 연결 헤더

require "include/config.inc.php"; //전역 변수 리스트

require "include/secure.inc.php"; //보안 라이브러리

require "include/lib.php"; //게시판 라이브러리

?>

<?

//파일명 입력 체크

if ($_REQUEST[fname] == "") {

print "인수를 입력해 주세요.";

exit;

}

$dn_dir = $_REQUEST[dir];

$dn_fname = $_REQUEST[fname];

$bufsize = 20000;

$strfname = checkpath($dn_dir, $dn_fname);

if ($dn_path != "error") {

//절 경로 생성

$dn_path = $UploadedPath . $strfname;

$fsize=filesize($dn_path);

Page 54: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │49

제3장

웹어플리케이션보안템플릿

/config.inc.jsp : 다운로드 기본 경로 지정

/secure.inc.jsp : 다운로드 입력값 체크 함수

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

다운

로드

보안

템플

릿

//파일 전송 루틴

header("HTTP/1.1 200 OK");

header("Content-Length: $fsize");

header("Content-Type: application/force-download");

header("Content-Disposition: attachment; filename=$dn_fname");

header("Content-Transfer-Encoding: binary");

if($fh = fopen($dn_path, "rb")) {

while($buf = fread($fh, $bufsize)) print $buf;

fclose($fh);

}

else {

echo "파일 에러";

header("HTTP/1.1 404 Not Found");

}

}

else {

echo "입력값 오류1";

}

?>

<JSP 보안 템플릿>

<%

String DN_PATH= "C:/TforWindows/Tomcat5/webapps/root/board/uploaded_files/"; //디폴트 다운로드

경로 지정

%>

<%!

//다운로드 경로 체크 함수

//$dn_dir - 다운로드 디렉토리 경로(path)

//$fname - 다운로드 파일명

//리턴 - true:다운로드 파일 경로, false: "error"

Page 55: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

50│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

/download.jsp : 다운로드 페이지

�String checkpath(String dn_path, String fname) {

//입력되는 디렉토리명에서 특수문자 유무 검사

if((dn_path.indexOf("..\\") != -1) || (dn_path.indexOf("../") != -1)) {

return "error";

}

//사용자 입력값으로 다운로드 파일 경로 생성

if (dn_path.equals("")) {

}

else {

dn_path = dn_path + "/";

}

String origfile = dn_path + fname;

//fname에서 파일명만 분리 - 파일명에 공격 위험성 문자 필터링

fname.replaceAll("\\","/"); //일부 버전에서 오류 발생

//String filename3 = fname.substring(fname.lastIndexOf('/') + 1);

//fname.replaceAll("\\","/")가 사용할 수 없는 경우 아래

String filename4 = fname.substring(fname.lastIndexOf('\\') + 1);

//분리한 파일명과 절 경로를 재구성

String FilePath = dn_path + filename4;

//사용자 입력값과 재구성한 입력값을 비교하여 공격 위험성이 존재하는지 확인

if (origfile.equals(FilePath)) {

return (FilePath);

}

else {

return "error";

}

}

%>

<%@ page import="java.util.*,java.io.*,java.sql.*,java.text.*" %>

<%@ page contentType="text/html;charset=euc-kr" %>

<%@ include file="config.inc.jsp" %>

<%@ include file="secure.inc.jsp" %>

Page 56: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │51

제3장

웹어플리케이션보안템플릿제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

다운

로드

보안

템플

릿

<%

//입력되는 파일명의 한 처리

String filename = java.net.URLDecoder.decode(request.getParameter("file"));

String filename2 = new String(filename.getBytes("euc-kr"),"8859_1");

String dirname = java.net.URLDecoder.decode(request.getParameter("dir"));

String dirname2 = new String(dirname.getBytes("euc-kr"),"8859_1");

String dn_path, FilePath;

dn_path = checkpath(dirname2, filename2);

if (!dn_path.equals("error")) {

//파일 전송 프로세스

FilePath = DN_PATH+dn_path;

File file = new File(FilePath); // 절 경로 입력.

byte b[] = new byte[(int)file.length()];

response.setHeader("Content-Disposition", "attachment;filename=" + filename2 + ";");

if (file.isFile()) {

BufferedInputStream fin = new BufferedInputStream(new FileInputStream(file));

BufferedOutputStream outs = new

BufferedOutputStream(response.getOutputStream());

int read = 0;

while ((read = fin.read(b)) != -1) {

outs.write(b,0,read);

}

outs.close();

fin.close();

}

}

else {

out.println("입력값 오류1");

return;

}

%>

Page 57: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

..................................................................................................................................................................................................................

..........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Page 58: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

................................................................................................................................................................................................................

........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

......................................................................................................

..............................................................................................................................................................................................................

............................................................................................................................................................................................................

......................................................................................................

......................................................................................................................................................................................................................................................................................................................

........................................................................................................

................................................................................................................................................................................................................

......................................................................................................

....................................................................................................................................................................................................................................................................................................................

......................................................................................................

..................................................................................................................................................................................................................................................................................................................

........................................................................................................

................................................................................................................................................................................................................................................................................................................................................................................................................................

......................................................................................................

....................................................................................................................................................................................................................................................................................................................

............................................................................................................................................................................................................

............................................................................................................................................................................................................

................................................................................................................................................................................................................

Cross Site Script(XSS) 보안 템플릿

Page 59: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

54│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

제4장 Cross Site Script(XSS)보안템플릿

XSS 취약점이란?

자바스크립트처럼 클라이언트 측에서 실행되는 언어로 작성된 악성 스크립트 코드를 웹 페이

지, 웹 게시판 또는 이메일에 포함시켜 이를 열람한 사용자 컴퓨터에서 악성 스크립트가 실행

되게 하고 사용자의 개인정보 등을 유출시키는 공격이다.

이 공격은 사용자로부터 입력 받은 데이터를 필터링하지 않고 그 로 동적으로 생성된 웹 페

이지에 포함시켜 사용자에게 보여줄 때 발생한다.

사 례

아래와 같이 사용자가 을 입력하는 부분에 악의적인 JavaScript를 이용하여 해당 정보를

열람하는 사용자의 Cookie 정보 등을 탈취할 수 있다.

아래 그림은 해당 을 열람한 사용자의 Cookie 정보가 공격자에게 전달된 것이다.

<그림 4-1> 악의적인 JavaScript

<그림 4-2> Cookie 정보가 공격자에게 전달된 화면

Page 60: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │55

웹어플리케이션보안템플릿

각 언어별 보안 템플릿

이 clearXSS 함수는 입력값에 위험성이 존재하는 태그를 필터링 하도록 되어 있으며 그 외에

태그에 입력값으로 사용하는 방식( 예) <img src="[입력값]“> )에는 적용이 되지 않는다.

/include/config.inc.asp

/include/secure.inc.asp

제4장

Cro

ssS

iteS

crip

t(X

SS

)

보안

템플릿

<ASP 보안 템플릿>

<%

atag = "p,br" 'XSS 허용할 태그 리스트

%>

'XSS 출력 필터 함수

'XSS 필터 함수

'$str - 필터링할 출력값

'$avatag - 허용할 태그 리스트 예) $avatag = "p,br"

Function clearXSS(strString, avatag)

'XSS 필터링

strString = replace(strString, "<", "&lt;")

strString = replace(strString, "\0", "")

'허용할 태그 변환

avatag = replace(avatag, " ", "") '공백 제거

if (avatag <> "") Then

taglist = split(avatag, ",")

for each p in taglist

strString = replace(strString, "&lt;"&p&" ", "<"&p&" ", 1, -1, 1)

strString = replace(strString, "&lt;"&p&">", "<"&p&">", 1, -1, 1)

strString = replace(strString, "&lt;/"&p&" ", "</"&p&" ", 1, -1, 1)

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

Page 61: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

56│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

/content.asp

<!--#include virtual="/include/connection.inc.asp"--> <% 'DB연결 헤더 %>

<!--#include virtual="/include/secure.inc.asp"--> <% '보안관련라이브러리 %>

<!--#include virtual="/include/config.inc.asp"--> <% '전역변수리스트 %>

<!--#include virtual="/head.asp"--> <% '초기 설정 페이지(에러 메시지 미출력) %>

<%

Dim strSQL

Dim intSeq, strName, strEmail, strSubject, strContent, intCount, dtmReg_Date, intExist

Dim blnTag, strUserIP

Dim atag

intSeq = gFilter(Request.QueryString("seq"))'SQL Injection 필터링

'읽은 횟수 검색

strSQL = "SELECT count(*) FROM board WHERE intSeq='" & intSeq & "'"

objRs.Open strSQL, objDBConn

intExist = objRs(0)

objRs.Close

If intExist <> 1 Then

Response.Write "해당 이 없습니다."

Else

'읽은 횟수 증가

strSQL = "UPDATE board SET intCount=intCount+1 WHERE intSeq='" & intSeq & "'"

objRs.Open strSQL, objDBConn

'게시물 SELECTZ

strSQL = "SELECT

strName,strEmail,strSubject,strContent,intCount,strUserIP,blnTag,dtmReg_Date FROM board WHERE

intSeq='" & intSeq & "'"

next

End If

clearXSS = strString

End Function

Page 62: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │57

제4장

Cro

ss Site

Scrip

t (XS

S) 보

안템

플릿

웹어플리케이션보안템플릿제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

objRs.Open strSQL, objDBConn

strName = objRs(0)

strEmail = objRs(1)

strSubject = objRs(2)

strContent = objRs(3)

intCount = objRs(4)

strUserIP = objRs(5)

blnTag = objRs(6)

dtmReg_Date = objRs(7)

objRs.Close

Set objRs = Nothing

objDBConn.Close

Set objDBConn = Nothing

'게시물 출력값에 XSS 필터링

'사용자가 입력하는 출력되는 값은 strName, strEmail, strSubject, strContent으로 이 부분은

XSS 공격이 가능한 부분들이다.

'일반적으로 본문만 선택적으로 HTML 태그 사용을 허용하며 나머지 부분들은 사용할 수 없도록

하는것이 바람직하다.

strName = clearXSS(strName, atag)

strEmail = clearXSS(strEmail, atag)

strSubject = clearXSS(strSubject, atag)

strContent = clearXSS(strContent, atag)

'줄넘김 처리

strContent = replace(strContent, vbLf, vbLf & "<br>")

%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ks_c_5601-1987">

<title>내용보기</title>

</head>

Page 63: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

58│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

�<body>

<div align=center>

<table border=1>

<tr>

<td>이름</td>

<td><%=strName%></td>

<td>등록일</td>

<td><%=dtmReg_Date%></td>

</tr>

<tr>

<td>이메일</td>

<td><%=strEmail%></td>

<td>조회</td>

<td><%=intCount%></td>

</tr>

<tr>

<td>제목</td>

<td colspan=3><%=strSubject%></td>

</tr>

<tr>

<td>내용</td>

<td colspan=3><%=strContent%></td>

</tr>

<tr>

<td colspan=4>

<a href="list.asp">목록으로</a> <a href="edit.asp?seq=<%=intSeq%>">수정하기</a> <a

href="delete.asp?seq=<%=intSeq%>">삭제하기</a>

</td>

</tr>

</table>

</div>

</body>

</html>

<%

End If

%>

Page 64: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │59

제4장

Cro

ss Site

Scrip

t (XS

S) 보

안템

플릿

웹어플리케이션보안템플릿

/include/config.inc.php

/include/secure.inc.php

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

<PHP 보안 템플릿>

<?

$avatag = "p,br"; //XSS에서 허용할 태그 리스트

?>

<?

//XSS 필터 함수

//$str - 필터링할 출력값

//$avatag - 허용할 태그 리스트 예) $avatag = "p,br"

function clearxss($str,$avatag) {

$str=str_replace("<","&lt;", $str);

$str=str_replace("\0","", $str);

//허용할 태그를 지정할 경우

$str=str_replace(" ", "", $avatag);

if ($avatag != "") {

$otag = explode (",", $avatag);

//허용할 태그를 존재 여부를 검사하여 원상태로 변환

for ($i = 0;$i < count($otag);$i++) {

$str = eregi_replace("&lt;".$otag[$i]." ", "<".$otag[$i]." ", $str);

$str = eregi_replace("&lt;".$otag[$i].">", "<".$otag[$i].">", $str);

$str = eregi_replace("&lt;/".$otag[$i], "</".$otag[$i], $str);

}

}

return $str;

}

?>

Page 65: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

60│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

/view.php�

<?

require "include/connect.inc.php"; //DB 연결 헤더

require "include/config.inc.php"; //전역 변수 리스트

require "include/secure.inc.php"; //보안 라이브러리

require "include/lib.php"; //게시판 라이브러리

?>

<?

$no = gfilter($_REQUEST[no]); // SQL Injection 필터

$board = gfilter($_REQUEST[board]); // SQL Injection 필터

//읽기 횟수 저장

$updok = mysql_query("UPDATE $board SET hit = hit + 1 WHERE no=$no", $connect);

$query = sprintf("SELECT * FROM %s WHERE no='%d'",$board,$no);

$result = mysql_query($query);

$view = @mysql_fetch_array($result); //@를 이용하여 에러 메세지 출력을 하지 않는다.

//XSS 필터링

$view[usrname] = clearxss($view[usrname],$avatag);

$view[usremail] = clearxss($view[usremail],$avatag);

$view[usrtitle] = clearxss($view[usrtitle],$avatag);

$view[contents] = clearxss($view[contents],$avatag);

$dates = date ("Y-m-d, h:i:s", $view[filluptime]);

$perpage = 10;

$tlpn = get_pagenum();

$nowpage = get_page($view[idx]);

if ($view[usremail] != "") {

$name = "<a href=\"mailto:$view[usremail]\">$view[usrname]</a>";

}

else {

$name = "$view[usrname]";

Page 66: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │61

제4장

Cro

ss Site

Scrip

t (XS

S) 보

안템

플릿

웹어플리케이션보안템플릿제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

}

if ($view[usrhomepage] != "") {

$homeurl = "<a href=\"$view[usrhomepage]\" target=\"_blank\">[Homepage]</a>";

}

else {

$homeurl = "";

}

echo "

<html>

<head>

<title> 내용 보기</title>

</head>

<body>

<center>

<table width=\"550\" cellspacing=\"1\"

border=\"0\" cellpadding=\"2\">

<tr>

<td align=\"left\"><font size=\"2\"><b>|<a href=\"list.php?board=$board&page=$nowpage\">게시물 목록

</a>|<a href=\"edit.php?board=$board&no=$no\">수정</a>|<a

href=\"delete.php?board=$board&no=$no\">삭제</a>|</b></font></td>

</tr>

</table>

<table width=\"550\" cellspacing=\"1\" border=\"0\" cellpadding=\"2\">

<tr>

<td colspan=\"2\" bgcolor=\"#A5A595\"><font color=\"white\" size=\"2\">$view[num] 번 :

<b>$view[usrtitle]</b></font></td>

</tr>

<tr>

<td align=\"left\" bgcolor=\"#E5E5D5\"><font size=\"2\">조회수: $view[hit]</font></td>

Page 67: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

62│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

�<td align=\"right\" bgcolor=\"#E5E5D5\"><font size=\"2\">$name 님이 $homeurl $dates 에 작성해주셨습

니다.</font></td></tr>

</table>";

if ($view[filesize] > 0) {

$view[contents] .= "<p align=\"right\">";

$view[contents] .= "<a href=\"dn.php?board=$board&no=$view[no]\">";

$view[contents] .= $view[filename];

$view[contents] .= "</a>";

}

echo "

<table width=\"550\" cellspacing=\"1\" border=\"0\" cellpadding=\"2\">

<tr>

<td><font size=\"2\">$view[contents]</font>

</td>

</tr>

</table>

<table width=\"550\" cellspacing=\"1\" border=\"0\" cellpadding=\"2\">

<tr>

<td align=\"right\"><font size=\"2\"><b>|<a href=\"list.php?board=$board&page=$nowpage\">게시물 목록

</a>|<a href=\"edit.php?board=$board&no=$no\">수정</a>|<a

href=\"delete.php?board=$board&no=$no\">삭제</a>|</b></font></td>

</tr>

</table>

</center>

</body>

</html>

";

?>

Page 68: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │63

제4장

Cro

ss Site

Scrip

t (XS

S) 보

안템

플릿

웹어플리케이션보안템플릿

/config.inc.jsp

/secure.inc.jsp

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

<JSP 보안 템플릿>

<%

String avatag = "p,br"; //허용할 확장자 리스트

%>

<%

//XSS 필터 함수

//$str - 필터링할 출력값

//$avatag - 허용할 태그 리스트 예) $avatag = "p,br"

String clearXSS(String str, String avatag) {

str = str.replaceAll("<","&lt;");

str = str.replaceAll(" 0"," ");

//허용할 태그를 지정할 경우

if (!avatag.equals("")) {

avatag.replaceAll(" ","");

String [] st = avatag.split(",");

//허용할 태그를 존재 여부를 검사하여 원상태로 변환

for( int x = 0; x < st.length; x++ ) {

str = str.replaceAll("&lt;"+str+" ", "<"+str+" ");

str = str.replaceAll("&lt;"+str+">", "<"+str+">");

str = str.replaceAll("&lt;/"+str, "</"+str);

}

}

return (str);

}

%>

Page 69: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

64│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

/view.jsp�

<!--

www.itmembers.net의 JSP게시판 만들기 강좌에서 손병목님이 작성하신 view.jsp파일을 strip Tokonizer

사용을 위해 인용하 습니다.

-->

<%@ page language="java" import="java.sql.*,java.util.*" contentType="text/html;charset=KSC5601" %>

<%@ include file="connection.inc.jsp" %>

<%@ include file="config.inc.jsp" %>

<%@ include file="secure.inc.jsp" %>

<%

String s_tablename = "bbs"; // 테이블 이름

String s_sql, s_number, s_name="", s_email="", s_homepage="", s_subject="", s_memo="" ;

String s_mail_addr="";

String s_page ;

int i_number, i_count=0, i_page ;

StringTokenizer st = null; // <br> 처리를 위해서

String s_temp = "";

s_number = request.getParameter("number"); // view.jsp?number=10 과 같이 넘어온 값 "10"을 받음.

//i_number = Integer.parseInt(s_number);

s_page = request.getParameter("page"); // view.jsp?page=3 과 같이 넘어온 값 "3"을 넘겨받음.

if(s_page==null) s_page="1";

//i_page = Integer.parseInt(s_page);

s_number = gFilter(s_number); //SQL Injection 필터

s_page = gFilter(s_page); //SQL Injection 필터

//out.println(s_number);

//out.println(s_page);

try {

s_sql = "select name,count,email,homepage,subject,memo from "+s_tablename+" where

number='"+s_number+"'";

rs = stmt.executeQuery(s_sql); // 쿼리문 실행 결과 값을 담을 객체

if(rs.next()) {

Page 70: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │65

제4장

Cro

ss Site

Scrip

t (XS

S) 보

안템

플릿

웹어플리케이션보안템플릿제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

//XSS 필터

s_name = clearXSS(rs.getString(1),avatag);

i_count = rs.getInt(2);

s_email = clearXSS(rs.getString(3),avatag);

s_homepage = clearXSS(rs.getString(4),avatag);

s_subject = clearXSS(rs.getString(5),avatag);

s_memo = clearXSS(rs.getString(6),avatag);

}

if(!s_email.equals("")) {

s_mail_addr="<a href=mailto:"+s_email+">"+s_email+"</a>";

} else {

s_mail_addr=s_email;

}

// Enter를 <br>로 처리

st = new StringTokenizer(s_memo,"\n");

while(st.hasMoreTokens()) {

s_temp = s_temp + st.nextToken()+"<br>";

}

s_memo = s_temp;

s_sql = "update "+s_tablename+" set count = count + 1 where number = "+s_number;

stmt.executeUpdate(s_sql);

stmt.close(); // 인클루드 파일(db_conn.jsp)에서 생성한 stmt 닫기

Conn.close(); // 인클루드 파일(db_conn.jsp)에서 생성한 Conn 닫기

} catch (Exception e) {

out.println(e);

}

%>

<html>

<head>

<title>JSP 게시판 프로젝트 - 보기</title>

<STYLE TYPE="text/css">

Page 71: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

66│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

�BODY,TD,SELECT,input,DIV,form,TEXTAREA,center,option,pre,blockquote {font-family:굴림font-

size:9pt;color:#555555;}

A:link {color:black;text-decoration:none;}

A:visited {color:black;text-decoration:none;}

A:active {color:black;text-decoration:none;}

A:hover {color:gray;text-decoration:none;}

</STYLE>

</head>

<body bgcolor=white background=./images/body_bg.gif>

<img src=./images/maintitle.gif>

<table border=0 cellspacing=1 cellpadding="3" width=670>

<tr>

<td align=center>

<font color=green><b>내용 보기 화면입니다.</b></font>

</td>

</tr>

<tr>

<td bgcolor="#EAC3EA">

<table border=0 cellspacing=1 cellpadding=0 width=670 bgcolor="white">

<tr>

<td width="100">

<p align="right"><b>이름 &nbsp;</b></p>

</td>

<td width="400">

<p><%= s_name %></p>

</td>

<td width="100">

<p align="right"><b>조회수 &nbsp;</b></p>

</td>

<td>

<p><%= i_count %></p>

</td>

</tr>

<tr>

<td width="100">

<p align="right"><b>전자우편&nbsp;</b></p>

</td>

<td colspan="3">

Page 72: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │67

제4장

Cro

ss Site

Scrip

t (XS

S) 보

안템

플릿

웹어플리케이션보안템플릿제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

<p><%= s_mail_addr %></p>

</td>

</tr>

<tr>

<td width="100">

<p align="right"><b>홈페이지 &nbsp;</b></p>

</td>

<td colspan="3">

<p><%= s_homepage %></p>

</td>

</tr>

<tr>

<td width="100">

<p align="right"><b>제목 &nbsp;</b></p>

</td>

<td colspan="3">

<p><%= s_subject %></p>

</td>

</tr>

<tr>

<td width="100">

<p align="right"><b>내용 &nbsp;</b></p>

</td>

<td colspan="3">

<p><%= s_memo %></p>

</td>

</tr>

</table>

<p align="center"><a href="list.jsp?page=<%= s_page %>">[목록]</a> &nbsp;<a

href="write.html">[쓰기]</a> &nbsp;<a href="modify.jsp?number=<%= s_number %>&page=<%=

s_page %>">[수정]</a> &nbsp;<a href="delete.jsp?number=<%= s_number %>&page=<%= s_page

%>">[삭제]</a></p>

</td>

</tr>

</table>

</body>

</html>

Page 73: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Page 74: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

................................................................................................................................................................................................................................................................................................................................................................................................................................

..............................................................................................................................................................................................................

..............................................................................................................................................................................................................

............................................................................................................................................................................................................

......................................................................................................

....................................................................................................................................................................................................................................................................................................................

........................................................................................................

........................................................................................................

................................................................................................................................................................................................................

............................................................................................................................................................................................................

..............................................................................................................................................................................................................

..................................................................................................................................................................................................................................................................................................................

......................................................................................................

........................................................................................................................................................................................................................................................................................................................

................................................................................................................................................................................................................

....................................................................................................................................................................................................................................................................................................................

......................................................................................................

............................................................................................................................................................................................................

....................................................................................................................................................................................................................................................................................................................

........................................................................................................

접근통제 보안 템플릿

Page 75: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

70│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

제5장접근통제보안템플릿

접근통제 취약점이란?

관리자 페이지 등 특정 사용자들에게만 접근이 허용되어야 하는 웹사이트에 해 불특정 다

수가 접근 가능하여 공격하는 취약점이다.

관리자 페이지는 회원 DB나 웹 컨텐츠를 관리할 수 있는 기능과 권한을 갖고 있으므로, 관리

자 이외에는 접근할 수 없도록 IP 접근통제, 추측하기 어려운 URL 사용(admin, manager 등 사

용금지) 등으로 접근자체를 차단하여야 한다.

사 례

많은 홈페이지들은 http://www.xxx.com/admin 등과 같이 관리자 페이지가 쉽게 추측가능하

다. 관리자 페이지에 접근이 가능할 경우 로그인을 위한 별도의 인증절차를 마련한다고 하더라

도, SQL Injection, 패스워드 유출 등의 취약점을 이용하여 웹 관리자 권한을 획득 할 수 있다.

다음 그림은 쉽게 유출가능한 관리자 페이지명으로 웹 관리자 페이지에 접근한 화면이다.

<그림 5-1> 유출 가능한 관리자 페이지 명

Page 76: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │71

웹어플리케이션보안템플릿

각 언어별 보안 템플릿

/admin/auth.asp : 접근통제할 페이지 초기에 include 하여 권한 검사를 수행하는 페이지

제5장

<ASP 보안 템플릿>

<%

'각 디렉토리별로 권한을 설정할 수 있다.

'권한은 admin, user, unknown 세가지 권한으로 나누며 admin은 IP Address과 로그인인증, user는 로그인

인증, unknown은 모두 접근이 가능하도록 구분한다.

'이 페이지를 각 폴더별로 넣고 접근을 통제할 웹페이지 초기 부분에 include 한다.

UserGrade = "admin" '해당 웹페이지의 통제 레벨 설정 admin의 경우 IP Address, 사용자인증 모두 체크

'세션 체크 정상적으로 로그인 했는지 조사

If UserGrade <> Session("user_grade") Then

Response.Write "<script>alert('접근 제한');history.go(-1);</script>"

Response.End

Else

'사용자 권한이 관리자일 경우

If UserGrade = "admin" Then

'접근한 사용자 IP Address와 세션에 설정된 IP Address에 포함되는지 조사

If (instr(Request.Servervariables("REMOTE_ADDR"), Session("access_ip"))) Then

'로그인 하 는지 여부 조사

If Session("logged_in") = "" Then

Response.Write "<script>alert('IP: 접근 제한');history.go(-

1);</script>"

Response.End

End If

Else

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

접근

통제

보안

템플

릿

Page 77: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

72│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

/admin/index.asp : 로그인 인증을 거친 후 auth.asp에서 사용할 세션값을 설정하는 페이지

�Response.Write "<script>alert('로그인: 접근 제한');history.go(-

1);</script>"

Reponse.End

End If

'권한이 사용자일 경우

ElseIf UserGrade = "user" Then

If Session("user_id") = "" Then

Response.Write "<script>alert('레벨: 접근 제한');history.go(-1);</script>"

Response.End

End If

End If

End If

%>

<!--#include virtual="/include/connection.inc"-->

<%

' 사용되는ID 값은 유일해야 한다.

' ID에 한 PW값을 가져와서 입력된 패스워드와 비교하는 방식으로 기존의 로그인 방식은 ID,PW를 모두

확인하는 방식으로 WHERE 구문의 조작으로 루틴을 우회할 수 있으나 해당 방식은 인젝션이 성공한다 하

더라도 임의의 인젝션된 값과 입력된 값을 비교하게 되어 공격의 성공율을 낮출 수 있다.

Dim strQuery, strSQL

Dim strID, strPW

strID = Request("Name")

strPW = Request("Password")

' 입력값 NULL 체크

If Len(strID) = 0 OR Len(strPW) = 0 then

'입력값 체크 실패

Else

'입력되는 ID값의 존재여부 파악

strSQL = "SELECT count(*) FROM userinfo WHERE strID = '" & strID & "'"

objRs.Open strSQL, objDBConn

Page 78: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │73

제5장

접근

통제

보안

템플

릿

웹어플리케이션보안템플릿제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

'유일하게 존재하는 경우

If objRs(0) = 1 Then

objRs.close

'접근 ID와 일치하는 패스워드값을 SELECT 함으로써 SQL 구문으로 인증 체크를

하지 않도록 한다.

'오류를 이용한 SQL Injection 기법에는 기존의SQL Injection 필터링 방법으로 통제

한다.

strSQL = "SELECT strPassword,strName FROM userinfo WHERE strID = '" & strID

& "'"

objRs.Open strSQL, objDBConn

'SELECT된 패스워드와 입력 패스워드 비교

If StrComp(trim(objRs(0)),strPW) = 0 Then

'로그인 성공 후 프로세스 작성

Session("logged_in") = 1 '로그인 여부

Session("user_id") = strID '로그인한 사용자 ID

Session("access_ip") = "192.168.100" '접근 허용한 IP 주소

Session("user_grade") = "admin" '로그인한 사용자 권한

Else

'입력된 패스워드와 SELECT한 패스워드가 다를 경우 로그인 실패

Response.Write strID & " Login Failed"

End If

Else

'ID가 복수일 경우 로그인 실패

Response.Write strID & " Login Failed"

End If

objRs.Close

End If

%>

<HTML>

<HEAD>

</HEAD>

<BODY>

<H3><P>텍스트 상자 정보 입력하기</P></H3>

<form action="login.asp" name=postform method=post>

<table border=0>

<tr><td>아이디 : </td>

<td><input type=text name=Name size=20 value=""></td>

Page 79: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

74│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

사용 예)

/admin/admin.asp : auth.asp를 include 하여 사용자 권한 검사

/admin/auth.php : 접근통제할 페이지 초기에 include 하여 권한 검사를 수행하는 페이지

�</tr>

<tr><td>패스워드 : </td>

<td><input type=password name=Password size=20 value=""></td>

</tr>

<tr><td colspan= 2 align=center><input type="submit" value= "로그인" id=submit1 name=submit1>

<input type="reset" value="취소하기" id=reset name=reset></td>

</tr>

</table>

</form>

</BODY>

</HTML>

<!--#include file="auth.asp"--><!--#include virtual="/include/connection.inc"--><%

%>관리자 페이지 입니다.

<PHP 보안 템플릿>

<?

//각 디렉토리별로 권한을 설정할 수 있다.

//권한은 admin, user, unknown 세가지 권한으로 나누며 admin은 IP Address과 로그인인증, user는 로그

인인증, unknown은 모두 접근이 가능하다.

$UserGrade = "admin";

@session_start();

//권한 검사

if ($UserGrade != $_SESSION["user_grade"]) {

print "권한 없음";

Page 80: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │75

제5장

접근

통제

보안

템플

릿

웹어플리케이션보안템플릿

/admin/login.php : 로그인 인증을 거친 후 auth.php에서 사용할 세션값을 설정하는 페이지

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

}

else {

if ($UserGrade == "admin") {

//IP 주소 검사

if (eregi($_SESSION["access_ip"], $_SERVER["REMOTE_ADDR"] ) == false) {

print "IP: 접근 제한";

exit

}

else {

//로그인 여부 조사

if (isset($_SESSION["logged_id"])) {

print "로그인: 접근 제한";

exit;

}

}

} else if ($UserGrade == "user") {

if ($_SESSION["user_id"] == "") {

print "권한 없음";

exit;

}

}

}

?>

<?

require_once "../include/lib.php";

require_once "../include/secure.inc";

@session_start();

$connect=db_connect();

$mb_table = "userinfo";

$user_id = getFilter($user_id);

$password = getFilter($user_pw);

Page 81: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

76│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

사용예) /admin/admin.php : auth.php를 include 하여 사용자 권한 검사

설정하고자 하는 디렉토리에 auth.php 생성

해당 디렉토리에 있는 접근 설정이 필요한 페이지에 아래 내용을 추가한다.

�if(!$user_id) print ("아이디를 입력하여 주십시요");

if(!$password) print ("비 번호를 입력하여 주십시요");

// 회원 로그인 체크

$result = mysql_query("select id,user_id,password from $mb_table where user_id='$user_id'");

$mb_data = mysql_fetch_array($result);

if($mb_data[password] == $password) {

// 회원로그인이 성공하 을 경우 세션을 생성하고 페이지를 이동함

//로그인 후 프로세스

$logged_in = 1;

session_register("logged_in");

session_register("user_id");

$user_grade = "admin";

session_register("user_grade");

$access_ip = "222.234.226.";

session_register("access_ip");

print "로그인 성공";

}

else { // 회원로그인이 실패하 을 경우 에러 표시

print ("로그인 실패");

}

db_close($connect);

?>

<?

include "auth.php";

?>

Page 82: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │77

제5장

접근

통제

보안

템플

릿

웹어플리케이션보안템플릿

/admin/auth.jsp : 접근통제할 페이지 초기에 include 하여 권한 검사를 수행하는 페이지

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

<%@ page language="java" import="java.sql.*,java.util.*" contentType="text/html;charset=KSC5601" %>

<%@ page import="java.util.*,java.lang.*,java.io.*,java.sql.*,java.text.*" %>

<%

HttpSession sess = request.getSession(true);

String access_ip = request.getRemoteAddr();

String admin_ip = (String)sess.getValue("admin_ip");

String UserGrade = "admin";

//권한 검사

if (UserGrade.equals(sess.getValue("user_grade"))) {

if (UserGrade.equals("admin")) {

//IP 검사

if (access_ip.indexOf(admin_ip) != -1) {

if (sess.getValue("logged_in").equals("")) {

out.println("권한 없음");

return;

}

}

else {

out.println("권한 없음");

return

}

}

else if (UserGrade.equals("user")) {

if (sess.getValue("user_id").equals("")) {

out.println("권한 없음");

return;

}

}

}

<JSP 보안 템플릿>

Page 83: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

78│ www.kisa.or.kr

제1 장 SQL Injection 보안템플릿 제2 장 업로드보안템플릿 제3 장 다운로드보안템플릿

/admin/login.jsp : 로그인 인증을 거친 후 auth.jsp에서 사용할 세션값을 설정하는 페이지

�else {

out.println("권한 없음");

return;

}

%>

<%@ page language="java" import="java.sql.*,java.util.*" contentType="text/html;charset=KSC5601" %>

<%@ include file="conn_db.jsp" %>

<%@ include file="secure.jsp" %>

<%

String s_tablename = "user"; // 테이블 이름

String s_id, s_pw, s_name; //SQL 구문 실행 결과값 저장

String g_id, g_pw; //입력값 저장

String s_sql, grade;

g_id = getFilter(request.getParameter("id"));

g_pw = getFilter(request.getParameter("pw"));

HttpSession sess = request.getSession(true);

try {

s_sql = "SELECT * FROM " + s_tablename + " WHERE id='" + g_id + "'";

rs = stmt.executeQuery(s_sql); // 쿼리문 실행 결과 값을 담을 객체

if (rs.next()) {

s_id = rs.getString(1);

s_pw = rs.getString(2);

s_name = rs.getString(3);

if (s_pw.equals(g_pw)) {

Page 84: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

www.krcert.or.kr │79

제5장

접근

통제

보안

템플

릿

웹어플리케이션보안템플릿

사용 예)/admin/admin.jsp : auth.jsp를 include 하여 사용자 권한 검사

설정하고자 하는 디렉토리에 auth.jsp 생성

해당 디렉토리에 있는 접근 설정이 필요한 페이지에 아래 내용을 추가한다.

제4장Cross Site Script (XSS) 보안템플릿 제5 장 접근통제보안템플릿

//로그인 후 처리 프로세스

sess.putValue("logged_in","1");

sess.putValue("user_id",s_id);

sess.putValue("admin_ip", "222.234.226.");

sess.putValue("user_grade", "admin");

out.println("로그인 성공");

}

else {

//로그인 실패 시 처리 프로세스

out.println("로그인 실패:패스워드 오류");

}

}

else {

//로그인 실패 시 처리 프로세스

out.println("로그인 실패: 사용자 없음");

}

//DB 처리

stmt.close(); // 인클루드 파일(db_conn.Jsp)에서 생성한 stmt 닫기

Conn.close(); // 인클루드 파일(db_conn.jsp)에서 생성한 Conn 닫기

} catch (Exception e) {

out.println(e);

}

%>

<%@ page language="java" import="java.sql.*,java.util.*" contentType="text/html;charset=KSC5601" %>

<%@ include file="auth.jsp" %>

Page 85: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

80│ www.kisa.or.kr

[1] 한국정보보호진흥원, 홈페이지 개발 보안 가이드, 2005

[2] http://www.kisa.or.kr/

[3] http://www.krcert.or.kr/

[4] http://www.innoboard.com/

[5] http://www.nzeo.com/ http://www.php.net/

[6] http://www.taeyo.pe.kr/

[7] http://www.okjsp.pe.kr/

[8] http://www.itmembers.net/

[9] http://www.php.net/

[10] http://www.owasp.org/

참 고 문 헌

Page 86: 웹어플리케이션보안템플릿 - pds10.egloos.compds10.egloos.com/pds/200809/25/90/060622_template.pdf · 2│ ★ 제1 장SQL Injection보안템플릿 제2 장업로드보안템플릿

2006년 6월 인쇄

2006년 6월 발행

발행인 이홍섭

발행처 한국정보보호진흥원

서울시 송파구 가락동 78번지 IT벤처타워(서관)

TEL. (02)4055-114, http://www.kisa.or.kr

인쇄처 호정씨앤피(Tel 02-2277-4718)

※ 본 템플릿 내용의 무단전재를 금하며, 가공∙인용할 때에는 반드시

한국정보보호진흥원『웹 어플리케이션 보안 템플릿』을 명기하여

주시기 바랍니다. 단, 본 템플릿의 프로그램 소스 코드는 자유로이

사용 하실 수 있습니다.