관리자 세션을 악용할 수 있는 img, embed, input등의 src 값 변조 시도를 사전 제거하는 코드 추가

git-svn-id: http://xe-core.googlecode.com/svn/sandbox@4354 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
zero 2008-07-14 08:15:57 +00:00
parent de22070cee
commit a557a12e42
3 changed files with 44 additions and 20 deletions

View file

@ -1022,17 +1022,10 @@
/**
* @brief 내용의 에디터 컴포넌트 코드를 변환
**/
function _fixQuotation($matches) {
$key = $matches[1];
$val = $matches[2];
if(substr($val,0,1)!='"') $val = '"'.$val.'"';
return sprintf('%s=%s', $key, $val);
}
function transEditorComponent($matches) {
// IE에서는 태그의 특성중에서 " 를 빼어 버리는 경우가 있기에 정규표현식으로 추가해줌
$buff = $matches[0];
$buff = preg_replace_callback('/([^=^"^ ]*)=([^ ^>]*)/i', array($this, _fixQuotation), $buff);
$buff = preg_replace_callback('/([^=^"^ ]*)=([^ ^>]*)/i', fixQuotation, $buff);
$buff = str_replace("&","&",$buff);
// 에디터 컴포넌트에서 생성된 코드

View file

@ -416,6 +416,9 @@
// XSS 사용을 위한 이벤트 제거
$content = preg_replace_callback("!<([a-z]+)(.*?)>!is", removeJSEvent, $content);
// 이미지나 동영상등의 태그에서 src에 관리자 세션을 악용하는 코드를 제거
$content = preg_replace_callback("!<([a-z]+)(.*?)>!is", removeSrcHack, $content);
return $content;
}
@ -425,6 +428,45 @@
return preg_replace('/ on([a-z]+)=/i',' _on$1=',$matches[0]);
}
function removeSrcHack($matches) {
$tag = $matches[1];
$buff = trim(preg_replace('/(\/>|>)/','/>',$matches[0]));
$buff = preg_replace_callback('/([^=^"^ ]*)=([^ ^>]*)/i', fixQuotation, $buff);
$oXmlParser = new XmlParser();
$xml_doc = $oXmlParser->parse($buff);
// src값에 module=admin이라는 값이 입력되어 있으면 이 값을 무효화 시킴
$src = $xml_doc->{$tag}->attrs->src;
if($src) {
$url_info = parse_url($src);
$query = $url_info['query'];
$queries = explode('&', $query);
$cnt = count($queries);
for($i=0;$i<$cnt;$i++) {
$pos = strpos($queries[$i],'=');
if($pos === false) continue;
$key = strtolower(trim(substr($queries[$i], 0, $pos)));
$val = strtolower(trim(substr($queries[$i] ,$pos+1)));
if(($key == 'module' && $val == 'admin') || $key == 'act' && preg_match('/admin/i',$val)) return sprintf("<%s>",$tag);
}
}
return $matches[0];
}
/**
* @brief attribute의 value를 " 로 둘러싸도록 처리하는 함수
**/
function fixQuotation($matches) {
$key = $matches[1];
$val = $matches[2];
if(substr($val,0,1)!='"') $val = '"'.$val.'"';
return sprintf('%s=%s', $key, $val);
}
// hexa값을 RGB로 변환
if(!function_exists('hexrgb')) {
function hexrgb($hexstr) {

View file

@ -72,7 +72,7 @@
$this->target_path = $path;
// element의 속성중 value에 " 로 안 묶여 있는 것을 검사하여 묶어줌
$content = preg_replace_callback('/([^=^"^ ]*)=([^ ^>]*)/i', array($this, '_fixQuotation'), $content);
$content = preg_replace_callback('/([^=^"^ ]*)=([^ ^>]*)/i', fixQuotation, $content);
// img, input, a, link등의 href, src값 변경
$content = preg_replace_callback('!(script|link|a|img|input)([^>]*)(href|src)=[\'"](.*?)[\'"]!is', array($this, '_replaceSrc'), $content);
@ -104,16 +104,5 @@
$buff = sprintf('url(%s)', $href);
return $buff;
}
/**
* @brief 태그의 속성에 " 를 추가
**/
function _fixQuotation($matches) {
$key = $matches[1];
$val = $matches[2];
if(substr($val,0,1)!='"') $val = '"'.$val.'"';
return sprintf('%s=%s', $key, $val);
}
}
?>