Overview Attack Flow Techniques Tools Demo Detection Prevention Legal Resources

Man-in-the-Middle (MitM) Attack Guide

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

A Man-in-the-Middle (MitM) attack is a type of cyberattack where an attacker secretly intercepts, relays, and potentially alters communication between two parties (e.g., a user and a web server) without their knowledge. The attacker positions themselves in the communication path, allowing them to eavesdrop on sensitive information (passwords, credit card numbers, session tokens), inject malicious content, or modify data in transit. MitM attacks exploit weaknesses in network protocols (ARP, DNS), lack of encryption (HTTP), or certificate validation failures (SSL/TLS).

Attack Prevalence: MitM attacks are a top 10 cybersecurity threat, affecting 35% of organizations annually (2023). Public Wi-Fi networks are the most common attack vector (60% of MitM attacks). The average MitM attack costs organizations $500,000+ in damages (data breach, credential theft, financial fraud).

35%
Organizations Affected Annually
60%
on Public Wi-Fi Networks
$500K+
Average Cost per Attack

Common targets of MitM attacks:

How MitM Attacks Work (Attack Chain)

1. Interception

Attacker positions between victim and target (ARP spoofing, rogue AP, DNS poisoning). Traffic is redirected through attacker's device.

2. Decryption

If SSL/TLS encrypted, attacker downgrades HTTPS to HTTP (SSLStrip) or uses fake certificate to decrypt.

3. Eavesdropping

Attacker reads captured packets to extract credentials, session tokens, financial data, personal information.

4. Injection

Attacker injects malicious content, modifies responses, or redirects to phishing pages.

// MitM attack chain (technical flow) [Victim] ↔ [Attacker (MitM)] ↔ [Target Server] // ARP spoofing example (local network MitM) Attacker sends ARP reply: "192.168.1.1 (gateway) is at MAC:AA:BB:CC:DD:EE:FF" Victim believes attacker is the gateway. All victim traffic goes through attacker before reaching internet. // ARP spoofing commands (ettercap) sudo ettercap -T -M arp:remote /192.168.1.105// /192.168.1.1// // DNS spoofing (redirect victim to malicious site) Victim requests example.com → Attacker DNS response: "example.com is at 203.0.113.5 (attacker server)" Victim visits fake website (phishing) // SSLStrip (HTTPS downgrade attack) Victim requests https://bank.com → Attacker modifies to http://bank.com Victim sends credentials over HTTP (unencrypted) Attacker captures credentials, then forwards HTTPS request to real bank // Bettercap (modern MitM tool) sudo bettercap -eval "set arp.spoof.targets 192.168.1.105; arp.spoof on; net.sniff on"

Common MitM Attack Techniques & Vectors

ARP Spoofing (ARP Cache Poisoning)

Attacker sends fake ARP (Address Resolution Protocol) replies to associate their MAC address with victim's gateway IP. All victim traffic destined for internet routes through attacker. Most common MitM attack on local networks (Ethernet/Wi-Fi). Detection: ARPwatch, static ARP entries.

Local Network

Rogue Access Point (Evil Twin)

Attacker sets up fake Wi-Fi access point with legitimate-sounding SSID ("Free Airport Wi-Fi", "Starbucks WiFi"). Victim connects to rogue AP, attacker performs MitM on all traffic. Often used in public places (airports, cafes, hotels).

Wireless

DNS Spoofing (DNS Cache Poisoning)

Attacker corrupts DNS cache (local router, DNS resolver) to redirect domain names to malicious IP addresses. Victim visits fake website (phishing) even when typing correct URL. Used in phishing campaigns and malware distribution.

DNS

SSL/TLS Stripping (HTTPS Downgrade)

Attacker downgrades HTTPS connections to HTTP by modifying responses, removing the "secure" flag from cookies, or stripping HSTS headers. Victim sends credentials over unencrypted HTTP. Tools: SSLStrip (Moxie Marlinspike), Bettercap.

HTTPS Bypass

Certificate Spoofing (Fake Cert)

Attacker presents fake SSL/TLS certificate to victim (self-signed, or stolen CA certificate). Browser warns user, but many users click through warnings. Advanced: CA compromise (DigiNotar, Comodo hack).

TLS

BGP Hijacking (Route Hijacking)

Attacker announces fraudulent BGP (Border Gateway Protocol) routes to redirect internet traffic through malicious AS. Can affect large regions or entire countries. Example: Pakistan Telecom hijacked YouTube (2008), Amazon Route 53 hijack (2018).

Internet-wide

Email MitM (SMTP/IMAP)

Attacker intercepts email communication by exploiting misconfigured SMTP (no STARTTLS) or DNS MX records. Can read, modify, or redirect emails. Target: corporate email, two-factor authentication codes.

Email

MitM Attack Tools (Educational Context)

Ettercap (ARP Spoofing)

Comprehensive MitM attack tool with ARP spoofing, DNS spoofing, packet sniffing, and payload injection. Supports both CLI and GUI. Features: unified sniffing, MITM filter scripts (ec_filter), connection killing, and session hijacking.

Wireshark (Packet Analysis)

Network protocol analyzer for capturing and analyzing network traffic. Used to inspect intercepted packets, extract credentials, and reconstruct sessions. Supports display filters (tcp.port==80), stream reassembly, and follow TCP streams.

Bettercap (Modern Framework)

Powerful MitM framework (replacing Ettercap) with ARP spoofing, DNS spoofing, HTTP/HTTPS proxy, SSLStrip, credential harvesting, and network sniffing. Features: REST API, JavaScript plugin system (caplets), Wi-Fi deauthentication, BLE attacks.

MITMf (MitM Framework)

Python-based framework with plugins for SSLStrip (HTTPS downgrade), spoofing, DNS spoofing, and credential harvesting. Includes features: responder, SMB authentication capture, and browser exploitation.

SSLStrip (Moxie Marlinspike)

Tool for downgrading HTTPS connections to HTTP. Intercepts HTTPS requests, strips "https://" to "http://", forwards to victim. Victim sends credentials unencrypted. Modern bypass: HSTS (HTTP Strict Transport Security) prevents SSLStrip.

dsniff (Collection)

Collection of MitM tools: arpspoof (ARP spoofing), dnsspoof (DNS spoofing), tcpkill (kill TCP connections), webmitm (HTTP/HTTPS proxy), mailsnarf (SMTP capture). Legacy but effective.

Subterfuse

Automated MitM framework with GUI interface. Features: ARP spoofing, SSLStrip, DNS spoofing, credential harvesting, and metasploit integration.

Burp Suite (Proxy)

Web application testing proxy that can act as MitM between browser and server. Intercepts and modifies HTTP/HTTPS requests. Used for penetration testing, not malicious attacks.

MitM Attack Simulation (ARP Spoofing)

This demonstration simulates how ARP spoofing positions an attacker between the victim and gateway to intercept traffic:

Click "Simulate MitM Attack" to see ARP spoofing and credential capture

This is a simulated demonstration. Real MitM attacks can capture credentials, session tokens, financial data, and modify traffic in transit. Always use HTTPS, verify SSL certificates, and avoid public Wi-Fi for sensitive transactions.

Detecting Man-in-the-Middle Attacks

ARP Spoofing Detection

Tools: ARPwatch monitors for ARP table changes. Detect duplicate MAC addresses for same IP. Static ARP entries (arp -s) prevent spoofing. Check for ARP cache anomalies: arp -a (Windows), arp -n (Linux). Use port security (Cisco) or 802.1X (NAC).

SSL/TLS Certificate Warnings

Browser SSL/TLS certificate warnings (expired, invalid, self-signed) indicate potential MitM. Do NOT click through warnings. Check certificate chain and issuer. Use HSTS (HTTP Strict Transport Security) to prevent SSLStrip.

Latency Anomalies

Unusual network latency (200ms+) or packet loss may indicate traffic being routed through attacker. Use traceroute (tracert) to compare route with expected path. Sudden changes in RTT (round trip time).

Network IDS/IPS (Snort/Suricata)

Signature detection for ARP spoofing: "ARP reply with different MAC address". Detect DNS spoofing (DNS response mismatches). Detect SSLStrip (HTTP downgrade). Use Zeek (Bro) for anomaly detection.

Rogue Access Point Detection

Wi-Fi scanning tools (Kismet, Airodump-ng) detect rogue APs. Compare MAC addresses (OUI) with legitimate APs. Monitor for Evil Twin (same SSID, different BSSID). Use 802.1X with RADIUS authentication.

Certificate Pinning & Monitoring

Mobile apps with certificate pinning detect fake certificates. Monitor certificate transparency logs (crt.sh) for unauthorized certificates issued for your domain. Use CT log monitoring (Facebook CT, CertSpotter).

// MitM detection commands and techniques # ARP spoofing detection (Linux) arp -a | grep -v "incomplete" # Check for duplicate IP addresses with different MACs ip neigh show | grep -v "REACHABLE" # ARP spoofing detection (Windows) arp -a # Look for gateway IP (192.168.1.1) with unexpected MAC address # Detect ARP spoofing with ARPwatch (install first) sudo apt-get install arpwatch sudo arpwatch -i eth0 # Monitor for SSLStrip (HTTPS downgrade) in logs # Check web server logs for HTTP requests to HTTPS-only resources grep "http://" /var/log/nginx/access.log # Detect DNS spoofing (compare with known-good DNS) dig +short example.com # Compare with expected IP address (should match certificate) # Network latency test (detect MitM) ping -c 10 google.com # High or variable RTT may indicate traffic interception mtr google.com # My Traceroute (continuous traceroute) # Snort rule for ARP spoofing detection alert arp any any -> any any ( msg:"ARP spoofing detected - duplicate IP address"; content:"|00 00 00 00 00 00|"; pcre:"/^[0-9a-f]{12}/i"; sid:1000001; )

Preventing Man-in-the-Middle Attacks

Use HTTPS & Enable HSTS

Always use HTTPS for all web traffic (not just login pages). Enable HTTP Strict Transport Security (HSTS) to force browsers to use HTTPS. Preload HSTS (hstspreload.org) to protect first visit. Prevents SSLStrip (HTTPS downgrade) attacks.

Verify SSL/TLS Certificates

Never click through certificate warnings. Check certificate issuer, validity dates, and domain name. Use certificate pinning for mobile apps. Monitor Certificate Transparency logs (crt.sh) for unauthorized certificates.

Use VPN on Public Wi-Fi

VPN encrypts all traffic between device and VPN server, preventing MitM on local network. Choose reputable VPN provider with no-logs policy (Mullvad, ProtonVPN, IVPN). Always enable VPN before connecting to public Wi-Fi.

Enable 802.1X (Network Access Control)

Enterprise networks: Use 802.1X with RADIUS authentication to prevent unauthorized devices (rogue APs). Port security (Cisco) limits MAC addresses per port. NAC solutions (Cisco ISE, Forescout, PacketFence).

DNSSEC (DNS Security Extensions)

DNSSEC cryptographically signs DNS responses, preventing DNS spoofing (cache poisoning). Validates authenticity and integrity of DNS data. Deploy DNSSEC on authoritative nameservers. Use DNSSEC-validating resolvers (1.1.1.1, 9.9.9.9, Quad9).

Static ARP Entries

Set static ARP entries for critical IPs (gateway) to prevent ARP spoofing. arp -s 192.168.1.1 aa:bb:cc:dd:ee:ff (Windows/Linux). Use DHCP snooping on switches (Cisco). Implement Dynamic ARP Inspection (DAI).

Browser Security Extensions

HTTPS Everywhere (EFF - forces HTTPS), uBlock Origin (blocks malicious domains), NoScript (blocks scripts on untrusted sites), and Certificate Patrol (notifies of certificate changes).

Monitor for Rogue Access Points

Regular Wi-Fi scans (Kismet, Airodump-ng) detect unauthorized APs. Use WIDS/WIPS (Wireless Intrusion Detection/Prevention Systems) in enterprise. Disable Wi-Fi when using Ethernet.

Best Practice - Defense-in-Depth for MitM Protection: Always use HTTPS with HSTS preloading (avoids SSLStrip), verify SSL/TLS certificates (do not click through warnings), use VPN on public Wi-Fi, enable 802.1X network access control (enterprise), deploy DNSSEC, and monitor for ARP spoofing (ARPwatch, static ARP). No single control prevents all MitM attacks - layered defense is essential. For high-risk environments (finance, healthcare, government), use certificate pinning, client certificates (mTLS), and application-layer encryption.

Further MitM Resources & Information

CISA MitM Mitigation Guide

CISA (Cybersecurity and Infrastructure Security Agency) guidance on detecting and preventing MitM attacks, including ARP spoofing, DNS spoofing, and rogue access points.

OWASP (Transport Layer Protection)

OWASP guidance on Transport Layer Protection (TLS, HSTS, certificate pinning). MitM prevention best practices for web applications and APIs.

Bettercap Documentation

Official Bettercap documentation (ARP spoofing, DNS spoofing, SSLStrip). Includes defense detection techniques and countermeasures.

SANS SEC504 (Hacker Tools)

Incident response course covering MitM attack detection, network traffic analysis, and defense strategies.

MITRE ATT&CK - MitM Techniques

MITRE ATT&CK framework tactics: T1557 (Adversary-in-the-Middle), T1565 (Data Manipulation), T1204 (User Execution).

SSL Labs (SSL/TLS Testing)

SSL Labs (Qualys) tests web servers for SSL/TLS vulnerabilities, including MitM risks (Downgrade attacks, weak cipher suites).

The DFIR Report - MitM Case Studies

Real MitM incident case studies (ARP spoofing, DNS hijacking, rogue AP), network traffic analysis (PCAP), and containment lessons.

US DOJ - MitM Prosecution Cases

US Department of Justice (DOJ) press releases on MitM attack prosecutions (wiretap violations, computer fraud, identity theft).

← Back to Knowledge Base