Multiple MCP tool implementations in DroidMind construct Android device shell commands by directly interpolating user-controlled parameters into f-strings. This allows an attacker (via prompt injection or a malicious MCP client) to execute arbitrary commands on the connected Android device by injecting shell metacharacters or command substitution syntax into tool parameters such as package_or_pid , package , and device_path .
The project implements a security model ( security.py ) with command allowlists, blocklists, and suspicious pattern detection — but this validation can be bypassed via $(...) command substitution syntax, which shlex.split() does not interpret. Additionally, some code paths bypass the security validation entirely by calling adb.shell() directly instead of going through the validated run_shell() method.
CVSS 3.1 Score: 9.8 (Critical) Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
CWE-78 : Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
CWE-77 : Improper Neutralization of Special Elements used in a Command ('Command Injection')
1. droidmind/tools/diagnostics.py — _resolve_pid() function
The android-diag tool's package_or_pid parameter is interpolated into device shell commands without input-specific validation:
2. droidmind/tools/logs.py — _get_app_logs_impl() function
The android-log tool's package parameter is interpolated into a device shell command:
3. droidmind/tools/file_operations.py — _read_file_impl() / _write_file_impl() functions
The android-file tool's device_path parameter is interpolated with ineffective single-quote wrapping:
4. droidmind/devices.py — list_directory() (validation bypass)
This method calls self._adb.shell() directly, completely bypassing the run_shell() security validation:
Attack 1: Command substitution bypass via android-diag
_resolve_pid() is called with the malicious package_or_pid
Command constructed: pidof $(cat /sdcard/Download/secrets.txt > /sdcard/Download/exfil.txt)
device.run_shell() validates with sanitize_shell_command() : shlex.split() sees ['pidof', '$(cat /sdcard/Download/secrets.txt > /sdcard/Download/exfil.txt)'] Base command pidof is in ALLOWED_SHELL_COMMANDS ✓ No suspicious patterns matched ✓ Validation passes
shlex.split() sees ['pidof', '$(cat /sdcard/Download/secrets.txt > /sdcard/Download/exfil.txt)']
Base command pidof is in ALLOWED_SHELL_COMMANDS ✓
No suspicious patterns matched ✓
Command sent to Android device shell via adb shell
Device shell interprets $(...) as command substitution
cat /sdcard/Download/secrets.txt > /sdcard/Download/exfil.txt executes on the device
Attack 2: Device reboot via android-log
Command constructed: ps -A | grep $(reboot)
Validation sees ps (allowed) piped to grep (allowed) with argument $(reboot)
Device shell executes reboot via command substitution
Attack 3: Quote breakout via android-file
Command constructed: [ -f 'x'; reboot; echo '' ] && echo 'exists' || echo 'not found'
Device shell breaks out of the single quotes
reboot executes on the device
The security model in security.py uses shlex.split() for command parsing, which is a Python lexer that does not interpret shell expansion features:
Command substitution : $(...) and backtick `...` are treated as literal strings by shlex but executed by the device shell
Variable expansion : ${var} is not interpreted by shlex
Process substitution : >(...) and <(...) are not handled
This creates a parsing discrepancy between the validator (Python's shlex ) and the executor (Android's /system/bin/sh ), allowing injection payloads that pass validation but are interpreted by the device shell.
Additionally, tool parameters that have a limited valid character set (package names are [a-zA-Z0-9._] , PIDs are digits, file paths should not contain shell metacharacters) are not validated against their expected format before being interpolated into shell commands.
An attacker who can influence the AI assistant's tool calls (via prompt injection in documents, web pages, or other content the AI processes) can:
Execute arbitrary commands on the connected Android device
Read sensitive data from the device (contacts, messages, files, credentials)
Modify or delete data on the device
Install malicious applications via pm install
Reboot or brick the device
Exfiltrate data from the device to external servers
Bypass DroidMind's security model which is designed to prevent exactly these operations
Short-term: Input validation per parameter type
Apply these in each tool before constructing shell commands:
Long-term: Use shlex.quote() as defense-in-depth
Also fix: devices.py line 190
Route through run_shell() instead of calling adb.shell() directly:
Security model improvement
Consider adding shell expansion detection to validate_shell_command() :
CWE-78: OS Command Injection
OWASP Command Injection
MCP Security Best Practices
The full story
This article is one source in a clustered incident — the cluster page carries the summary, timeline and every other outlet covering it.
