T09 · Insecure Skill Coding Practices
- Location
adb-helpers.sh:317- Finding
Android Shell Command Injection Through Untrusted Text Input
- Content
View full analysis
/dev/null; then # Use clipboard-based input for CJK adb shell "echo '$text' | am broadcast -a clipper.set" 2>/dev/null \ || adb shell input text "$escaped" echo "Typed (clipboard fallback): $text" else adb shell input text "$escaped" echo "Typed: $text" fi ``` ### Technical Analysis The `adb_input_text` function embeds the caller-controlled `text` value directly into a command string interpreted by the Android shell: ```bash adb shell "echo '$text' | am broadcast -a clipper.set" ``` The local double quotes only protect the argument from the local shell. Once transmitted through `adb shell`, the Android shell parses the embedded single quotes and metacharacters. A single quote in `text` can terminate the intended string, after which separators such as `;`, `&&`, pipes, or command substitutions can introduce additional commands. The vulnerable branch is selected for text detected as non-ASCII. An attacker can include a non-ASCII character alongside the shell payload to reach this branch. The fallback command also passes transformed, unvalidated text to `adb shell input text`; it should not be treated as a safe shell-escaping mechanism. ### Attack Path 1. The attacker controls or influences text supplied to `adb_input_text`. 2. The attacker includes at least one non-ASCII character so the clipboard fallback branch is selected. 3. The input contains a single quote that closes the `echo` argument, followed by Android shell syntax and an attacker-selected command. 4. The function constructs the complete string and sends it to `adb shell`. 5. The Android shell parses and executes ...[truncated 1087 chars]- Remediation
View remediation
