Advertisement
speer0

heartbleed test

Apr 8th, 2014
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.39 KB | None | 0 0
  1. #!/usr/local/bin/perl
  2. #####################################################
  3. #                                                   #
  4. # Built to check for heartbleed bug vulnerabilities #
  5. # Date: 20140408                                    #
  6. # Desc: Scans hosts which respond on common SSL     #
  7. #       ports (443, 8443) for Heartbeat.            #
  8. #                                                   #
  9. #####################################################
  10.  
  11. use strict;
  12. use warnings;
  13. use Getopt::Std;
  14. use NetAddr::IP;
  15.  
  16. my @ips;
  17. my $date = `date`;
  18. chomp ($date);
  19. my $fn;
  20. my @networks;
  21. my @ports = ('443', '8443');
  22. my $timeout;
  23. my %args;
  24. # -i ip address(s) to scan seperated by commas
  25. # -n network(s) to scan seperated by commas
  26. # -p port(s) to scan seperated by commas
  27. # -t timeout in seconds for server to respond
  28. # -o output filename
  29. # -h help
  30. getopts('i:n:p:t:o:h', \%args);
  31.  
  32. if ($args{h}){
  33.   print "\nUsage of this tool:
  34.  
  35. # -i ip address(s)\/hostnames(s) to scan seperated by commas
  36. # -n network(s) CIDR to scan seperated by commas
  37. # -p port(s) to scan seperated by commas
  38. # -t timeout in seconds for server to respond
  39. # -o output filename
  40. # -h help\n";
  41. }
  42. if ($args{i}){ @ips = split(',',$args{i}); }
  43. if ($args{n}){ @networks = split(',', $args{n}); }
  44. if ($args{p}){ @ports = split(',', $args{p}); }
  45. if ($args{o}){
  46.   $fn = $args{o};
  47.   open (LOG,'>>',$fn) || die "Can't Open File: $fn\n";;
  48.   print LOG "$date\n";
  49. }
  50. if ($args{t}){ $timeout = $args{t}; }
  51. else{ $timeout = 2; }
  52.  
  53. if (@networks){
  54.   foreach my $network (@networks){
  55.     my $net = NetAddr::IP->new($network);
  56.     my @hosts = $net->hostenum;
  57.     for my $ip (@hosts) {
  58.       push (@ips, $ip->addr);
  59. }}}
  60.  
  61. if (@ips){
  62.   foreach my $ip (@ips){
  63.     foreach my $port (@ports){
  64.       my $nmap = `nmap -p$port $ip 2>&1| grep open`;
  65.       if ($nmap =~ "open"){
  66.         my $return = `timeout $timeout openssl s_client -connect $ip:$port -tlsextdebug 2>&1| grep 'TLS server extension "heartbeat"'`;
  67.         if ($return){
  68.           my $hostname = `host $ip 2>&1`;
  69.           chomp $hostname;
  70.           print "$ip: Vulnerable  -  $hostname\n";
  71.           if ($args{o}){
  72.             print LOG "$ip: Vulnerable  -  $hostname\n";
  73.           }
  74.         }
  75.         else{
  76.           print "$ip: Not Vulnerable\n";
  77.           if ($args{o}){
  78.             print LOG "$ip: Not Vulnerable\n";}
  79.           }
  80. }}}}
  81. if ($args{o}){ close (LOG); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement