Skip to content
XSS Write-up Intermediate

Bypassing Naxsi filtering engine

Naxsi, an nginx WAF module, failed to properly handle null bytes in JSON and multipart request bodies, allowing an attacker to bypass its filtering rules and deliver XSS payloads to a protected application. The flaws were in the JSON parser and multipart parser, which did not reject or correctly process null bytes, causing the pattern-matching engine to stop early and miss malicious content.

synacktiv.com

Published on synacktiv.com

Rédigé par Corentin Bayet, Mehdi Talbi - 05/11/2020 - dans Exploit - Téléchargement

The author, on synacktiv.com

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.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the JSON and multipart parsers did not reject or properly handle null bytes, and the string search function stopped at the first null byte, so filtering rules were not applied to data after it.

Impact

An attacker could bypass Naxsi's filtering rules and deliver XSS payloads to a protected web application, undermining the WAF's main purpose.

What the attacker needed

Naxsi WAF protecting a web application; Ability to send crafted HTTP requests

The fix

The vulnerabilities were fixed in version 1.1a by adding a call to naxsi_escape_nullbytes at the start of ngx_http_basestr_ruleset_n and by replacing ngx_strstr with sstrfaststr, which does not stop on null bytes, and adding a boundary check.

How it was found

  1. Send a JSON POST request with an XSS payload to confirm Naxsi blocks it.
  2. Insert a null byte before the XSS payload in the JSON value.
  3. Observe that the request is passed to the web application despite the payload.
  4. Send a multipart/form-data POST request with an XSS payload to confirm Naxsi blocks it.
  5. Insert a null byte (or the string "\r\n--") after the payload in the multipart body.
  6. Observe that the request is not blocked and the XSS is exploited.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A web application firewall (WAF) inspects incoming requests to block attacks like cross-site scripting (XSS). Naxsi is a WAF for the nginx web server. The researchers found that by inserting a special character called a null byte into certain request formats, they could make Naxsi stop checking the rest of the input, so malicious code slipped through and reached the web application.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.