Updates meterpreter autoroute to accept CIDR notation.

git-svn-id: file:///home/svn/framework3/trunk@9667 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Tod Beardsley 2010-07-03 01:27:24 +00:00
parent 9984b662e0
commit 2250a83913
2 changed files with 27 additions and 4 deletions

View File

@ -201,7 +201,11 @@ module Socket
addr_ntoi(resolv_nbo(host))
end
def self.resolv_to_cidr(mask)
#
# Converts an ASCII IP address to a CIDR mask. Returns
# nil if it's not convertable.
#
def self.addr_atoc(mask)
mask_i = resolv_nbo_i(mask)
cidr = nil
0.upto(32) do |i|
@ -213,6 +217,15 @@ module Socket
return cidr
end
#
# Resolves a CIDR bitmask into a dotted-quad. Returns
# nil if it's not convertable.
#
def self.addr_ctoa(cidr)
return nil unless (0..32) === cidr.to_i
addr_itoa(((1 << cidr)-1) << 32-cidr)
end
#
# Resolves a host to a dotted address.
#

View File

@ -28,9 +28,18 @@ remove_route = false
usage
return false
when "-s"
subnet = v
if v =~ /[0-9\x2e]+\x2f[0-9]{1,2}/
subnet,cidr = v.split("\x2f")
netmask = Rex::Socket.addr_ctoa(cidr.to_i)
else
subnet = v
end
when "-n"
netmask = v
if (0..32) === v.to_i
netmask = Rex::Socket.addr_ctoa(v.to_i)
else
netmask = v
end
when "-p"
print_only = true
when "-d"
@ -111,6 +120,7 @@ def usage()
print_status "Examples:"
print_status " run autoroute -s 10.1.1.0 -n 255.255.255.0 # Add a route to 10.10.10.1/255.255.255.0"
print_status " run autoroute -s 10.10.10.1 # Netmask defaults to 255.255.255.0"
print_status " run autoroute -s 10.10.10.1/24 # CIDR notation is also okay"
print_status " run autoroute -p # Print active routing table"
print_status " run autoroute -d -s 10.10.10.1 # Deletes the 10.10.10.1/255.255.255.0 route"
print_status "Use the \"route\" and \"ipconfig\" Meterpreter commands to learn about available routes"
@ -129,7 +139,7 @@ def validate_cmd(subnet=nil,netmask=nil)
return false
end
if(netmask and !(Rex::Socket.resolv_to_cidr(netmask)))
if(netmask and !(Rex::Socket.addr_atoc(netmask)))
print_error "Netmask invalid (must define contiguous IP addressing)"
usage
return false