Exploiting Struts RCE on 2.5.26
A double OGNL evaluation in Struts2 UIBean tags allows an attacker to execute arbitrary code by passing a crafted expression in a URL parameter, bypassing the OGNL sandbox via a new syntax for creating a BeanMap. This leads to remote code execution on the server.
Late last year, 2020, a fix for a remote code execution (RCE) vulnerability discovered by Alvaro Munoz and Masato Anzai, was published by Apache Struts that goes by S2-061 or CVE-2020-17530 a "Forced OGNL evaluation, when evaluated on raw user input in tag attributes, may lead to remote code execution - similar to…
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 certain UIBean tags perform a second OGNL evaluation on the 'name' attribute when no 'value' attribute is provided, and the sandbox can be bypassed by directly instantiating a BeanMap using OGNL's map syntax.
Impact
An attacker could execute arbitrary code on the server, leading to full compromise, though the report notes that the vendor initially did not consider it a vulnerability and a fix was later released.
What the attacker needed
Struts2 application using vulnerable UIBean tags; Attacker can send crafted requests
How it was found
- Identify a Struts2 application using a UIBean tag with a name attribute that includes user input via %{} syntax and lacks a value attribute.
- Craft a URL parameter containing an OGNL expression that creates a BeanMap and manipulates the value stack to clear sandbox restrictions.
- Send a request to the vulnerable endpoint with the crafted parameter, causing the expression to be evaluated twice and executing 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.
Struts2 is a Java web framework that uses OGNL, a language for accessing object properties, to evaluate expressions in web pages. If user input is evaluated twice by OGNL, an attacker can inject code that runs on the server. This report shows a way to bypass the sandbox that Struts uses to block dangerous code, allowing remote code execution.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.