Описание
OpenSTAManager has an OS Command Injection in P7M File Processing
Summary
A critical OS Command Injection vulnerability exists in the P7M (signed XML) file decoding functionality. An authenticated attacker can upload a ZIP file containing a .p7m file with a malicious filename to execute arbitrary system commands on the server.
Vulnerable Code
File: src/Util/XML.php:100
The Problem:
- The
$fileparameter is passed directly intoexec()without sanitization - Although wrapped in double quotes, an attacker can escape them
- The filename comes from uploaded ZIP archives (user-controlled)
Attack Vector
Entry Points:
-
plugins/importFE_ZIP/actions.php:126 (when automatic import is enabled)
foreach ($files_xml as $xml) { if (string_ends_with($xml, '.p7m')) { $file = XML::decodeP7M($directory.'/'.$xml); // $xml from ZIP! -
plugins/importFE/src/FatturaElettronica.php:56 (constructor)
if (string_ends_with($name, '.p7m')) { $file = XML::decodeP7M($this->file); // $name from user input!
Attack Flow:
- Attacker creates ZIP with malicious filename
- Upload ZIP via importFE_ZIP plugin
- Application extracts ZIP and iterates files
- For
.p7mfiles,decodeP7M()is called - Malicious filename is injected into
exec()command - Arbitrary command executes as web server user
Proof of Concept
⚠️ IMPORTANT NOTE: PHP's ZipArchive::extractTo() splits filenames on / character. Payload must NOT contain / in commands. Use cd directory && command instead of absolute paths.
Step 1: Create Malicious ZIP
Step 2: Upload ZIP
Step 3: Exploitation Result
Response (500 error is expected - XML parsing fails AFTER command execution):
Verification - Webshell Created:
Step 4: Remote Code Execution
Webshell is publicly accessible without authentication:
Impact
- Remote Code Execution: Full server compromise
- Data Exfiltration: Access to all application data and database
- Privilege Escalation: Potential escalation if web server runs with elevated privileges
- Persistence: Install backdoors and maintain access
- Lateral Movement: Pivot to other systems on the network
Prerequisites
- Authenticated user with access to invoice import functionality
Remediation
Input Sanitization
or
Validate Filename Before Processing
Credit
Discovered by: Łukasz Rybak
Пакеты
devcode-it/openstamanager
<= 2.9.8
Отсутствует