Skip to content
Race condition Write-up Advanced

gcp-dhcp-takeover-code-exec

The ISC DHCP client on Google Compute Engine VMs seeds its pseudo-random transaction IDs (XIDs) with predictable values (time, PID, and part of the MAC address), allowing an attacker on the same subnet to guess XIDs and flood the victim with forged DHCP replies. By impersonating the metadata server, the attacker could inject an SSH public key and gain root access to the VM.

Imre Rad Follow

Published on github.com

BranchesTags

Imre Rad (@ImreRad), on github.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The DHCP client seeds its pseudo-random number generator with predictable values (current time, process ID, and the last four bytes of the MAC address), making XIDs guessable.

Impact

An attacker could gain root access to targeted VMs, but the attack is a race condition that is not fully reliable and requires the attacker to be on the same subnet or the firewall to be open.

What the attacker needed

Attacker on same subnet or open firewall; victim uses ISC dhclient; ability to send crafted DHCP packets

The fix

Google fixed the issue; recommended mitigations include blocking UDP port 68 between VMs, not managing the metadata hostname via DHCP, and using TLS for metadata communication.

How it was found

  1. Set up a rogue metadata server on an attacker-controlled host.
  2. Craft DHCP packets with guessed XIDs and flood the victim's dhclient directly.
  3. Send a DHCPACK that sets the rogue metadata server's IP and hostname, poisoning /etc/hosts.
  4. Send a second DHCPACK to restore the network configuration while leaving the poisoned hosts entry.
  5. The guest agent connects to the rogue metadata server and fetches the attacker's SSH public key.
  6. Log in to the victim as root using the attacker's private key.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

When a computer joins a network, it asks a DHCP server for an IP address. To match replies to its request, it uses a random number called a transaction ID (XID). Here, the random number was not random enough: an attacker could guess it and send fake replies that the victim accepted. The fake replies told the victim to use the attacker's server as the metadata server, which is a special internal service that hands out SSH keys, so the attacker could then log in as root.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by Imre Rad

View all

2 more disclosed reports, best first.

More from Google

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.