@mobilenext/mobile-mcp Path Traversal Vulnerability
The @mobilenext/mobile-mcp package before version 0.0.49 is vulnerable to a Path Traversal vulnerability in the mobile_save_screenshot and mobile_start_screen_recording tools where the `saveTo` and `output` parameters are passed directly to filesystem operations without validation, potentially allowing an attacker to write files outside the intended workspace, leading to privilege escalation and persistence by overwriting sensitive host files.
The @mobilenext/mobile-mcp npm package, versions prior to 0.0.49, contains a critical path traversal vulnerability. This flaw stems from the mobile_save_screenshot and mobile_start_screen_recording tools which improperly handle user-supplied paths. Specifically, the saveTo parameter in mobile_save_screenshot and the output parameter in mobile_start_screen_recording are passed directly to filesystem write operations without adequate validation. This oversight enables a malicious actor to write arbitrary files to locations outside of the intended workspace. A successful exploit of this vulnerability allows for the potential overwriting of sensitive system files, enabling privilege escalation and persistence on the host system.
Attack Chain
- An attacker gains control over the
saveTooroutputparameter of the vulnerable functions. This could be achieved through a malicious application, supply chain attack, or other means of code injection. - The attacker crafts a path containing traversal sequences (e.g.,
../) designed to navigate outside of the intended save directory. - The attacker calls the
mobile_save_screenshotormobile_start_screen_recordingtool with the manipulated path as thesaveTooroutputparameter, respectively. - The vulnerable function passes the attacker-controlled path to
fs.writeFileSync()without validation. fs.writeFileSync()writes the screenshot or screen recording data to the attacker-specified path.- If the path leads to a sensitive system file (e.g.,
~/.bashrc,~/.ssh/authorized_keys), it is overwritten with the contents of the screenshot or screen recording. - The attacker can overwrite configuration files or executables in order to achieve code execution.
- The attacker achieves persistence and/or elevated privileges on the system.
Impact
Successful exploitation of this path traversal vulnerability can have severe consequences. An attacker can overwrite critical system files, such as shell configuration files (.bashrc, .zshrc), SSH authorized keys (.ssh/authorized_keys), or application configuration files. This can lead to arbitrary code execution, privilege escalation, and persistent backdoor access to the affected system. The reported impact includes potential for a broken shell and unauthorized access. All users of @mobilenext/mobile-mcp versions prior to 0.0.49 are vulnerable.
Recommendation
- Upgrade to
@mobilenext/mobile-mcpversion 0.0.49 or later to remediate the vulnerability. - Implement robust input validation for all file paths used in file system operations. Specifically, validate the
saveToandoutputparameters of themobile_save_screenshotandmobile_start_screen_recordingfunctions. - Deploy the Sigma rule “Detect Mobile-MCP Path Traversal Attempts” to your SIEM to detect attempts to exploit this vulnerability.
- Monitor application logs for unusual file access patterns or attempts to write to sensitive system directories.
Detection coverage 2
Detect Mobile-MCP Path Traversal Attempts
highDetects attempts to exploit the path traversal vulnerability in @mobilenext/mobile-mcp by monitoring for calls to 'mobile_save_screenshot' or 'mobile_start_screen_recording' with suspicious file paths.
Detect Mobile-MCP Arbitrary File Write via API Call
mediumDetects attempts to write arbitrary files by monitoring API calls with base64 encoded command lines or shell commands.
Detection queries are kept inside the platform. Get full rules →