Skip to content
RCE Write-up Advanced

Hiding payloads in Java source code strings

Java source code treats unicode escapes such as an encoded double quote as real syntax, so a string literal can be closed early and arbitrary code appended. An attacker could hide executable code inside what looks like a harmless string assignment, and running it would execute commands on the local machine.

portswigger.net

Published on portswigger.net

In this post we'll show you how Java handles unicode escapes in source code strings in a way you might find surprising - and how you can abuse them to conceal payloads.

The author, on portswigger.net

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 Java compiler processes unicode escapes before parsing, so an escaped quote inside a string literal terminates the string and the remaining text is compiled as code.

Impact

A user who runs an untrusted Bambda could have arbitrary code executed on their local machine, though the text notes that Bambdas already allow arbitrary code execution by design.

What the attacker needed

Victim runs untrusted Java code; attacker supplies the snippet

The fix

Users should validate any Bambda from an untrusted source before using it, since the feature intentionally allows arbitrary code execution.

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.

Java lets you write characters using a special escape code, for example a quote mark can be written as a unicode escape. The compiler turns that escape into a real quote before it reads the string, so the string ends earlier than it looks and the rest of the line becomes code. Someone could therefore hand you a snippet that looks like a plain text value but actually runs a command when compiled.

What is RCE?

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

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.