Skip to content

Commit 72f6458

Browse files
author
HD Moore
committed
Add IPv6 range support, permission tweak
1 parent 0bbbcd5 commit 72f6458

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

lib/rex/socket/range_walker.rb

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,28 @@ def parse(parseme)
5353
return nil if not parseme
5454
ranges = []
5555
parseme.split(', ').map{ |a| a.split(' ') }.flatten.each { |arg|
56-
if arg.include?("/")
56+
57+
# Handle IPv6 first (support ranges, but not CIDR)
58+
if arg.include?(":")
59+
addrs = arg.split('-', 2)
60+
61+
# Handle a single address
62+
if addrs.length == 1
63+
# IPv6 ranges are not yet supported (or useful)
64+
return false unless Rex::Socket.is_ipv6?(arg)
65+
66+
addr = Rex::Socket.addr_atoi(arg)
67+
ranges.push [addr, addr, true]
68+
end
69+
70+
# Handle IPv6 ranges in the form of 2001::1-2001::10
71+
return false if not (Rex::Socket.is_ipv6?(addrs[0]) and Rex::Socket.is_ipv6?(addrs[1]))
72+
addr1 = Rex::Socket.addr_atoi(addrs[0])
73+
addr2 = Rex::Socket.addr_atoi(addrs[1])
74+
ranges.push [addr1, addr2, true]
75+
76+
# Handle IPv4 CIDR
77+
elsif arg.include?("/")
5778
# Then it's CIDR notation and needs special case
5879
return false if arg =~ /[,-]/ # Improper CIDR notation (can't mix with 1,3 or 1-3 style IP ranges)
5980
return false if arg.scan("/").size > 1 # ..but there are too many slashes
@@ -72,20 +93,15 @@ def parse(parseme)
7293
ranges += expanded
7394
else
7495
return false
75-
end
76-
77-
elsif arg.include?(":")
78-
# IPv6 ranges are not yet supported (or useful)
79-
return false unless Rex::Socket.is_ipv6?(arg)
80-
81-
addr = Rex::Socket.addr_atoi(arg)
82-
ranges.push [addr, addr, true]
96+
end
8397

98+
# Handle hostnames
8499
elsif arg =~ /[^-0-9,.*]/
85100
# Then it's a domain name and we should send it on to addr_atoi
86101
# unmolested to force a DNS lookup.
87102
Rex::Socket.addr_atoi_list(arg).each { |addr| ranges.push [addr, addr] }
88-
103+
104+
# Handle IPv4 ranges
89105
elsif arg =~ /^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})-([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/
90106
# Then it's in the format of 1.2.3.4-5.6.7.8
91107
# Note, this will /not/ deal with DNS names, or the fancy/obscure 10...1-10...2

0 commit comments

Comments
 (0)