Permalink
Browse files

Added support for IPv6 - both short and long version. It's slower tha…

…n IPv4, because checks both short and long version, so left it in separate

 block. Got rid of unused Net::IP module.
  • Loading branch information...
1 parent 8d9d6dc commit 683cfe5a2411114387a9be8d9a99fa7996958374 @rozie rozie committed Jan 14, 2011
Showing with 35 additions and 15 deletions.
  1. +35 −15 known_hosts_bruteforcer.pl
View
@@ -8,20 +8,19 @@
# 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>
+# 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>
+# 20110114 : v1.3 added support for IPv6 - Pawe³ Ró¿añski <rozie(at)poczta(dot)onet(dot)pl>
#
# Todo
# ----
-# - Support for IPv6 addresses
# - Increase performances
-#
+# - Consider cleaning up -i option - $MAXIP, $ipMode and so on - -r has all functions and IPv6 support.
use Getopt::Std;
use Digest::HMAC_SHA1;
use MIME::Base64;
-use Net::IP;
-use NetAddr::IP;
+use NetAddr::IP qw(:lower);
$MAXLEN = 8; # Maximum hostnames length to check
$MAXIP = 4294967296; # 2^32 # The whole IPv4 space
@@ -104,15 +103,36 @@
print "Running IP range mode\n";
$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";
- }
+ $ver=$block->version();
+
+ if ($ver == 4){
+ print "IPv4 detected on input\n";
+ 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";
+ }
+ }
+ elsif ($ver == 6){
+ print "IPv6 detected on input\n";
+ for ($loops=0;$loops<$count;$loops++){
+ $tmpHost=$block->nth($loops);
+ $addr=new NetAddr::IP ($tmpHost);
+ $tmpHost=($addr->addr);
+ $tmpHostShort=($addr->short);
+ if ($line = searchHash($tmpHost)) {
+ printf("*** Found host: %s (line %d) ***\n", $tmpHost, $line + 1);
+ }
+ if ($line = searchHash($tmpHostShort)) {
+ printf("*** Found host: %s (line %d) ***\n", $tmpHostShort, $line + 1);
+ }
+ ($verbose) && (($loops % 1000) == 0) && print STDERR "Testing: $tmpHost && $tmpHostShort ($loops probes) ...\n";
+ }
+ }
# Inform that all was checked and finish program
print "Whole range checked.\n";
exit 0;

2 comments on commit 683cfe5

Net::IP is still being used:

$ ./known_hosts_bruteforcer.pl -f known_hosts.test -v -i -s 127.0.0.1
Reading hashes from known_hosts.test ...
Can't locate object method "new" via package "Net::IP" (perhaps you forgot to load "Net::IP"?) at known_hosts_bruteforcer.pl line 152.

The following seems to fix it:

--- known_hosts_bruteforcer.pl.orig 2015-06-08 21:30:00.870428090 -0700
+++ known_hosts_bruteforcer.pl      2015-06-08 21:36:07.465222197 -0700
@@ -149,8 +149,8 @@
 
                 # If we have an initial IP, check the syntax and use it
                 if ($initialStr ne "") {
-                        my $ip = new Net::IP($initialStr);
-                        $initialIP = $ip->intip();
+                        my $ip = new NetAddr::IP($initialStr);
+                        $initialIP = $ip->bigint;
                 }
                 else {
                         $initialIP = 0;
Owner

xme replied Jun 9, 2015

Fixed! Thank for reporting this issue.

Please sign in to comment.