home *** CD-ROM | disk | FTP | other *** search
/ PC Master 56 (Alt) / PCMaster56.iso / programs / hackers / ssh3 / ssh3.pl
Encoding:
Perl Script  |  2001-12-03  |  2.1 KB  |  79 lines

  1. #!/usr/bin/perl
  2. #
  3. # A local SSH 3.0.0 vulnerability scanner for the 
  4. # SSH Short Password Login Vulnerability, BugtraqID: 3078
  5. #
  6. # Note: You must have superuser access on the system to scan it.
  7. #
  8. # usage: ./ssh3.pl <host>
  9. #        Optional: -e turn off error
  10. #                  -h specify a different /etc/shadow file
  11. # (Options must come before host name)
  12. # Written by hypoclear hypoclear@jungle.net - http://hypoclear.cjb.net
  13. #
  14. # This and all of my programs fall under my disclaimer, which
  15. # can be found at: http://hypoclear.cjb.net/hypodisclaim.txt
  16.  
  17.  
  18. use IO::Socket; use Getopt::Std;
  19. getopts('h:e');
  20.  
  21. die "\nusage: $0 <host>\n\tOptional: -e turn off error\n\t\t  -h specify a different /etc/shadow file\n\n" unless @ARGV > 0;
  22. if (!defined $opt_h)
  23.  { $opt_h = "/etc/shadow";
  24.  }
  25.  
  26. $out = &bannerGrab($ARGV[0],22);
  27. sysread $out, $message,100;
  28. close $out;
  29.  
  30. if (($message =~ /3.0.0/) || (defined $opt_e))
  31.  { print "Running SSH 3.0.0, checking for vulnerabilities...\n\n";
  32.    open(SHADOW, "<$opt_h") || die "Cannot open $opt_h!\nNote: You must have superuser access to run this script.\n\n";
  33.    while(<SHADOW>)
  34.      { $name = $_;
  35.        $name =~ s/:.*$//;
  36.        $_ =~ s/^.*?\://;
  37.        $_ =~ s/:.*$//;
  38.        $name =~ s/\s//g; $_=~s/\s//g;
  39.        push(@name,$name);
  40.        push(@hash,$_);
  41.        push(@lnnum,$cnt++); $cnt++;
  42.      }
  43.    close(SHADOW);
  44.  
  45.    foreach $hash (@hash)
  46.      { @chars = split(//,$hash);
  47.        foreach $char (@chars)
  48.          { $count++;
  49.          }
  50.        if ($count <= 2)
  51.         { print "$name[$line]\t(line $lnnum[$line]) may be vulnerable!\n";
  52.           $vulnFlag = 1;
  53.         }
  54.        $count=0; $line++;
  55.      }
  56.    if ($vulnFlag != 1)
  57.     { print "No accounts appear to be vulnerable.\n";
  58.     }
  59.  }
  60. else
  61.  { if (!defined $opt_e)
  62.     { print "You are not running SSH 3.0.0.\n";
  63.       die "If you feel that this is an error run with the -e option.\n";
  64.     }
  65.  }
  66. print "\n";
  67.  
  68.  
  69. sub bannerGrab
  70. { $host  = gethostbyname($_[0]) || warn "cannot connect to $ARGV[0]\n";
  71.   $port  = getservbyport($_[1], 'tcp'); 
  72.   $haddr = sockaddr_in($_[1], $host); 
  73.   socket(OUT, PF_INET, SOCK_STREAM, getprotobyname('tcp')) || warn "$!\n"; 
  74.   connect(OUT, $haddr) ;
  75.   return OUT; 
  76. }
  77.  
  78.