In this blog, I will simulate a DDoS attack where attackers exploit the misconfiguration of the X-Forwarded-For HTTP header by load balancers. This vulnerability can allow malicious users to spoof their IP address, bypass rate limiting, pollute logs and denial of service (DoS) through resource exhaustion.

In this lab, we'll:

  • Understand how X-Forwarded-For is used and configured in loadbalancers
  • Explore the vulnerability when its misconfigured.
  • Simulate an attack using Gobuster
  • Little by little, we will explore and analyze the remediation steps
  • Analyze logs and network behavior using wireshark.

Note: In part 2, I'll use AWS Application Load Balancer and WAF and simulate the attack again.


Types of Load Balancers Using X-Forwarded-For

  • Nginx (open-source reverse proxy)
  • Citrix Netscaler / ADC
  • AWS ALB / Cloudfront
  • HAProxy
  • F5 BIG-IP
  • Apache HTTP Server (mod_proxy)

These systems use X-Forwarded-For to pass along the client IP when acting as a proxy.


Use Cases of X-Forwarded-For

  • Network engineers and DevOps teams: for logging the source IP
  • Web application developers: for applying rate limiting per user
  • Security teams: for geolocation, threat intelligence, and abuse detection

XFF is used to determine the original client IP address when a server is behind a proxy or load balancer. This is useful for logging, tracking, and even for security measures like geo-blocking. 

Use Case Example:

When a request passes through multiple proxies, each proxy appends its IP address to the existing XFF header, creating a chain of IP addresses. This can be helpful for logging and analytics, but it also poses security risks

Example:

X-Forwarded-For: 192.0.2.5, 10.0.0.4
  • 10.0.0.4 = original client IP (set first)
  • 192.0.2.5 = proxy or load balancer IP appended after

What can go Wrong if Misconfigured?

If the load balancer appends the real client IP instead of overwriting a spoofed header:

┌────────────┐
│  Attacker  │
└────┬───────┘
     │  (spoofed IP: 1.2.3.4 (attacker is pretending to be this IP — could even be a backend/internal IP like the app server))
     │  real IP: 203.0.113.99 (this is the actual IP of the attacker, but ignored due to the spoofed IP being placed first)
     │  X-Forwarded-For: 1.2.3.4
     ▼
┌────────────────────────────┐
│ Load Balancer (Append Mode)│
└────┬───────────────────────┘
     │  Appends real IP:
     │  X-Forwarded-For: 1.2.3.4, 203.0.113.99
     ▼
┌────────────┐
│  Web App   │
└────┬───────┘
     │ Logs IP: 1.2.3.4 (spoofed)
     │ Rate limit fails

 

Step 1: The Application is Behind a Load Balancer

The App is using NGINX/load balancer to forward traffix to the backend

Step 2: Load Balancer Uses Default Behavior

The load balancer appends the real source IP to the X-Forwarded-For header instead of overwriting it:

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  # Vulnerable default

Step 3: Attacker Sends a Spoofed IP

The attacker includes a forged IP in the X-Forwarded-For header:

X-Forwarded-For: 1.2.3.4

Step 4: Load Balancer Appends Real IP

X-Forwarded-For: 1.2.3.4, 203.0.113.99

Step 5: Application Trusts the First IP

Most backends use only the first IP in X-Forwarded-For:

req.headers['x-forwarded-for'].split(',')[0]  # Attacker-controlled

So the attacker successfully pretends to be a different user, often bypassing:

  • Rate limiting
  • IP-based access controls
  • Security logging

Step 6: Attack Escalates

The attacker sends:

  • Thousands of requests with rotating spoofed IPs
  • Each one looks like a new user
  • The backend fails to block or rate limit
  • CPU spikes and logs are polluted

Simulation of the Attack

 I will attack a vulnerable application running in Docker under nginx.

  1. While simulating a directory brute-force attack using Gobuster on react.piconeuron.com, I observed a significant spike in system resource usage.

    The command below was used to bypass the rate limiting of WAF/Nginx by using a for loop bash script, changing the last octet of the  IP Address (192.168.1.1 - 192.168.1.100)

    for i in $(seq 1 100); do
      gobuster dir -u https://react.piconeuron.com/ \
        -w /usr/share/wordlists/dirbuster/directory-list-2.3-small.txt \
        -k \
        -t 200 \
        -H "User-Agent: gobuster/3.4" \
        -H "X-Forwarded-For: 192.168.0.$i" \
        --status-codes-blacklist 400
  2. As seen below, the CPU Utilization is high

    • Load Average is Spiking

      load average: 3.03, 2.81, 2.09

      • These are the 1, 5, and 15-minute averages of processes waiting for CPU.
      • Currently, I am using 1 vCPU. Given the result above, then

        3.03 means 3x more processes than the CPU can handle right now

        Values above 1.00 indicate CPU saturation

    • CPU Utlization breakdown

      %Cpu(s): 60.9 us, 25.8 sy, 12.4 si, 0.3 st

      60.9 user - User space - the node app is using the majority of CPU

      25.8 sy - System (kernel) - NGINX, Docker, and kernel I/O

      12.4 si - Software interrupts - due to network I/O flood from Gobuster

    • Top Offending Proccesses

      4864 - Command: node - %CPU: 53.8% - The backend node.js app is under extreme load

      4809 - Command: docker-proxy - %CPU: 27.1% - Docker bridge handling go buster flood

      5583 - Command: nginx - %CPU: 7.1% - NGINX reverse proxy taing the hit and passing it to the backend

  3. As seen in AWS Cloudwatch, the CPU usage spiked to near 100%, and network traffic surged. The sudden increased in CPU and network usage indicated that there is an anomaly going on (which is the gobuster attack).

  4. When checking with curl, the website took a long time to respond and eventually timed out due to high CPU utilization. The site also became unreachable during this period (see images below).

    ┌──(gracez㉿kaligrace)-[~]
    └─$ curl -o /dev/null -s -w "\nStatus: %{http_code}\nConnect: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n" \
    -H "X-Forwarded-For: 123.123.123.123" \
    -H "User-Agent: curl-test" \
    https://react.piconeuron.com      
    
    
    Status: 000
    Connect: 0.000000s
    TTFB: 0.000000s
    Total: 143.458642s
  5. As also seen in nginx log, there are a lot of request with http status of 400. Indicating the possibility of an attack.

    Using the awk filter command below, I filter those malicious traffics.

    awk '$0 ~ /\[29\/May/ && $0 ~ /gobuster/ && $9 == 400' /var/log/nginx/access.log.1 | tail -n 20

Current NGINX configuration for https://react.piconeuron.com

server {
    listen 80;
    server_name react.piconeuron.com;

    # Redirect all HTTP traffic to HTTPS
    return 301 https://$host$request_uri;
}


server {
    listen 443 ssl;
    server_name react.piconeuron.com;

    ssl_certificate /etc/letsencrypt/live/react.piconeuron.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/react.piconeuron.com/privkey.pem;


location / {
    proxy_pass http://localhost:8000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto https;
    proxy_cache_bypass $http_upgrade;

Experiment number 1:

  1. Adding a rate limiter in nginx configuration can stop an attacker.

    1. Initial load

    2. Initiating attack