BatBadBut: You can't securely execute commands on Windows
Programming language runtimes on Windows failed to properly escape command arguments when executing batch files, because CreateProcess implicitly spawns cmd.exe which has different parsing rules. An attacker who controls part of the command arguments could inject arbitrary commands.
Hello, I’m RyotaK ( @ryotkak ), a security engineer at Flatt Security Inc.
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
Likely the root cause is that CreateProcess implicitly invokes cmd.exe for batch files, and language runtimes escape arguments using rules for normal executables, not cmd.exe's parsing rules.
Impact
An attacker could achieve arbitrary command execution on Windows if the application meets specific conditions, such as executing a batch file with user-controlled arguments and using a runtime that fails to escape properly.
What the attacker needed
Application executes a command on Windows; command is a batch file or lacks extension; user controls part of command arguments; runtime fails to escape for cmd.exe
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 on Windows runs a batch file (a script ending in .bat or .cmd), Windows secretly uses the command prompt (cmd.exe) to do it. The command prompt treats special characters like quotes and percent signs differently from other programs, so if a program tries to protect against injection by escaping those characters in the usual way, it can fail. An attacker who can control part of the input to such a command could then run their own commands on the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.