#
# IPAddress::IPv6 - IP version 6 address manipulation library
#
# Class IPAddress::IPv6 is used to handle IPv6 type addresses.
#
# == IPv6 addresses
#
# IPv6 addresses are 128 bits long, in contrast with IPv4 addresses
# which are only 32 bits long. An IPv6 address is generally written as
# eight groups of four hexadecimal digits, each group representing 16
# bits or two octect. For example, the following is a valid IPv6
#
# Letters in an IPv6 address are usually written downcase, as per
# RFC. You can create a new IPv6 object using uppercase letters, but
# they will be converted.
module Dnsruby
#Dnsruby::IPv6 class
class IPv6
#IPv6 address format a:b:c:d:e:f:g:h
Regex_8Hex = /\A
#Compresses IPv6 format a::b
# IPv4 mapped IPv6 address format a:b:c:d:e:f:w.x.y.z
# Compressed IPv4 mapped IPv6 address format a::b:w.x.y.z
# A composite IPv6 address RegExp
# Created a new IPv6 address from +arg+ which may be:
#
# Sets up resolution with IPv6 support if the address is an ip
# @since 2.0.0
class IPv6
# The regular expression to use to match an IPv6 ip address.
# Parse an IPv6 address into its host and port.
# Initialize the IPv6 resolver.
# @example Initialize the resolver.
# IPv6.new("::1", 28011, 'localhost')
#
# @example Get an IPv6 socket.
#
# This module provides common tools for IPv6
###
module Exploit::Remote::Ipv6
OptString.new("SMAC", [ false, "The source MAC address"]),
OptAddress.new("SHOST", [ false, "The source IPv6 address" ] ),
OptInt.new("TIMEOUT", [ true, "Timeout when waiting for host response.", 5])
], Msf::Exploit::Remote::Ipv6
#
def ipv6_interface(opts={})
#
def ipv6_link_address(opts={})
Rex::Socket.ipv6_link_address(ipv6_interface(opts))
end
#
def ipv6_mac(opts={})
Rex::Socket.ipv6_mac(ipv6_interface(opts))
# AddrIpv6 handles addressing for IPv6Header
# Int32 :a4
class AddrIpv6 < Struct.new(:a1, :a2, :a3, :a4)
# Reads in a string and casts it as an IPv6 address
# Reads in a colon-delimited hex string and casts it as an IPv6 address.
# IPv6Header is complete IPv6 struct, used in IPv6Packet.
#
# Fixnum (4 bits) :ipv6_v Default: 6 # Versiom
# Fixnum (8 bits) :ipv6_class Defualt: 0 # Class
# Fixnum (20 bits) :ipv6_label Defualt: 0 # Label
# Int16 :ipv6_len Default: calc # Payload length
# AddrIpv6 handles addressing for IPv6Header
# Int32 :a4
class AddrIpv6 < Struct.new(:a1, :a2, :a3, :a4)
# Reads in a string and casts it as an IPv6 address
# Reads in a colon-delimited hex string and casts it as an IPv6 address.
# IPv6Header is complete IPv6 struct, used in IPv6Packet.
#
# Fixnum (4 bits) :ipv6_v Default: 6 # Versiom
# Fixnum (8 bits) :ipv6_class Defualt: 0 # Class
# Fixnum (20 bits) :ipv6_label Defualt: 0 # Label
# Int16 :ipv6_len Default: calc # Payload length
#
# This module provides common tools for IPv6
###
module Exploit::Remote::Ipv6
OptString.new("SMAC", [ false, "The source MAC address"]),
OptAddress.new("SHOST", [ false, "The source IPv6 address" ] ),
OptInt.new("TIMEOUT", [ true, "Timeout when waiting for host response.", 5])
], Msf::Exploit::Remote::Ipv6
#
def ipv6_interface(opts={})
#
def ipv6_link_address(opts={})
Rex::Socket.ipv6_link_address(ipv6_interface(opts))
end
#
def ipv6_mac(opts={})
Rex::Socket.ipv6_mac(ipv6_interface(opts))
# AddrIpv6 handles addressing for IPv6Header
# Int32 :a4
class AddrIpv6 < Struct.new(:a1, :a2, :a3, :a4)
# Reads in a string and casts it as an IPv6 address
# Reads in a colon-delimited hex string and casts it as an IPv6 address.
# IPv6Header is complete IPv6 struct, used in IPv6Packet.
#
# Fixnum (4 bits) :ipv6_v Default: 6 # Versiom
# Fixnum (8 bits) :ipv6_class Defualt: 0 # Class
# Fixnum (20 bits) :ipv6_label Defualt: 0 # Label
# Int16 :ipv6_len Default: calc # Payload length
#
# This module provides common tools for IPv6
###
module Exploit::Remote::Ipv6
OptString.new("SMAC", [ false, "The source MAC address"]),
OptAddress.new("SHOST", [ false, "The source IPv6 address" ] ),
OptInt.new("TIMEOUT", [ true, "Timeout when waiting for host response.", 5])
], Msf::Exploit::Remote::Ipv6
#
def ipv6_interface(opts={})
#
def ipv6_link_address(opts={})
Rex::Socket.ipv6_link_address(ipv6_interface(opts))
end
#
def ipv6_mac(opts={})
Rex::Socket.ipv6_mac(ipv6_interface(opts))
# Given a long, convert it to an IPv6 address,
# optionally compressing the address returned
ipv6[3] = (long >> 64) & (0xFFFF)
ipv6[4] = (long >> 48) & (0xFFFF)
ipv6[5] = (long >> 32) & (0xFFFF)
ipv6[6] = (long >> 16) & (0xFFFF)
ipv6[7] = long & (0xFFFF)
ipv6 = ipv6.map { |o| o.to_s(16) }.join(":")
compress ? Misc.compressipv6(ipv6) : ipv6
end
# Compress an IPv6 address
# Inspired by Daniele Bellucci and jacked from ipaddr
def Misc.compressipv6(ipv6)
# IPAddr provides a set of methods to manipulate an IP address. Both IPv4 and
# IPv6 are supported.
#
# p ipaddr1 #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>
#
# ipaddr2 = ipaddr1.mask(48) #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0000/ffff:ffff:ffff:0000:0000:0000:0000:0000>
# Returns true if the ipaddr is an IPv4-mapped IPv6 address.
def ipv4_mapped?
return ipv6? && (@addr >> 32) == 0xffff
# Returns true if the ipaddr is an IPv4-compatible IPv6 address.
def ipv4_compat?
if !ipv6? || (@addr >> 32) != 0
# Returns a new ipaddr built by converting the native IPv4 address
# into an IPv4-mapped IPv6 address.
it "should accept long IPv6 addresses" do
# Taken from wikipedia article about ipv6
proc { @class.new(:name => "foo", :ip => '2001:0db8:85a3:08d3:1319:8a2e:0370:7344') }.should_not raise_error
it "should accept shortened IPv6 addresses" do
"::ffff:192.168.1.1",
"0:0:0:0:0:0:13.1.68.3", # IPv4-compatible IPv6 address, full, deprecated
"0:0:0:0:0:FFFF:129.144.52.38", # IPv4-mapped IPv6 address, full
"::13.1.68.3", # IPv4-compatible IPv6 address, compressed, deprecated
"::FFFF:129.144.52.38", # IPv4-mapped IPv6 address, compressed
"fe80:0:0:0:204:61ff:254.157.241.86",
# Additional cases: http://crisp.tweakblogs.net/blog/2031/ipv6-validation-%28and-caveats%29.html
].each do |ip|
it "should accept #{ip.inspect} as an IPv6 address" do
describe 'PostgreSQL inet/cidr types' do
ipv6_broken = (IPAddr.new('::1'); false) rescue true
@ipv4nm = IPAddr.new(@v4nm)
unless ipv6_broken
@ipv6 = IPAddr.new(@v6)
@ipv6nm = IPAddr.new(@v6nm)
end
unless ipv6_broken
@ds.delete
@ds.insert(@ipv6, @ipv6nm)
v = rs.first[:j]
rs.first[:i].should == @ipv6
rs.first[:c].should == @ipv6nm
rs.first[:i].should be_a_kind_of(IPAddr)
describe "default ipv4 and ipv6 gateway on different interfaces" do
it "doesn't set macaddress, ipv4 setup is valid and has precedence over ipv6" do
describe "ipv6 only node" do
it "informs about macaddress being set using the ipv6 setup" do
Ohai::Log.should_receive(:warn).any_number_of_times
Ohai::Log.should_receive(:info).with(/^macaddress set to 00:16:3E:2F:36:79 from the ipv6 setup/).once
describe "ip6address is already set" do
describe "node has ipv4 and ipv6" do
describe "ipv6 only node" do
describe "ipv6 only node" do
def use_ipv6?
end
list.any? {|a| a.ipv6? && !a.ipv6_loopback? && !a.ipv6_linklocal? }
end
private :use_ipv6?
#
# +address+ must be a Resolv::IPv4, Resolv::IPv6 or a String. Retrieved
#
# +address+ must be a Resolv::IPv4, Resolv::IPv6 or a String. Retrieved
##
# An IPv6 address record.
def initialize(address)
@address = IPv6.create(address)
##
# The Resolv::IPv6 address for this AAAA.
# * /etc/nsswitch.conf is not supported.
# * IPv6 is not supported.
# +name+ can be a Resolv::DNS::Name or a String. Retrieved addresses will
# be a Resolv::IPv4 or Resolv::IPv6
#
# +address+ must be a Resolv::IPv4, Resolv::IPv6 or a String. Retrieved
#
# +address+ must be a Resolv::IPv4, Resolv::IPv6 or a String. Retrieved
#
# +address+ must be a Resolv::IPv4, Resolv::IPv6 or a String. Retrieved
ptr = IPv4.create(address).to_name
when IPv6::Regex
ptr = IPv6.create(address).to_name
##
# A Resolv::DNS IPv6 address.
class IPv6