Skip to content
RCE Write-up Advanced

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.

ryotak Follow

Published on flatt.tech

Hello, I’m RyotaK ( @ryotkak ), a security engineer at Flatt Security Inc.

RyotaK, on flatt.tech

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.

More by ryotak

View all

6 more disclosed reports, 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.