Bypassing Space Filters

πŸš«βž‘οΈβœ… Space Evasion: Comprehensive techniques for bypassing space character filters in command injection attacks

Overview

Space characters are commonly blacklisted in input validation filters, especially when the expected input shouldn't contain spaces (like IP addresses). However, there are numerous methods to achieve command separation and argument passing without using actual space characters.

This section demonstrates multiple space bypass techniques using Linux as the primary example, with Windows compatibility notes where applicable.

Focus: Practical space filter evasion methods with hands-on exploitation examples.


Bypass Blacklisted Operators

Confirming Newline Works

From our filter identification phase, we discovered that the newline character (\n / %0a) is not blacklisted while other operators are blocked.

Verification Test:

# Test newline operator
ip=127.0.0.1%0a

# Expected result: Normal ping output (βœ… Not blocked)
# Confirms newline can be used as injection operator

Response Analysis:

Key Finding: Newline character works as injection operator on both Linux and Windows platforms.


Space Filter Detection

Testing Space Character

Attempted Payload:

Response:

Isolated Space Test:

Result: Invalid input - Confirms space character (%20) is blacklisted.

Understanding Space Filter Logic

Common PHP Implementation:

Why Spaces Are Filtered:

  • Input validation - Expected inputs (IP addresses) shouldn't contain spaces

  • Command prevention - Spaces enable argument separation in commands

  • Security measure - Reduces attack surface for command injection


Space Bypass Techniques

Method 1: Tab Characters

Technique: Replace spaces with tab characters (\t / %09)

Why It Works:

  • Both Linux and Windows accept tabs between command arguments

  • Commands execute identically with tabs as with spaces

  • Tab character often not included in blacklists

Implementation:

Expected Response:

Verification: βœ… Successfully bypassed space filter using tab character.

Method 2: Environment Variables ($IFS)

Technique: Use Linux Internal Field Separator environment variable

Understanding $IFS:

  • Default value contains space and tab characters

  • Automatic expansion replaces ${IFS} with its value

  • Universal availability on Unix/Linux systems

Local Testing:

Web Application Implementation:

Expected Response:

Verification: βœ… Successfully bypassed space filter using ${IFS}.

Method 3: Bash Brace Expansion

Technique: Use Bash brace expansion feature for automatic spacing

Understanding Brace Expansion:

  • Automatic separation - Bash adds spaces between comma-separated values

  • No explicit spaces - Command contains no space characters

  • Argument processing - Each element becomes separate argument

Local Testing:

Web Application Implementation:

Multi-Argument Example:


Additional Space Bypass Methods

Method 4: Redirection Operators

Technique: Use input/output redirection for spacing

Method 5: Variable Assignment

Technique: Assign commands to variables without spaces

Method 6: Base64 Encoding

Technique: Encode entire command to avoid problematic characters

Method 7: Hex Encoding

Technique: Use hex encoding with printf

Method 8: Alternative Separators

Extended Whitespace Characters:

Testing Extended Characters:


HTB Academy Lab Solution

Challenge Requirements

Task: Execute the command ls -la and find the size of index.php file.

Known Constraints:

  • Newline (\n/%0a) injection operator works

  • Space characters are blacklisted

  • Need to bypass space in ls -la

Solution Approaches

Method 1: Tab Character Bypass

Method 2: IFS Variable Bypass

Method 3: Brace Expansion Bypass

Expected Output Analysis

Command Output:

File Size Identification:

  • index.php: 1613 bytes

  • style.css: 842 bytes

Answer: 1613


Advanced Bypass Combinations

Multi-Method Combinations

Combining Techniques:

Platform-Specific Methods

Linux-Specific:

Windows CMD:

Windows PowerShell:


Systematic Testing Methodology

Step-by-Step Approach

Phase 1: Confirm Working Injection

Phase 2: Test Space Alternatives

Phase 3: Execute Target Command

Phase 4: Parse Results

Payload Development Template

Progressive Complexity:


Comprehensive Reference Table

Space Bypass Methods Comparison

Method

Syntax

URL Encoded

Platform

Reliability

Tab

\t

%09

Universal

High

IFS Variable

${IFS}

%24%7bIFS%7d

Unix/Linux

High

Brace Expansion

{cmd,arg}

%7bcmd,arg%7d

Bash

Medium

Vertical Tab

\v

%0b

Universal

Medium

Form Feed

\f

%0c

Universal

Low

Base64

echo X|base64 -d|sh

Complex

Unix/Linux

Medium

Hex Encoding

printf "cmd\x20arg"

Complex

Unix/Linux

Medium

Redirection

cat<file

cat%3cfile

Unix/Linux

High

Selection Strategy

Primary Methods (High Success Rate):

  1. Tab character (%09) - Universal compatibility

  2. IFS variable (${IFS}) - Reliable on Unix/Linux

  3. Brace expansion ({cmd,arg}) - Clean syntax

Fallback Methods:

  1. Extended whitespace (%0b, %0c) - When primary blocked

  2. Encoding methods - When characters are heavily filtered

  3. Platform-specific - When environment is known


Detection Evasion Tips

Stealth Considerations

Avoid Common Patterns:

  • Don't always use the same bypass method

  • Vary payload structure between requests

  • Mix different techniques in single payload

Blend with Normal Traffic:

  • Use realistic command arguments

  • Avoid obviously malicious commands

  • Time requests to appear natural

Error Handling:

Payload Obfuscation

Multi-Layer Encoding:

This comprehensive guide to space filter bypasses provides multiple reliable methods for maintaining command injection capabilities even when space characters are blacklisted, ensuring successful exploitation across various filtering scenarios.

Last updated