Quantcast
Channel: Comunidad Underground Hispana
Viewing all articles
Browse latest Browse all 11602

[Perl] Emails Extractor 0.2

$
0
0
Un simple script en Perl para buscar direcciones de correo en :

[+] Un archivo de texto cualquiera
[+] Una pagina
[+] Usando un dork en google para scanear todas las paginas encontradas con el dork
[+] Lo mismo que el anterior pero en bing

El codigo.

Código:

#!usr/bin/perl
#Email Extractor 0.2
#(C) Doddy Hackman 2013
#Credits : Regex based on
#http://stackoverflow.com/questions/15710275/print-email-addresses-to-a-file-in-perl
#Thanks to motherconfessor & amon

use LWP::UserAgent;
use URI::Escape;

my $nave = LWP::UserAgent->new;
$nave->agent(
"Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8.1.12) Gecko/20080201Firefox/2.0.0.12"
);
$nave->timeout(10);

my $buscador = qr/[A-Z0-9._%+-]+\@[A-Z0-9.-]+\.[A-Z]{2,4}/i
  ;    # Thanks to motherconfessor & amon
my @emails;

head();

if ( $ARGV[0] eq "-file" ) {

    print "\n[+] Opening file ...\n";

    if ( -f $ARGV[1] ) {

        my $code = openfile( $ARGV[1] );

        while ( $code =~ /($buscador)/g ) {
            my $email = $1;
            push( @emails, $email );
        }

        my @emails = repes(@emails);

        print "\n[+] Mails Found : " . int(@emails) . "\n";

        for (@emails) {
            savefile( $ARGV[2], $_ );
        }

    }
    else {
        print "\n[-] File not found\n";
    }

}
elsif ( $ARGV[0] eq "-google" ) {

    print "\n[+] Searching in Google ...\n";

    my @links = google( $ARGV[1], $ARGV[2] );

    print "[+] Scanning [" . int(@links) . "] pages ...\n";

    for my $ink (@links) {
        my $code = toma($ink);

        while ( $code =~ /($buscador)/g ) {
            my $email = $1;
            push( @emails, $email );
        }

    }

    my @emails = repes(@emails);

    print "\n[+] Mails Found : " . int(@emails) . "\n";

    for (@emails) {
        savefile( $ARGV[2], $_ );
    }

}
elsif ( $ARGV[0] eq "-bing" ) {

    print "\n[+] Searching in Bing ...\n";

    my @links = bing( $ARGV[1], $ARGV[2] );

    print "[+] Scanning [" . int(@links) . "] pages ...\n";

    for my $ink (@links) {
        my $code = toma($ink);

        while ( $code =~ /($buscador)/g ) {
            my $email = $1;
            push( @emails, $email );
        }

    }

    my @emails = repes(@emails);

    print "\n[+] Mails Found : " . int(@emails) . "\n";

    for (@emails) {
        savefile( $ARGV[3], $_ );
    }

}
elsif ( $ARGV[0] eq "-page" ) {

    my $code = toma( $ARGV[1] );

    print "\n[+] Loading page ...\n";

    while ( $code =~ /($buscador)/g ) {
        my $email = $1;
        push( @emails, $email );
    }

    my @emails = repes(@emails);

    print "\n[+] Mails Found : " . int(@emails) . "\n";

    for (@emails) {
        savefile( $ARGV[2], $_ );
    }

}
else {
    sintax();
}

copyright();

# Functions

sub bing {

    my ( $a, $b ) = @_;
    for ( $pages = 10 ; $pages <= $b ; $pages = $pages + 10 ) {
        my $code =
          toma( "http://www.bing.com/search?q=" . $a . "&first=" . $pages );

        while ( $code =~ /<h3><a href="(.*?)"/mig ) {
            push( @founds, $1 );
        }
    }
    my @founds = repes( cortar(@founds) );
    return @founds;
}

sub google {
    my ( $a, $b ) = @_;
    my @founds;
    for ( $pages = 10 ; $pages <= $b ; $pages = $pages + 10 ) {
        $code = toma(
            "http://www.google.com.ar/search?hl=&q=" . $a . "&start=$pages" );
        while ( $code =~ /(?<="r"><. href=")(.+?)"/mig ) {
            my $url = $1;
            if ( $url =~ /\/url\?q\=(.*?)\&amp\;/ ) {
                push( @founds, uri_unescape($1) );
            }
        }
    }
    my @founds = repes( cortar(@founds) );
    return @founds;
}

sub cortar {
    my @nuevo;
    for (@_) {
        if ( $_ =~ /=/ ) {
            @tengo = split( "=", $_ );
            push( @nuevo, @tengo[0] . "=" );
        }
        else {
            push( @nuevo, $_ );
        }
    }
    return @nuevo;
}

sub toma {
    return $nave->get( $_[0] )->content;
}

sub savefile {

    if ( $_[0] eq "" ) {
        open( SAVE, ">>logs.txt" );
    }
    else {
        open( SAVE, ">>" . $_[0] );
    }

    print SAVE $_[1] . "\n";
    close SAVE;
}

sub openfile {
    open my $FILE, q[<], $_[0];
    my $word = join q[], <$FILE>;
    close $FILE;
    return $word;
}

sub repes {
    my @limpio;
    foreach $test (@_) {
        push @limpio, $test unless $repe{$test}++;
    }
    return @limpio;
}

sub sintax {
    print "\n[+] Sintax : $0 <options> <logs>\n";
    print "\n[+] Examples : \n\n";
    print "[+] $0 -file test.txt logs.txt\n";
    print "[+] $0 -google 50 mailist logs.txt\n";
    print "[+] $0 -bing 50 mailist logs.txt\n";
    print "[+] $0 -page http://localhost/index.php logs.txt\n";
}

sub head {
    print "\n-- == Email Extractor 0.2 == --\n";
}

sub copyright {
    print "\n-- == (C) Doddy Hackman 2013 == --\n\n";
    exit(1);
}

#The End ?

Mostraria un ejemplo de uso pero puedo tener problemas cuando el script devuelve como 500 mails ajenos claramente para spam xD.

Viewing all articles
Browse latest Browse all 11602

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>