OS Command Injection

OS Command Injection Reference

Overview

OS Command Injection allows attackers to execute arbitrary operating system commands on a server by injecting malicious input into system commands.

CWE: CWE-78, CWE-88

Common Attack Vectors

Command Separators

  • Unix/Linux: &, &&, |, ||, ;, \n, backticks, $()

  • Windows: &, &&, |, ||, cmd /c

Context Breakouts

  • Quote escape: " or ' followed by separators

  • Parameter injection: Additional arguments to existing commands

Testing Payloads

Basic Detection

Blind Injection

Testing Methodology

1. Parameter Identification

2. Injection Testing

3. System Enumeration

Vulnerable Code Patterns

High Risk

Exploitation Techniques

Command Chaining

Data Exfiltration

Reverse Shell

Detection Techniques

Response Analysis

  • Look for system command output (usernames, OS info)

  • Check for error messages revealing command structure

  • Monitor response times for blind injection

OAST Testing

Mitigation

Secure Coding

Input Validation

  • Whitelist allowed characters

  • Validate input length and format

  • Escape shell metacharacters

  • Use parameterized commands

Tools

Manual Testing

  • Burp Suite: Parameter manipulation

  • curl: Command line testing

  • Netcat: Network interaction testing

Automated

  • Commix: Command injection tool

  • OWASP ZAP: Web app scanner

  • sqlmap: Parameter injection testing

Quick Reference

Testing Checklist

Common Endpoints

  • File operations: /upload, /download, /convert

  • System utilities: /ping, /traceroute, /nslookup

  • Admin functions: /backup, /restore, /config

  • API endpoints: /api/exec, /api/run, /api/system

Last updated