2010-10-15 22:48:18 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# 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/
|
2010-10-15 22:48:18 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
2011-07-26 01:29:21 +00:00
|
|
|
include Msf::Exploit::Remote::Ipv6
|
2010-10-15 22:48:18 +00:00
|
|
|
include Msf::Exploit::Remote::Capture
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'IPv6 Local Neighbor Discovery',
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Description' => %q{
|
|
|
|
Enumerate local IPv6 hosts which respond to Neighbor Solicitations with a link-local address.
|
|
|
|
Note, that like ARP scanning, this usually cannot be performed beyond the local
|
|
|
|
broadcast network.
|
|
|
|
},
|
|
|
|
'Author' => 'belch',
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
2010-12-27 16:43:53 +00:00
|
|
|
OptString.new('SHOST', [false, "Source IP Address"]),
|
2012-07-10 17:28:24 +00:00
|
|
|
OptString.new('SMAC', [false, "Source MAC Address"]),
|
2010-10-15 22:48:18 +00:00
|
|
|
], self.class)
|
|
|
|
|
|
|
|
deregister_options('SNAPLEN', 'FILTER')
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_batch_size
|
|
|
|
datastore['BATCHSIZE'] || 256
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_batch(hosts)
|
2011-07-27 20:21:47 +00:00
|
|
|
open_pcap({'SNAPLEN' => 68, 'FILTER' => "arp[6:2] == 0x0002"})
|
|
|
|
|
2012-07-10 17:28:24 +00:00
|
|
|
@netifaces = true
|
|
|
|
if not netifaces_implemented?
|
|
|
|
print_error("WARNING : Pcaprub is not uptodate, some functionality will not be available")
|
|
|
|
@netifaces = false
|
|
|
|
end
|
|
|
|
|
2010-12-27 16:43:53 +00:00
|
|
|
print_status("Discovering IPv4 nodes via ARP...")
|
2010-10-15 22:48:18 +00:00
|
|
|
|
2012-07-10 17:28:24 +00:00
|
|
|
@interface = datastore['INTERFACE'] || Pcap.lookupdev
|
|
|
|
@shost = datastore['SHOST']
|
|
|
|
@shost ||= get_ipv4_addr(@interface) if @netifaces
|
|
|
|
raise RuntimeError ,'SHOST should be defined' unless @shost
|
|
|
|
|
|
|
|
@smac = datastore['SMAC']
|
|
|
|
@smac ||= get_mac(@interface) if @netifaces
|
|
|
|
raise RuntimeError ,'SMAC should be defined' unless @smac
|
2010-10-15 22:48:18 +00:00
|
|
|
|
|
|
|
addrs = []
|
|
|
|
|
|
|
|
begin
|
2010-12-27 16:43:53 +00:00
|
|
|
found = {}
|
2010-10-15 22:48:18 +00:00
|
|
|
hosts.each do |dhost|
|
2012-08-07 20:59:01 +00:00
|
|
|
|
2012-07-10 17:28:24 +00:00
|
|
|
probe = buildprobe(@shost, @smac, dhost)
|
2010-10-15 22:48:18 +00:00
|
|
|
capture.inject(probe)
|
|
|
|
while(reply = getreply())
|
2011-07-26 01:29:21 +00:00
|
|
|
next unless reply.is_arp?
|
|
|
|
if not found[reply.arp_saddr_ip]
|
|
|
|
print_status(sprintf(" %16s ALIVE",reply.arp_saddr_ip))
|
|
|
|
addrs << [reply.arp_saddr_ip, reply.arp_saddr_mac]
|
|
|
|
report_host(:host => reply.arp_saddr_ip, :mac=>reply.arp_saddr_mac)
|
|
|
|
found[reply.arp_saddr_ip] = true
|
2010-12-27 16:43:53 +00:00
|
|
|
end
|
2010-10-15 22:48:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-12-27 16:43:53 +00:00
|
|
|
etime = ::Time.now.to_f + (hosts.length * 0.05)
|
2010-10-15 22:48:18 +00:00
|
|
|
|
2010-12-27 16:43:53 +00:00
|
|
|
while (::Time.now.to_f < etime)
|
2010-10-15 22:48:18 +00:00
|
|
|
while(reply = getreply())
|
2011-07-26 01:29:21 +00:00
|
|
|
next unless reply.is_arp?
|
|
|
|
if not found[reply.arp_saddr_ip]
|
|
|
|
print_status(sprintf(" %16s ALIVE",reply.arp_saddr_ip))
|
|
|
|
addrs << [reply.arp_saddr_ip, reply.arp_saddr_mac]
|
|
|
|
report_host(:host => reply.arp_saddr_ip, :mac=>reply.arp_saddr_mac)
|
|
|
|
found[reply.arp_saddr_ip] = true
|
2010-12-27 16:43:53 +00:00
|
|
|
end
|
2010-10-15 22:48:18 +00:00
|
|
|
end
|
|
|
|
|
2010-12-27 16:43:53 +00:00
|
|
|
::IO.select(nil, nil, nil, 0.50)
|
2010-10-15 22:48:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
ensure
|
|
|
|
close_pcap()
|
|
|
|
end
|
|
|
|
|
2010-10-19 22:54:19 +00:00
|
|
|
neighbor_discovery(addrs)
|
2010-10-15 22:48:18 +00:00
|
|
|
end
|
|
|
|
|
2010-10-19 22:54:19 +00:00
|
|
|
def map_neighbor(nodes, adv)
|
2010-10-15 22:48:18 +00:00
|
|
|
nodes.each do |node|
|
2010-10-19 22:54:19 +00:00
|
|
|
ipv4_addr, mac_addr = node
|
2011-07-26 01:29:21 +00:00
|
|
|
next unless adv.eth_saddr == mac_addr
|
|
|
|
ipv6_addr = adv.ipv6_saddr
|
2010-10-15 22:48:18 +00:00
|
|
|
return {:eth => mac_addr, :ipv4 => ipv4_addr, :ipv6 => ipv6_addr}
|
2010-10-19 22:54:19 +00:00
|
|
|
end
|
2010-10-15 22:48:18 +00:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def neighbor_discovery(neighs)
|
2010-12-27 16:43:53 +00:00
|
|
|
print_status("Discovering IPv6 addresses for IPv4 nodes...")
|
|
|
|
print_status("")
|
2011-11-20 02:12:07 +00:00
|
|
|
|
2012-07-10 17:28:24 +00:00
|
|
|
smac = @smac
|
2010-10-19 22:54:19 +00:00
|
|
|
open_pcap({'SNAPLEN' => 68, 'FILTER' => "icmp6"})
|
2010-10-15 22:48:18 +00:00
|
|
|
|
2010-10-19 22:54:19 +00:00
|
|
|
begin
|
2010-10-15 22:48:18 +00:00
|
|
|
neighs.each do |neigh|
|
|
|
|
host, dmac = neigh
|
|
|
|
|
2011-07-26 01:29:21 +00:00
|
|
|
shost = ipv6_linklocaladdr(smac)
|
|
|
|
neigh = ipv6_linklocaladdr(dmac)
|
2010-10-15 22:48:18 +00:00
|
|
|
|
|
|
|
probe = buildsolicitation(smac, shost, neigh)
|
|
|
|
|
|
|
|
capture.inject(probe)
|
2011-07-26 01:29:21 +00:00
|
|
|
Kernel.select(nil,nil,nil,0.1)
|
2010-10-15 22:48:18 +00:00
|
|
|
|
2010-10-19 22:54:19 +00:00
|
|
|
while(adv = getadvertisement())
|
2011-07-26 01:29:21 +00:00
|
|
|
next unless adv.is_ipv6?
|
2010-10-15 22:48:18 +00:00
|
|
|
|
|
|
|
addr = map_neighbor(neighs, adv)
|
|
|
|
next if not addr
|
|
|
|
|
2010-12-27 16:43:53 +00:00
|
|
|
print_status(sprintf(" %16s maps to %s",addr[:ipv4], addr[:ipv6]))
|
2012-02-10 09:22:51 +00:00
|
|
|
report_note(
|
|
|
|
:host => addr[:ipv4],
|
2012-02-29 05:52:48 +00:00
|
|
|
:type => 'host.ipv4.ipv6.mapping',
|
2012-02-10 09:22:51 +00:00
|
|
|
:data => "system with IPv4 address #{addr[:ipv4]} matches to IPv6 address #{addr[:ipv6]}"
|
|
|
|
) # with this we have the results in our database
|
2012-02-06 07:56:35 +00:00
|
|
|
|
2010-10-15 22:48:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-12-27 16:43:53 +00:00
|
|
|
etime = ::Time.now.to_f + (neighs.length * 0.5)
|
2010-10-15 22:48:18 +00:00
|
|
|
|
2010-12-27 16:43:53 +00:00
|
|
|
while (::Time.now.to_f < etime)
|
2010-10-15 22:48:18 +00:00
|
|
|
while(adv = getadvertisement())
|
2012-04-02 15:02:59 +00:00
|
|
|
next if not adv
|
2010-10-15 22:48:18 +00:00
|
|
|
|
|
|
|
addr = map_neighbor(neighs, adv)
|
|
|
|
next if not addr
|
|
|
|
|
2010-12-27 16:43:53 +00:00
|
|
|
print_status(sprintf(" %16s maps to %s",addr[:ipv4], addr[:ipv6]))
|
2010-10-15 22:48:18 +00:00
|
|
|
end
|
2010-12-27 16:43:53 +00:00
|
|
|
::IO.select(nil, nil, nil, 0.50)
|
2010-10-15 22:48:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
ensure
|
|
|
|
close_pcap()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def buildprobe(shost, smac, dhost)
|
2011-07-26 01:29:21 +00:00
|
|
|
p = PacketFu::ARPPacket.new
|
|
|
|
p.eth_saddr = smac
|
|
|
|
p.eth_daddr = "ff:ff:ff:ff:ff:ff"
|
|
|
|
p.arp_opcode = 1
|
|
|
|
p.arp_saddr_mac = p.eth_saddr
|
|
|
|
p.arp_daddr_mac = p.eth_daddr
|
|
|
|
p.arp_saddr_ip = shost
|
|
|
|
p.arp_daddr_ip = dhost
|
|
|
|
p.to_s
|
2010-10-15 22:48:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def getreply
|
|
|
|
pkt = capture.next
|
2011-07-26 01:29:21 +00:00
|
|
|
Kernel.select(nil,nil,nil,0.1)
|
2010-10-15 22:48:18 +00:00
|
|
|
return if not pkt
|
2011-07-26 01:29:21 +00:00
|
|
|
p = PacketFu::Packet.parse(pkt)
|
|
|
|
return unless p.is_arp?
|
|
|
|
return unless p.arp_opcode == 2
|
|
|
|
p
|
2010-10-15 22:48:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def buildsolicitation(smac, shost, neigh)
|
2011-07-26 01:29:21 +00:00
|
|
|
dmac = ipv6_soll_mcast_mac(neigh)
|
|
|
|
dhost = ipv6_soll_mcast_addr6(neigh)
|
|
|
|
|
|
|
|
p = PacketFu::IPv6Packet.new
|
|
|
|
p.eth_saddr = smac
|
|
|
|
p.eth_daddr = dmac
|
|
|
|
p.ipv6_saddr = shost
|
|
|
|
p.ipv6_daddr = dhost
|
|
|
|
p.ipv6_next = 0x3a
|
|
|
|
p.ipv6_hop = 255
|
|
|
|
p.payload = ipv6_neighbor_solicitation(
|
|
|
|
IPAddr.new(neigh).to_i,
|
|
|
|
p.eth_src
|
|
|
|
)
|
|
|
|
p.ipv6_len = p.payload.size
|
|
|
|
ipv6_checksum!(p)
|
|
|
|
p.to_s
|
2010-10-15 22:48:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def getadvertisement
|
|
|
|
pkt = capture.next
|
2011-07-26 01:29:21 +00:00
|
|
|
Kernel.select(nil,nil,nil,0.1)
|
2010-10-15 22:48:18 +00:00
|
|
|
return if not pkt
|
2011-07-26 01:29:21 +00:00
|
|
|
p = PacketFu::Packet.parse(pkt)
|
|
|
|
return unless p.is_ipv6?
|
|
|
|
return unless p.ipv6_next == 0x3a
|
|
|
|
return unless p.payload[0,2] == "\x88\x00"
|
|
|
|
p
|
2010-10-15 22:48:18 +00:00
|
|
|
end
|
2011-07-26 01:29:21 +00:00
|
|
|
|
2010-10-15 22:48:18 +00:00
|
|
|
end
|