跳转至

What is IPv6

IPv6 Basic theory

Networks

IPv6 addresses are structured to enhance network organization and device interaction. An IPv6 address is divided into:

  1. Network Prefix: The initial 48 bits, determining the network segment.
  2. Subnet ID: Following 16 bits, used for defining specific subnets within the network.
  3. Interface Identifier: The concluding 64 bits, uniquely identifying a device within the subnet.

While IPv6 omits the ARP protocol found in IPv4, it introduces ICMPv6 with two primary messages:

  • Neighbor Solicitation (NS): Multicast messages for address resolution.
  • Neighbor Advertisement (NA): Unicast responses to NS or spontaneous announcements.

IPv6 also incorporates special address types:

  • Loopback Address (::1): Equivalent to IPv4's 127.0.0.1, for internal communication within the host.
  • Link-Local Addresses (FE80::/10): For local network activities, not for internet routing. Devices on the same local network can discover each other using this range.

Practical Usage of IPv6 in Network Commands

To interact with IPv6 networks, you can use various commands:

  • Ping Link-Local Addresses: Check the presence of local devices using ping6.
  • Neighbor Discovery: Use ip neigh to view devices discovered at the link layer.
  • alive6: An alternative tool for discovering devices on the same network.

Below are some command examples:

Bash
ping6 –I eth0 -c 5 ff02::1 > /dev/null 2>&1
ip neigh | grep ^fe80

# Alternatively, use alive6 for neighbor discovery
alive6 eth0
Text Only
# in windows
netsh interface ipv6 show address

IPv6 addresses can be derived from a device's MAC address for local communication. Here's a simplified guide on how to derive the Link-local IPv6 address from a known MAC address, and a brief overview of IPv6 address types and methods to discover IPv6 addresses within a network.

IPv6的Link-Local地址通常基于**EUI-64**(Extended Unique Identifier 64)格式生成。EUI-64是一种64位的全局唯一标识符,通常由设备的MAC地址转换而来

具体算法如下:

  1. 将mac地址每一位转化为16进制
  2. 对第一位的倒数第二位bit取反(xor 0x02)
  3. 开头插入fe80::,中间插入fffe

Given a MAC address 12:34:56:78:9a:bc, you can construct the Link-local IPv6 address as follows:

  1. Convert MAC to IPv6 format: 1234:5678:9abc
  2. Prepend fe80:: and insert fffe in the middle: fe80::1234:56ff:fe78:9abc
  3. Invert the seventh bit from the left, changing 1234 to 1034: fe80::1034:56ff:fe78:9abc
Python
#/usr/bin/python3

def mac_to_ipv6_linklocal(mac):
    # Split MAC address into bytes
    mac_bytes = mac.split(':')

    # Convert MAC bytes to integers
    mac_ints = [int(b, 16) for b in mac_bytes]

    # Modify the MAC address to fit into the IPv6 link-local address format
    # Invert the 7th bit of the first byte (2nd bit of the end byte)
    # for example:
    # mac_ints[0] = 0x5c = 0b01011100, 0x02 = 0b00000010
    # 0x5c ^ 0x02 = 0x5e = 0b01011110
    mac_ints[0] ^= 0x02

    # Construct the IPv6 link-local address
    ipv6_linklocal = 'fe80::%02x%02x:%02xff:fe%02x:%02x%02x' % (
        mac_ints[0], mac_ints[1], mac_ints[2], mac_ints[3],
        mac_ints[4], mac_ints[5])

    return ipv6_linklocal


if __name__ == '__main__':
    # Example usage
    mac_address = '12:34:56:78:9a:bc'
    ipv6_address = mac_to_ipv6_linklocal(mac_address)
    print(f'IPv6 link-local address: {ipv6_address}')

Note

值得一提的是,在linux和windows上生成link-local的算法并不同,上述是linux的算法

IPv6 Address Types

  • Unique Local Address (ULA): For local communications, not meant for public internet routing. Prefix: FEC00::/7
  • Multicast Address: For one-to-many communication. Delivered to all interfaces in the multicast group. Prefix: FF00::/8
  • Anycast Address: For one-to-nearest communication. Sent to the closest interface as per routing protocol. Part of the 2000::/3 global unicast range.

Address Prefixes

  • fe80::/10: Link-Local addresses (similar to 169.254.x.x)
  • fc00::/7: Unique Local-Unicast (similar to private IPv4 ranges like 10.x.x.x, 172.16.x.x, 192.168.x.x)
  • 2000::/3: Global Unicast
  • ff02::1: Multicast All Nodes
  • ff02::2: Multicast Router Nodes

Discovering IPv6 Addresses within a Network

  1. Obtain the MAC address of a device within the network.
  2. Derive the Link-local IPv6 address from the MAC address.

Way 2: Using Multicast

  1. Send a ping to the multicast address ff02::1 to discover IPv6 addresses on the local network.
Bash
service ufw stop # Stop the firewall
ping6 -I <IFACE> ff02::1 # Send a ping to multicast address
ip -6 neigh # Display the neighbor table

IPv6 Man-in-the-Middle (MitM) Attacks

Several techniques exist for executing MitM attacks in IPv6 networks, such as:

  • Spoofing ICMPv6 neighbor or router advertisements.
  • Using ICMPv6 redirect or "Packet Too Big" messages to manipulate routing.
  • Attacking mobile IPv6 (usually requires IPSec to be disabled).
  • Setting up a rogue DHCPv6 server.

Identifying IPv6 Addresses in the eild

Exploring Subdomains

A method to find subdomains that are potentially linked to IPv6 addresses involves leveraging search engines. For instance, employing a query pattern like ipv6.* can be effective. Specifically, the following search command can be used in Google:

Text Only
site:ipv6./

Utilizing DNS Queries

To identify IPv6 addresses, certain DNS record types can be queried:

  • AXFR: Requests a complete zone transfer, potentially uncovering a wide range of DNS records.
  • AAAA: Directly seeks out IPv6 addresses.
  • ANY: A broad query that returns all available DNS records.

Probing with Ping6

After pinpointing IPv6 addresses associated with an organization, the ping6 utility can be used for probing. This tool helps in assessing the responsiveness of identified IPv6 addresses, and might also assist in discovering adjacent IPv6 devices.

IPv6的安全问题

IPv6对安全的增强

相较于IPv4来说,IPv6的安全增强源于两个方面:一是地址空间的大幅增加对安全形成了增强,二就是IPv6的协议簇中增加了很多安全特性。

首先IPv6地址长达128位,地址空间容量是IPv4的n多n多倍。这意味着当前黑客嗅探使用的大网段扫描方式,比如整个A段,整个B段扫描将会难以实现,广泛的IPv6地址扫描是不可行的,需要指定较小的IP范围。这使得业务系统被互联网探测引擎(如fofa、鹰图。shodan等)资产测绘或者扫描到的可能性降低。

其次,IPv6巨大的地址空间会为每一个网络设备分配唯一的地址,可保证路由器转发的每个数据包都有真实的源地址,而不是像IPv4一样使用NAT方式进行网络地址转换,导致难以直接访问到某个服务或设备,并且多台设备使用同一IP上网。因此IPv6具备很好的事后应急排查与溯源的能力。

IPv6支持IPSec协议,与IPv4环境相比下,无需另行部署增加加密手段(如IPsec VPN等)即可实现数据加密传输。并且IPv6协议中没有广播机制,所以IPv4网络中存在的所有利用广播机制进行攻击的现象都得以缓解,并且由于地址空间大,针对DHCP协议的攻击难度也大幅提升。

IPv6存在的安全风险

虽然IPv6的安全性在协议簇中得到了增强,但是仍然在部分方面存在安全风险;一是IPv6沿袭了IPv4存在的安全风险,二是IPv4和IPv6实施的双栈配置等过度机制可能会引入安全风险,三是新协议使用中形成的新的安全风险。

协议安全风险

虽然IPv6协议和报文结构都有所变化,但是一些存在于IPv4网络中的攻击仍然存在。将在IPv6网络中继续存在的攻击类型包括:DoS攻击、路由选择攻击、应用层攻击等。

其次,IPV6的报文结构相比于IPv4新引入了流标签、RHO、路由头等字段,还有在IPv6协议簇中引入了新的协议。这些新增加的东西都可能存在漏洞,用于发起嗅探或者DoS攻击等。IPv6特有的攻击风险包括:逐跳扩展头攻击,邻居发现协议等。

不同类型安全设备在实现IPv6协议栈时,存在因编码、实施造成的安全风险。目前CVE漏洞库中已经存在大量与IPv6相关的安全漏洞被收录。

网络层:

所有支持IPv6的机器,在不明确禁止RA(路由器公告消息)的情况下,如果在接口上配置了/64的IPv6全球单播地址(GUA)或本地唯一地址(UAL)的情况下,会周期性的以多播/组播的方式发送RA报文,同时以RA响应主机的RS(路由器请求)报文。

但是RA信息中附带可用的IPv6前缀,主机可以利用这个前缀生成自己的IPv6地址。加上主机使用link-local地址连接路由器,几乎不需要其他配置,主机即可访问内部或外部的IPv6资源。

在这种情况下,未配置的内部和边界防火墙有很大可能对IPv6流量置之不理,内部的流量可以出去,外面的流量也可以直接进入内网。(PS. 存在真实情况,在今年X月份的一场攻防演练中,我作为蓝队应急溯源组参演,在攻防演练期间,有攻击队使用IPv6地址绕过防火墙和waf,直接对内网展开了扫描和攻击)

DNS和应用层:

在实际引用中,DNS是一定会使用的,而DNS的解析器和DNS服务器默认配置早已支持IPv6资源的AAAA记录。同一个域名的AAAA请求和A请求几乎同时发出,客户端程序获得这两种地址时,IPv6的应用层请求会先于IPv4的请求发出,间隔很短只有几百毫秒,IP4实际上成为了fallback的手段。假如网站的安全策略只针对站点的IPv4地址做了限制,那么限制是无效的。

在IPv4向IPv6过渡的过程中,可以采用三种方案:隧道、翻译和双栈,但是都可能会引入新的风险问题。首先隧道机制只是对数据包进行简单封装,并不会对流量内容做检测,攻击者可以通过配置IPv4或者IPv6,将IPv6报文封装成IPv4报文进行传输,或者将IPv4流量承载在IPv6报文中进行传输,可能会直接穿过防护到达目标网络中。

翻译机制也就是协议转换,是作为IPv6网络节点和IPv4网络节点互通的路由,极易被攻击,一旦被攻击可能导致网络瘫痪。

最后双栈机制也并不安全,如果同时运行IPv4和IPv6两个逻辑通道,会增加系统的暴露面,也就意味着攻击面扩大,需要安全防护的暴露面扩大。其次部分操作系统默认启用IPv6功能,使得IPv4网络存在隐蔽的IPv6通道,并且没有安全配置,攻击者可利用该通道进行攻击。双栈还会使得网络节点负载变大,故障率增高。

安全设备风险

首先IPv6环境下所有设备均可以使用全球单播地址,不需要使用NAT转换即可实现互联互通,同时也就缺少了NAT设备造成的网络隔离的情况,因此防火墙或者其他安全设备的安全域划分和访问控制策略就需要更加严格管理。

其次在IPv6和IPv4的混合网络中,防火墙和安全网关之类的防护设备需要同时配置双栈协议,针对双栈协议增加安全策略来保障安全性,对安全设备的功能和性能的需求会更高。

在应用层中WAF、IPS、IDS等应用层安全设备的IPv6报文解析能力以及IPv6地址的黑白名单功能可能并不完善,无法达到对恶意IPv6ip限制的要求。

最后,规则库类的设备可能无法识别IPv6地址,如IP地址归属等。并且日志相关信息可能无法相互对应,导致如果出现安全事件的话,排查较为困难。

IPv6中可能存在的网络安全攻击

2

  • 报文监听

IPv6中可使用IPSec对其网络层的数据传输进行加密保护,但RFC6434中不再强制要求实施IPSec,因此在未启用IPSec的情况下,对数据包进行监听依旧是可行的,具体我们可以通过Wireshark工具接获报文,然在本地进行分析。

  • 应用层攻击

IPv4网络中应用层可实施的攻击在IPv6网络下依然可行,比如SQL注入、缓冲溢出等,IPS、反病毒、URL过滤等应用层的防御不受网络层协议变化的影响。

  • 中间人攻击

中间人攻击是指攻击者能够在两个通信方之间的通信链路上拦截、篡改或者窃听通信内容。攻击者可以通过欺骗的方式,使通信方误以为他们在直接通信,而实际上攻击者已经介入其中,从而窃取敏感信息或者进行其他恶意行为。 启用IPSec对数据进行认证与加密操作前需要建立SA,通常情况下动态SA的建立通过密钥交换协议IKE、IKEv2实现,由DH(Diffie-Hellman)算法对IKE密钥载荷交换进行安全保障,然而DH密钥交换并未对通信双方的身份进行验证,因此可能遭受中间人攻击。

  • 泛洪攻击

在IPv4与IPv6中,向目标主机发送大量网络流量依旧是有效的攻击方式,泛洪攻击可能会造成严重的资源消耗或导致目标崩溃。另外,由于IPv6网络通常包含更多的设备和更复杂的路由路径,因此对于网络管理员来说,识别和缓解IPv6网络上的DDOS攻击可能会更具挑战性。

  • 分片攻击

在IPv6中,中间节点不可以对分段数据包进行处理,只有端系统可以对IP数据包进行分分段与重组,因此攻击者可能借助该性质构造恶意数据包。 在RFC8200中声明禁止重组重叠的IPv6分片,且其限制最小MTU为1280字节[2],因此处理时将丢弃除最后分片外小于1280字节的分片,在一定程序上也缓解了分片攻击。

  • 路由攻击

在IPv6下,由于部分路由协议并未发生变化,因此路由攻击依旧可行。 攻击者篡改路由表,将通信流量导向攻击者所控制的路由器,然后在路由器上进行中间人攻击。这种攻击可以通过IPv6的加密和身份验证来防范,但是这需要网络管理员和网络设备厂商共同协作,实现IPv6的安全性。

  • 地址欺骗

攻击者伪造IPv6地址,使得通信双方误认为他们在直接通信,实际上攻击者在中间拦截并篡改了通信内容。这种攻击在IPv6网络中比IPv4更容易实现,因为IPv6地址空间更为广阔,而且IPv6地址可以通过随机生成来避免被识别和防御。