SECURITY 12 min

Advanced AitM Phishing with Evilginx: 2FA Bypass, Session Hijacking, and FIDO2 Defense

Technical and defensive analysis of Adversary-in-the-Middle (AitM) phishing using Evilginx: how reverse proxies hijack session cookies to bypass legacy 2FA, Blue Team detection telemetry, and definitive defense via FIDO2 Passkeys.

Written by Samir El Azem Crovetto • Senior Backend Engineer & DevSecOps

Ethical and Legal Notice: The content of this guide is strictly intended for educational, technical awareness, and defensive security auditing within authorized enterprise environments. Analyzing offensive adversary tooling such as Evilginx is essential for engineering resilient identity architectures and evaluating conditional access controls. Any unauthorized usage against third-party systems is illegal.


The Collapse of Legacy 2FA Against AitM Phishing

For over a decade, the standard cybersecurity baseline for securing user identities has been concise: "enable two-factor authentication (2FA)". Organizations assumed that even if an adversary harvested a user's password via a credential leak or cloned landing page, the secondary factor—an SMS one-time passcode or an authenticator app notification (such as Google Authenticator or Microsoft Authenticator)—would reliably prevent unauthorized access.

In the modern enterprise threat landscape, this assumption is fundamentally broken.

The widespread maturation of Adversary-in-the-Middle (AitM) frameworks, spearheaded by tools such as Evilginx (versions 2 and 3), has transformed credential harvesting from static landing page clones to real-time dynamic proxying. Evilginx does not attempt to break TLS encryption, guess six-digit OTP codes, or exploit cryptographic implementation flaws: it deploys as a transparent reverse proxy stationed between the victim and legitimate Identity Providers (IdPs) such as Microsoft Entra ID, Google Workspace, or Okta.

The operational outcome is catastrophic: the targeted user completes their authentic login sequence, enters their password, and verifies their secondary MFA challenge. However, the adversary captures far more than the password: they intercept the post-MFA authenticated session cookies, enabling full account takeover without ever prompting the user for MFA again.

This technical guide examines the internal architecture of Evilginx, the anatomy of phishlets, detection strategies for Blue Teams, and the only mathematical defense: the adoption of phishing-resistant credentials founded on FIDO2 and WebAuthn Passkeys.


Architecture of an Adversary-in-the-Middle Reverse Proxy

To understand why traditional controls fail, consider the end-to-end request lifecycle mediated by Evilginx:

sequenceDiagram
    autonumber
    actor Victim as Target User (Browser)
    participant Proxy as AitM Proxy (Evilginx 3)
    participant IdP as Legitimate IdP (Entra ID / Okta)

    Victim->>Proxy: 1. Clicks lure link to lookalike domain
    Proxy->>IdP: 2. Requests authentic login page over TLS
    IdP-->>Proxy: 3. Returns genuine HTML/JS and challenge
    Proxy-->>Victim: 4. Rewrites URLs and serves authentic page
    Victim->>Proxy: 5. Submits credentials (username + password)
    Proxy->>IdP: 6. Relays credentials to genuine IdP in real time
    IdP-->>Proxy: 7. Prompts for MFA challenge (Authenticator / TOTP)
    Proxy-->>Victim: 8. Displays authentic live MFA prompt
    Victim->>Proxy: 9. Enters TOTP code or approves push notification
    Proxy->>IdP: 10. Forwards MFA approval to genuine IdP
    IdP-->>Proxy: 11. Authentication successful: Issues Session Cookie
    Note over Proxy: Evilginx intercepts & stores Session Cookie (ESTSAUTH, JWT)
    Proxy-->>Victim: 12. Redirects victim to genuine application portal
    Note over Proxy: Adversary imports session cookie into browser
    Proxy->>IdP: 13. Persistent access without password or MFA prompt

Core Architecture Components of Evilginx:

  1. Embedded Authoritative DNS Server: Evilginx acts as an authoritative DNS nameserver for domains under adversary control. It dynamically resolves A records for target subdomains and coordinates ACME DNS-01 validation challenges with Let's Encrypt to provision valid Wildcard TLS certificates, ensuring the browser displays trusted HTTPS padlocks.
  2. Phishlet Engine: Phishlets are YAML configuration manifests defining proxying rules for specific enterprise authentication platforms. They dictate which target subdomains to proxy, what text strings or URLs to rewrite dynamically in HTTP responses, and which session cookies must be intercepted and stored.
  3. Lure Management: Parameterized, obfuscated URLs linked to specific targets to track campaign telemetry (opens, link clicks, credential submissions) and govern post-compromise redirection.

2. Technical Anatomy of a Phishlet: How Sessions are Hijacked

A phishlet maps the exact behavioral semantics of a target authentication service. Below is an illustrative excerpt showing how Evilginx targets Microsoft Entra ID / Office 365 environments:

# Illustrative phishlet configuration structure (YAML)
name: 'o365-defensive-audit'
author: 'SecDevOps Research'
min_ver: '3.0.0'

# Proxied hosts configuration
proxy_hosts:
  - {phish_sub: 'login', orig_sub: 'login', domain: 'microsoftonline.com', session: true, is_landing: true}
  - {phish_sub: 'portal', orig_sub: 'portal', domain: 'office.com', session: false, is_landing: false}

# Credential capture rules
credentials:
  username:
    key: 'login'
    search: '(.*)'
    type: 'post'
  password:
    key: 'passwd'
    search: '(.*)'
    type: 'post'

# Target authentication tokens to intercept from Set-Cookie headers
auth_tokens:
  - domain: '.login.microsoftonline.com'
    keys: ['ESTSAUTH', 'ESTSAUTHPERSISTENT', 'SignInStateCookie']
  - domain: '.portal.office.com'
    keys: ['SessionId']

# Dynamic response filters to prevent leakage to legitimate endpoints
sub_filters:
  - {triggers_on: 'login.microsoftonline.com', orig_sub: 'login', domain: 'microsoftonline.com', search: 'login.microsoftonline.com', replace: 'login.{hostname}'}

Intercepting the ESTSAUTH Token

Within Microsoft Entra ID, the presence of the ESTSAUTH cookie in an HTTP request serves as proof that the client has satisfied all required authentication factors.

When Evilginx intercepts this Set-Cookie header in the server response, it outputs the captured credentials and session tokens to the administrative console:

[17:15:22] [o365] Captured credentials for user: cfo@enterprise.com
[17:15:22] [o365] Password: **********
[17:15:35] [o365] Captured 3 auth tokens:
[17:15:35] [o365] ESTSAUTH = 0.AXoA8k... [SESSION COOKIE]
[17:15:35] [o365] ESTSAUTHPERSISTENT = 0.AXoA8k... [PERSISTENT COOKIE]

The adversary imports this token into a standard browser via cookie manipulation extensions and accesses Outlook Web, OneDrive, or Azure Cloud Shell without triggering re-authentication.


3. Telemetry & Threat Hunting for Blue Teams

While AitM attacks appear authentic to users, they generate distinct anomalous signatures across network traffic and Identity Provider logs:

1. Microsoft Entra ID Sign-in Log Anomalies

Security Operations Center (SOC) analysts can identify reverse proxy compromises by correlating specific fields in Entra ID sign-in telemetry:

  • IP Address vs. Operating System Mismatch: The initial interactive sign-in occurs from a legitimate residential or corporate ISP, but subsequent API calls utilizing the session token originate from cloud hosting ranges (such as DigitalOcean, AWS, Linode, or Hetzner).
  • Missing Device Compliance State: When organizations enforce Conditional Access policies requiring compliant Intune-managed devices, the adversary cannot reuse the stolen cookie from an unmanaged workstation.
  • Impossible Travel Telemetry: Consecutive sessions authenticated from geographically disparate regions within minutes.

2. Network Perimeter and PCAP Signatures

When inspecting network packet captures in Wireshark, as detailed in our guide on Network Forensics and Encrypted Traffic Analysis:

  • Anomalous JA4 TLS Fingerprints: Evilginx uses Go HTTP libraries to negotiate outbound TLS handshakes with legitimate IdPs. The resulting JA4 fingerprint diverges significantly from authentic browser signatures (Chrome, Edge, Safari).
  • Round-Trip Time (RTT) Jitter: Real-time proxy forwarding introduces latency anomalies detectable in TCP handshake and HTTP response timings.

4. Why Awareness-Based Defenses Inevitably Fail

Organizations historically instructed employees to recognize phishing through superficial visual clues:

  • "Look for the green HTTPS padlock." -> Ineffective: Evilginx provisions genuine Let's Encrypt certificates automatically.
  • "Watch for misspelled brand names or flawed design." -> Ineffective: Evilginx mirrors authentic brand assets directly from the legitimate server in real time.
  • "Use an authenticator app instead of SMS." -> Ineffective: The reverse proxy transparently forwards the TOTP code or push challenge immediately.

The defensive engineering conclusion is unmistakable: human vigilance cannot compensate for structural protocol weaknesses.


5. The Mathematical Defense: FIDO2, WebAuthn, and Passkeys

The only technological architecture capable of defeating Adversary-in-the-Middle attacks is authentication founded on FIDO2 / WebAuthn Passkeys.

The Mechanism: Cryptographic Origin Binding

Unlike passwords or OTP codes, which are simple strings that a user can enter into any arbitrary web form, a physical FIDO2 security key (e.g., YubiKey) or an OS-level Passkey conducts a cryptographic handshake mediated by the browser:

  1. The browser examines the fully qualified domain name displayed in the URL bar (e.g., login.micros0ft-portal.com).
  2. The browser packages this domain inside a clientDataJSON data structure.
  3. The security key signs the challenge using its private key, binding the cryptographic signature specifically to the domain reported by the browser.
  4. The signed response is forwarded through the Evilginx proxy to the authentic Identity Provider (login.microsoftonline.com).
  5. The legitimate IdP validates the cryptographic signature and verifies the origin claim. Recognizing that the signature is tied to the adversary's domain (micros0ft-portal.com) rather than its own (microsoftonline.com), it immediately rejects the authentication assertion.
sequenceDiagram
    autonumber
    actor V as User with FIDO2 Key / Passkey
    participant B as Web Browser (Chrome/Edge)
    participant P as AitM Proxy (Evilginx)
    participant IdP as Legitimate IdP (microsoftonline.com)

    V->>B: Visits login.micros0ft-portal.com
    B->>P: Requests WebAuthn challenge
    P->>IdP: Requests genuine WebAuthn challenge
    IdP-->>P: Emits Cryptographic Challenge
    P-->>B: Relays Challenge
    Note over B: Browser detects origin: "login.micros0ft-portal.com"
    B->>V: Prompts for FIDO2 touch / biometric
    V-->>B: Key signs: {challenge, origin: "login.micros0ft-portal.com"}
    B->>P: Transmits signature bound to lookalike domain
    P->>IdP: Forwards signature to genuine IdP
    Note over IdP: IdP verifies expected origin: "login.microsoftonline.com"<br/>Received origin: "login.micros0ft-portal.com"<br/>MISMATCH DETECTED
    IdP-->>P: ERROR: Authentication Rejected (Invalid Origin Binding)
    P-->>B: Login Failed (Attack Blocked)

The attack is thwarted cryptographically without requiring the user to identify the fraudulent URL.

Complementary Architectural Safeguards:

  1. Enforce Phishing-Resistant MFA Policies: Require FIDO2, Windows Hello for Business, or Passkeys within Microsoft Entra ID or Okta, disabling SMS and TOTP as detailed in our guide on Modern Authentication vs. Authorization.
  2. Conditional Access for Compliant Devices: Restrict critical enterprise applications to managed devices authenticated via mTLS device certificates.
  3. Continuous Access Evaluation (CAE): Enforce real-time session revocation upon network location shifts.
  4. Infrastructure Defense: Anchor identity controls with strict SSH Server Hardening and isolated Docker Container Architecture.

Conclusion

Evilginx and modern AitM frameworks have proven that shared secrets and replayable second factors are fundamentally obsolete. Treating web authentication as simple form submissions is an untenable security posture.

Enterprise resilience requires transitioning toward a Zero Trust architecture, where user identity is validated through unexportable, origin-bound asymmetric cryptography (Passkeys / FIDO2), governed by continuous verification in DevSecOps Pipelines.

If your organization needs to assess its resilience against AitM phishing, implement phishing-resistant FIDO2 authentication architectures, or audit cloud conditional access policies, explore my Cybersecurity Consulting Services or connect directly on my About Me profile.