The guard relay is the one hop that knows an onion service's real IP address. If an attacker can figure out which guard a service uses, they've narrowed the problem down to one machine they can watch, subpoena or try to compromise. Guard discovery is that first step.

The classic approach is surprisingly simple. The attacker runs some middle relays, then makes the target onion service build circuit after circuit (for example by connecting to it repeatedly). Each new circuit picks a fresh middle relay. Sooner or later one of the attacker's relays lands in the middle position, right next to the guard, and a traffic signal sent from the client side confirms it. Now the attacker knows the guard.

The fix Tor adopted is vanguards: pinning the second and third hops of onion service circuits to small, slowly rotating sets, so the attacker can't just keep rolling for a middle position next to the guard. A lightweight version is now built into tor itself, and a fuller version exists as an add-on.

Clients face a milder form of the same issue, but services matter more because they stay online and accept connections from anyone.