Blog | G5 Cyber Security

WAF Bypass: Injection Attacks Still Possible

TL;DR

Yes, a website behind a Web Application Firewall (WAF) can still be vulnerable to injection attacks. WAFs aren’t perfect and attackers constantly find ways around them. Proper coding practices are essential even with a WAF in place.

Why WAFs Aren’t Enough

A WAF acts as a shield, examining incoming web traffic for malicious patterns (like SQL injection or cross-site scripting). However, it’s not foolproof. Here’s why:

How Injection Attacks Can Still Succeed

Here are some common ways attackers bypass WAF protection:

1. Obfuscation & Encoding

  1. Character Encoding: Attackers use different character encodings (e.g., URL encoding, Unicode) to disguise malicious payloads.
  2. Case Manipulation: Changing the case of keywords (e.g., SELECT vs. select) can sometimes bypass rules.
  3. Whitespace & Comments: Adding extra spaces or comments within the payload can confuse the WAF.
// Example SQL Injection with whitespace obfuscation
SELECT * FROM users WHERE username = 'admin' ;-- 

2. Payload Fragmentation

Splitting a malicious payload into multiple requests can bypass WAFs that analyze traffic on a per-request basis.

  1. Multiple Requests: Send parts of the injection across several HTTP requests.

3. Exploiting Application Logic

WAFs struggle with attacks targeting flaws in the application’s code, not just malicious syntax.

  1. Second-Order Injection: Injecting data that is stored and later executed without proper sanitization.
  2. Blind SQL Injection: Inferring data by observing the application’s behaviour (e.g., response times).

4. HTTP Parameter Pollution

Sending multiple parameters with the same name can sometimes cause the WAF to misinterpret the request.

// Example:  http://example.com/page?param=value1&param=malicious%20payload

5. Resource-Based Injection

  1. File Uploads: Injecting malicious code into uploaded files (e.g., PHP, JavaScript).
  2. XML External Entity (XXE) Attacks: Exploiting vulnerabilities in XML parsing to access internal resources or execute arbitrary code.

Protecting Your Website – Beyond the WAF

Here’s how to strengthen your website’s security:

  1. Input Validation: Sanitize all user input before processing it. Use whitelisting (allowing only known good characters) instead of blacklisting (blocking known bad characters).
  2. Parameterized Queries/Prepared Statements: Prevent SQL injection by using parameterized queries or prepared statements in your database interactions. This separates the data from the query structure.
  3. Output Encoding: Encode output to prevent cross-site scripting (XSS) attacks.
  4. Least Privilege Principle: Grant only necessary permissions to database users and application components.
  5. Regular Security Audits & Penetration Testing: Identify vulnerabilities before attackers do.
  6. Keep Software Updated: Patch known security flaws in your web server, framework, and libraries.

Remember, a WAF is a valuable tool but it’s just one layer of defence. A strong security posture requires a multi-layered approach with secure coding practices at its core.

Exit mobile version