2009-04-03 00:59:25 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# 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
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::Ip
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
|
|
|
|
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),
|
|
|
|
OptInt.new('TIMEOUT', [true, "The reply read timeout in milliseconds", 500])
|
|
|
|
])
|
2009-10-18 21:22:55 +00:00
|
|
|
|
|
|
|
register_advanced_options([
|
|
|
|
OptInt.new('SAMPLES', [true, "The IPID sample size", 6])
|
|
|
|
])
|
2009-04-03 00:59:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def rport
|
|
|
|
datastore['RPORT'].to_i
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_host(ip)
|
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
|
|
|
|
|
2009-04-03 00:59:25 +00:00
|
|
|
socket = connect_ip(false)
|
|
|
|
return if not socket
|
|
|
|
|
|
|
|
pcap = ::Pcap.open_live(::Pcap.lookupdev, 68, false, 1)
|
|
|
|
|
|
|
|
shost = Rex::Socket.source_address(ip)
|
|
|
|
|
|
|
|
to = (datastore['TIMEOUT'] || 500).to_f / 1000.0
|
|
|
|
|
|
|
|
ipids = []
|
|
|
|
|
2009-07-17 20:36:40 +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)
|
|
|
|
|
|
|
|
socket.sendto(probe, ip)
|
|
|
|
|
|
|
|
reply = readreply(pcap, to)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
disconnect_ip(socket)
|
|
|
|
|
|
|
|
return if ipids.empty?
|
|
|
|
|
|
|
|
print_status("#{ip}'s IPID sequence class: #{analyze(ipids)}")
|
|
|
|
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
|
|
|
|
|
|
|
|
n.l3 = Racket::IPv4.new
|
|
|
|
n.l3.src_ip = shost
|
|
|
|
n.l3.dst_ip = dhost
|
|
|
|
n.l3.protocol = 0x6
|
|
|
|
n.l3.id = rand(0x10000)
|
|
|
|
|
|
|
|
n.l4 = Racket::TCP.new
|
|
|
|
n.l4.src_port = sport
|
|
|
|
n.l4.seq = rand(0x100000000)
|
|
|
|
n.l4.dst_port = dport
|
|
|
|
n.l4.flag_syn = 1
|
|
|
|
|
|
|
|
n.l4.fix!(n.l3.src_ip, n.l3.dst_ip, "")
|
|
|
|
|
|
|
|
n.pack
|
2009-04-03 00:59:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def readreply(pcap, to)
|
|
|
|
reply = nil
|
|
|
|
|
|
|
|
begin
|
|
|
|
timeout(to) do
|
|
|
|
pcap.each do |r|
|
2009-07-17 20:36:40 +00:00
|
|
|
eth = Racket::Ethernet.new(r)
|
|
|
|
|
|
|
|
next if not eth.ethertype == 0x0800
|
|
|
|
|
|
|
|
ip = Racket::IPv4.new(eth.payload)
|
|
|
|
next if not ip.protocol == 6
|
|
|
|
|
|
|
|
tcp = Racket::TCP.new(ip.payload)
|
|
|
|
|
|
|
|
reply = {:raw => r, :eth => eth, :ip => ip, :tcp => tcp}
|
|
|
|
|
2009-04-03 00:59:25 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue TimeoutError
|
|
|
|
end
|
|
|
|
|
|
|
|
return reply
|
|
|
|
end
|
2009-07-17 20:36:40 +00:00
|
|
|
|
2009-04-03 00:59:25 +00:00
|
|
|
end
|
|
|
|
|