[Perl] DH Twitter Locator 0.6

Iniciado por BigBear, 11 Noviembre 2016, 14:20 PM

0 Miembros y 1 Visitante están viendo este tema.

BigBear

Un script en Perl para scanear los tweets de cualquier usuario , basado en la idea original de "tinfoleak by Vicente Aguilera Diaz"

Funciones :

  • Extrae informacion del perfil
  • Scanea los tweets en busca de apps y locations
  • Permite cargar las localizaciones en google maps
  • Guarda todo en logs

    El codigo :

    Código (perl) [Seleccionar]

    # !usr/bin/perl
    # DH Twitter Locator 0.6
    # (C) Doddy Hackman 2016
    # Credits :
    # Based in idea original of : tinfoleak by Vicente Aguilera Diaz

    use LWP::UserAgent;
    use IO::Socket::SSL;
    use HTTP::Request::Common;
    use JSON;
    use Data::Dumper;
    use MIME::Base64;
    use Date::Parse;
    use DateTime;
    use Getopt::Long;
    use Color::Output;
    Color::Output::Init;

    my $consumer_key = "IQKbtAYlXLripLGPWd0HUA";
    my $consumer_secret = "GgDYlkSvaPxGxC4X8liwpUoqKwwr3lCADbz8A7ADU";

    my $bearer_token = "$consumer_key:$consumer_secret";
    my $bearer_token_64 = encode_base64($bearer_token);

    my $nave = LWP::UserAgent->new(ssl_opts => {verify_hostname => 0,SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE});
    $nave->agent(
    "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0"
    );
    $nave->timeout(5);

    GetOptions(
    "profile"   => \$profile,
    "apps"   => \$apps,
        "locations"  => \$locations,
        "username=s"   => \$username,
        "count=i"   => \$count,
        "savefile=s"  => \$savefile,
    );

    head();

    if ($profile) {
    if($profile && $username) {
    search_profile($username);
    } else {
    sintax();
    }
    }
    if ($apps) {
    if($apps && $username && $count) {
    search_apps($username,$count);
    } else {
    sintax();
    }
    }
    if ($locations) {
    if($locations && $username && $count) {
    search_locations($username,$count);
    } else {
    sintax();
    }
    }
    if(!$profile and !$apps and !$locations) {
    sintax();
    } else {
    if($savefile) {
    printear_logo("\n[+] Logs $savefile saved\n");
    }
    }

    copyright();

    # Functions

    sub search_profile {
    my ($username) = @_;

    printear_titulo("\n[+] Loading Profile in Username : ");
    print $username." ...\n\n";

    #my $code = toma("http://localhost/twitter/getuser.php");
    my $code = get_code("https://api.twitter.com/1.1/users/show.json?screen_name=".$username);

    my $resultado = JSON->new->decode($code);

    my $screen_name = $resultado->{"screen_name"};
    if($screen_name eq "") {
    $screen_name = "Not Found";
    }
    my $name = $resultado->{"name"};
    if($name eq "") {
    $name = "Not Found";
    }
    my $id = $resultado->{"id_str"};
    if($id eq "") {
    $id = "Not Found";
    }
    my $created = parse_date($resultado->{"created_at"});
    if($created eq "") {
    $created = "Not Found";
    }
    my $followers = $resultado->{"followers_count"};
    if($followers eq "") {
    $followers = "Not Found";
    }
    my $tweets_count = $resultado->{"statuses_count"};
    if($tweets_count eq "") {
    $tweets_count = "Not Found";
    }
    my $location = $resultado->{"location"};
    if($location eq "") {
    $location = "Not Found";
    }
    my $description = $resultado->{"description"};
    if($description eq "") {
    $description = "Not Found";
    }
    my $url = $resultado->{"url"};
    if($url eq "") {
    $url = "Not Found";
    }
    my $profile_image = $resultado->{"profile_image_url"};
    if($profile_image eq "") {
    $profile_image = "Not Found";
    }

    printear("Screen Name : ");
    print $screen_name."\n";
    printear("Username : ");
    print $name."\n";
    printear("ID : ");
    print $id."\n";
    printear("Created at : ");
    print $created."\n";
    printear("Followers : ");
    print $followers."\n";
    printear("Tweets count : ");
    print $tweets_count."\n";
    printear("Location : ");
    print $location."\n";
    printear("Description : ");
    print $description."\n";
    printear("URL : ");
    print $url."\n";
    printear("Profile Image : ");
    print $profile_image."\n";

    printear_titulo("\n[+] Profile Loaded\n");

    if($savefile) {
    savefile($savefile,"\n[+] Loading Profile in Username : $username\n");
    savefile($savefile,"Screen Name : $screen_name");
    savefile($savefile,"Username : $name");
    savefile($savefile,"ID : $id");
    savefile($savefile,"Created at : $created");
    savefile($savefile,"Followers : $followers");
    savefile($savefile,"Tweets count : $tweets_count");
    savefile($savefile,"Location : $location");
    savefile($savefile,"Description : $description");
    savefile($savefile,"URL : $url");
    savefile($savefile,"Profile Image : $profile_image");
    savefile($savefile,"\n[+] Profile Loaded");
    }

    #for my $number(1..5) {
    # sleep(1);
    # printear_logo("number : ");
    # printear_titulo($number."\r");
    #}
    #printear_titulo("Number : Finished\n");
    }

    sub search_apps {
    my($username,$count) = @_;

    printear_titulo("\n[+] Searching Apps in Username : ");
    print $username." ...\n\n";

    #my $code = toma("http://localhost/twitter/timeline.php");
    my $code = get_code("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$username."&include_rts=True&count=".$count);

    my $resultado = JSON->new->decode($code);

    my @resultado = @$resultado;

    my $i = 0;

    if(int(@resultado) eq "0") {
    printear_rojo("[-] Tweets not found\n");
    } else {
    printear("[+] Tweets found : ");
    print int(@resultado)."\n\n\n";
    printear("  Tweet\t\t Date\t\t   Apps\n");
    print "  -----------------------------------------------------\n\n";

    if($savefile) {
    savefile($savefile,"\n[+] Searching Apps in Username : $username\n");
    savefile($savefile,"[+] Tweets found : ".int(@resultado)."\n");
    savefile($savefile,"  Tweet\t\t Date\t\t   Apps\n");
    savefile($savefile,"  -----------------------------------------------------\n");
    }

    for my $result(@resultado) {
    $i++;
    my $source_split = $result->{"source"};
    if($source_split=~/>(.*)<\/a>/) {
    my $source = $1;
    my $datetime = parse_date($result->{"created_at"});
    if($source ne "") {
    printf("   %-5s %-22s %-15s\n", $i,$datetime,$source);
    if($savefile) {
    savefile($savefile,"   $i\t$datetime\t$source");
    }
    }
    }
    }

    printear_titulo("\n\n[+] Apps Loaded\n");

    if($savefile) {
    savefile($savefile,"\n[+] Apps Loaded\n");
    }
    }

    }

    sub search_locations {
    my($username,$count) = @_;

    printear_titulo("\n[+] Searching Locations in Username : ");
    print $username." ...\n\n";

    #my $code = toma("http://localhost/twitter/timeline.php");
    my $code = get_code("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=".$username."&include_rts=True&count=".$count);

    my $resultado = JSON->new->decode($code);

    my @resultado = @$resultado;

    my $i = 0;

    if(int(@resultado) eq "0") {
    printear_rojo("[-] Tweets not found\n");
    } else {
    printear("[+] Tweets found : ");
    print int(@resultado)."\n\n\n";

    printear("  Tweet\t\t Date\t\t     Locations\n");
    print "  -----------------------------------------------------\n\n";

    if($savefile) {
    savefile($savefile,"\n[+] Searching Locations in Username : $username\n");
    savefile($savefile,"[+] Tweets found : ".int(@resultado)."\n");
    savefile($savefile,"  Tweet\t\t Date\t\t   Locations\n");
    savefile($savefile,"  -----------------------------------------------------\n");
    }

    for my $result(@resultado) {
    $i++;
    my $place = $result->{"place"}{"country"};
    my $coordinates1 = $result->{"geo"}{"coordinates"}[0];
    my $coordinates2 = $result->{"geo"}{"coordinates"}[1];
    my $datetime = parse_date($result->{"created_at"});
    if($place ne "") {
    my $data = "";
    if($coordinates1 ne "" && $coordinates2 ne "") {
    $data = $place." [".$coordinates1.",".$coordinates2."]";
    } else {
    $data = $place;
    }
    printf("   %-5s %-22s %-15s\n", $i,$datetime,$data);
    if($savefile) {
    savefile($savefile,"   $i\t$datetime\t$data");
    }
    }
    }
    printear_titulo("\n\n[+] Locations Loaded\n");
    if($savefile) {
    savefile($savefile,"\n[+] Locations Loaded\n");
    }
    }

    }

    # More Functions

    sub get_token {
    my $code = $nave->request(POST(
    "https://api.twitter.com/oauth2/token",
    "Content-Type" => "application/x-www-form-urlencoded;charset=UTF-8",
    "Authorization" => "Basic $bearer_token_64",
    Content => { "grant_type" => "client_credentials" }
    ))->content;
    my $resultado = JSON->new->decode($code);
    my $token = $resultado->{"access_token"};
    return $token;
    }

    sub get_code {
    my $url = shift;
    my $code = $nave->request(GET($url,"Authorization" => "Bearer " . get_token()))->content;
    return $code;
    }

    sub parse_date {
        my $date = shift;       
        $time = str2time($date);   
        my $datetime = DateTime->from_epoch(epoch => $time);
        return $datetime->mdy("/")." ".$datetime->hms;
    }

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

    sub savefile {
    my ($filename,$text) = @_;
    open( SAVE, ">>" . $filename );
    print SAVE $text . "\n";
    close SAVE;
    }

    sub printear {
        cprint( "\x036" . $_[0] . "\x030" );
    }

    sub printear_logo {
        cprint( "\x037" . $_[0] . "\x030" );
    }

    sub printear_titulo {
        cprint( "\x0310" . $_[0] . "\x030" );
    }

    sub printear_rojo {
        cprint( "\x034" . $_[0] . "\x030" );
    }

    sub printear_azul {
        cprint( "\x033" . $_[0] . "\x030" );
    }

    sub sintax {
        printear("\n[+] Sintax : ");
        print "perl $0 <option> <value>\n";
        printear("\n[+] Options : \n\n");
        print "-profile : Show profile information\n";
        print "-apps : List apps in tweets\n";
        print "-locations : List locations in tweets\n";
        print "-username <username> : Set username to find\n";
    print "-count <count> : Set count to find\n";
    print "-savefile <filename> : Save results\n";
        printear("\n[+] Example : ");
        print "perl dh_twitter_locator.pl -profile -apps -locations -username test -count 800 -savefile results.txt\n";
        copyright();
    }

    sub head {
        printear_logo("\n-- == DH Twitter Locator 0.6 == --\n\n");
    }

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

    #The End ?


    Un video con ejemplos de uso :

    [youtube=640,360]https://www.youtube.com/watch?v=56J0Hko5TfA[/youtube]

    Si quieren bajar el programa lo pueden hacer de aca :

    SourceForge.
    Github.

    Eso seria todo.