Skip to content

OS Command Injection

Description

The code uses subprocess with untrusted input, which can lead to OS command injection. An attacker could inject malicious commands, potentially leading to code execution or data breaches.

Examples

Insecure Code

python
subprocess.Popen('ls ' + input(), shell=True)

Secure Code

python
subprocess.Popen(['ls', input()], stdout=subprocess.PIPE)

Remediation

Use subprocess with the 'args' parameter instead of 'shell=True' to avoid executing untrusted input. Ensure all input is properly sanitized and validated.

Rule Details

FieldValue
IDCODE-0152
CategoryInjection
SeverityHIGH
CWECWE-78
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsos-command-injection, injection
OWASPA1:2017-Injection, A03:2021-Injection