Skip to content
RCE Write-up Advanced

RCE on Apache Struts 2.5.30 and 6.x

A bypass of a previous fix for a double OGNL evaluation vulnerability in Apache Struts allowed remote code execution when a developer used untrusted input in a select tag's listValueKey attribute. An attacker could exploit this to execute arbitrary code on the server.

Chris Follow

Published on mc0wn.blogspot.com

The original lives on mc0wn.blogspot.com

We do not hold its text, 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 developer used untrusted user input in a select tag's listValueKey attribute, which is evaluated by OGNL, and the previous fix (replacing single quotes with double quotes) could be bypassed by using other top-level variables like #__component_stack to reach a second evaluation.

Impact

An attacker could execute arbitrary code on the server, but this only applies to rare cases where a developer incorrectly uses untrusted input in a select tag's listValueKey attribute.

What the attacker needed

A Struts application using a select tag with listValueKey; Developer uses untrusted input in listValueKey; Attacker can control the input

The fix

The fix should be to avoid using untrusted user input in OGNL evaluations, and Apache Struts added a maximum character limit for expressions to mitigate this specific exploit.

How it was found

  1. Identify a Struts select tag where the listValueKey attribute uses untrusted user input.
  2. Craft an OGNL expression that uses #__component_stack[1].setVar() to trigger a second evaluation.
  3. Use the setVar method to call findString, which performs OGNL evaluation on the provided string.
  4. In the second evaluation, use BeanMap gadgets to bypass sandbox restrictions and execute arbitrary code.

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.

Apache Struts is a Java framework for building web applications. It uses a language called OGNL to evaluate expressions. If user input reaches an OGNL evaluation twice, an attacker can run their own code on the server. This report shows a way to bypass a fix that tried to block such attacks.

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 Chris

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.