GHSA-pmj8-r2j7-xg6c AVideo has an OS Command Injection via $() Shell Substitution Bypass in sanitizeFFmpegCommand()
SummaryThe `sanitizeFFmpegCommand()` function in `plugin/API/standAlone/functions.php` is designed to prevent OS command injection in ffmpeg commands by stripping dangerous shell metacharacters (`&&`, `;`, `|`, `` ` ``, `<`, `>`). However, it fails to strip `$()` (bash command substitution syntax). Since the sanitized command is executed inside a double-quoted `sh -c` context in `execAsync()`, an attacker who can craft a valid encrypted payload can achieve arbitrary command execution on the standalone encoder server.Details**Vulnerable sanitization function** (`plugin/API/standAlone/functions.php:59-82`):The character class `[;|`<>]` on line 70 does not include `$`, `(`, `)`, or `\n`. This means `$(...)` command substitution passes through completely unmodified.**Execution sink** (`objects/functionsExec.php:656-658`):The `addcslashes($command, '"')` call at line 639 only escapes double-quote characters. The `$()` construct is preserved intact and interpreted by `sh` as command substitution within the double-quoted string.**Execution flow:**Attacker sends `codeToExecEncrypted` parameter to `plugin/API/standAlone/ffmpeg.json.php`Standalone encoder calls main server's unauthenticated `decryptString` API to decryptDecrypted `ffmpegCommand` passes through `sanitizeFFmpegCommand()` — `$()` is NOT strippedCommand passes prefix check (starts with `ffmpeg`)`execAsync()` wraps it in `sh -c "..."` — `$()` is evaluated as command substitution**Auth barrier analysis:**Requires a valid AES-256-CBC encrypted JSON payload with a timestamp within 30 secondsKey is `sha256(saltV2)` on the main server; `saltV2` is generated by `random_bytes(16)` — cryptographically strongIV is `substr(sha256(systemRootPath), 0, 16)` — predictable but insufficient aloneOn legacy installations without `saltV2`, falls back to `$global['salt']` which may be weakerThe `decryptString` API endpoint (`API.php:5963`) is unauthenticated, enabling probing but not payload craftingPoCAssuming the attacker has obtained the encryption key (e.g., from a leaked configuration file, a legacy installation with a weak salt, or via a separate vulnerability):**Sanitization trace for the payload:**`str_replace('&&', '', ...)` → no `&&` present, passes`preg_replace('/\s*&?>.*(?:2>&1)?/', '', ...)` → no `>` outside `$()`, passes`preg_replace('/[;|`<>]/', '', ...)` → no `;|`<>` present, passesPrefix check → starts with `ffmpeg`, passes`addcslashes($command, '"')` → no `"` in payload, `$()` untouchedImpact**Remote Code Execution**: Full arbitrary command execution on the standalone encoder server with the privileges of the web server process**Lateral Movement**: Standalone encoders typically have network access to the main AVideo server, enabling further attacks**Data Exfiltration**: Access to all video files, configuration, and credentials stored on the encoder**Service Disruption**: Attacker can terminate encoding processes or consume system resourcesThe attack complexity is High due to the encryption key requirement, but the impact is Critical once the barrier is bypassed. Legacy installations without `saltV2` are at significantly higher risk.Recommended FixReplace the denylist-based sanitization with proper argument escaping:**Better long-term fix**: Instead of sanitizing a complete shell command string, parse the ffmpeg arguments and use `escapeshellarg()` on each individual argument before reassembling the command. This eliminates the need for a denylist entirely.
CVSS v3.1 score: 8.1