metasploit-framework/modules/auxiliary/scanner/ip/ipidseq.rb

193 lines
4.1 KiB
Ruby
Raw Normal View History

##
# This module requires Metasploit: http//metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
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
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).
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.
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
)
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'])
])
2013-08-30 21:28:54 +00:00
register_advanced_options([
OptInt.new('SAMPLES', [true, "The IPID sample size", 6])
])
2013-08-30 21:28:54 +00:00
deregister_options('FILTER','PCAPFILE')
end
2013-08-30 21:28:54 +00:00
def rport
datastore['RPORT'].to_i
end
2013-08-30 21:28:54 +00:00
def run_host(ip)
open_pcap
2013-08-30 21:28:54 +00:00
raise "SAMPLES option must be >= 2" if datastore['SAMPLES'] < 2
2013-08-30 21:28:54 +00:00
pcap = self.capture
2013-08-30 21:28:54 +00:00
shost = Rex::Socket.source_address(ip)
2013-08-30 21:28:54 +00:00
to = (datastore['TIMEOUT'] || 500).to_f / 1000.0
2013-08-30 21:28:54 +00:00
ipids = []
2013-08-30 21:28:54 +00:00
pcap.setfilter(getfilter(shost, ip, rport))
2013-08-30 21:28:54 +00:00
datastore['SAMPLES'].times do
sport = rand(0xffff - 1025) + 1025
2013-08-30 21:28:54 +00:00
probe = buildprobe(shost, sport, ip, rport)
2013-08-30 21:28:54 +00:00
capture_sendto(probe, ip)
2013-08-30 21:28:54 +00:00
reply = probereply(pcap, to)
2013-08-30 21:28:54 +00:00
next if not reply
2013-08-30 21:28:54 +00:00
ipids << reply.ip_id
end
2013-08-30 21:28:54 +00:00
close_pcap
2013-08-30 21:28:54 +00:00
return if ipids.empty?
2013-08-30 21:28:54 +00:00
print_status("#{ip}'s IPID sequence class: #{analyze(ipids)}")
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
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
2013-08-30 21:28:54 +00:00
# ipids.each do |ipid|
# print_status("Got IPID ##{ipid}")
# end
2013-08-30 21:28:54 +00:00
return "Unknown" if ipids.size < 2
2013-08-30 21:28:54 +00:00
diffs = []
i = 1
2013-08-30 21:28:54 +00:00
while i < ipids.size
p = ipids[i - 1]
c = ipids[i]
2013-08-30 21:28:54 +00:00
if p != 0 or c != 0
allzeros = false
end
2013-08-30 21:28:54 +00:00
if p <= c
diffs[i - 1] = c - p
else
diffs[i - 1] = c - p + 65536
end
2013-08-30 21:28:54 +00:00
if ipids.size > 2 and diffs[i - 1] > 20000
return "Randomized"
end
2013-08-30 21:28:54 +00:00
i += 1
end
2013-08-30 21:28:54 +00:00
return "All zeros" if allzeros
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
2013-08-30 21:28:54 +00:00
allsame = false if diff != 0
2013-08-30 21:28:54 +00:00
mul256 = false if diff > 5120 or (diff % 256) != 0
2013-08-30 21:28:54 +00:00
inc = false if diff >= 10
end
2013-08-30 21:28:54 +00:00
return "Constant" if allsame
2013-08-30 21:28:54 +00:00
return "Broken little-endian incremental!" if mul256
2013-08-30 21:28:54 +00:00
return "Incremental!" if inc
2013-08-30 21:28:54 +00:00
"Unknown"
end
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
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
2013-08-30 21:28:54 +00:00
def probereply(pcap, to)
reply = nil
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
end