PowerShell script, Unicode quotes and ウィンドウズ - a story of uncommon command injection
A hypothetical application that inserts user input into a dynamically generated PowerShell script while sanitising only typical ASCII quotes could be vulnerable to command injection via Unicode quote characters, though exploitation is not straightforward.
Published on blog.stmcyber.com
Author: Krzysztof Andrusiak, 14.09.2021
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The escape function only sanitised ASCII quote characters, while PowerShell treats several Unicode quote characters as equivalent string delimiters, allowing an attacker to break out of the string.
Impact
Command injection into a PowerShell script could lead to remote code execution, but the text stresses it is not that easy.
What the attacker needed
Application builds PowerShell script from user input; Sanitisation covers only typical quotes; PowerShell treats Unicode quotes as delimiters
The fix
The sanitisation should account for Unicode quote characters that PowerShell treats as delimiters, not just typical quotes.
How it was found
- Identify that the application inserts user input into a dynamically generated PowerShell script and sanitises only ASCII quotes.
- Find a Unicode quote character that PowerShell accepts as a string delimiter.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
PowerShell treats some Unicode quote characters like normal quotes. An application that sanitises only typical quotes when building a PowerShell script could let an attacker break out of the string, though it is not easy.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.