Skip to content
Path traversal Write-up Intermediate

Breaking Parser Logic: Gain Access To NGINX Plus API — Read/Write Upstreams.

The reverse proxy's path normalisation logic could be bypassed using an encoded traversal sequence, allowing access to the internal NGINX Plus API. The attacker could then read and write to the API, including creating a new upstream server to redirect traffic.

Cyberlix Follow

Published on cyberlix.io

Hi hackers, in this talk I will explain how I could direct traffic from an internal server to my own by breaking the way their reverse proxy’s requests are handled.

admin, on cyberlix.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

This write-up describes a path traversal finding on a private bug crowd program the researcher was invited to. The target ran an NGINX reverse proxy in front of an internal API, and the goal was to break the proxy's request parsing so that traffic could be directed from an internal server to a server the researcher controlled.

The report opens with a short explanation of what a reverse proxy does: it sits between the public-facing web and the internal servers, processes incoming requests and upstreams them to the appropriate backend. The example given is a public site at http://company.com and a backend portal holding customer PII at http://portal.company.com:8282/. Without a reverse proxy the portal would be reachable directly from a browser, so an intermediate proxy is placed in front of it to block or deny clients trying to reach the portal directly. Nginx, Apache, HAProxy and Squid are named as examples of such proxies, with Nginx described as one of the most popular.

The diagram illustrates the workings of a reverse proxy: clients talk to the proxy, and the proxy forwards to the internal servers.

Proxies are configured with rules or filters that decide how requests are handled. The report's premise is that bad parser logic and bad regular expressions let attackers break that logic and reach internal servers, such as the portal above, and with it the customers' PII data.

The specific class of bug covered is secondary context path traversal, which the author distinguishes from the many other variants of reverse proxy, load balancer and caching server vulnerabilities.

Setup

The engagement was a private bug crowd program the researcher had been invited to. No account, role, product version or specific tooling beyond the browser and a fuzzer is described. Reconnaissance was done in Chrome DevTools, and fuzzing was done with ffuf using a larger path traversal wordlist than the few payloads shown. The report does not describe any precondition beyond the target running an Nginx reverse proxy.

Finding it

Step 1: Reconnaissance in DevTools

The researcher starts recon in Chrome DevTools, keeping only Fetch/XHR and Docs checked and everything else unchecked, which greatly reduces the number of static files that get populated. The report notes that these files should never be ignored because in some cases they help.

The screenshot shows Chrome DevTools with the network filter set to Fetch/XHR and Docs.

Step 2: Spotting an interesting endpoint

While going through the requests, the researcher found an API endpoint that looked interesting and immediately ran ffuf with common path traversal payloads:

Text
/experience/..;/
/experience/../
/experience/..%2f
/experience/%2e%2e%2f

These are only a few out of the many payloads in the list actually used. The point was to look for nuances in the responses rather than just status codes.

Step 3: Reading the responses

All of the payloads returned 403 except one:

Text
/experience/..%2f

That one returned a 404. A 404 instead of a 403 is a strong indicator that the request may be reaching the internal root of the API.

Step 4: Going one directory further back

To test the idea further, the researcher went back one directory:

Text
/experience/..%2f..%2f

This returned a 400 Bad Request.

The screenshot shows the Nginx 400 Bad Request response.

At this point the researcher knew it was an Nginx reverse proxy, because the 400 response leaked the server type. What was needed was a path that yielded a valid 200 OK. Content discovery was run against the traversed path, the same one that had produced the 404 in step 3, using a placeholder for the discovered name:

Text
/experience/..%2fHERE

The scan results contained a path /api and a file dashboard.html, both returning 200 OK with different responses.

Step 5: Confirming the hit is internal

Navigating to the discovered file through the traversal:

Text
/experience/..%2fdashboard.html

revealed an NGINX Plus API. The report links to the NGINX Plus Live Activity Monitoring documentation as the description of what was found.

To be sure the hit was internal and not simply a file in the web root, the researcher verified that dashboard.html and /api were not reachable at the root:

Both returned 403, which confirmed the traversal was reaching something the web root did not expose.

Step 6: Enumerating the API

There was not much on dashboard.html, so the researcher looked at the /api path found through the traversal. It contained a set of numbers in JSON. Cross-referencing the NGINX API documentation (http://nginx.org/en/docs/http/ngx_http_api_module.html#example) showed that these numbers are different versions of the API. Navigating to one of the versions exposed a set of paths, all reached through the same traversal prefix:

Text
/experience/..%2f/api/7/
/experience/..%2f/api/7/nginx
/experience/..%2f/api/7/connections
/experience/..%2f/api/7/http/requests
/experience/..%2f/api/7/http/server_zones/server_backend
/experience/..%2f/api/7/http/caches/cache_backend
/experience/..%2f/api/7/http/upstreams/backend
/experience/..%2f/api/7/http/upstreams/backend/servers/
/experience/..%2f/api/7/http/upstreams/backend/servers/1
/experience/..%2f/api/7/http/keyvals/one?key=arg1
/experience/..%2f/api/7/stream/
/experience/..%2f/api/7/stream/server_zones/server_backend
/experience/..%2f/api/7/stream/upstreams/
/experience/..%2f/api/7/stream/upstreams/backend
/experience/..%2f/api/7/stream/upstreams/backend/servers/1

At this point the researcher had a P3 and wanted to escalate it to a P1.

Exploitation

Step 1: Looking for write access

After a conversation with colleagues on Slack, the idea came up to try writing to the API. The API documentation lists many POST and GET verbs for some of the paths, but it also documents that writing to the API is disabled by default. The researcher nearly gave up at this point.

A stock photo used to illustrate the moment of doubt.

Step 2: Trying the parameters anyway

The researcher played with the different parameters, assuming the API would not allow writes. Instead the request returned 204, meaning the write had actually worked: an upstream was created and written to the API. That escalated the finding to a P1, and it was triaged within an hour.

Step 3: Final proof of concept

The final POC is shown in the report as a screenshot.

The screenshot shows the final proof of concept request.

And the response it produced:

The screenshot shows the response to the proof of concept.

The report does not reproduce the request or response bodies in text, so the exact method, path, body and headers of the write are not stated here.

Root cause

The proxy's parser logic and the regular expressions used to decide which requests are allowed are the weak point. The report attributes the bug to bad parser logic and bad regular expressions but does not describe the exact mechanism. The direct root paths /dashboard.html and /api both returned 403, confirming the traversal reached something the web root did not expose. The 400 on the double traversal leaked the server type, which identified Nginx as the reverse proxy. The report does not state the exact configuration, so the precise rule that failed is not known;

The second half of the root cause is on the API side: writing to the NGINX Plus API is documented as disabled by default, yet the write succeeded.

Impact

As stated in the report, malicious agents can re-route traffic to their own server and cause disruption to internal services. The internal NGINX Plus API was reachable through the proxy and an upstream could be created through it, which would allow traffic to be re-routed to an attacker's server. The impact depends on the proxy being reachable and on the API accepting writes, which the report shows was the case here.

Fix

Variants to test

  1. Encoded traversal with a semicolon: /experience/..;/. A positive result is a status code that differs from the 403 returned for ordinary paths, for example a 404 or 200.
  2. Plain traversal: /experience/../. Same signal: a status that differs from the baseline 403.
  3. Encoded slash traversal: /experience/..%2f. Here it returned 404, indicating the internal root was reachable.
  4. Fully encoded dots and slash: /experience/%2e%2e%2f. Same signal as above.
  5. Double traversal: /experience/..%2f..%2f. Here it returned 400, which leaked the server type; a 400 or a different error page is worth noting.
  6. Traversal plus a discovered name: /experience/..%2fHERE. A 200 OK for a name that is 403 at the web root confirms an internal hit.
  7. Compare the traversed path with the direct path, for example /dashboard.html and /api at the root. A 403 at the root and a 200 through the traversal is the confirmation step.
  8. Enumerate API versions and endpoints through the traversal, such as /experience/..%2f/api/7/http/upstreams/backend. A JSON response listing upstreams or servers is a positive result.
  9. Try write verbs on endpoints that document POST, even where writes are documented as disabled by default. A 204 response indicates the write succeeded.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

What happened, in plain words

A security researcher was invited to test a private bug bounty program (a scheme where companies pay people to find weaknesses in their systems). The company ran a piece of software called a reverse proxy in front of an internal service. The researcher found a way to make the proxy hand over requests to that internal service, and then found a way to change settings inside it. The result was that traffic could be redirected from the company's internal server to a server the researcher controlled.

This article walks through the whole story from the beginning, assuming you have never done security testing before. You only need to know how to use a browser. Every technical word is explained the first time it appears, and there is a glossary at the end.

What a reverse proxy is

Imagine a large office building. Visitors cannot walk straight into the offices; they go to a reception desk first. The receptionist checks who you are, decides whether you are allowed in, and then walks your message to the right office. A reverse proxy is the receptionist of the internet. It sits between the public web and the company's internal servers. When a request arrives from the outside, the proxy looks at it, applies its rules, and then forwards ("upstreams") it to the correct internal server.

The report gives a small scenario. There is a public website:

Text
http://company.com

Behind it there is an internal portal holding all the customers' PII (personally identifiable information: names, addresses, and so on). That portal has its own address:

Text
http://portal.company.com:8282/

Without a reverse proxy, anyone with a browser could type that portal address and reach it directly, because nothing stands in the way. To prevent that, the company puts an intermediate proxy in front of the portal. The proxy blocks or denies requests from clients who try to reach the portal directly. The report names several products that can do this job: Nginx, Apache, HAProxy and Squid. Nginx is described as one of the most popular.

The diagram shows how a reverse proxy works: clients talk to the proxy, and the proxy forwards their requests to the internal servers.

A proxy is configured with rules or filters. These rules tell it how to handle each request that passes through. The problem, as the report explains, is that people often write bad parser logic and bad regular expressions. A parser is the part of the software that reads a request and works out what it means; a regular expression is a pattern used to match text. When those are written badly, an attacker can craft a request that the rule reads one way but the internal server reads another way. That mismatch is what lets someone slip past the rules and reach internal servers, such as the portal above, and with it the customers' PII.

The specific type of bug in this report is called secondary context path traversal. "Path traversal" means using special sequences in a URL to climb out of the folder you are supposed to be in, a bit like writing .. in a file manager to go up one directory. "Secondary context" means the trick happens in a second layer, here the proxy, rather than in the application itself. The report notes that this is only one of many variants of reverse proxy, load balancer and caching server vulnerabilities.

Setting the scene

The engagement was a private bug bounty program the researcher had been invited to. The report does not describe any account, role, product version or special tooling beyond a browser and a fuzzer. Reconnaissance (the information-gathering phase at the start of a test) was done in Chrome DevTools, and fuzzing (sending many automatically generated inputs to see how a system reacts) was done with a tool called ffuf, using a larger list of traversal payloads than the few shown. A payload here simply means the piece of text you put in a request to try to trigger the bug.

The report does not describe any precondition beyond the target running an Nginx reverse proxy. "Encoded" means written in a form the URL standard allows, for example %2f instead of /.

Finding it

Step 1: Looking around in DevTools

The researcher starts with Chrome DevTools, the set of developer tools built into the Chrome browser. You open them with F12 or by right-clicking a page and choosing Inspect. One of the tabs, the Network tab, lists every request the page makes. The researcher keeps only the Fetch/XHR and Docs filters ticked and unticks everything else. XHR stands for XMLHttpRequest, a way for a page to fetch data in the background without reloading; the filter groups those background requests together. Ticking only these two greatly reduces the number of static files (images, stylesheets and so on) that appear in the list, so the interesting requests stand out. The report adds a warning: never ignore these files, because in some cases they help.

The screenshot shows Chrome DevTools with the network filter set to Fetch/XHR and Docs.

Step 2: Spotting an interesting endpoint

While going through the requests, the researcher found an API endpoint that looked interesting. An API (application programming interface) is a way for one piece of software to talk to another, usually by sending requests to specific addresses and getting data back, often in JSON (a text format for structured data, full of curly brackets and quoted names). An endpoint is one of those addresses.

The researcher immediately ran ffuf with some common path traversal payloads:

Text
/experience/..;/
/experience/../
/experience/..%2f
/experience/%2e%2e%2f

Line by line:

  • /experience/..;/ uses .. to try to go up one directory, followed by a semicolon. Some servers treat the semicolon as a separator and ignore what comes after it, so the rule may see a different path from the one the backend resolves.
  • /experience/../ is the plainest form of traversal: go up one directory.
  • /experience/..%2f is the same idea, but the slash is written as %2f, its URL-encoded form. A proxy may not decode it before applying its rules, while the backend does.
  • /experience/%2e%2e%2f encodes the dots too: %2e is a dot. This is a fully encoded version of ../.

These are only a few out of the many payloads in the list actually used. The point was to look for small differences in the responses, not just at the status codes.

Step 3: Reading the responses

A status code is the three-digit number a web server sends back with every response. You have probably seen 404 (not found) and 403 (forbidden). All of the payloads returned 403 except one:

Text
/experience/..%2f

That one returned a 404. Why does that matter? A 403 means the proxy's rule recognised the request and refused it. A 404 means the request got past the rule and reached something that did not have that exact page. So a 404 instead of a 403 is a strong hint that the request may be reaching the internal root of the API.

Step 4: Going one directory further back

To test the idea further, the researcher went back one more directory:

Text
/experience/..%2f..%2f

This returned a 400 Bad Request. A 400 means the server could not understand the request at all. That is a different reaction again, and it is useful information.

The screenshot shows the Nginx 400 Bad Request response.

At this point the researcher knew it was an Nginx reverse proxy, because the 400 response leaked the server type. Leaked means the error page revealed information it should not have. What was needed now was a path that returned a valid 200 OK, the code for "here is your page".

So the researcher ran content discovery against the traversed path, the same one that had produced the 404 in step 3, using a placeholder for the discovered name:

Text
/experience/..%2fHERE

Content discovery means trying a list of common file and folder names to see which ones exist. HERE is just a stand-in for whatever name the scan finds. The scan results contained a path /api and a file dashboard.html, both returning 200 OK with different responses.

Step 5: Confirming the hit is internal

Navigating to the discovered file through the traversal:

Text
/experience/..%2fdashboard.html

revealed an NGINX Plus API. NGINX Plus is the commercial version of Nginx, and it has a feature called Live Activity Monitoring, which the report links to as the description of what was found. That feature exposes a dashboard and an API showing what the server is doing right now: connections, requests, upstream servers and so on.

To be sure the hit was internal and not simply a file sitting in the public web root, the researcher checked whether dashboard.html and /api were reachable directly:

Both returned 403. That is the confirmation: the same names are forbidden when asked for directly, but reachable when asked for through the traversal. So the traversal really is reaching something the public web root does not expose.

Step 6: Listing the API

There was not much on dashboard.html, so the researcher looked at the /api path found through the traversal. It contained a set of numbers in JSON. Cross-referencing the NGINX API documentation (http://nginx.org/en/docs/http/ngx_http_api_module.html#example) showed that these numbers are different versions of the API. Navigating to one of the versions exposed a set of paths, all reached through the same traversal prefix:

Text
/experience/..%2f/api/7/
/experience/..%2f/api/7/nginx
/experience/..%2f/api/7/connections
/experience/..%2f/api/7/http/requests
/experience/..%2f/api/7/http/server_zones/server_backend
/experience/..%2f/api/7/http/caches/cache_backend
/experience/..%2f/api/7/http/upstreams/backend
/experience/..%2f/api/7/http/upstreams/backend/servers/
/experience/..%2f/api/7/http/upstreams/backend/servers/1
/experience/..%2f/api/7/http/keyvals/one?key=arg1
/experience/..%2f/api/7/stream/
/experience/..%2f/api/7/stream/server_zones/server_backend
/experience/..%2f/api/7/stream/upstreams/
/experience/..%2f/api/7/stream/upstreams/backend
/experience/..%2f/api/7/stream/upstreams/backend/servers/1

What these paths mean, in plain words:

  • /api/7/ is the root of version 7 of the API.
  • /api/7/nginx gives general information about the Nginx instance.
  • /api/7/connections reports on connections.
  • /api/7/http/requests reports on HTTP requests.
  • /api/7/http/server_zones/server_backend reports on a group of servers called server_backend.
  • /api/7/http/caches/cache_backend reports on a cache called cache_backend.
  • /api/7/http/upstreams/backend reports on an upstream called backend. An upstream is the group of internal servers that the proxy forwards traffic to.
  • /api/7/http/upstreams/backend/servers/ and .../servers/1 list the individual servers in that upstream.
  • /api/7/http/keyvals/one?key=arg1 reads a key-value store, a simple table of names and values; ?key=arg1 is a query parameter, the part of a URL after the question mark that passes extra information.
  • The /api/7/stream/... paths do the same for stream (non-HTTP) traffic.

At this point the researcher had a P3. Bug bounty programs rank findings by severity, and P3 is a medium-level rating. The researcher wanted to escalate it to a P1, the highest level.

Exploitation

Step 1: Looking for write access

After a conversation with colleagues on Slack, the idea came up to try writing to the API. Reading data is one thing; changing it is much more serious. The API documentation lists many POST and GET verbs for some of the paths. A verb (or method) is the word at the start of a request that says what you want to do: GET means "give me this", POST usually means "create or change this". But the documentation also says that writing to the API is disabled by default. The researcher nearly gave up at this point.

A stock photo used to illustrate the moment of doubt.

Step 2: Trying the parameters anyway

The researcher played with the different parameters, assuming the API would not allow writes. Instead the request returned 204. A 204 means "no content": the server accepted the request and did what it was asked, but has nothing to send back. In other words, the write had actually worked. An upstream was created and written to the API. That escalated the finding to a P1, and it was triaged within an hour. Triaged means the program's staff reviewed the report and accepted it as valid.

Step 3: Final proof of concept

The final proof of concept (a demonstration that the bug really works) is shown in the report as a screenshot.

The screenshot shows the final proof of concept request.

And the response it produced:

The screenshot shows the response to the proof of concept.

The report does not reproduce the request or response bodies in text, so the exact method, path, body and headers of the write are not stated here.

Why it worked

The weak point is the proxy's parser logic and the regular expressions used to decide which requests are allowed. The report attributes the bug to bad parser logic and bad regular expressions but does not describe the exact mechanism. Normalisation is the process of turning a messy path into its clean, standard form, so that a/../b becomes b. The rule sees a path under /experience/, while the backend resolves it to the API root. The direct root paths /dashboard.html and /api both returned 403, confirming the traversal reached something the web root did not expose. The 400 on the double traversal leaked the server type, which identified Nginx as the reverse proxy.

The second half of the cause is on the API side: writing to the NGINX Plus API is documented as disabled by default, yet the write succeeded.

Impact

As stated in the report, malicious agents can re-route traffic to their own server and cause disruption to internal services. The internal NGINX Plus API was reachable through the proxy and an upstream could be created through it, which would allow traffic to be re-routed to an attacker's server. The impact depends on the proxy being reachable and on the API accepting writes, which the report shows was the case here.

Fix

Variants to test

  1. Encoded traversal with a semicolon: /experience/..;/. A positive result is a status code that differs from the 403 returned for ordinary paths, for example a 404 or 200.
  2. Plain traversal: /experience/../. Same signal: a status that differs from the baseline 403.
  3. Encoded slash traversal: /experience/..%2f. Here it returned 404, indicating the internal root was reachable.
  4. Fully encoded dots and slash: /experience/%2e%2e%2f. Same signal as above.
  5. Double traversal: /experience/..%2f..%2f. Here it returned 400, which leaked the server type; a 400 or a different error page is worth noting.
  6. Traversal plus a discovered name: /experience/..%2fHERE. A 200 OK for a name that is 403 at the web root confirms an internal hit.
  7. Compare the traversed path with the direct path, for example /dashboard.html and /api at the root. A 403 at the root and a 200 through the traversal is the confirmation step.
  8. Enumerate API versions and endpoints through the traversal, such as /experience/..%2f/api/7/http/upstreams/backend. A JSON response listing upstreams or servers is a positive result.
  9. Try write verbs on endpoints that document POST, even where writes are documented as disabled by default. A 204 response indicates the write succeeded.

Glossary

  • API: a way for one piece of software to talk to another, usually by sending requests to specific addresses and receiving data back.
  • API endpoint: one specific address in an API that you can send a request to.
  • Bug bounty program: a scheme where a company pays researchers to find and report weaknesses in its systems.
  • Content discovery: trying a list of common file and folder names to see which ones exist on a server.
  • DevTools: the developer tools built into browsers such as Chrome, including a Network tab that lists every request a page makes.
  • Encoded: written in a form the URL standard allows, for example %2f for / and %2e for ..
  • Endpoint: a specific address that accepts requests.
  • ffuf: a tool that sends many automatically generated requests to a target, used here for fuzzing.
  • Fuzzing: sending many automatically generated inputs to a system to see how it reacts.
  • GET: a request method meaning "give me this".
  • JSON: a text format for structured data, made of curly brackets, quoted names and values.
  • Leaked: revealed information that was not meant to be public, such as the server type in an error page.
  • Normalisation: turning a messy path into its clean, standard form, so that a/../b becomes b.
  • NGINX Plus: the commercial version of the Nginx web server and reverse proxy, which includes a Live Activity Monitoring feature.
  • Parser logic: the part of a program that reads a request and works out what it means.
  • Path traversal: using special sequences in a URL, such as .., to climb out of the folder you are supposed to be in.
  • Payload: the piece of text you put in a request to try to trigger a bug.
  • PII: personally identifiable information, such as names and addresses.
  • POST: a request method usually meaning "create or change this".
  • Proof of concept: a demonstration that a bug really works.
  • Query parameter: the part of a URL after the question mark that passes extra information, such as ?key=arg1.
  • Reconnaissance: the information-gathering phase at the start of a security test.
  • Regular expression: a pattern used to match text.
  • Reverse proxy: a server that sits between the public web and internal servers, checking requests and forwarding them to the right place.
  • Secondary context path traversal: a path traversal trick that works in a second layer, such as the proxy, rather than in the application itself.
  • Status code: the three-digit number a web server sends back with every response, such as 200, 204, 400, 403 or 404.
  • Triaged: reviewed by the bug bounty program's staff and accepted as valid.
  • Upstream: the group of internal servers that a reverse proxy forwards traffic to.
  • XHR: XMLHttpRequest, a way for a page to fetch data in the background without reloading; the Fetch/XHR filter in DevTools groups those requests.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.