2009-04-03 00:59:25 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2009-04-03 00:59:25 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'timeout'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Exploit::Capture
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
include Msf::Auxiliary::Report
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'IPID Sequence Scanner',
|
|
|
|
'Description' => %q{
|
|
|
|
This module will probe hosts' IPID sequences and classify
|
|
|
|
them using the same method Nmap uses when it's performing
|
|
|
|
its IPID Idle Scan (-sI) and OS Detection (-O).
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
Nmap's probes are SYN/ACKs while this module's are SYNs.
|
|
|
|
While this does not change the underlying functionality,
|
|
|
|
it does change the chance of whether or not the probe
|
|
|
|
will be stopped by a firewall.
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
Nmap's Idle Scan can use hosts whose IPID sequences are
|
|
|
|
classified as "Incremental" or "Broken little-endian incremental".
|
|
|
|
},
|
|
|
|
'Author' => 'kris katterjohn',
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
register_options([
|
|
|
|
Opt::RPORT(80),
|
|
|
|
OptInt.new('TIMEOUT', [true, "The reply read timeout in milliseconds", 500]),
|
|
|
|
OptString.new('INTERFACE', [false, 'The name of the interface'])
|
|
|
|
])
|
2009-10-18 21:22:55 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
register_advanced_options([
|
|
|
|
OptInt.new('SAMPLES', [true, "The IPID sample size", 6])
|
|
|
|
])
|
2010-01-26 22:36:27 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
deregister_options('FILTER','PCAPFILE')
|
|
|
|
end
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def rport
|
|
|
|
datastore['RPORT'].to_i
|
|
|
|
end
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def run_host(ip)
|
|
|
|
open_pcap
|
2010-01-27 18:40:38 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
raise "SAMPLES option must be >= 2" if datastore['SAMPLES'] < 2
|
2009-10-18 21:22:55 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
pcap = self.capture
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
shost = Rex::Socket.source_address(ip)
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
to = (datastore['TIMEOUT'] || 500).to_f / 1000.0
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
ipids = []
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
pcap.setfilter(getfilter(shost, ip, rport))
|
2009-10-18 21:22:55 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
datastore['SAMPLES'].times do
|
|
|
|
sport = rand(0xffff - 1025) + 1025
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
probe = buildprobe(shost, sport, ip, rport)
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2015-09-27 21:05:05 +00:00
|
|
|
next unless capture_sendto(probe, ip)
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
reply = probereply(pcap, to)
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
next if not reply
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
ipids << reply.ip_id
|
|
|
|
end
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
close_pcap
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
return if ipids.empty?
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
print_status("#{ip}'s IPID sequence class: #{analyze(ipids)}")
|
2010-07-01 23:33:07 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
#Add Report
|
|
|
|
report_note(
|
|
|
|
:host => ip,
|
|
|
|
:proto => 'ip',
|
|
|
|
:type => 'IPID sequence',
|
|
|
|
:data => "IPID sequence class: #{analyze(ipids)}"
|
|
|
|
)
|
|
|
|
end
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# Based on Nmap's get_ipid_sequence() in osscan2.cc
|
|
|
|
def analyze(ipids)
|
|
|
|
allzeros = true
|
|
|
|
allsame = true
|
|
|
|
mul256 = true
|
|
|
|
inc = true
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# ipids.each do |ipid|
|
|
|
|
# print_status("Got IPID ##{ipid}")
|
|
|
|
# end
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
return "Unknown" if ipids.size < 2
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
diffs = []
|
|
|
|
i = 1
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
while i < ipids.size
|
|
|
|
p = ipids[i - 1]
|
|
|
|
c = ipids[i]
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
if p != 0 or c != 0
|
|
|
|
allzeros = false
|
|
|
|
end
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
if p <= c
|
|
|
|
diffs[i - 1] = c - p
|
|
|
|
else
|
|
|
|
diffs[i - 1] = c - p + 65536
|
|
|
|
end
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
if ipids.size > 2 and diffs[i - 1] > 20000
|
|
|
|
return "Randomized"
|
|
|
|
end
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
i += 1
|
|
|
|
end
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
return "All zeros" if allzeros
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
diffs.each do |diff|
|
|
|
|
if diff > 1000 and ((diff % 256) != 0 or ((diff % 256) == 0 and diff >= 25600))
|
|
|
|
return "Random positive increments"
|
|
|
|
end
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
allsame = false if diff != 0
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
mul256 = false if diff > 5120 or (diff % 256) != 0
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
inc = false if diff >= 10
|
|
|
|
end
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
return "Constant" if allsame
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
return "Broken little-endian incremental!" if mul256
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
return "Incremental!" if inc
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
"Unknown"
|
|
|
|
end
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def getfilter(shost, dhost, dport)
|
|
|
|
"tcp and src host #{dhost} and src port #{dport} and " +
|
|
|
|
"dst host #{shost}"
|
|
|
|
end
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# This gets set via the usual capture_sendto interface
|
|
|
|
def buildprobe(shost, sport, dhost, dport)
|
|
|
|
p = PacketFu::TCPPacket.new
|
|
|
|
p.ip_saddr = shost
|
|
|
|
p.ip_daddr = dhost
|
|
|
|
p.tcp_sport = sport
|
|
|
|
p.tcp_dport = dport
|
|
|
|
p.tcp_flags.syn = 1
|
|
|
|
p.recalc
|
|
|
|
p
|
|
|
|
end
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def probereply(pcap, to)
|
|
|
|
reply = nil
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
begin
|
|
|
|
Timeout.timeout(to) do
|
|
|
|
pcap.each do |r|
|
|
|
|
pkt = PacketFu::Packet.parse(r)
|
|
|
|
next unless pkt.is_tcp?
|
|
|
|
next unless pkt.tcp_flags.syn == 1 || pkt.tcp_flags.rst == 1
|
|
|
|
reply = pkt
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue Timeout::Error
|
|
|
|
end
|
|
|
|
|
|
|
|
return reply
|
|
|
|
end
|
2009-11-02 18:16:51 +00:00
|
|
|
|
2009-04-03 00:59:25 +00:00
|
|
|
end
|