# Command Injection (CWE-78) User input is passed unsanitized to system shell commands, allowing attackers to execute arbitrary commands on the server. **Stack:** Go - Prevalence: Common Found in many applications - Impact: Critical Full server compromise - Prevention: Avoid shell Use execFile, not exec **OWASP:** Injection (A03:2021-Injection) - #3 ## Description This could allow attackers to execute unexpected, dangerous commands directly on the operating system. This weakness can lead to a vulnerability in environments in which the attacker does not have direct access to the operating system. ## Prevention Präventionsstrategien für OS Command Injection basierend auf 1 Shoulder-Erkennungsregeln. ### Go Use exec.Command with explicit arguments, never shell invocation ## Warning Signs - [CRITICAL] user input flowing to os/exec command execution, enabling OS command injection ## Consequences - Nicht autorisierte Befehle ausführen - Anwendungsdaten lesen - Schutzmechanismus umgehen ## Mitigations - Nutze Bibliotheksaufrufe statt externer Prozesse - Wenn du Runtime.exec() verwendest, nimm die Variante, die ein Array von Argumenten erwartet - Verwende strukturierte Mechanismen, die die Trennung von Daten und Code automatisch erzwingen ## Detection - Total rules: 3 - Critical: 3 - Languages: go, javascript, typescript, python ## Rules by Language ### Go (1 rules) - **Command Injection via os/exec** [CRITICAL]: Detects user input flowing to os/exec command execution, enabling OS command injection. - Remediation: Use exec.Command with explicit arguments and validate input against an allowlist. ```go allowed := map[string]bool{"file1.txt": true, "file2.txt": true} if !allowed[userInput] { return errors.New("not allowed") } cmd := exec.Command("cat", userInput) ``` Learn more: https://shoulder.dev/learn/go/cwe-78/command-injection