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-b9f4589650da
unstable
kris 2008-12-20 20:34:05 +00:00
parent 90f906d8c5
commit 0e8ce1cc46
3 changed files with 26 additions and 41 deletions

View File

@ -112,29 +112,6 @@ module Db
end 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 # A shotgun approach to network-wide exploitation
# #
@ -181,9 +158,9 @@ module Db
when '-X' when '-X'
targ_exc << OptAddressRange.new('TEMPRANGE', [ true, '' ]).normalize(args.shift) targ_exc << OptAddressRange.new('TEMPRANGE', [ true, '' ]).normalize(args.shift)
when '-PI' when '-PI'
port_inc = parse_port_range(args.shift) port_inc = Rex::Socket.portspec_crack(args.shift)
when '-PX' when '-PX'
port_exc = parse_port_range(args.shift) port_exc = Rex::Socket.portspec_crack(args.shift)
when '-m' when '-m'
regx = args.shift regx = args.shift
when '-h' when '-h'

View File

@ -351,6 +351,29 @@ module Socket
[ (~((2 ** (32 - bitmask)) - 1)) & 0xffffffff ].pack('N').unpack('CCCC').join('.') [ (~((2 ** (32 - bitmask)) - 1)) & 0xffffffff ].pack('N').unpack('CCCC').join('.')
end 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 # Utility class methods

View File

@ -12,7 +12,6 @@
require 'msf/core' require 'msf/core'
class Metasploit3 < Msf::Auxiliary class Metasploit3 < Msf::Auxiliary
include Msf::Exploit::Remote::Tcp include Msf::Exploit::Remote::Tcp
@ -44,22 +43,8 @@ class Metasploit3 < Msf::Auxiliary
def run_host(ip) def run_host(ip)
timeout = datastore['TIMEOUT'].to_i timeout = datastore['TIMEOUT'].to_i
ports = []
# Build ports array from port specification ports = Rex::Socket.portspec_crack(datastore['PORTS'])
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 }
if ports.empty? if ports.empty?
print_status("Error: No valid ports specified") print_status("Error: No valid ports specified")