Advertisement
Doddy

[Perl] DH Spider 0.5

Oct 13th, 2016
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6.74 KB | None | 0 0
  1. #!usr/bin/perl
  2. # DH Spider 0.5
  3. #(C) Doddy Hackman 2016
  4. #Credits : Regex based on
  5. #http://stackoverflow.com/questions/15710275/print-email-addresses-to-a-file-in-perl
  6. #Thanks to motherconfessor & amon
  7. #http://doddyhackman.webcindario.com/?tipo=perl&id=137
  8.  
  9. use DH_Searcher;
  10. use LWP::UserAgent;
  11. use IO::Socket::SSL;
  12. use Getopt::Long;
  13. use Color::Output;
  14. Color::Output::Init;
  15. use Try::Tiny;
  16.  
  17. my @agents = (
  18. 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0',
  19.     'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14',
  20. 'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36',
  21. 'Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0',
  22. 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.8pre) Gecko/20070928 Firefox/2.0.0.7 Navigator/9.0RC1',
  23.     'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))',
  24. 'Mozilla/5.0 (Windows NT 6.0; rv:2.0) Gecko/20100101 Firefox/4.0 Opera 12.14',
  25. 'Mozilla/5.0 (Windows; U; Windows NT 6.1; tr-TR) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'
  26. );
  27.  
  28. my $buscador = qr/[A-Z0-9._%+-]+\@[A-Z0-9.-]+\.[A-Z]{2,4}/i; # Thanks to motherconfessor & amon
  29.  
  30. GetOptions(
  31.     "google"   => \$google,
  32.     "bing"  => \$bing,
  33.     "dork=s"  => \$dork,
  34.     "count=i"  => \$count,
  35.     "filename=s"   => \$filename,
  36.     "page=s"   => \$page,    
  37.     "savefile=s"   => \$savefile
  38. );
  39.  
  40. head();
  41.  
  42. if ($google) {
  43.     if($dork ne "" && $count ne "") {
  44.         dh_spider($dork,$count,"","google");
  45.     } else {
  46.         printear("[-] Use dork and count to scan in google\n");
  47.     }
  48. }
  49. elsif ($bing) {
  50.     if($dork ne "" && $count ne "") {
  51.         dh_spider($dork,$count,"","bing");
  52.     } else {
  53.         printear("[-] Use dork and count to scan in google\n");
  54.     }
  55. }
  56. elsif ($filename) {
  57.     if(-f $filename) {
  58.         dh_spider("","",$filename,"filename");
  59.     } else {
  60.         printear_rojo("[-] File $filename not found\n");
  61.     }
  62. } elsif($page) {
  63.     if($page ne "") {
  64.         dh_spider_single($page);
  65.     }
  66. } else {
  67.     sintax();
  68. }
  69.  
  70. copyright();
  71.  
  72. # Functions
  73.  
  74. sub dh_spider_single {
  75.     my $page = shift;
  76.     my $contador = "0";
  77.     my $algo = 0;
  78.     my @emails_found;
  79.     printear_logo("[+] Searching emails in page ...\n\n");
  80.     my $code = toma($page);
  81.     while ( $code =~ /($buscador)/g ) {
  82.         my $email = $1;
  83.         push( @emails, $email );
  84.         printear_titulo("[+] $page : ");
  85.         printear_azul("$email\n");
  86.         $algo = 1;
  87.         $contador++;
  88.         push(@emails_found,$email);
  89.     }
  90.     if($algo ne "1") {
  91.         printear_titulo("[-] $page : ");
  92.         printear_rojo("Emails not found\n");           
  93.     }
  94.     $algo = 0;
  95.     printear("\n[+] Emails Found : ");
  96.     print "$contador\n";
  97.     if($savefile && $contador > 0) {
  98.         my @emails = repes(@emails_found);
  99.         for my $email(@emails) {
  100.             chomp $mail;
  101.             savefile($savefile,$email);
  102.         }
  103.         printear("\n[+] Logs $savefile saved\n");
  104.     }
  105.     printear_logo("\n[+] Finished\n");
  106. }
  107.  
  108. sub dh_spider {
  109.     my($dork,$count,$filename,$option) = @_;
  110.    
  111.     my $contador = "0";
  112.     my $algo = 0;
  113.    
  114.     my @links;
  115.     my @emails_found;
  116.    
  117.     my $searcher = DH_Searcher->new();
  118.    
  119.     if($option eq "filename") {
  120.         printear("[+] Opening file : ");
  121.         print "$filename\n\n";
  122.         @links = open_file($filename);
  123.     } elsif($option eq "bing") {
  124.         printear("[+] Service : ");
  125.         print "Bing\n";
  126.         printear("[+] Dork : ");
  127.         print "$dork\n";
  128.         printear("[+] Count : ");
  129.         print "$count\n\n";
  130.         printear_logo("[+] Searching pages ...\n\n");
  131.         @links = $searcher->search_bing($dork,$count*10);
  132.     } elsif($option eq "google") {
  133.         printear("[+] Service : ");
  134.         print "Google\n";
  135.         printear("[+] Dork : ");
  136.         print "$dork\n";
  137.         printear("[+] Count : ");
  138.         print "$count\n\n";
  139.         printear_logo("[+] Searching pages ...\n\n");
  140.         @links = $searcher->search_google($dork,$count*10);
  141.     }
  142.        
  143.     printear("[+] Links found : ");
  144.     print int(@links)."\n\n";
  145.     printear_logo("[+] Searching emails ...\n\n");
  146.     for my $link(@links) {
  147.         chomp $link;
  148.         my $code = toma($link);
  149.         while ( $code =~ /($buscador)/g ) {
  150.             my $email = $1;
  151.             push( @emails, $email );
  152.             printear_titulo("[+] $link : ");
  153.             printear_azul("$email\n");
  154.             $algo = 1;
  155.             $contador++;
  156.             push(@emails_found,$email);
  157.         }
  158.         if($algo ne "1") {
  159.             printear_titulo("[-] $link : ");
  160.             printear_rojo("Emails not found\n");           
  161.         }
  162.         $algo = 0;     
  163.     }
  164.     printear("\n[+] Emails Found : ");
  165.     print "$contador\n";
  166.     if($savefile && $contador > 0) {
  167.         my @emails = repes(@emails_found);
  168.         for my $email(@emails) {
  169.             chomp $mail;
  170.             savefile($savefile,$email);
  171.         }
  172.         printear("\n[+] Logs $savefile saved\n");
  173.     }
  174.     printear_logo("\n[+] Finished\n");
  175.     $searcher->destroy();
  176. }
  177.  
  178. # More Functions
  179.  
  180. sub toma {
  181.    
  182.     my $page = shift;
  183.    
  184.     my $contenido = "";
  185.    
  186.     if($page ne "") {
  187.         try {
  188.             my $nave = LWP::UserAgent->new(ssl_opts => {verify_hostname => 0,SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE});
  189.             $nave->agent( $agents[ rand @agents ] );
  190.             $nave->timeout($timeout);
  191.             $contenido = $nave->get($page)->content;
  192.         } catch {
  193.             $contenido = "Error";
  194.         };
  195.    
  196.     } else {
  197.         $contenido = "Error";
  198.     }
  199.    
  200.     return $contenido;
  201. }
  202.  
  203. sub open_file {
  204.     my $file = shift;
  205.     my @words;
  206.     open( FILE,$file);
  207.     @words = <FILE>;
  208.     close FILE;
  209.     return @words;
  210. }
  211.  
  212. sub repes {
  213.     my @limpio;
  214.     foreach $test (@_) {
  215.         push @limpio, $test unless $repe{$test}++;
  216.     }
  217.     return @limpio;
  218. }
  219.  
  220. sub savefile {
  221.     my ($filename,$text) = @_;
  222.     open( SAVE, ">>" . $filename );
  223.     print SAVE $text . "\n";
  224.     close SAVE;
  225. }
  226.  
  227. sub printear {
  228.     cprint( "\x036" . $_[0] . "\x030" );
  229. }
  230.  
  231. sub printear_logo {
  232.     cprint( "\x037" . $_[0] . "\x030" );
  233. }
  234.  
  235. sub printear_titulo {
  236.     cprint( "\x0310" . $_[0] . "\x030" );
  237. }
  238.  
  239. sub printear_rojo {
  240.     cprint( "\x035" . $_[0] . "\x030" );
  241. }
  242.  
  243. sub printear_azul {
  244.     cprint( "\x033" . $_[0] . "\x030" );
  245. }
  246.  
  247. sub sintax {
  248.  
  249.     printear("[+] Sintax : ");
  250.     print "perl $0 <option> <value>\n";
  251.     printear("\n[+] Options : \n\n");
  252.     print "-google -dork <dork> -count <count> : Find emails in google\n";
  253.     print "-bing -dork <dork> -count <count> : Find bing in google\n";
  254.     print "-filename <filename> : Find emails in filename with URLS\n";
  255.     print "-page <page> : Find emails in a single page\n";
  256.     print "-savefile <savefile> : Save emails in logs\n";
  257.     printear("\n[+] Example : ");
  258.     print "perl dh_spider.pl -bing -dork contacto.php -count 5 -savefile emails_found.txt\n";
  259.     copyright();
  260. }
  261.  
  262. sub head {
  263.     printear_logo("\n-- == DH Spider 0.5 == --\n\n\n");
  264. }
  265.  
  266. sub copyright {
  267.     printear_logo("\n\n-- == (C) Doddy Hackman 2016 == --\n\n");
  268.     exit(1);
  269. }
  270.  
  271. #The End ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement