What is a Man-in-the-Middle (MITM) Attack?

A Man-in-the-Middle (MITM) attack is a class of cyberattack where an adversary secretly positions themselves between two parties who believe they are communicating directly with each other. The attacker can eavesdrop on the conversation, alter messages in transit, or impersonate one side entirely — all without either party realizing the link has been compromised. MITM attacks operate at every layer of the network stack, from ARP on a local Ethernet segment to BGP at the scale of the global internet.

Understanding MITM attacks requires understanding the trust assumptions baked into internet protocols. Most foundational protocols — ARP, DNS, BGP — were designed in an era when every participant on the network was assumed to be cooperative. Attackers exploit this inherited trust to insert themselves into communication paths that were never designed to be adversarial.

The Anatomy of a MITM Attack

Every MITM attack follows a common pattern regardless of the specific technique: interception, then exploitation. First, the attacker redirects traffic so it flows through their system instead of going directly from sender to receiver. Second, they act on the intercepted traffic — reading credentials, injecting malware, modifying financial transactions, or simply collecting intelligence.

Normal Communication Client Server MITM Interception Client Server Attacker Traffic routed through attacker

The power of a MITM attack lies in its invisibility. From the client's perspective, responses appear to come from the legitimate server. From the server's perspective, requests appear to come from the legitimate client. The attacker operates as an invisible relay, with full ability to read and modify traffic in both directions.

ARP Spoofing: MITM on the Local Network

The Address Resolution Protocol (ARP) maps IP addresses to MAC (hardware) addresses on a local network segment. When a device wants to send a packet to another device on the same LAN, it broadcasts an ARP request: "Who has IP 192.168.1.1? Tell me your MAC address." The device with that IP responds, and the sender caches the mapping in its ARP table.

ARP has zero authentication. Any device on the network can send an ARP reply claiming to own any IP address, and recipients will trust it unconditionally. This is ARP spoofing (also called ARP poisoning), and it is the most common MITM technique on local networks.

How ARP Spoofing Works

Consider a typical office or home network with a gateway router at 192.168.1.1 and a victim workstation at 192.168.1.50. The attacker's machine is also on the same LAN at 192.168.1.99:

  1. The attacker sends a gratuitous ARP reply to the victim: "192.168.1.1 is at [attacker's MAC address]." The victim's ARP cache now maps the gateway's IP to the attacker's MAC.
  2. The attacker simultaneously sends a gratuitous ARP reply to the gateway: "192.168.1.50 is at [attacker's MAC address]." The gateway's ARP cache now maps the victim's IP to the attacker's MAC.
  3. All traffic between the victim and the gateway now flows through the attacker's machine. The attacker forwards packets in both directions to avoid detection while inspecting or modifying everything.
ARP Spoofing Attack Gateway Router 192.168.1.1 Victim 192.168.1.50 Attacker 192.168.1.99 Victim thinks attacker is the gateway Gateway thinks attacker is the victim ARP: 192.168.1.1 -> [attacker MAC] ARP: 192.168.1.50 -> [attacker MAC]

Tools like arpspoof (part of the dsniff suite) and ettercap automate this process. Once positioned, the attacker can use tools like mitmproxy or Wireshark to inspect all traffic, capture credentials sent over unencrypted protocols (HTTP, FTP, SMTP, Telnet), or inject malicious content into web pages.

Defenses: Dynamic ARP Inspection (DAI) on managed switches validates ARP packets against a trusted DHCP snooping table. Static ARP entries can be configured for critical gateways. At the host level, tools like arpwatch alert on unexpected ARP changes. Most importantly, encrypting traffic with TLS/HTTPS ensures that even if Layer 2 is compromised, the attacker sees only ciphertext.

DNS Spoofing and Cache Poisoning

DNS translates domain names to IP addresses, and corrupting this translation is one of the most effective ways to redirect traffic. DNS spoofing encompasses any technique that causes a DNS resolver to return a forged answer, sending the victim to an attacker-controlled server instead of the legitimate one.

On-Path DNS Spoofing

An attacker who has already achieved a MITM position (e.g., via ARP spoofing or a rogue Wi-Fi access point) can intercept DNS queries as they leave the victim's machine and respond with forged answers before the real DNS server can reply. Since traditional DNS uses unencrypted UDP on port 53, modifying queries and responses in transit is trivial.

DNS Cache Poisoning (Kaminsky Attack)

The more dangerous variant does not require a MITM position at all. In 2008, Dan Kaminsky disclosed a fundamental flaw in DNS that allowed remote attackers to poison the cache of recursive resolvers. The attack exploits the fact that DNS transaction IDs are only 16 bits wide (65,536 possible values). An attacker floods the resolver with forged responses, each guessing a different transaction ID, while simultaneously triggering legitimate queries for the target domain. If a forged response arrives with the correct transaction ID before the real answer, the resolver caches the attacker's IP address for that domain.

Once a resolver's cache is poisoned, every user relying on that resolver is silently redirected. The attacker could redirect bank.example.com to a pixel-perfect phishing site running on their own infrastructure, complete with a valid-looking URL in the browser's address bar.

DNS Cache Poisoning User DNS Resolver (cache poisoned) Real Server 93.184.216.34 Attacker Server 198.51.100.66 bank.com? 198.51.100.66 User connects to attacker's server Poisoned Cache: bank.com=FAKE IP ignored

Defenses: DNSSEC cryptographically signs DNS responses so resolvers can verify their authenticity. Source port randomization (introduced post-Kaminsky) increases the entropy an attacker must guess. DNS over HTTPS (DoH) and DNS over TLS (DoT) encrypt the entire DNS transaction, preventing on-path manipulation. Modern resolvers combine all three defenses.

BGP Hijacking: MITM at Internet Scale

While ARP and DNS attacks work on local networks or individual resolvers, BGP hijacking can reroute traffic across the entire internet. BGP is the protocol that autonomous systems use to exchange routing information, and like ARP, it was designed with implicit trust between participants. Any AS can announce any IP prefix, and neighboring routers will generally accept the announcement.

How BGP Becomes a MITM Vector

A standard BGP hijack (announcing someone else's prefix) creates a blackhole — traffic flows to the attacker but never reaches its destination, and the victim quickly notices. A BGP interception attack is more subtle: the attacker announces the victim's prefix to attract traffic, but carefully maintains a path back to the legitimate origin so they can forward the traffic after inspecting it. From the victim's perspective, their service continues to work normally, just with slightly higher latency.

The attacker accomplishes this by selectively announcing the hijacked prefix only to certain peers while ensuring their own path to the victim remains unaffected. This requires careful BGP engineering — the attacker must avoid poisoning their own route to the victim, typically by using AS path prepending and community-based filtering on specific peering sessions.

BGP Interception (MITM via BGP Hijack) Origin AS 203.0.113.0/24 Attacker AS announces 203.0.113.0/24 Transit ISP prefers shorter path Source AS 1. Traffic attracted 2. Forwarded to origin Attacker reads/modifies traffic, then forwards it Victim sees normal service with slightly higher latency

Real-World BGP MITM Incidents

In 2013, researchers at Renesys (now Dyn/Oracle) documented persistent BGP interceptions where traffic between cities in the same country was detoured through distant autonomous systems in other continents. Traffic from Guadalajara to Washington D.C. was routed through Belarus; traffic within the US was routed through Iceland. In each case, the traffic was forwarded to its final destination after passing through the intercepting AS — a textbook MITM pattern that went undetected for months.

In 2018, a BGP hijack targeting Amazon's Route 53 DNS service redirected DNS queries for MyEtherWallet.com to an attacker-controlled server, which served a phishing page and stole cryptocurrency. The attacker announced Amazon's DNS prefix from a small ISP in Ohio, attracting traffic that would normally flow to Amazon's infrastructure. This attack combined BGP hijacking with DNS interception — two MITM layers stacked together.

You can use the BGP looking glass to monitor for suspicious route changes. Try looking up critical prefixes and verify the origin AS:

SSL Stripping and TLS Interception

Even when an attacker has achieved a MITM position, TLS (HTTPS) should protect the confidentiality and integrity of web traffic. TLS encrypts the channel between client and server and uses certificates to authenticate the server's identity. An attacker who intercepts TLS-encrypted traffic sees only ciphertext. But several attack techniques aim to circumvent TLS protections.

SSL Stripping

Introduced by Moxie Marlinspike at Black Hat 2009, SSL stripping exploits the moment when a user first connects to a website over HTTP before being redirected to HTTPS. The MITM attacker intercepts the initial HTTP request, establishes their own HTTPS connection to the real server, and serves the content back to the victim over plain HTTP. The victim sees no padlock in the browser and communicates in cleartext with the attacker, while the attacker relays everything to the real server over an encrypted channel.

The attack works because most users do not manually type https:// — they rely on the server to redirect them. The attacker simply never passes along the redirect. To the victim, the page looks identical to the real site, just without the padlock icon (which most non-technical users never check).

TLS Interception with Forged Certificates

A more aggressive approach involves the attacker generating a forged TLS certificate for the target domain. When the victim connects, the attacker presents the fake certificate and establishes two separate TLS sessions: one with the victim (using the forged cert) and one with the real server (using the real cert). The attacker decrypts traffic from the victim, inspects or modifies it, re-encrypts it, and forwards it to the server.

This attack is thwarted by the certificate authority (CA) system: the browser will reject the forged certificate because it is not signed by a trusted CA. The victim would see a certificate warning — unless the attacker has compromised a CA or installed their root certificate on the victim's machine. This has happened in practice:

HTTP Strict Transport Security (HSTS)

HSTS is the primary defense against SSL stripping. When a server sends the Strict-Transport-Security header, the browser remembers to always use HTTPS for that domain, even if the user types an HTTP URL. Browsers also ship with a preloaded HSTS list covering major websites, so the very first connection to those sites is always HTTPS — the attacker never gets a chance to strip it.

Wi-Fi MITM: Evil Twin and Rogue Access Points

Wireless networks are particularly vulnerable to MITM attacks because the attacker does not need physical access to network cabling — they just need to be within radio range.

Evil Twin Attack

An evil twin is a rogue Wi-Fi access point that mimics a legitimate network. The attacker creates an access point with the same SSID (network name) as a trusted network — "Starbucks_WiFi", "Airport_Free_WiFi", or even a corporate SSID. If the attacker's signal is stronger than the real access point, devices will automatically connect to the evil twin, routing all their traffic through the attacker.

Once connected, the attacker is the default gateway for all traffic. They can perform DNS spoofing to redirect specific domains, inject content into HTTP pages, capture credentials, or log all traffic for later analysis. With tools like hostapd-wpe, an attacker can also capture enterprise Wi-Fi credentials (WPA2-Enterprise with PEAP/MSCHAPv2) by presenting a fake RADIUS authentication server.

KARMA and Known Network Attacks

Devices constantly probe for previously connected networks by broadcasting "Are you NetworkX?" An attacker running a KARMA attack responds to every probe with "Yes, I am NetworkX," causing the device to connect automatically. This works because most devices do not verify the identity of an access point beyond matching the SSID name. The attacker's single access point can simultaneously impersonate dozens of different networks, capturing victims who have ever connected to any open network.

Evil Twin Wi-Fi Attack Legitimate AP "CoffeeShop_WiFi" Evil Twin (Attacker) "CoffeeShop_WiFi" Laptop Phone weak signal stronger signal all traffic flows through attacker Devices auto-connect to the stronger signal with the same SSID

Defenses: WPA3-Enterprise with server certificate validation prevents credential capture. Enterprise environments should use 802.1X with proper certificate pinning. For individuals, using a VPN on untrusted networks encrypts all traffic regardless of the access point's trustworthiness. Cellular connections are generally safer than unknown Wi-Fi networks.

Protocol-Level MITM: DHCP and ICMP

Beyond ARP and Wi-Fi, other network protocols are also exploitable for MITM positioning:

DHCP Spoofing

When a device joins a network, it uses DHCP to obtain an IP address, default gateway, and DNS server. An attacker running a rogue DHCP server can respond to DHCP requests faster than the legitimate server, assigning themselves as the default gateway and DNS server. This achieves a MITM position without any ARP manipulation — the victim's operating system willingly routes all traffic through the attacker because it was told to do so during network configuration.

ICMP Redirect Attacks

ICMP redirect messages are used by routers to inform hosts of a better route. An attacker can send forged ICMP redirect messages to a victim, instructing it to route traffic for specific destinations through the attacker's machine. Most modern operating systems disable processing of ICMP redirects by default, but older or misconfigured systems remain vulnerable.

HTTPS and Certificate Pinning as Defenses

TLS/HTTPS is the single most important defense against MITM attacks at the application layer. When properly implemented, it provides three guarantees that together make interception detectable or impossible:

Certificate Transparency (CT) adds another layer: all publicly trusted CAs must log every certificate they issue to public, append-only CT logs. Domain owners can monitor these logs for unauthorized certificates issued for their domains. If a CA is compromised and issues a fraudulent certificate, CT logs make the fraud publicly visible within hours.

Certificate pinning goes further by hard-coding the expected certificate or public key into the application. If the app receives a certificate that does not match the pin, it refuses to connect — even if the certificate is signed by a trusted CA. This prevents MITM attacks that rely on compromised or government-controlled CAs. While HTTP Public Key Pinning (HPKP) was deprecated for websites due to operational risks, certificate pinning remains widely used in mobile apps and critical infrastructure.

DNSSEC: Authenticating DNS Responses

DNSSEC (DNS Security Extensions) adds cryptographic signatures to DNS records, allowing resolvers to verify that a response genuinely came from the authoritative nameserver for a domain and was not modified in transit. Without DNSSEC, a resolver has no way to distinguish a legitimate DNS response from a forged one — it simply trusts the first valid-looking answer it receives.

DNSSEC works through a chain of trust anchored at the DNS root zone. The root zone is signed with a well-known key. Each TLD zone is signed and its key is vouched for by the root. Each domain's zone is signed and its key is vouched for by the TLD. A validating resolver walks this chain from root to leaf, verifying signatures at each level. If any signature is invalid or missing (and the zone should be signed), the response is rejected.

DNSSEC prevents cache poisoning attacks because forged responses lack valid signatures. However, DNSSEC does not encrypt DNS queries — it only authenticates responses. An observer can still see which domains you are looking up; they just cannot forge the answers. For full DNS privacy, DNSSEC should be combined with DNS over HTTPS or DNS over TLS.

DNS over HTTPS: Encrypting the Last Mile

DNS over HTTPS (DoH) solves the confidentiality problem that DNSSEC does not address. By encrypting DNS queries inside TLS connections, DoH prevents on-path attackers from seeing or modifying DNS traffic. An attacker performing ARP spoofing or running an evil twin AP can no longer intercept DNS queries to redirect victims to phishing sites — the DNS queries are encrypted and authenticated through the TLS connection to the DoH resolver.

The combination of DNSSEC and DoH provides comprehensive DNS security: DNSSEC ensures the DNS data itself is authentic (signed by the domain owner), while DoH ensures the query and response cannot be observed or tampered with in transit. Together, they close the DNS-based MITM attack surface.

RPKI: Securing BGP Against Route Hijacking

Resource Public Key Infrastructure (RPKI) is to BGP what DNSSEC is to DNS — a cryptographic system for authenticating route announcements. RPKI allows IP address holders to create Route Origin Authorizations (ROAs) that cryptographically declare which autonomous systems are authorized to announce their prefixes.

When a network performs Route Origin Validation (ROV), it checks incoming BGP announcements against the RPKI database. If an AS announces a prefix for which it has no valid ROA, the route is classified as "RPKI Invalid" and can be dropped. This prevents the most common form of BGP hijacking — an unauthorized AS announcing someone else's prefix.

RPKI adoption has grown steadily. Major networks including Cloudflare (AS13335), Google (AS15169), and Amazon (AS16509) both sign their own routes with ROAs and perform validation on routes they receive. As of 2025, approximately 50% of IPv4 routes and 60% of IPv6 routes have valid ROAs.

However, RPKI has limitations as a MITM defense. It validates the origin AS of a route, not the entire AS path. A sophisticated attacker who is a legitimate transit provider could still perform path manipulation without triggering RPKI validation failures. BGPsec, a proposed extension that cryptographically signs each hop in the AS path, would address this gap, but it has seen minimal deployment due to performance and scalability concerns.

You can check the RPKI status of any route using the looking glass:

Real-World MITM Attacks: A Timeline

MITM attacks are not theoretical exercises — they have been deployed by criminals, intelligence agencies, and governments at scale:

Defense in Depth: Layering MITM Protections

No single defense prevents all MITM attacks. Effective protection requires layering defenses across the network stack:

Defense in Depth Against MITM Layer 2 (Link) DAI, 802.1X port security, static ARP, ARP inspection Layer 3 (Network) RPKI/ROV, BGPsec, DHCP snooping, source-address validation Layer 4 (Transport) TLS 1.3, certificate pinning, HSTS preloading Layer 7 (App) DNSSEC, DoH/DoT, Certificate Transparency User VPN on untrusted networks, verify cert warnings DEPTH
Attack Vector Layer Primary Defenses
ARP spoofing L2 Dynamic ARP Inspection, 802.1X, static ARP
DHCP spoofing L2/L3 DHCP snooping, 802.1X
Evil twin / rogue AP L1/L2 WPA3-Enterprise, VPN, WIDS
DNS spoofing/poisoning L7 DNSSEC, DoH/DoT, source port randomization
BGP hijacking L3 RPKI/ROV, BGP monitoring, looking glasses
SSL stripping L7 HSTS, HSTS preload list
TLS interception (forged cert) L4/L7 TLS cert validation, cert pinning, CT logs

Detection: How to Spot a MITM Attack

While prevention is ideal, detection serves as a critical second line of defense:

The Evolving Threat Landscape

The internet has made significant progress against MITM attacks. HTTPS adoption has gone from under 40% of web traffic in 2015 to over 95% in 2025. RPKI adoption continues to grow, with major networks dropping RPKI-invalid routes. DNSSEC and DoH are closing the DNS manipulation gap.

But new attack surfaces continue to emerge. The proliferation of IoT devices creates millions of endpoints with weak or no TLS implementation. 5G network slicing introduces new trust boundaries that could be exploited. Quantum computing threatens to eventually break the RSA and elliptic-curve cryptography that underpins TLS, DNSSEC, and RPKI — driving urgent work on post-quantum cryptographic algorithms.

The fundamental lesson of MITM attacks is that trust must be cryptographically verified, never assumed. Every protocol that operates on implicit trust — from ARP on a LAN to BGP across the global internet — is a potential MITM vector until authentication is added. The ongoing work to retrofit authentication into these protocols is one of the most important security efforts in internet infrastructure.

See It in Action

Use the BGP looking glass to verify routing integrity and check for signs of route hijacking:

See BGP routing data in real time

Open Looking Glass
More Articles
How TLS/HTTPS Works: Securing the Internet's Traffic
Certificate Transparency: How CT Logs Secure the Web's PKI
How Firewalls Work: Packet Filtering, Stateful Inspection, and Beyond
What is Cross-Site Scripting (XSS)?
What is Cross-Site Request Forgery (CSRF)?
What is Server-Side Request Forgery (SSRF)?