What Is a Man-in-the-Middle Attack? How to Prevent It (2026)
How man-in-the-middle attacks work, from evil twin Wi-Fi and ARP spoofing to SSL stripping and AiTM phishing, plus the defenses that actually stop them.

A man-in-the-middle attack is exactly what it sounds like. Someone places themselves between you and the website, app or person you’re talking to, and quietly reads or changes what passes between you.
You usually can’t see it happening. The page loads, the login works, the email arrives. Meanwhile, an attacker on the same café Wi-Fi, a fake hotspot or a malicious proxy may be collecting your passwords, session cookies or payment details.
This guide explains how these attacks work, the most common types, real cases, and the defenses that actually stop them. We also ran a quick check of how modern sites and tools block the classic tricks, so you can see the protections at work.
- A MITM attacker secretly sits between you and a site, reading or changing traffic.
- Common types: evil twin Wi-Fi, ARP and DNS spoofing, SSL stripping, fake certificates.
- AiTM phishing steals session cookies and can bypass regular 2FA.
- HTTPS with HSTS stops most attacks, if you never click through certificate warnings.
- Add a trustworthy VPN on public Wi-Fi and passkeys for important accounts.
What Is a Man-in-the-Middle Attack?
A man-in-the-middle (MITM) attack is when an attacker secretly relays, and possibly alters, the communication between two parties who believe they’re talking directly to each other.
You might also see it called an on-path attack, a machine-in-the-middle attack or, for the modern phishing version, an adversary-in-the-middle (AiTM) attack. The idea is the same. The attacker gets into the path your data takes, then takes advantage of that position.
Every MITM attack has two stages:
- Interception. The attacker gets your traffic flowing through a device they control. That might be a fake Wi-Fi network, a poisoned local network, a hijacked DNS answer or a proxy you chose to use.
- Decryption or manipulation. Once traffic passes through them, the attacker reads it, changes it or steals something from it, such as a password or a session cookie.
Encryption is what stops the second stage. That’s why most modern MITM attacks are really attacks on encryption: tricking you onto an unencrypted connection, getting you to accept a fake certificate, or stealing a session after you’ve logged in.
Common Types of Man-in-the-Middle Attacks
Attackers have several ways to get into the middle. Some need physical closeness, like sharing a Wi-Fi network, while others work from anywhere.
1Evil Twin Wi-Fi Hotspots
An attacker sets up a Wi-Fi network with a trusted-sounding name, such as “Airport_Free_WiFi” or the same name as the café’s real network. Your device connects, and every byte you send goes through the attacker’s hardware.
Some devices auto-join networks with names they’ve seen before, which makes this easier. Our guides to staying safe on hotel Wi-Fi and airport Wi-Fi cover the specific traps in those places.
2ARP Spoofing
On a local network, devices use the Address Resolution Protocol (ARP) to find which hardware address owns which IP address. ARP has no authentication. An attacker on the same network can send fake replies saying “the router is me,” and other devices start sending their traffic to the attacker first.
This works on any shared network where the attacker can join, including legitimate ones. A real café or office network is enough if the attacker is connected to it too.
3DNS Spoofing
DNS turns names like bank.example into IP addresses. If an attacker can answer your DNS queries, they can send you to their own server instead of the real one. That can happen through a compromised router, a malicious hotspot, or by poisoning a DNS resolver’s cache.
Plain DNS isn’t encrypted, so anyone on the path can also see which sites you look up. Our explainer on DNS leaks shows how those lookups can escape even when you think they’re protected.
4SSL Stripping
Many people type a site name without https://. The browser’s first request then goes out over plain HTTP, and the site redirects it to HTTPS. SSL stripping attacks that first moment.
The attacker keeps your side of the connection on HTTP, while they talk to the real site over HTTPS. You see the site, but without the padlock, and everything you type passes through them in plain text. Security researcher Moxie Marlinspike demonstrated the technique with his sslstrip tool in 2009, and HSTS was designed largely to stop it.
5HTTPS Spoofing and Fake Certificates
Instead of removing encryption, the attacker replaces it. They present their own certificate for the site, decrypt your traffic, then re-encrypt it to the real server. Browsers catch this because the fake certificate isn’t signed by a trusted authority for that domain, and they show a full-page warning.
The attack only works if you click through the warning, or if the attacker has managed to install their own root certificate on your device. That second case is why you should be careful with apps or “security” tools that ask to install a certificate.
6Malicious Proxies and VPNs
Sometimes the man in the middle is a service you chose. A free proxy or a shady VPN sits in your traffic path by design. Research on open proxies has found operators injecting ads and tracking scripts, swapping downloads for malware and attempting certificate interception.
A trustworthy VPN protects you from local MITM attacks. An untrustworthy one becomes the attacker. We cover how to tell the difference in are free VPNs safe.
7Session Hijacking and Adversary-in-the-Middle Phishing
This is the modern version, and it beats regular two-factor authentication. The attacker sends you a phishing link to a page that proxies the real login site. You enter your password and your 2FA code on what looks like the real page, and the proxy passes them on.
The real site logs you in and returns a session cookie, which the attacker captures. With that cookie, they’re logged in as you, with no need for the password or the code again.
MITM Attack Types at a Glance
Each attack gets into the middle in a different way, and each has a defense that hits it hardest.
| Attack | Where it happens | What it targets | Best defense |
|---|---|---|---|
| Evil twin Wi-Fi | Public places | All traffic from your device | Verify the network, use a VPN |
| ARP spoofing | Shared local networks | Traffic to the router | VPN, Dynamic ARP Inspection |
| DNS spoofing | Router, hotspot or resolver | Which server you reach | HTTPS, encrypted DNS, VPN |
| SSL stripping | Any network path | The first HTTP request | HSTS, HTTPS-only mode |
| Fake certificates | Any network path | Encrypted sessions | Never bypass certificate warnings |
| Malicious proxy or VPN | The service itself | Everything you route through it | Use trusted providers only |
| AiTM phishing | A lookalike login page | Passwords, 2FA codes, session cookies | Passkeys or FIDO2 keys |
What Can an Attacker Actually Steal?
What an attacker gets depends on what’s encrypted. On a fully HTTPS connection, very little. On anything less, quite a lot.
- Login credentials sent to any site or app that doesn’t encrypt them properly.
- Session cookies, which let the attacker act as you without a password. This is the main prize in AiTM phishing.
- Payment details typed into a stripped or spoofed checkout page.
- The sites you visit. Even with HTTPS, plain DNS lookups and the server name in the connection reveal your browsing pattern.
- Downloads and updates fetched over HTTP, which can be swapped for malware in transit.
- Email and messages in older apps or services that don’t use transport encryption.
Businesses face a bigger version of the same problem. One hijacked mailbox can be used to send fake invoices to customers and suppliers, as the Microsoft case below shows.
Real-World Examples
MITM attacks aren’t just theory. A few documented cases show how they play out.
- AiTM phishing at scale. In July 2022, Microsoft reported a phishing campaign that had targeted more than 10,000 organizations since September 2021. It used proxy-based phishing pages to steal session cookies and bypass multi-factor authentication, then used the hijacked mailboxes for invoice fraud. Read the Microsoft Security Blog report.
- Tampering open proxies. Academic studies of public proxy lists found proxies modifying web pages to inject ads, tracking code and cryptocurrency miners, and a small share inserting forged TLS certificates.
- sslstrip. The 2009 demonstration showed how easily a user on a shared network could be kept on HTTP without noticing, which pushed browsers and sites toward HSTS and HTTPS by default.
How HTTPS and HSTS Shut Most of These Down
Properly checked HTTPS defeats most MITM attacks. HSTS closes the gap that SSL stripping used, by telling browsers never to use plain HTTP for a site.
HTTPS does two things. It encrypts the connection, so an attacker in the middle sees only scrambled data. And it authenticates the server with a certificate, so an attacker can’t impersonate the site without triggering a warning.
HSTS (HTTP Strict Transport Security) is a response header that tells the browser: for this site, only ever use HTTPS, for the next N seconds. After one visit, the browser upgrades every future request itself, before anything leaves your device.
The preload list goes one step further. Sites on it are built into the browser, so even the very first visit is protected.
We checked how a few major sites and Python’s own HTTP library handle this. The script reads each site’s HSTS header, asks the official preload list for its status, then tries to connect to three deliberately broken test sites from badssl.com.
import requests
UA = {"User-Agent": "Mozilla/5.0 (compatible; hsts-check/1.0)"}
SITES = ["github.com", "www.paypal.com", "en.wikipedia.org", "example.com"]
print("1) Does the site force HTTPS with HSTS?")
for host in SITES:
r = requests.get(f"https://{host}/", timeout=15, allow_redirects=False, headers=UA)
hsts = r.headers.get("Strict-Transport-Security", "missing")
preload = requests.get("https://hstspreload.org/api/v2/status",
params={"domain": host.removeprefix("www.").removeprefix("en.")}, timeout=15).json()["status"]
print(f" {host:18} HSTS: {hsts[:44]:44} preload list: {preload}")
print("2) Does Python refuse certificates an attacker might use?")
for bad in ["self-signed.badssl.com", "expired.badssl.com", "wrong.host.badssl.com"]:
try:
requests.get(f"https://{bad}/", timeout=15)
print(f" {bad:24} ACCEPTED (dangerous)")
except requests.exceptions.SSLError as e:
reason = str(e).split("certificate verify failed: ")[-1].split(" (_ssl")[0]
print(f" {bad:24} rejected: {reason[:48]}")GitHub, PayPal and Wikipedia all sent long-lived HSTS headers with preload, and all three are on the preload list. The example.com test domain sends no HSTS header at all. A first visit to a site like that, typed without https://, is still open to stripping on a hostile network.
The max-age values matter too. GitHub and PayPal ask browsers to remember the rule for 31,536,000 seconds, which is one year. Wikipedia asks for about three years. In Chrome, you can check a domain’s stored HSTS state at chrome://net-internals/#hsts.
Python refused all three bad certificates: self-signed, expired and issued for the wrong host. Browsers do the same thing, which is why a certificate warning is your clearest MITM alarm.
How to Prevent Man-in-the-Middle Attacks
No single setting stops every MITM attack. A handful of habits and tools, layered together, make you a very hard target.
1Treat Certificate Warnings as a Hard Stop
A warning like “Your connection is not private” on a site that normally works is the browser telling you it can’t verify who’s on the other end. On public Wi-Fi especially, close the tab instead of clicking “Proceed anyway.”
2Use HTTPS Everywhere
Turn on HTTPS-Only mode in Firefox, or “Always use secure connections” in Chrome. Your browser will then try HTTPS for every site and warn you before loading any page over plain HTTP. This covers sites that don’t use HSTS.
3Use a Trustworthy VPN on Public Networks
A VPN encrypts all your device’s traffic to the VPN server, including DNS lookups and apps that don’t use HTTPS. An attacker on the café Wi-Fi then sees only an encrypted tunnel. Our guide to VPN encryption explains what that tunnel protects, and our VPN directory compares providers.
Turn on the VPN’s kill switch, too. It blocks traffic if the tunnel drops, so nothing slips out unprotected. See our VPN kill switch explainer for how it works.
4Switch to Phishing-Resistant MFA
Codes from SMS or an authenticator app can be relayed by an AiTM phishing page.
Passkeys and FIDO2 security keys can’t, because they’re tied to the real site’s domain and won’t sign in to a lookalike. Canada’s Centre for Cyber Security recommends phishing-resistant MFA as the defense against exactly this attack. Our explainer on what a passkey is shows how to set one up.
5Turn On Encrypted DNS
Plain DNS lookups travel unencrypted, so anyone on the path can read or fake them. DNS over HTTPS (DoH) and DNS over TLS (DoT) encrypt those lookups. Most modern browsers and operating systems support one or both, usually under a “secure DNS” or “private DNS” setting.
6Keep Devices and Apps Updated
Updates fix flaws in the code that checks certificates and handles encryption. An outdated app or router may accept connections a current one would reject. Turn on automatic updates for your operating system, browser and router firmware.
7Be Careful With Networks You Don’t Control
- Confirm the network name with staff before connecting in hotels, cafés and airports.
- Turn off auto-join for open networks, so your device doesn’t connect to a lookalike on its own.
- Prefer your phone’s hotspot for anything sensitive, like banking or work logins.
- Forget public networks after you use them.
8Secure Your Home and Office Network
Use WPA3 or at least WPA2 with a strong password, change the router’s default admin password, and keep its firmware updated. Businesses can go further with switch features like Dynamic ARP Inspection, which drops fake ARP replies, and with 802.1X authentication for network access.
9Never Install Certificates You Don’t Trust
A root certificate on your device lets its owner decrypt your HTTPS traffic without any warning. Only install one if it comes from your employer’s IT team on a work-managed device, and remove any you don’t recognize.
Signs You Might Be Under a MITM Attack
A well-run attack is hard to spot, but some symptoms are worth taking seriously.
- Certificate warnings on sites that normally load fine.
- A missing padlock, or
http://in the address bar, on a site that normally uses HTTPS. - Unexpected ads, pop-ups or redirects on sites that don’t usually have them.
- Being logged out of accounts repeatedly, or seeing sign-ins from places you’ve never been.
- Two Wi-Fi networks with the same name nearby, especially an open one.
If you see these, disconnect from the network, switch to mobile data, change the passwords you used on that network, and sign out of other sessions from each account’s security page.
It’s also worth knowing what the network owner can see even without an attack. Our guide to whether Wi-Fi owners can see your browsing history covers that.
Frequently Asked Questions
Final Thoughts
Man-in-the-middle attacks work by getting into the path of your data, then breaking or sidestepping the encryption that protects it. Evil twin hotspots, ARP and DNS spoofing put the attacker in the middle. SSL stripping, fake certificates and session theft are how they profit from it.
The defenses are well understood. Take certificate warnings seriously, use HTTPS-only browsing, put a trustworthy VPN between you and public networks, and move your important accounts to passkeys. Together, they turn most MITM attacks into nothing more than an attacker staring at encrypted traffic.
Keep Reading
More articles you might enjoy


