2008-10-15 14:00:56 +00:00
|
|
|
##
|
2008-10-23 02:43:21 +00:00
|
|
|
# $Id$
|
2008-10-15 14:00:56 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
##
|
2010-04-30 08:40:19 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2008-10-15 14:00:56 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2009-04-13 14:33:26 +00:00
|
|
|
# http://metasploit.com/framework/
|
2008-10-15 14:00:56 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
|
|
|
require 'msf/core'
|
2009-07-17 20:36:40 +00:00
|
|
|
require 'racket'
|
2008-10-15 14:00:56 +00:00
|
|
|
|
2008-10-15 22:25:35 +00:00
|
|
|
class Metasploit3 < Msf::Auxiliary
|
2008-10-15 14:00:56 +00:00
|
|
|
|
2008-10-15 22:25:35 +00:00
|
|
|
include Msf::Exploit::Remote::Tcp
|
2010-11-24 19:25:18 +00:00
|
|
|
include Msf::Exploit::Capture
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2008-10-15 22:25:35 +00:00
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
include Msf::Auxiliary::Scanner
|
2008-10-15 14:00:56 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2008-10-15 14:00:56 +00:00
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'TCP Port Scanner',
|
2008-10-23 02:43:21 +00:00
|
|
|
'Version' => '$Revision$',
|
2008-10-15 14:00:56 +00:00
|
|
|
'Description' => 'Enumerate open TCP services',
|
2009-04-03 15:05:35 +00:00
|
|
|
'Author' => [ 'hdm', 'kris katterjohn' ],
|
2008-10-15 14:00:56 +00:00
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
2008-10-27 23:33:34 +00:00
|
|
|
OptString.new('PORTS', [true, "Ports to scan (e.g. 22-25,80,110-900)", "1-10000"]),
|
2010-07-06 15:53:05 +00:00
|
|
|
OptInt.new('TIMEOUT', [true, "The socket connect timeout in milliseconds", 1000]),
|
|
|
|
OptBool.new('VERBOSE', [false, "Display verbose output", false]),
|
2010-07-09 22:21:34 +00:00
|
|
|
OptInt.new('CONCURRENCY', [true, "The number of concurrent ports to check per host", 10]),
|
2008-10-15 14:00:56 +00:00
|
|
|
], self.class)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2008-10-15 14:00:56 +00:00
|
|
|
deregister_options('RPORT')
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2008-10-15 14:00:56 +00:00
|
|
|
def run_host(ip)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2008-10-27 23:33:34 +00:00
|
|
|
timeout = datastore['TIMEOUT'].to_i
|
|
|
|
|
2008-12-20 20:34:05 +00:00
|
|
|
ports = Rex::Socket.portspec_crack(datastore['PORTS'])
|
2008-10-27 23:33:34 +00:00
|
|
|
|
|
|
|
if ports.empty?
|
2010-07-25 21:37:54 +00:00
|
|
|
print_error("Error: No valid ports specified")
|
2008-10-27 23:33:34 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2010-07-09 22:21:34 +00:00
|
|
|
while(ports.length > 0)
|
|
|
|
t = []
|
|
|
|
r = []
|
2008-10-15 14:00:56 +00:00
|
|
|
begin
|
2010-07-09 22:21:34 +00:00
|
|
|
1.upto(datastore['CONCURRENCY']) do
|
|
|
|
this_port = ports.shift
|
|
|
|
break if not this_port
|
2010-11-12 06:19:49 +00:00
|
|
|
t << framework.threads.spawn("Module(#{self.refname})-#{ip}:#{this_port}", false, this_port) do |port|
|
2010-07-09 22:21:34 +00:00
|
|
|
begin
|
|
|
|
s = connect(false,
|
|
|
|
{
|
|
|
|
'RPORT' => port,
|
|
|
|
'RHOST' => ip,
|
|
|
|
'ConnectTimeout' => (timeout / 1000.0)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
print_status("#{ip}:#{port} - TCP OPEN")
|
|
|
|
r << [ip,port,"open"]
|
|
|
|
rescue ::Rex::ConnectionRefused
|
|
|
|
print_status("#{ip}:#{port} - TCP closed") if datastore['VERBOSE']
|
|
|
|
r << [ip,port,"closed"]
|
|
|
|
rescue ::Rex::ConnectionError, ::IOError, ::Timeout::Error
|
|
|
|
rescue ::Interrupt
|
|
|
|
raise $!
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_error("#{ip}:#{port} exception #{e.class} #{e} #{e.backtrace}")
|
|
|
|
ensure
|
|
|
|
disconnect(s) rescue nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
t.each {|x| x.join }
|
|
|
|
|
|
|
|
rescue ::Timeout::Error
|
|
|
|
ensure
|
|
|
|
t.each {|x| x.kill rescue nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
r.each do |res|
|
|
|
|
report_service(:host => res[0], :port => res[1], :state => res[2])
|
2008-10-15 14:00:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-10-27 23:33:34 +00:00
|
|
|
end
|
2010-07-09 22:21:34 +00:00
|
|
|
|