Bypassing Character Filters

πŸ”€ Character Crafting: Advanced techniques for generating blacklisted characters using environment variables and character manipulation

Overview

Beyond injection operators and space characters, many other characters are commonly blacklisted in command injection filters. The most frequently blocked characters include:

  • Forward slash (/) - Essential for Linux/Unix directory paths

  • Backslash (\) - Required for Windows directory paths

  • Semicolon (;) - Common command separator

  • Special characters - Various symbols used in advanced payloads

This section demonstrates sophisticated techniques to generate any required character while avoiding direct use of blacklisted characters.

Focus: Creative character generation methods for comprehensive filter bypass.


Linux Environment Variable Extraction

Understanding Environment Variables

Concept: Linux environment variables contain various characters that can be extracted using substring operations.

Syntax: ${VARIABLE:start:length}

  • start - Starting position (0-indexed)

  • length - Number of characters to extract

Extracting Forward Slash (/)

Using $PATH Variable:

Analysis:

  • ${PATH} starts with /usr/local/bin...

  • ${PATH:0:1} extracts position 0, length 1 = /

Web Application Usage:

Alternative Environment Variables:

Extracting Semicolon (;)

Using $LS_COLORS Variable:

Understanding the Extraction:

Web Application Usage:

Environment Variable Discovery

Finding Useful Variables:

Common Variables with Useful Characters:

Variable Syntax Alternatives

Different Environment Variable Formats:

Web Application Usage Variations:

Advantages of Each Syntax:

Explicit ${VAR} Syntax:

  • βœ… Clear boundaries - Prevents variable name confusion

  • βœ… Safer parsing - Bash interprets correctly in complex contexts

  • βœ… Substring support - Required for ${VAR:start:length}

  • βœ… Best practice - Recommended in professional scripts

Short $VAR Syntax:

  • βœ… Compact - Shorter payloads

  • βœ… Less encoding - Fewer special characters to URL encode

  • βœ… Faster typing - Quick manual testing

  • ❌ Ambiguous boundaries - Can cause parsing issues in complex strings

URL Encoding Comparison

Encoding Length Differences:

Practical Payload Size Impact:

Advanced Character Extraction

Extracting Multiple Characters:

Dynamic Position Calculation:


Windows Character Extraction

Windows Command Line (CMD)

Understanding Windows Substring Syntax: %VARIABLE:~start,length% or %VARIABLE:~start,end%

Extracting Backslash ():

Breaking Down the Extraction:

Alternative Windows Variables:

Windows PowerShell

Array-Based Character Access:

Environment Variable Discovery:

Complex Character Extraction:


Character Shifting Techniques

Linux Character Shifting

Understanding ASCII Shifting:

  • Each character has an ASCII value

  • We can shift characters by 1 position to get adjacent characters

  • Useful when the exact character is blocked but adjacent ones aren't

Basic Shifting Command:

How It Works:

Finding Characters for Shifting:

Practical ASCII Reference

Common Characters and Their Predecessors:

Web Application Usage:

Windows Character Shifting

PowerShell Shifting:

CMD Character Arithmetic:


HTB Academy Lab Solution

Challenge Requirements

Task: Find the name of the user in the '/home' folder.

Constraints:

  • Forward slash (/) likely blacklisted

  • Need to execute ls /home or similar command

  • Must use character bypass techniques

Solution Approaches

Method 1: Environment Variable for Slash

Method 2: Brace Expansion + Environment Variable

Method 3: IFS + Environment Variable

Method 4: Character Shifting for Slash

Method 5: Short Syntax Alternative

Expected Output Analysis

Command Execution:

Alternative Possible Usernames:

  • htb-student

  • ubuntu

  • user

  • kali

  • pentester

Answer: Based on typical HTB Academy naming: htb-student


Advanced Character Generation

Comprehensive Character Mapping

Environment Variable Character Sources:

Multi-Character Generation

Building Complex Strings:

Variable Concatenation:

Platform-Agnostic Approaches

Cross-Platform Character Generation:


Detection Evasion Strategies

Randomizing Character Sources

Varying Environment Variables:

Dynamic Position Selection:

Obfuscation Techniques

Multi-Layer Character Generation:

Payload Fragmentation:


Comprehensive Testing Methodology

Character Discovery Process

Step 1: Environment Enumeration

Step 2: Position Mapping

Step 3: Extraction Testing

Step 4: Web Application Testing

Payload Development Template

Progressive Character Bypass:

This comprehensive guide to character filter bypasses enables sophisticated payload construction while evading detection, ensuring successful command injection even when multiple character classes are blacklisted.

Last updated