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
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2010-11-11 22:43:22 +00:00
|
|
|
# http://metasploit.com/framework/
|
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"]),
|
2010-10-15 22:48:18 +00:00
|
|
|
OptString.new('SMAC', [true, "Source MAC Address"]),
|
|
|
|
], 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"})
|
|
|
|
|
2010-12-27 16:43:53 +00:00
|
|
|
print_status("Discovering IPv4 nodes via ARP...")
|
2010-10-15 22:48:18 +00:00
|
|
|
|
2010-10-19 22:54:19 +00:00
|
|
|
shost = datastore['SHOST']
|
2010-10-15 22:48:18 +00:00
|
|
|
smac = datastore['SMAC']
|
|
|
|
|
|
|
|
addrs = []
|
|
|
|
|
|
|
|
begin
|
2010-12-27 16:43:53 +00:00
|
|
|
found = {}
|
2010-10-15 22:48:18 +00:00
|
|
|
hosts.each do |dhost|
|
2010-12-27 16:43:53 +00:00
|
|
|
shost = datastore['SHOST'] || Rex::Socket.source_address(dhost)
|
2010-10-15 22:48:18 +00:00
|
|
|
|
|
|
|
probe = buildprobe(datastore['SHOST'], datastore['SMAC'], dhost)
|
|
|
|
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
|
|
|
|
2010-10-19 22:54:19 +00:00
|
|
|
smac = datastore['SMAC']
|
|
|
|
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],
|
|
|
|
:proto => 'IP',
|
|
|
|
:sname => 'all',
|
|
|
|
:type => 'ipv4.ipv6.mapping',
|
|
|
|
: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())
|
|
|
|
next if not adv[:icmpv6]
|
|
|
|
|
|
|
|
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
|