Skip to content

OS Command Injection

Description

The `subprocess` function is used with `shell=True`, which can lead to OS command injection attacks. This occurs because the command is spawned using a shell process, propagating current shell settings and variables, making it easier for malicious actors to execute commands.

Examples

Insecure Code

python
subprocess.run('ls -l', shell=True)

Secure Code

python
subprocess.run(['ls', '-l'])

Remediation

Use `shell=False` instead of `shell=True` when calling the `subprocess` function to prevent OS command injection attacks.

Rule Details

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