Skip to content
Browse files

Changed to NetAddr::IP and changed algorithm for IP range. Now is IPv…

…6 ready (but not tested IPv6, probably needs some changes) and requires

 less memory (no array with all checked IPs), but iteration is slightly slower (non significant).
  • Loading branch information...
1 parent ddd3ce8 commit 8d9d6dcd3e1c1425a2117863a31fc94ecd4defa0 @rozie rozie committed Dec 28, 2010
Showing with 14 additions and 11 deletions.
  1. +14 −11 known_hosts_bruteforcer.pl
View
25 known_hosts_bruteforcer.pl
@@ -2,13 +2,14 @@
#
# SSH known_hosts file bruteforcer
#
-# v1.1 - Xavier Mertens <xavier(at)rootshell(dot)be>
+# v1.2 - Xavier Mertens <xavier(at)rootshell(dot)be>
#
# This Perl script read a SSH known_host file containing hashed hosts and try to find hostnames
# or IP addresses
#
# 20101103 : Created
# 20101116 : v1.1 added support for IP range - Paweł Różański <rozie(at)poczta(dot)onet(dot)pl>
+# 20101228 : v1.2 change to NetAddr::IP, needs less memory, IPv6 ready - PaweÅ^ RóżaÅ^Äski <rozie(at)poczta(dot)onet(dot)pl>
#
# Todo
# ----
@@ -20,7 +21,7 @@
use Digest::HMAC_SHA1;
use MIME::Base64;
use Net::IP;
-use Net::Netmask;
+use NetAddr::IP;
$MAXLEN = 8; # Maximum hostnames length to check
$MAXIP = 4294967296; # 2^32 # The whole IPv4 space
@@ -101,14 +102,16 @@
# This block will be executed only for IP range check
if ($ipRange){
print "Running IP range mode\n";
- $block = new Net::Netmask ($ipRange);
- @ips_to_check = ($block->enumerate());
- foreach $tmpHost(@ips_to_check){
- if ($line = searchHash($tmpHost)) {
- printf("*** Found host: %s (line %d) ***\n", $tmpHost, $line + 1);
- }
- ($verbose) && (($loops % 1000) == 0) && print STDERR "Testing: $tmpHost ($loops probes) ...\n";
- $loops++;
+ $block = new NetAddr::IP ($ipRange);
+ $count=$block->num();
+ for ($loops=0;$loops<$count;$loops++){
+ $tmpHost=$block->nth($loops);
+ $addr=new NetAddr::IP ($tmpHost);
+ $tmpHost=($addr->addr);
+ if ($line = searchHash($tmpHost)) {
+ printf("*** Found host: %s (line %d) ***\n", $tmpHost, $line + 1);
+ }
+ ($verbose) && (($loops % 1000) == 0) && print STDERR "Testing: $tmpHost ($loops probes) ...\n";
}
# Inform that all was checked and finish program
print "Whole range checked.\n";
@@ -273,4 +276,4 @@ sub getPos {
}
}
-# Eof
+# Eof

0 comments on commit 8d9d6dc

Please sign in to comment.
Something went wrong with that request. Please try again.