Advertisement
ditatompel

adf.ly link extract

Nov 8th, 2012
558
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.27 KB | None | 0 0
  1. <?php
  2. /**
  3.  * adf.ly Link Extractor
  4.  *
  5.  * This program used to extract link behind adf.ly advertise link.
  6.  * Still very early release, just for fun coding purpose :)
  7.  * coded by devilzc0der
  8.  *
  9.  * Usage : new adfLyExtract($argv);
  10.  */
  11.  
  12. class adfLyExtract
  13. {
  14.     const V = 0.01; // this is the program version
  15.     var $reqLib = array('curl_init', 'fopen', 'fread', 'get_headers');
  16.    
  17.     /* Contructor. Check compability, set up arguments, print banner and execute main program. */
  18.     function __construct($opts) {
  19.        
  20.         $this->checkReqLib();
  21.        
  22.         $cmd = $this->arguments($opts);
  23.         print $this->banner();
  24.        
  25.         /* Print help screen then exit if list param is not set */
  26.         if ( !array_key_exists('list', $cmd) )
  27.             exit( $this->usage($cmd['input'][0]) );
  28.        
  29.         if ( $this->cekFile($cmd['list']) )
  30.             $this->readData($cmd['list']);
  31.         else print $this->crot(" [!] Data is not exist or not wirtable!", 'red') . "\n";
  32.     }
  33.    
  34.     // check function compability
  35.     function checkReqLib() {
  36.         $ok = 1;
  37.         foreach( $this->reqLib as $func ) {
  38.             if ( !function_exists($func) ) {
  39.                 print 'You need function ' . $this->crot($func,'cyan') . " to execute this tool!\n";
  40.                 $ok = 0;
  41.             }
  42.         }
  43.         if ( !$ok ) exit;
  44.     }
  45.    
  46.     /* The cool banner */
  47.     function banner() {
  48.         $msg = " ________________________________________________________\n";
  49.         $msg .= "|         mm                                             |\n";
  50.         $msg .= "|      /^(  )^\   adf.ly Link Extractor " .  $this->crot('v' . self::V,'cyan') . "            |\n";
  51.         $msg .= "|      \,(..),/   This program used to extract link      |\n";
  52.         $msg .= "|        V~~V     behind " . $this->crot('adf.ly', 'red') . " advertise link.          |\n";
  53.         $msg .= "|  Coded by devilzc0der, just for fun coding purpose. :) |\n";
  54.         $msg .= "|________________________________________________________|\n\n";
  55.         return $msg;
  56.     }
  57.    
  58.     /* Help Screen */
  59.     function usage($file) {
  60.         $msg = "\nUsage : ";
  61.         $msg .= $file . " --list=[list]\n";
  62.         $msg .= "Example : ";
  63.         $msg .= $file . " --list=/home/dit/linklist.txt -v\n";
  64.         return $msg;
  65.     }
  66.    
  67.     /**
  68.      * Check list file
  69.      * @return bool. TRUE if file exists and readable.
  70.      */
  71.     function cekFile ($file) {
  72.         if ( !is_file($file) || !is_readable($file) ) return false;
  73.         else return true;
  74.     }
  75.    
  76.     /* Check adf.ly link */
  77.     function dovalidLink($link) {
  78.         return preg_match("|^http://adf.ly/+([a-z0-9-]+)?$|i", $link);
  79.     }
  80.    
  81.     /**
  82.      * Read target data
  83.      * @return string.
  84.      */
  85.     function readData ($file) {
  86.         $msg = NULL;
  87.         $read = fopen($file, "r");
  88.         $msg .= fread($read, filesize($file));
  89.         $link = explode("\n", $msg);
  90.         for ($i = 0; $i < count($link); $i++) {
  91.             if ( !empty($link[$i]) ) {
  92.                 print " " . $link[$i];
  93.                 if ( $this->dovalidLink($link[$i]) )
  94.                     $this->con_host($link[$i]);
  95.                 else
  96.                     print " " . $this->crot('[FAILED]', 'red') . " => Invalid adf.ly Link! \t[SKIP]\n";
  97.             }
  98.         }
  99.         fclose($read);
  100.         return $msg;
  101.     }
  102.    
  103.     function con_host($host) {
  104.         $ch = curl_init($host);
  105.        
  106.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  107.         curl_setopt($ch, CURLOPT_TIMEOUT, 200);
  108.         curl_setopt($ch, CURLOPT_HEADER, 1);
  109.         // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  110.         // curl_setopt($ch, CURLOPT_REFERER, "http://devilzc0de.org/");
  111.         curl_setopt($ch, CURLOPT_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');
  112.         $pg = curl_exec($ch);
  113.         if ($pg) {
  114.             if ( preg_match("/http\/1\.1 200 ok/i", $pg) ) {
  115.                 preg_match_all('/var url = \'(.*)\';/isU',$pg, $exploit);
  116.                 if ( $exploit[1][0] ) {
  117.                     $check = get_headers('http://adf.ly' . $exploit[1][0], 1);
  118.                     if ( !empty($check) )
  119.                         if (preg_match('/301/', $check[0]) || preg_match('/302/', $check[0]) )
  120.                             print ' ' . $this->crot('[OK]','cyan') . ' => ' . $this->crot($check['Location'],'l_cyan') . "\n";
  121.                     else
  122.                         print "\t No repsond from server.\n";
  123.                 }
  124.             }
  125.             else
  126.                 print " " . $this->crot('[FAILED]','red') . " => Invalid HTTP header respond!\n";
  127.            
  128.         }
  129.         else
  130.             return false;
  131.     }
  132.    
  133.    
  134.    
  135.     /**
  136.      * Make UNIX like parameter command.
  137.      * This function from losbrutos and modified by earomero. Thankyou. =)
  138.      * @author losbrutos <losbrutos@free.fr>
  139.      * @author earomero <earomero@gmail.com>
  140.      * @param array argv
  141.      * @return array
  142.      */
  143.     function arguments($argv) {
  144.         $_ARG = array();
  145.         foreach ($argv as $arg) {
  146.             if (preg_match('#^-{1,2}([a-zA-Z0-9]*)=?(.*)$#', $arg, $matches)) {
  147.                 $key = $matches[1];
  148.                 switch ($matches[2]) {
  149.                     case '':
  150.                     case 'true':
  151.                     $arg = true;
  152.                     break;
  153.                     case 'false':
  154.                     $arg = false;
  155.                     break;
  156.                     default:
  157.                     $arg = $matches[2];
  158.                 }
  159.                
  160.                 // make unix like -afd == -a -f -d
  161.                 if(preg_match("/^-([a-zA-Z0-9]+)/", $matches[0], $match)) {
  162.                     $string = $match[1];
  163.                     for($i=0; strlen($string) > $i; $i++) {
  164.                         $_ARG[$string[$i]] = true;
  165.                     }
  166.                 } else {
  167.                     $_ARG[$key] = $arg;
  168.                 }
  169.             } else {
  170.                 $_ARG['input'][] = $arg;
  171.             }
  172.         }
  173.         return $_ARG;
  174.     }
  175.    
  176.     /**
  177.      * Function to print colorful output to terminal.
  178.      * @param string    $string    String to be colored.
  179.      * @param string    $fontColor The available color
  180.      *        Available color :
  181.      *                  black, dark_gray, blue, green, l_green, cyan, l_cyan
  182.      *                  red, l_red, purple, l_purple, brown, yellow, l_gray,
  183.      *                  white.
  184.      * @return string
  185.      */
  186.     private function crot($string, $fontColor=NULL) {
  187.         switch ($fontColor) {
  188.             case 'black' : $color = '0;30'; break;
  189.             case 'dark_gray' : $color = '1;30'; break;
  190.             case 'blue' : $color = '0;34'; break;
  191.             case 'l_blue' : $color = '1;34'; break;
  192.             case 'green' : $color = '0;32'; break;
  193.             case 'l_green' : $color = '1;32'; break;
  194.             case 'cyan' : $color = '0;36'; break;
  195.             case 'l_cyan' : $color = '0;36'; break;
  196.             case 'red' : $color = '0;31'; break;
  197.             case 'l_red' : $color = '1;31'; break;
  198.             case 'purple' : $color = '0;35'; break;
  199.             case 'l_purple' : $color = '1;35'; break;
  200.             case 'brown' : $color = '0;33'; break;
  201.             case 'yellow' : $color = '1;33'; break;
  202.             case 'l_gray' : $color = '0;37'; break;
  203.             case 'white' : $color = '1;37'; break;
  204.         }
  205.         $colored_string = "";
  206.         $colored_string .= "\033[" . $color . "m";
  207.         $colored_string .=  $string . "\033[0m";
  208.         return $colored_string;
  209.     }
  210. }
  211. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement