2009-04-03 00:59:25 +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-04-03 00:59:25 +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/
|
2009-04-03 00:59:25 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
2009-07-17 20:36:40 +00:00
|
|
|
require 'racket'
|
2009-04-03 00:59:25 +00:00
|
|
|
require 'timeout'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
2010-01-26 22:36:27 +00:00
|
|
|
include Msf::Exploit::Capture
|
2009-04-03 00:59:25 +00:00
|
|
|
include Msf::Auxiliary::Scanner
|
2010-06-17 14:03:53 +00:00
|
|
|
include Msf::Auxiliary::Report
|
2009-04-03 00:59:25 +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).
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
Nmap's Idle Scan can use hosts whose IPID sequences are
|
|
|
|
classified as "Incremental" or "Broken little-endian incremental".
|
|
|
|
},
|
2009-04-03 15:05:35 +00:00
|
|
|
'Author' => 'kris katterjohn',
|
2009-04-03 00:59:25 +00:00
|
|
|
'License' => MSF_LICENSE,
|
2009-07-17 20:36:40 +00:00
|
|
|
'Version' => '$Revision$'
|
2009-04-03 00:59:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
begin
|
|
|
|
require 'pcaprub'
|
|
|
|
@@havepcap = true
|
|
|
|
rescue ::LoadError
|
|
|
|
@@havepcap = false
|
|
|
|
end
|
|
|
|
|
|
|
|
register_options([
|
|
|
|
Opt::RPORT(80),
|
2009-11-26 04:14:16 +00:00
|
|
|
OptInt.new('TIMEOUT', [true, "The reply read timeout in milliseconds", 500]),
|
|
|
|
OptString.new('INTERFACE', [false, 'The name of the interface'])
|
2009-04-03 00:59:25 +00:00
|
|
|
])
|
2009-10-18 21:22:55 +00:00
|
|
|
|
|
|
|
register_advanced_options([
|
|
|
|
OptInt.new('SAMPLES', [true, "The IPID sample size", 6])
|
|
|
|
])
|
2010-01-26 22:36:27 +00:00
|
|
|
|
|
|
|
deregister_options('FILTER','PCAPFILE')
|
2009-04-03 00:59:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def rport
|
|
|
|
datastore['RPORT'].to_i
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
2010-01-27 18:40:38 +00:00
|
|
|
open_pcap
|
|
|
|
|
2009-10-18 21:22:55 +00:00
|
|
|
raise "Pcaprub is not available" if not @@havepcap
|
|
|
|
raise "SAMPLES option must be >= 2" if datastore['SAMPLES'] < 2
|
|
|
|
|
2010-01-27 18:40:38 +00:00
|
|
|
pcap = self.capture
|
2009-04-03 00:59:25 +00:00
|
|
|
|
|
|
|
shost = Rex::Socket.source_address(ip)
|
|
|
|
|
|
|
|
to = (datastore['TIMEOUT'] || 500).to_f / 1000.0
|
|
|
|
|
|
|
|
ipids = []
|
|
|
|
|
2010-01-27 18:40:38 +00:00
|
|
|
pcap.setfilter(getfilter(shost, ip, rport))
|
2009-10-18 21:22:55 +00:00
|
|
|
|
|
|
|
datastore['SAMPLES'].times do
|
2009-04-03 00:59:25 +00:00
|
|
|
sport = rand(0xffff - 1025) + 1025
|
|
|
|
|
|
|
|
probe = buildprobe(shost, sport, ip, rport)
|
|
|
|
|
2010-01-27 18:40:38 +00:00
|
|
|
capture_sendto(probe, ip)
|
2009-04-03 00:59:25 +00:00
|
|
|
|
2010-01-27 18:40:38 +00:00
|
|
|
reply = probereply(pcap, to)
|
2009-04-03 00:59:25 +00:00
|
|
|
|
|
|
|
next if not reply
|
|
|
|
|
2009-07-17 20:36:40 +00:00
|
|
|
ipids << reply[:ip].id
|
2009-04-03 00:59:25 +00:00
|
|
|
end
|
|
|
|
|
2010-01-26 22:36:27 +00:00
|
|
|
close_pcap
|
2009-04-03 00:59:25 +00:00
|
|
|
|
|
|
|
return if ipids.empty?
|
|
|
|
|
|
|
|
print_status("#{ip}'s IPID sequence class: #{analyze(ipids)}")
|
2010-07-01 23:33:07 +00:00
|
|
|
|
2010-06-17 14:03:53 +00:00
|
|
|
#Add Report
|
|
|
|
report_note(
|
|
|
|
:host => ip,
|
|
|
|
:proto => 'ip',
|
|
|
|
:type => 'IPID sequence',
|
|
|
|
:data => "IPID sequence class: #{analyze(ipids)}"
|
|
|
|
)
|
2009-04-03 00:59:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Based on Nmap's get_ipid_sequence() in osscan2.cc
|
|
|
|
def analyze(ipids)
|
|
|
|
allzeros = true
|
|
|
|
allsame = true
|
|
|
|
mul256 = true
|
|
|
|
inc = true
|
|
|
|
|
2009-07-17 20:36:40 +00:00
|
|
|
# ipids.each do |ipid|
|
2009-04-03 00:59:25 +00:00
|
|
|
# print_status("Got IPID ##{ipid}")
|
2009-07-17 20:36:40 +00:00
|
|
|
# end
|
2009-04-03 00:59:25 +00:00
|
|
|
|
|
|
|
return "Unknown" if ipids.size < 2
|
|
|
|
|
|
|
|
diffs = []
|
|
|
|
i = 1
|
|
|
|
|
|
|
|
while i < ipids.size
|
|
|
|
p = ipids[i - 1]
|
|
|
|
c = ipids[i]
|
|
|
|
|
|
|
|
if p != 0 or c != 0
|
|
|
|
allzeros = false
|
|
|
|
end
|
|
|
|
|
|
|
|
if p <= c
|
|
|
|
diffs[i - 1] = c - p
|
|
|
|
else
|
|
|
|
diffs[i - 1] = c - p + 65536
|
|
|
|
end
|
|
|
|
|
|
|
|
if ipids.size > 2 and diffs[i - 1] > 20000
|
|
|
|
return "Randomized"
|
|
|
|
end
|
|
|
|
|
|
|
|
i += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
return "All zeros" if allzeros
|
|
|
|
|
|
|
|
diffs.each do |diff|
|
|
|
|
if diff > 1000 and ((diff % 256) != 0 or ((diff % 256) == 0 and diff >= 25600))
|
|
|
|
return "Random positive increments"
|
|
|
|
end
|
|
|
|
|
|
|
|
allsame = false if diff != 0
|
|
|
|
|
|
|
|
mul256 = false if diff > 5120 or (diff % 256) != 0
|
|
|
|
|
|
|
|
inc = false if diff >= 10
|
|
|
|
end
|
|
|
|
|
|
|
|
return "Constant" if allsame
|
|
|
|
|
|
|
|
return "Broken little-endian incremental!" if mul256
|
|
|
|
|
|
|
|
return "Incremental!" if inc
|
|
|
|
|
|
|
|
"Unknown"
|
|
|
|
end
|
|
|
|
|
2009-07-17 20:36:40 +00:00
|
|
|
def getfilter(shost, dhost, dport)
|
2009-04-03 00:59:25 +00:00
|
|
|
"tcp and src host #{dhost} and src port #{dport} and " +
|
2009-07-17 20:36:40 +00:00
|
|
|
"dst host #{shost}"
|
2009-04-03 00:59:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def buildprobe(shost, sport, dhost, dport)
|
2009-07-17 20:36:40 +00:00
|
|
|
n = Racket::Racket.new
|
|
|
|
|
2009-12-29 23:32:50 +00:00
|
|
|
n.l3 = Racket::L3::IPv4.new
|
2009-07-17 20:36:40 +00:00
|
|
|
n.l3.src_ip = shost
|
|
|
|
n.l3.dst_ip = dhost
|
|
|
|
n.l3.protocol = 0x6
|
|
|
|
n.l3.id = rand(0x10000)
|
2009-11-07 03:17:19 +00:00
|
|
|
n.l3.ttl = 255
|
2009-11-02 18:16:51 +00:00
|
|
|
|
2009-12-29 23:32:50 +00:00
|
|
|
n.l4 = Racket::L4::TCP.new
|
2009-07-17 20:36:40 +00:00
|
|
|
n.l4.src_port = sport
|
|
|
|
n.l4.seq = rand(0x100000000)
|
|
|
|
n.l4.dst_port = dport
|
|
|
|
n.l4.flag_syn = 1
|
2009-11-02 18:16:51 +00:00
|
|
|
|
|
|
|
n.l4.fix!(n.l3.src_ip, n.l3.dst_ip, "")
|
|
|
|
|
2009-07-17 20:36:40 +00:00
|
|
|
n.pack
|
2009-04-03 00:59:25 +00:00
|
|
|
end
|
|
|
|
|
2010-01-26 22:36:27 +00:00
|
|
|
def probereply(pcap, to)
|
2009-04-03 00:59:25 +00:00
|
|
|
reply = nil
|
|
|
|
|
|
|
|
begin
|
2009-11-02 18:16:51 +00:00
|
|
|
Timeout.timeout(to) do
|
2009-04-03 00:59:25 +00:00
|
|
|
pcap.each do |r|
|
2009-12-29 23:32:50 +00:00
|
|
|
eth = Racket::L2::Ethernet.new(r)
|
2009-11-02 18:16:51 +00:00
|
|
|
|
2009-07-17 20:36:40 +00:00
|
|
|
next if not eth.ethertype == 0x0800
|
2009-11-02 18:16:51 +00:00
|
|
|
|
2009-12-29 23:32:50 +00:00
|
|
|
ip = Racket::L3::IPv4.new(eth.payload)
|
2009-07-17 20:36:40 +00:00
|
|
|
next if not ip.protocol == 6
|
2009-11-02 18:16:51 +00:00
|
|
|
|
2009-12-29 23:32:50 +00:00
|
|
|
tcp = Racket::L4::TCP.new(ip.payload)
|
2009-11-02 18:16:51 +00:00
|
|
|
|
2009-07-17 20:36:40 +00:00
|
|
|
reply = {:raw => r, :eth => eth, :ip => ip, :tcp => tcp}
|
2009-11-02 18:16:51 +00:00
|
|
|
|
2009-04-03 00:59:25 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2009-11-02 18:22:50 +00:00
|
|
|
rescue Timeout::Error
|
2009-04-03 00:59:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return reply
|
|
|
|
end
|
2009-11-02 18:16:51 +00:00
|
|
|
|
2009-04-03 00:59:25 +00:00
|
|
|
end
|