All vulnerabilities
CRITICALAppSecexploited in the wildransomware

APPSEC-CMDI

Web app · OS Command Injection

Summary

OS command injection occurs when user-controlled input reaches a function that spawns an operating-system shell, so shell metacharacters such as ; | & $() or backticks let an attacker append or substitute their own commands; calling a shell-interpreting API like system(), exec with shell=true, or backticks on a string built from input executes the injected command with the server process's privileges. It maps to OWASP A03:2021 Injection (CWE-78). A landmark mass-exploited case is GitLab CVE-2021-22205, disclosed April 14, 2021: GitLab passed uploaded images to ExifTool, whose mishandling of malicious DjVu metadata (CVE-2021-22204) allowed command injection. Rescored to CVSS 10.0 once confirmed unauthenticated, it gave remote code execution as the git user and was widely exploited in the wild, including for botnets, cryptomining, and ransomware staging.

How to avoid it in your code

  • Avoid shelling out entirely; call platform/library APIs directly instead of exec/system.
  • If a process must be spawned, use an argument-array exec without a shell and never shell=true.
  • Pass user data only as separate arguments, never interpolated into a command string.
  • Allowlist permitted values and reject shell metacharacters rather than blacklisting.
  • Patch and sandbox third-party parsers (e.g. ExifTool) and run the service as a low-privilege user.

References

Related vulnerabilities

All AppSec →