Senin, 17 Desember 2012

[PHP] adf.ly Link Extract ( showcase )

[PHP] adf.ly Link Extract ( showcase )
Misi om.. maling

Ane mau sharing nih konsepnya buat crawl link. Kebetulan ane ambil contoh dari situs adf.ly seneng

Source :
PHP Code:
<?php/**
 * adf.ly Link Extractor
 *
 * This program used to extract link behind adf.ly advertise link.
 * Still very early release, just for fun coding purpose :)
 * coded by devilzc0der
 *
 * Usage : new adfLyExtract($argv);
 */
class adfLyExtract{
    const 
0.01// this is the program version
    
var $reqLib = array('curl_init''fopen''fread''get_headers');
   
    
/* Contructor. Check compability, set up arguments, print banner and execute main program. */
    
function __construct($opts) {
       
        
$this->checkReqLib();
       
        
$cmd $this->arguments($opts);
        print 
$this->banner();
       
        
/* Print help screen then exit if list param is not set */
        
if ( !array_key_exists('list'$cmd) )
            exit( 
$this->usage($cmd['input'][0]) );
       
        if ( 
$this->cekFile($cmd['list']) )
            
$this->readData($cmd['list']);
        else print 
$this->crot(" [!] Data is not exist or not wirtable!"'red') . "\n";
    }
   
    
// check function compability
    
function checkReqLib() {
        
$ok 1;
        foreach( 
$this->reqLib as $func ) {
            if ( !
function_exists($func) ) {
                print 
'You need function ' $this->crot($func,'cyan') . " to execute this tool!\n";
                
$ok 0;
            }
        }
        if ( !
$ok ) exit;
    }
   
    
/* The cool banner */
    
function banner() {
        
$msg " ________________________________________________________\n";
        
$msg .= "|         mm                                             |\n";
        
$msg .= "|      /^(  )^\   adf.ly Link Extractor " .  $this->crot('v' self::V,'cyan') . "            |\n";
        
$msg .= "|      \,(..),/   This program used to extract link      |\n";
        
$msg .= "|        V~~V     behind " $this->crot('adf.ly''red') . " advertise link.          |\n";
        
$msg .= "|  Coded by devilzc0der, just for fun coding purpose. :) |\n";
        
$msg .= "|________________________________________________________|\n\n";
        return 
$msg;
    }
   
    
/* Help Screen */
    
function usage($file) {
        
$msg "\nUsage : ";
        
$msg .= $file " --list=[list]\n";
        
$msg .= "Example : ";
        
$msg .= $file " --list=/home/dit/linklist.txt -v\n";
        return 
$msg;
    }
   
    
/**
     * Check list file
     * @return bool. TRUE if file exists and readable.
     */
    
function cekFile ($file) {
        if ( !
is_file($file) || !is_readable($file) ) return false;
        else return 
true;
    }
   
    
/* Check adf.ly link */
    
function dovalidLink($link) {
        return 
preg_match("|^http://adf.ly/+([a-z0-9-]+)?$|i"$link);
    }
   
    
/**
     * Read target data
     * @return string.
     */
    
function readData ($file) {
        
$msg NULL;
        
$read fopen($file"r");
        
$msg .= fread($readfilesize($file));
        
$link explode("\n"$msg);
        for (
$i 0$i count($link); $i++) {
            if ( !empty(
$link[$i]) ) {
                print 
" " $link[$i];
                if ( 
$this->dovalidLink($link[$i]) )
                    
$this->con_host($link[$i]);
                else
                    print 
" " $this->crot('[FAILED]''red') . " => Invalid adf.ly Link! \t[SKIP]\n";
            }
        }
        
fclose($read);
        return 
$msg;
    }
   
    function 
con_host($host) {
        
$ch curl_init($host);
       
        
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        
curl_setopt($chCURLOPT_TIMEOUT200);
        
curl_setopt($chCURLOPT_HEADER1);
        
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        // curl_setopt($ch, CURLOPT_REFERER, "http://devilzc0de.org/");
        
curl_setopt($chCURLOPT_USERAGENT'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9; Mozilla Firefox');
        
$pg curl_exec($ch);
        if (
$pg) {
            if ( 
preg_match("/http\/1\.1 200 ok/i"$pg) ) {
                
preg_match_all('/var url = \'(.*)\';/isU',$pg$exploit);
                if ( 
$exploit[1][0] ) {
                    
$check get_headers('http://adf.ly' $exploit[1][0], 1);
                    if ( !empty(
$check) )
                        if (
preg_match('/301/'$check[0]) || preg_match('/302/'$check[0]) )
                            print 
' ' $this->crot('[OK]','cyan') . ' => ' $this->crot($check['Location'],'l_cyan') . "\n";
                    else
                        print 
"\t No repsond from server.\n";
                }
            }
            else
                print 
" " $this->crot('[FAILED]','red') . " => Invalid HTTP header respond!\n";
           
        }
        else
            return 
false;
    }
   
   
   
    
/**
     * Make UNIX like parameter command.
     * This function from losbrutos and modified by earomero. Thankyou. =)
     * @author losbrutos <losbrutos@free.fr>
     * @author earomero <earomero@gmail.com>
     * @param array argv
     * @return array
     */
    
function arguments($argv) {
        
$_ARG = array();
        foreach (
$argv as $arg) {
            if (
preg_match('#^-{1,2}([a-zA-Z0-9]*)=?(.*)$#'$arg$matches)) {
                
$key $matches[1];
                switch (
$matches[2]) {
                    case 
'':
                    case 
'true':
                    
$arg true;
                    break;
                    case 
'false':
                    
$arg false;
                    break;
                    default:
                    
$arg $matches[2];
                }
               
                
// make unix like -afd == -a -f -d
                
if(preg_match("/^-([a-zA-Z0-9]+)/"$matches[0], $match)) {
                    
$string $match[1];
                    for(
$i=0strlen($string) > $i$i++) {
                        
$_ARG[$string[$i]] = true;
                    }
                } else {
                    
$_ARG[$key] = $arg;
                }
            } else {
                
$_ARG['input'][] = $arg;
            }
        }
        return 
$_ARG;
    }
   
    
/**
     * Function to print colorful output to terminal.
     * @param string    $string    String to be colored.
     * @param string    $fontColor The available color
     *        Available color :
     *                  black, dark_gray, blue, green, l_green, cyan, l_cyan
     *                  red, l_red, purple, l_purple, brown, yellow, l_gray,
     *                  white.
     * @return string
     */
    
private function crot($string$fontColor=NULL) {
        switch (
$fontColor) {
            case 
'black' $color '0;30'; break;
            case 
'dark_gray' $color '1;30'; break;
            case 
'blue' $color '0;34'; break;
            case 
'l_blue' $color '1;34'; break;
            case 
'green' $color '0;32'; break;
            case 
'l_green' $color '1;32'; break;
            case 
'cyan' $color '0;36'; break;
            case 
'l_cyan' $color '0;36'; break;
            case 
'red' $color '0;31'; break;
            case 
'l_red' $color '1;31'; break;
            case 
'purple' $color '0;35'; break;
            case 
'l_purple' $color '1;35'; break;
            case 
'brown' $color '0;33'; break;
            case 
'yellow' $color '1;33'; break;
            case 
'l_gray' $color '0;37'; break;
            case 
'white' $color '1;37'; break;
        }
        
$colored_string "";
        
$colored_string .= "\033[" $color "m";
        
$colored_string .=  $string "\033[0m";
        return 
$colored_string;
    }
}
?>

Sebenarnya dengan tau konsepnya melalui http header itu bikin link checker semacem short URL gitu.

Jadi kita ambil contoh dari link http://adf.ly/EPxj1
Biasa klo kita klik kan muncul tuh advertise2 dan kita harus nunggu sampai countdown di sebelah kanan atas selesai.
Setelah selesai, maka tombol countdown tadi bakal berubah jadi link wow

[Image: adfly01.png]

Kan ada tuh di sebelah kiri bawah link dimana klo tombol "Skip Ad" ditekan maka kita bakal menuju ke link tersebut.
Dalam kasus ane :
Quote:/go/806332b7d247abb48c24eff0ea43eb34/aHR0cDovL3d3dy56aWRkdS5jb20vZG93bmxvYWRsaW5rLzIwODA0NzkzL0d1bnNsaW5nZXIubXAz

Apaan tuh om? Klo di klik kaga ke situ tapi malah ke tempat download aslinya. ( Ziddu )
Ane juga ga tau.. ngakak
Tapi mari kita cari tau..
Caranya kita pake wget buat ambil respon header pada link tersebut ( Yg di windows ane kurang tau pakenya apa hammer )

Quote:wget -S --spider http://adf.ly/go/806332b7d247abb48c24eff0ea43eb34/aHR0cDovL3d3dy56aWRkdS5jb20vZG93bmxvYWRsaW5rLzIwODA0NzkzL0d1bnNsaW5nZXIubXAz

Image has been scaled down 9% (807x360). Click this bar to view original image (886x395). Click image to open in new window.
[Image: adfly03.png]

Perhatikan pada output yg ane lingkari merah.
Pertama : HTTP/1.1 302 Found
dan yg ke dua : Location: http://www.ziddu.com/downloadlink/20804793/Gunslinger.mp3

Apa sih HTTP 302 Found itu?
Yang ane dapet dari google sih itu maksudnya temporary redirect, yang bakal meneruskan request ( redirect ) ke lokasi yang baru. ( dalam hal ini pada Location : http://www.ziddu.com/downloadlink/20804793/Gunslinger.mp3 )


Nah dari situ kita bisa tau gimana prosesnya..
1. Kita kunjungi link http://adf.ly/EPxj1 (HTTP 200 OK )
PHP Code:
if ( preg_match("/http\/1\.1 200 ok/i"$pg) ) { // line 114 

2. Kita ambil link http://adf.ly/go/806332b7d247abb48c24eff0ea43eb34/aHR0cDovL3d3dy56aWRkdS5jb20vZG93bmxvYWRsaW5rLzIwODA0NzkzL0d1bnNsaW5nZXIubXAz ( HTTP 302 Found / temporary redirect )
[Image: adfly02.png]
PHP Code:
preg_match_all('/var url = \'(.*)\';/isU',$pg$exploit); // line 115 

3. Kita menuju ke link aslinya ( Location : http://www.ziddu.com/downloadlink/20804793/Gunslinger.mp3 )
PHP Code:
if (preg_match('/301/'$check[0]) || preg_match('/302/'$check[0]) ) // line 119 

Nah jadi kita tau kan cara kerjanya.
Silahkan dikembangkan om2 sekalian..

NB : Sekedar untuk sharing dan pembelajaran aja, tidak ada maksud lain.
Salam sayang dari ane.. cium

1 komentar:

  1. Are you looking to earn money from your visitors by popunder ads?
    In case you do, have you tried using Ero Advertising?

    BalasHapus