☼
⌃
☰

Web Application Firewall

Table of Contents

A Web Application Firewall (WAF) is a specific type of firewall that acts as a shield for web applications. As noted in Web Security, it is positioned in front of a web application to filter and monitor HTTP/HTTPS traffic between the application and the internet. Its primary purpose is to protect against web-based attacks that traditional network firewalls are not equipped to handle.

Related: Web Security OWASP pfSense Snort Suricata ffuf Nikto

How a WAF Works

Unlike a traditional firewall that typically operates at the network (Layer 3) and transport (Layer 4) layers of the OSI Model, a WAF operates at the application layer (Layer 7). This allows it to inspect the actual content of HTTP/HTTPS requests and responses, giving it a deep understanding of web traffic and enabling it to identify and block malicious payloads, code injections, and other application-specific threats.

WAFs generally employ two main detection models:

  1. Negative Security Model (Blocklist): This model uses predefined signatures to block known attacks. It's effective against common vulnerabilities but requires constant updates to keep up with new threats and may miss zero-day attacks.
  2. Positive Security Model (Allowlist): This model defines what traffic is explicitly allowed and blocks everything else. It is very effective but can be more complex to configure, as it requires a thorough understanding of the application's normal behavior.

Core Protections

A WAF is a critical component in defending against common web application attacks, many of which are outlined in the Web Security note and the OWASP Top 10. Key protections include:

  • Injection Attacks: Prevents attacks like SQL Injection by inspecting request parameters for malicious SQL code.
  • Cross-Site Scripting (XSS): Filters and sanitizes user inputs and outputs to block the injection of malicious scripts that would otherwise execute in a user's browser.
  • Cross-Site Request Forgery (CSRF): Can help mitigate CSRF by inspecting requests for valid anti-CSRF tokens.
  • Denial of Service (DoS): Provides protection against application-layer DoS attacks by implementing rate limiting and blocking traffic from malicious sources.

WAF vs. Other Security Tools

  • WAF vs. Traditional Firewall (pfSense): A traditional firewall like pfSense controls access based on IP addresses and ports. It doesn't understand the HTTP protocol and cannot see the malicious payload within an allowed request. A WAF inspects the content of the web traffic itself.
  • WAF vs. IDS/IPS (Snort, Suricata): Intrusion Detection and Prevention Systems like Snort and Suricata monitor the entire network for a broad range of threats. While they can detect some web attacks, a WAF is specialized for web application protocols and provides more granular control and deeper inspection of HTTP/HTTPS traffic. They often work together in a layered security approach.

Types of WAFs

WAFs can be deployed in several ways:

  • Network-based WAF: A hardware appliance installed on the local network, offering high performance but at a significant cost.
  • Host-based WAF: Integrated directly into the web server's software. It offers deep customization but consumes server resources.
  • Cloud-based WAF: A service offered by a third-party provider. This model is easy to set up, affordable, and always up-to-date with the latest threat intelligence. Examples include services from Cloudflare, AWS WAF, and Akamai.

Detecting a WAF (Pentest-Relevant)

Before attempting bypass techniques, confirm a WAF is actually present and identify which one:

SHELL
# wafw00f — dedicated WAF fingerprinting tool
wafw00f https://target.com

# Manual indicators worth checking:
# - Unusual response headers (X-Sucuri-ID, Server: cloudflare, etc.)
# - A generic "Request Blocked" page for obviously malicious payloads
# - Consistent, suspiciously fast 403s on payloads that should reach
#   the application at all

Bypass Techniques (Pentest-Relevant)

WAFs rely on pattern matching, which creates predictable gaps:

  • Encoding/Obfuscation: URL encoding, double encoding, case variation, or alternate syntax for the same payload can slip past a signature written for the literal/common form — e.g. %53%45%4C%45%43%54 instead of SELECT, or mixed-case SeLeCt
  • Comment Injection: Inserting SQL/JS comments mid-payload to break up a recognizable signature while preserving the parsed meaning: SEL/**/ECT in SQL contexts
  • HTTP Parameter Pollution: Sending the same parameter multiple times — some WAFs and backends parse this differently, and a WAF checking only the first instance can be bypassed by putting the payload in a later duplicate
  • Alternate Request Methods/Encoding: Switching between GET/POST, or using multipart form encoding instead of standard URL encoding, since WAF rule coverage is sometimes inconsistent across formats
  • Fragmentation: Splitting a payload across multiple parameters or request stages where a single-request signature can't correlate them together

None of this is a substitute for testing — always confirm whether a bypass actually worked by checking if the payload had its intended effect on the application, not just whether the WAF failed to return a block page.

Tips

  • On the exam, a WAF blocking your initial payload isn't a dead end — it's a signal to try encoding variations before assuming the underlying vulnerability doesn't exist
  • ffuf and Nikto scans can trigger aggressive WAF rate-limiting or IP blocks quickly — if a scan that should work suddenly starts returning uniform errors partway through, check whether you've been blocked before assuming a tool or target issue
  • Confirming WAF presence early (via wafw00f or response header inspection) saves time — it tells you upfront whether unusual blocking behavior later is expected (WAF interference) or a sign something else is wrong