Move my portspec parsing code from scanner/portscan/tcp to Rex as
Socket.portspec_crack and use it to also replace the incomplete parsing code used for db_autopwn git-svn-id: file:///home/svn/framework3/trunk@6033 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
90f906d8c5
commit
0e8ce1cc46
|
@ -112,29 +112,6 @@ module Db
|
|||
end
|
||||
|
||||
|
||||
def parse_port_range(desc)
|
||||
res = []
|
||||
desc.split(",").each do |r|
|
||||
s,e = r.split("-")
|
||||
e ||= s
|
||||
s = s.to_i
|
||||
e = e.to_i
|
||||
|
||||
if(e < s)
|
||||
t = s
|
||||
s = e
|
||||
e = t
|
||||
end
|
||||
|
||||
s.to_i.upto(e.to_i) do |i|
|
||||
next if i == 0
|
||||
res << i
|
||||
end
|
||||
end
|
||||
|
||||
res
|
||||
end
|
||||
|
||||
#
|
||||
# A shotgun approach to network-wide exploitation
|
||||
#
|
||||
|
@ -181,9 +158,9 @@ module Db
|
|||
when '-X'
|
||||
targ_exc << OptAddressRange.new('TEMPRANGE', [ true, '' ]).normalize(args.shift)
|
||||
when '-PI'
|
||||
port_inc = parse_port_range(args.shift)
|
||||
port_inc = Rex::Socket.portspec_crack(args.shift)
|
||||
when '-PX'
|
||||
port_exc = parse_port_range(args.shift)
|
||||
port_exc = Rex::Socket.portspec_crack(args.shift)
|
||||
when '-m'
|
||||
regx = args.shift
|
||||
when '-h'
|
||||
|
|
|
@ -351,6 +351,29 @@ module Socket
|
|||
[ (~((2 ** (32 - bitmask)) - 1)) & 0xffffffff ].pack('N').unpack('CCCC').join('.')
|
||||
end
|
||||
|
||||
#
|
||||
# Converts a port specification like "80,21-23,443" into a sorted,
|
||||
# unique array of valid port numbers like [21,22,23,80,443]
|
||||
#
|
||||
def self.portspec_crack(pspec)
|
||||
ports = []
|
||||
|
||||
# Build ports array from port specification
|
||||
pspec.split(/,/).each do |item|
|
||||
start, stop = item.split(/-/).map { |p| p.to_i }
|
||||
|
||||
start ||= 0
|
||||
stop ||= item.match(/-/) ? 65535 : start
|
||||
|
||||
start, stop = stop, start if stop < start
|
||||
|
||||
start.upto(stop) { |p| ports << p }
|
||||
end
|
||||
|
||||
# Sort, and remove dups and invalid ports
|
||||
ports.sort.uniq.delete_if { |p| p < 0 or p > 65535 }
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# Utility class methods
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
|
||||
require 'msf/core'
|
||||
|
||||
|
||||
class Metasploit3 < Msf::Auxiliary
|
||||
|
||||
include Msf::Exploit::Remote::Tcp
|
||||
|
@ -44,22 +43,8 @@ class Metasploit3 < Msf::Auxiliary
|
|||
def run_host(ip)
|
||||
|
||||
timeout = datastore['TIMEOUT'].to_i
|
||||
ports = []
|
||||
|
||||
# Build ports array from port specification
|
||||
datastore['PORTS'].split(/,/).each do |item|
|
||||
start, stop = item.split(/-/).map { |p| p.to_i }
|
||||
|
||||
start ||= 0
|
||||
stop ||= item.match(/-/) ? 65535 : start
|
||||
|
||||
start, stop = stop, start if stop < start
|
||||
|
||||
start.upto(stop) { |p| ports << p }
|
||||
end
|
||||
|
||||
# Sort, and remove dups and invalid ports
|
||||
ports = ports.sort.uniq.delete_if { |p| p < 0 or p > 65535 }
|
||||
ports = Rex::Socket.portspec_crack(datastore['PORTS'])
|
||||
|
||||
if ports.empty?
|
||||
print_status("Error: No valid ports specified")
|
||||
|
|
Loading…
Reference in New Issue