GitHub Security Advisory: GHSA-j945-qm58-4gjx
Package: motioneye (PIP)
Severity: HIGH (CVSS 7.2)
CWE: CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), CWE-116: Improper Encoding or Escaping of Output
Vulnerable versions: < 0.43.1b5
Patched in: 0.43.1b5

Summary: motionEye vulnerable to RCE via unsanitized motion config parameter

Details:
## Summary
A command injection vulnerability in MotionEye allows attackers to achieve Remote Code Execution (RCE) by supplying malicious values in configuration fields exposed via the Web UI. Because MotionEye writes user-supplied values directly into Motion configuration files without sanitization, attackers can inject shell syntax that is executed when the Motion process restarts. This issue enables full takeover of the MotionEye container and potentially the host environment (depending on container privileges).

## Details
### Root Cause:
MotionEye accepts arbitrary strings from fields such as **image_file_name**  and **movie_filename** in the Web UI. These are written directly into **/etc/motioneye/camera-*.conf**. When MotionEye restarts the Motion service (motionctl.start), the Motion binary reads this configuration. Because Motion treats these fields as shell-expandable, injected characters (e.g. $(), backticks) are interpreted as shell commands.

### Vulnerability flow:
Dashboard (Web UI)
   ↓
ConfigHandler.set_config()
   ↓
camera-*.conf written
   ↓
motionctl.restart()
   ↓
Motion parses config → executes payload


### Affected code:
The issue arises in how config.py handles user input before writing to config files. No sanitization or allowlisting is applied to filename fields.


### Proof of Concept (PoC)

The following steps reproduce the Remote Code Execution (RCE) vulnerability in MotionEye.  
Tested using the official Docker image.

---

#### Environment Setup
1. **Start MotionEye container**  
   Launch the vulnerable container:  
   ```bash
   docker run -d --name motioneye -p 9999:8765 ghcr.io/motioneye-project/motioneye:edge
   ```

2. **Verify version**  
   Confirm the running version inside logs:  
   ```bash
   docker logs motioneye | grep "motionEye server"
   ```  
   **Result:**  
   ```
   motionEye server 0.43.1b4
   ```
    <img width="741" height="168" alt="version_ver" src="https://github.com/user-attachments/assets/ac85d238-da7f-4274-9381-0119c01a1320" />

3. **Container shell access (for verification later)**  
   Keep a shell handy to verify results:  
   ```bash
   docker exec -it motioneye /bin/bash
   ls -la /tmp
   ```

---

#### Exploitation Steps
4. **Access Web Interface**  
   - Open browser at: `http://127.0.0.1:9999`  
   - Login with default credentials: **admin** / *(blank password)*  
   - Add a sample RTSP network camera (required to enable camera-specific settings).
    
    <img width="1623" height="869" alt="add_camera" src="https://github.com/user-attachments/assets/d506a891-8b80-4b69-84f2-b195fcaca0cc" />

5. **Attempt malicious filename input**  
   - Go to: **Camera Settings → Still Images**  
   - In the **Image File Name** field, try:  
     ```bash
     $(touch /tmp/test).%Y-%m-%d-%H-%M-%S
     ```  
   - **Observation:** This is blocked by client-side validation in the browser.
    
    <img width="739" height="104" alt="er1" src="https://github.com/user-attachments/assets/817549fc-5cb2-