Technical Deep-Dives

Man-in-the-Middle Attacks: Interception, Detection & Prevention

How MITM attacks work, covering network positioning techniques, TLS interception methods, SSL stripping, HSTS, certificate pinning, ECH, and comprehensive defense strategies.

T&RG
Theertha & Rathnakara GN
Cyber Secify
7 min read

Article 5 of 6: Understanding TLS Security Series

A Man-in-the-Middle (MITM) attack occurs when an attacker secretly intercepts and potentially modifies communication between two parties who believe they are communicating directly.

This article covers MITM attack techniques, TLS interception methods, detection strategies, and modern defenses including Encrypted Client Hello (ECH).

MITM Attack Overview

VICTIM  ────►  ATTACKER  ────►  SERVER
        ◄────            ◄────
Thinks talking     Intercepts, reads,     Thinks talking
to server          modifies traffic       to client
Attack PhaseDescription
1. PositioningAttacker places themselves between victim and server
2. InterceptionTraffic is routed through attacker’s system
3. DecryptionAttacker terminates TLS, creates new connection to server
4. InspectionAttacker reads/modifies plaintext data
5. Re-encryptionData re-encrypted and forwarded to destination

MITM Defense Layers

LayerTechnologyProtection
ProtocolTLS 1.3Encrypted handshake, mandatory ECDHE
DowngradeHSTS + PreloadPrevents SSL stripping
CertificateCertificate TransparencyDetects rogue certificates
MobileCertificate PinningRejects unexpected certificates
DNSDoH/DoT + DNSSECPrevents DNS spoofing
PrivacyECH (Encrypted Client Hello)Hides SNI from observers
Network802.1X, WPA3-EnterprisePrevents rogue AP, ARP attacks
VPNAlways-on VPNEncrypts all traffic to trusted endpoint

1. Network Positioning Techniques

Theory: How It Works

Before intercepting TLS traffic, the attacker must position themselves in the network path. Several techniques exist:

ARP Spoofing (Local Network):

  1. Attacker sends fake ARP replies to victim
  2. Victim’s ARP cache maps gateway IP to attacker’s MAC
  3. All traffic to gateway flows through attacker

DNS Spoofing:

  1. Attacker responds to DNS queries before legitimate server
  2. Victim resolves domain to attacker’s IP
  3. All HTTPS traffic goes to attacker’s server

Rogue Access Point:

  1. Attacker sets up fake WiFi with legitimate-sounding name
  2. Victim connects to attacker’s network
  3. All traffic passes through attacker-controlled router

Practical: Tools & Detection

# ARP Spoofing with arpspoof (dsniff)
arpspoof -i eth0 -t <victim_ip> <gateway_ip>
arpspoof -i eth0 -t <gateway_ip> <victim_ip>

# Using ettercap
ettercap -T -M arp:remote /<victim_ip>// /<gateway_ip>//

# Using bettercap
bettercap -iface eth0 -eval "set arp.spoof.targets <victim_ip>; arp.spoof on"

Reality: Detection & Prevention

TechniqueDetectionPrevention
ARP SpoofingARP table changes, duplicate IPsStatic ARP entries, DAI on switches
DNS SpoofingUnexpected DNS responsesDNSSEC, DNS over HTTPS (DoH)
Rogue APDuplicate SSIDs, weak signal802.1X, WPA3, VPN
BGP HijackingRoute changes, tracerouteRPKI, BGPsec

2. TLS Interception Techniques

Theory: How It Works

Once positioned, the attacker must break TLS encryption. There are several approaches:

SSL Stripping:

  1. Attacker intercepts HTTP redirect to HTTPS
  2. Maintains HTTP connection to victim
  3. Creates HTTPS connection to server
  4. Victim never sees HTTPS, so no certificate warnings

Fake Certificate:

  1. Attacker generates certificate for target domain
  2. Signs with self-signed or rogue CA
  3. Presents to victim, and browser shows warning
  4. If victim clicks through, attacker has plaintext

Trusted CA Interception (Corporate/Government):

  1. Organization installs root CA on all devices
  2. Proxy generates trusted certs for any domain
  3. No warnings shown (legitimate use for monitoring)

Practical: Tools

# SSL Stripping with sslstrip
# Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# Redirect HTTP to sslstrip
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

# Run sslstrip
sslstrip -l 8080
# TLS Interception with mitmproxy
# Generate CA certificate
mitmproxy  # Creates ~/.mitmproxy/mitmproxy-ca-cert.pem

# Install CA on victim device, then intercept
mitmproxy --mode transparent --showhost

Reality: Effectiveness

TechniqueWarning?EffectivenessDefense
SSL StrippingNo padlockHigh if no HSTSHSTS preload
Self-signed certYes (scary)Low (obvious)User education
Rogue CA certNoCriticalCert pinning
Corporate proxyNo (trusted)TotalPolicy/legal

3. HSTS (HTTP Strict Transport Security)

Theory: How It Works

HSTS forces browsers to only use HTTPS for a domain, defeating SSL stripping attacks.

How HSTS Works:

  1. Server sends HSTS header: Strict-Transport-Security: max-age=31536000
  2. Browser remembers: “Only use HTTPS for this domain”
  3. Future HTTP requests automatically upgraded to HTTPS
  4. SSL stripping fails because browser refuses HTTP

HSTS Preloading:

First visit is still vulnerable to SSL stripping. Solution: HSTS preload list is hardcoded in browsers. Sites submit to hstspreload.org and are included in browser source code.

Practical: Configuration

# HSTS Header Examples

# Basic HSTS (1 year)
Strict-Transport-Security: max-age=31536000

# Include subdomains
Strict-Transport-Security: max-age=31536000; includeSubDomains

# Ready for preload list
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload

Nginx Configuration:

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;

Check HSTS Status:

# Check if HSTS header present
curl -sI https://example.com | grep -i strict

Reality: Limitations

LimitationDetails
First VisitInitial HTTP request still vulnerable; use preload
ExpiryIf max-age expires, protection lost; use long max-age
SubdomainsMust explicitly include subdomains
Preload RemovalRemoving from preload list takes months

4. Certificate Pinning

Theory: How It Works

Certificate pinning associates a host with its expected certificate or public key, preventing MITM even with a rogue CA.

What Can Be Pinned:

  • Leaf certificate: most specific, breaks on renewal
  • Intermediate CA: good balance, survives leaf renewal
  • Public key (SPKI): survives cert renewal if key unchanged
  • Root CA: least specific, highest risk if CA compromised

Practical: Implementation

Generate Pin Hash:

# Extract SPKI hash from certificate
openssl x509 -in cert.pem -pubkey -noout | \
  openssl pkey -pubin -outform der | \
  openssl dgst -sha256 -binary | base64

Mobile App Pinning (Android, OkHttp):

CertificatePinner pinner = new CertificatePinner.Builder()
  .add("example.com", "sha256/AAAAAAAAAAAAAAAAAAAAAA...=")
  .build();

Reality: Considerations

ConsiderationDetails
Backup PinsAlways include backup pin to prevent lockout on rotation
HPKP DeprecatedHTTP Public Key Pinning removed from browsers (too risky)
Mobile AppsStill widely used in mobile apps (more controlled)
CT AlternativeCertificate Transparency provides similar protection

5. Encrypted Client Hello (ECH)

ECH encrypts the SNI field in Client Hello, hiding which website you’re connecting to. Combined with TLS 1.3 encrypted certificates and DoH, this provides near-complete privacy from network observers.

# Check ECH support
dig +short TYPE65 _https.cloudflare.com

# Check HSTS header
curl -sI https://example.com | grep -i strict

2026 ECH Adoption:

PlatformStatus
CloudflareECH enabled by default for all sites
ChromeECH supported since 2023
FirefoxECH enabled by default

6. MITM Detection Techniques

Practical: Detection Methods

Network Layer Detection:

# Detect ARP spoofing
arp -a | sort  # Look for duplicate MACs
arpwatch -i eth0  # Monitor ARP changes

# Detect rogue DHCP
nmap --script broadcast-dhcp-discover

Certificate Analysis:

# Check certificate issuer
openssl s_client -connect example.com:443 2>/dev/null | \
  openssl x509 -noout -issuer

# Check Certificate Transparency logs
# Visit: crt.sh, censys.io, or transparencyreport.google.com

Detection Indicators:

IndicatorNormalMITM Suspected
Certificate IssuerLet’s Encrypt, DigiCert, etc.Unknown CA, self-signed
Gateway MACConsistentChanges frequently
DNS ResponseExpected IPDifferent IP, fast response
LatencyNormalIncreased (extra hop)
CT LogsCertificate presentCertificate missing

Users rarely notice MITM attacks. Detection is most effective at the infrastructure level with proper monitoring and automated alerting.

Key Takeaways

  • MITM requires network positioning first (ARP, DNS, rogue AP)
  • SSL stripping is defeated by HSTS + preload list
  • Rogue CA certs detected by Certificate Transparency
  • Certificate pinning protects mobile apps
  • TLS 1.3 encrypted handshake hides more metadata
  • ECH hides SNI for complete privacy
  • Use VPN on untrusted networks
  • Never click through certificate warnings

Previous: Article 4: TLS Attacks & Vulnerabilities

Next: Article 6: TLS Hardening Guide

This is part of our 6-article series on Understanding TLS Security.

MITM vulnerabilities are a core focus of our Web Application Pentest, API Pentest, and IoT Pentest. We test certificate pinning, TLS interception, and protocol downgrade attacks. Get a free security snapshot or view pricing.

Share this article
MITMman-in-the-middleSSL strippingHSTScertificate pinningARP spoofingECHTLS security