# Command Injection (CWE-78) User input is passed unsanitized to system shell commands, allowing attackers to execute arbitrary commands on the server. **Stack:** Python - 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 Strategie zapobiegania dla OS Command Injection oparte na 1 regułach detekcji Shoulder. ### Python Use subprocess.run with list arguments and shell=False ## Warning Signs - [CRITICAL] untrusted user input flowing into operating system command execution functions without proper saniti ## Consequences - Wykonanie nieautoryzowanych poleceń - Odczyt danych aplikacji - Obejście mechanizmu ochrony ## Mitigations - Korzystaj z wywołań biblioteki zamiast procesów zewnętrznych - Jeśli korzystasz z Runtime.exec(), używaj wersji przyjmującej tablicę argumentów - Stosuj uporządkowane mechanizmy, które automatycznie wymuszają rozdział danych od kodu ## Detection - Total rules: 3 - Critical: 3 - Languages: go, javascript, typescript, python ## Rules by Language ### Python (1 rules) - **OS Command Injection** [CRITICAL]: Detects untrusted user input flowing into operating system command execution functions without proper sanitization. - Remediation: Use subprocess with argument lists and shell=False. ```python subprocess.run(["ping", "-c", "2", ip_address], check=True) ``` Learn more: https://shoulder.dev/learn/python/cwe-78/command-injection