Referrrrer
Category: Web
Description
Defeated the security of the website which implements authentication based on the Referer header.
URL : http://static-01.heroctf.fr:7000
Format : Hero{flag}
Author : xanhacks
Attachments: Referrrrer.zip
Write-up
- Upon examining the codebase, we discovered two important files:
app/index.jsandnginx/nginx.conf. These files contain the logic for the backend and the configurations for the reverse proxy (NGINX) respectively. - Let's start by analyzing
nginx/nginx.conf. This file contains standard configurations for routing traffic to the/and/adminpaths. Of particular interest is the route to/admin, which performs a regex check on the HTTPRefererheader. It ensures that theRefererheader must start withhttps://admin.internal.combefore forwarding the request to the backend server. If the condition is not met, a status code of403 (Forbidden)is returned. - Moving on to
app/index.js, we find similar routes for/and/admin. The route that stands out is/admin, where the code checks the value of the HTTPRefererheader. It specifically requires theRefererheader to be exactlyYOU_SHOUD_NOT_PASS!in order to retrieve the flag. - However, there is a conflict between the requirements of NGINX and the backend. NGINX expects the
Refererheader to start withhttps://admin.internal.com, while the backend requires it to be exactlyYOU_SHOUD_NOT_PASS!. - Upon further investigation, we discovered that within the Express.js request object, the
referervalue is first retrieved fromheader.referrerbeforeheader.referer, as shown here. - This means that we can set up a request with both the
RefererandReferrerheaders. The former will pass the check for NGINX, while the latter will pass the check for the backend. - The request looks like this:
Text Only
Flag: Hero{ba7b97ae00a760b44cc8c761e6d4535b}