T09 · Insecure Skill Coding Practices
- Location
keyboard_control.ps1.txt:7- Finding
Unescaped Text Is Interpreted as SendKeys Control Syntax
- Content
View full analysis
Vulnerability Details
File Location:
keyboard_control.ps1.txt, lines 7-9
Vulnerability Type: Keyboard input injection through unsafe SendKeys interpretation
Risk Level: Mediumpowershell if ($Text) { [System.Windows.Forms.SendKeys]::SendWait($Text) }Technical Analysis
The
-Textparameter is passed directly toSystem.Windows.Forms.SendKeys.SendWait(). This API does not treat its argument as literal text: characters such as+,^,%,~, parentheses, and braces have special meanings representing modifier keys, key combinations, repetition, or named keys.The accompanying documentation presents
-Textas a facility for typing ordinary text. Consequently, data containing SendKeys metacharacters can be interpreted as keyboard commands without the caller intending or recognizing that behavior. If untrusted content reaches this parameter, an attacker can construct text that activates shortcuts in whichever window currently has focus.Attack Path
- An attacker supplies or influences text that an agent is asked to type into a desktop application.
- The agent invokes
keyboard_control.ps1.txtand passes that content through the-Textparameter. - The script forwards the content unchanged to
SendWait(). - SendKeys parses embedded metacharacters as modifier keys or special-key expressions rather than literal characters.
- The resulting shortcut is delivered to the currently focused window, causing an action such as submitting a form, opening an application command, changing content, or closing a document.
Exploitation requires the script to be invoked with attacker-influenced text while an actionable desktop window has focus.
Impact Assessment
Successful exploitation can perform unintended GUI actions with the permissions and interactive desktop access of the user running the script. The affected scope is the active Windows session and applications accessible to th ...[truncated 425 chars]
- Remediation
View remediation
Remediation Suggestions
- Treat
-Textstrictly as literal text and escape every SendKeys metacharacter before passing it toSendWait(). - Keep literal text entry and special-key operations in separate code paths. Do not permit raw SendKeys expressions through the text-entry path.
- Restrict
-Keyto an explicit allowlist of required named keys and combinations rather than accepting arbitrary SendKeys syntax. - Require the caller to identify the intended target window, activate it, and verify that it has focus immediately before injecting input.
- Add confirmation or policy checks before sending shortcuts capable of destructive or security-sensitive actions.
- Add tests covering literal input containing
+,^,%,~, parentheses, braces, and bracket-like key expressions. - Where feasible, use a text-entry mechanism that inserts literal Unicode text without interpreting control syntax, while avoiding clipboard use for sensitive content.
- Treat
