Skip to content
RCE Write-up Advanced

PowerShell script, Unicode quotes, and ウィンドウズ — a story of uncommon command injection.

A PowerShell injection vulnerability existed because the sanitisation function only removed ASCII quotes, while PowerShell also treats certain Unicode quote characters as string delimiters. An attacker could inject commands into a dynamically generated PowerShell script, but only if the Windows system used a code page that maps the attacker's bytes to a Unicode quote.

Arafat Ashrafi Talha Follow

Published on systemweakness.com

Can you see the difference between “ and “ or ‘ and ‘ ? You can?

Arafat Ashrafi Talha, on systemweakness.com

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 sanitiser only escaped ASCII quotes, but PowerShell's parser treats several Unicode quote characters from the General Punctuation block as equivalent string delimiters.

Impact

An unauthenticated attacker could achieve remote code execution, but only when the target Windows system uses a locale whose default OEM code page maps the attacker's bytes to a Unicode quote character, such as Japanese Windows.

What the attacker needed

Target runs Windows with a suitable locale; attacker can send HTTP requests; no authentication needed

The fix

The sanitiser should escape all Unicode quote characters that PowerShell treats as string delimiters, not just ASCII quotes.

How it was found

  1. Send a request to the date endpoint with a format parameter containing a crafted byte sequence that maps to a Unicode quote in the target code page, followed by a command.
  2. The server inserts the unsanitised value into a dynamically generated PowerShell script.
  3. PowerShell interprets the Unicode quote as the end of the string and executes the injected command.
  4. Observe the command output in the HTTP response.

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.

When a program builds a command by pasting user input into a string, it must escape characters that could break out of that string. Here the escaping missed some unusual quote characters that PowerShell also accepts as string delimiters. The catch is that the bytes sent over HTTP must be converted by Windows into one of those quote characters, which only happens on certain system locales.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by Arafat Ashrafi Talha

View all

1 more disclosed report, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.