2009-03-27 00:49:55 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
2009-11-02 18:16:51 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2009-03-27 00:49:55 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2009-03-27 00:49:55 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
2010-01-26 21:59:30 +00:00
|
|
|
include Msf::Exploit::Capture
|
2009-03-27 00:49:55 +00:00
|
|
|
include Msf::Auxiliary::Scanner
|
2010-06-17 14:03:53 +00:00
|
|
|
include Msf::Auxiliary::Report
|
2010-06-21 16:53:52 +00:00
|
|
|
|
2009-03-27 00:49:55 +00:00
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'TCP ACK Firewall Scanner',
|
|
|
|
'Description' => %q{
|
|
|
|
Map out firewall rulesets with a raw ACK scan. Any
|
|
|
|
unfiltered ports found means a stateful firewall is
|
|
|
|
not in place for them.
|
|
|
|
},
|
2009-04-03 15:05:35 +00:00
|
|
|
'Author' => 'kris katterjohn',
|
2009-03-27 00:49:55 +00:00
|
|
|
'Version' => '$Revision$', # 03/26/2009
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
|
|
|
|
|
|
|
register_options([
|
|
|
|
OptString.new('PORTS', [true, "Ports to scan (e.g. 22-25,80,110-900)", "1-10000"]),
|
|
|
|
OptInt.new('TIMEOUT', [true, "The reply read timeout in milliseconds", 500]),
|
2009-09-24 03:34:04 +00:00
|
|
|
OptInt.new('BATCHSIZE', [true, "The number of hosts to scan per set", 256]),
|
|
|
|
OptString.new('INTERFACE', [false, 'The name of the interface'])
|
2009-03-27 00:49:55 +00:00
|
|
|
], self.class)
|
2010-01-26 22:16:03 +00:00
|
|
|
|
|
|
|
deregister_options('FILTER','PCAPFILE')
|
2009-03-27 00:49:55 +00:00
|
|
|
end
|
|
|
|
|
2011-12-04 19:16:44 +00:00
|
|
|
# No IPv6 support yet
|
|
|
|
def support_ipv6?
|
|
|
|
false
|
|
|
|
end
|
2012-03-18 05:07:27 +00:00
|
|
|
|
2009-03-27 00:49:55 +00:00
|
|
|
def run_batch_size
|
|
|
|
datastore['BATCHSIZE'] || 256
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_batch(hosts)
|
2010-01-27 18:31:36 +00:00
|
|
|
open_pcap
|
2009-03-27 00:49:55 +00:00
|
|
|
|
2010-01-27 18:31:36 +00:00
|
|
|
pcap = self.capture
|
2009-03-27 00:49:55 +00:00
|
|
|
|
|
|
|
ports = Rex::Socket.portspec_crack(datastore['PORTS'])
|
|
|
|
|
|
|
|
if ports.empty?
|
|
|
|
print_error("Error: No valid ports specified")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
to = (datastore['TIMEOUT'] || 500).to_f / 1000.0
|
|
|
|
|
|
|
|
# Spread the load across the hosts
|
|
|
|
ports.each do |dport|
|
|
|
|
hosts.each do |dhost|
|
|
|
|
shost, sport = getsource(dhost)
|
|
|
|
|
2010-01-27 18:31:36 +00:00
|
|
|
pcap.setfilter(getfilter(shost, sport, dhost, dport))
|
2009-03-27 00:49:55 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
probe = buildprobe(shost, sport, dhost, dport)
|
|
|
|
|
2010-01-27 18:31:36 +00:00
|
|
|
capture_sendto(probe, dhost)
|
2009-03-27 00:49:55 +00:00
|
|
|
|
2010-01-27 18:31:36 +00:00
|
|
|
reply = probereply(pcap, to)
|
2009-03-27 00:49:55 +00:00
|
|
|
|
|
|
|
next if not reply
|
|
|
|
|
|
|
|
print_status(" TCP UNFILTERED #{dhost}:#{dport}")
|
2010-06-17 14:03:53 +00:00
|
|
|
|
|
|
|
#Add Report
|
|
|
|
report_note(
|
|
|
|
:host => dhost,
|
|
|
|
:proto => 'tcp',
|
|
|
|
:port => dport,
|
|
|
|
:type => "TCP UNFILTERED #{dhost}:#{dport}",
|
|
|
|
:data => "TCP UNFILTERED #{dhost}:#{dport}"
|
|
|
|
)
|
2010-06-21 16:53:52 +00:00
|
|
|
|
2009-03-27 00:49:55 +00:00
|
|
|
rescue ::Exception
|
|
|
|
print_error("Error: #{$!.class} #{$!}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-26 21:59:30 +00:00
|
|
|
close_pcap
|
2009-03-27 00:49:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def getfilter(shost, sport, dhost, dport)
|
|
|
|
# Look for associated RSTs
|
|
|
|
"tcp and (tcp[13] & 0x04) != 0 and " +
|
|
|
|
"src host #{dhost} and src port #{dport} and " +
|
|
|
|
"dst host #{shost} and dst port #{sport}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def getsource(dhost)
|
|
|
|
# srcip, srcport
|
|
|
|
[ Rex::Socket.source_address(dhost), rand(0xffff - 1025) + 1025 ]
|
|
|
|
end
|
|
|
|
|
|
|
|
def buildprobe(shost, sport, dhost, dport)
|
2011-07-26 01:29:21 +00:00
|
|
|
p = PacketFu::TCPPacket.new
|
|
|
|
p.ip_saddr = shost
|
|
|
|
p.ip_daddr = dhost
|
|
|
|
p.tcp_sport = sport
|
|
|
|
p.tcp_ack = rand(0x100000000)
|
|
|
|
p.tcp_flags.ack = 1
|
|
|
|
p.tcp_dport = dport
|
|
|
|
p.tcp_win = 3072
|
|
|
|
p.recalc
|
|
|
|
p
|
2009-03-27 00:49:55 +00:00
|
|
|
end
|
|
|
|
|
2010-01-26 21:59:30 +00:00
|
|
|
def probereply(pcap, to)
|
2009-07-17 20:36:40 +00:00
|
|
|
reply = nil
|
2009-03-27 00:49:55 +00:00
|
|
|
begin
|
2009-11-02 18:16:51 +00:00
|
|
|
Timeout.timeout(to) do
|
2009-03-27 00:49:55 +00:00
|
|
|
pcap.each do |r|
|
2011-07-26 01:29:21 +00:00
|
|
|
pkt = PacketFu::Packet.parse(r)
|
|
|
|
next unless pkt.is_tcp?
|
|
|
|
reply = pkt
|
2009-07-17 20:36:40 +00:00
|
|
|
break
|
2009-03-27 00:49:55 +00:00
|
|
|
end
|
|
|
|
end
|
2009-11-02 18:22:50 +00:00
|
|
|
rescue Timeout::Error
|
2009-03-27 00:49:55 +00:00
|
|
|
end
|
2009-07-17 20:36:40 +00:00
|
|
|
return reply
|
2009-03-27 00:49:55 +00:00
|
|
|
end
|
2011-07-26 01:29:21 +00:00
|
|
|
|
2009-03-27 00:49:55 +00:00
|
|
|
end
|