T09 · Insecure Skill Coding Practices
- Location
bluetooth-monitor.sh:110- Finding
Terminal Escape Sequence Injection Through Bluetooth Device Names
- Content
View full analysis
Vulnerability Details
File Location:
bluetooth-monitor.sh, lines 110, 146, and 151
Vulnerability Type: Unsafe rendering of attacker-controlled terminal output
Risk Level: MediumVulnerable Code
bash echo -e "🔗 ${GREEN}$name${NC}"The same unsafe output pattern is used for paired devices:
bash if [ -n "$connected" ]; then echo -e "🔗 ${GREEN}$name${NC} (已连接 / Connected)" # 获取电量 / Get battery level battery=$(get_battery_level "$name") show_battery_bar "$battery" "$name" else echo -e "🔗 $name (未连接 / Disconnected)" fiTechnical Analysis
The
namevariable is extracted from Bluetooth device metadata returned byblueutil. Bluetooth device names are not inherently trusted because they can be selected by the owner of a nearby or previously paired device.The script embeds this value in an
echo -ecall. The-eoption enables interpretation of backslash escapes. Consequently, a name containing supported escape notation can produce terminal control characters instead of being displayed literally.Depending on the terminal emulator and its configuration, terminal control sequences can:
- Clear or overwrite displayed content.
- Move the cursor and create misleading output.
- Change terminal titles or colors.
- Produce fake success, warning, or command-prompt messages.
- Invoke terminal-specific OSC functionality, potentially including clipboard manipulation.
This is terminal-output injection rather than shell command injection. The device name is not passed to
evalor executed as a command.Attack Path
- An attacker configures a Bluetooth device with a name containing backslash escape notation understood by
echo -e. - The maliciously named device becomes visible as a connected or paired device on the target Mac.
- The user executes
bluetooth-monitor connectedorbluetooth-monitor paired. blueutilreturns the att ...[truncated 769 chars]
- Remediation
View remediation
Remediation Suggestions
Do not pass untrusted device metadata to
echo -e. Useprintfwith a constant format string and place color codes and untrusted values in separate arguments:bash printf '🔗 %b%s%b\n' "$GREEN" "$name" "$NC" printf '🔗 %b%s%b (Connected)\n' "$GREEN" "$name" "$NC" printf '🔗 %s (Disconnected)\n' "$name"As defense in depth, remove terminal control characters from device names before rendering them:
bash safe_name=$(printf '%s' "$name" | LC_ALL=C tr -d '\000-\010\013\014\016-\037\177')Use
safe_nameonly for display. Preserve the original device name separately if it is required for exact data lookup. Apply the same safe-output rule to every value obtained from Bluetooth metadata.
