Blog | G5 Cyber Security

Bypassing Input Filters

TL;DR

Input filters block characters that could cause problems (like website hacking). This guide shows common ways attackers get around these filters, and how to protect against them. It’s aimed at anyone managing web applications or security.

Understanding Metacharacter Filtering

Metacharacters are special symbols with extra meaning (e.g., <, >, "). Filters try to remove or escape these characters to prevent attacks like cross-site scripting (XSS) and SQL injection.

Bypass Techniques

  1. Character Encoding:
  • Case Variation: Some filters only check for lowercase metacharacters. Try uppercase versions (e.g., &LT;).
  • Double Encoding: Encode the character multiple times. The filter might decode it once, leaving a still-encoded character that bypasses further checks. For example, encoding < as %26lt;.
  • Using Alternative Syntax:
  • Whitespace and Comments:
  • Contextual Bypass: The effectiveness of a bypass depends on where the input is used.
  • Example: Bypassing a Simple HTML Tag Filter

    Let’s say the filter blocks <script>.

    Input: <script>alert('XSS')</script>  (Blocked)
    Bypass 1 (HTML Entities): &lt;script&gt;alert('XSS')&lt;/script&gt; (May work)
    Bypass 2 (Case Variation): &LT;Script&GT;alert('XSS')&LT;/Script&GT; (May work if case-insensitive filtering isn't used)

    Protecting Against Bypasses

    1. Input Validation:
  • Output Encoding/Escaping: Encode all user input before displaying it on the page, based on the context where it’s used (HTML, JavaScript, URL, etc.). This prevents malicious code from being executed even if the filter is bypassed. Use a well-tested library for encoding.
  • Content Security Policy (CSP): A powerful security mechanism that tells the browser which sources of content are allowed to load. It can significantly reduce the risk of XSS attacks.
  • Regular Updates: Keep your filtering libraries and frameworks up to date to benefit from the latest security patches.
  • Security Audits & Penetration Testing: Regularly test your application for vulnerabilities, including input filter bypasses.
  • Exit mobile version