Skip to content
RCE Write-up Advanced

Bypassing OGNL sandboxes for fun and charities

The OGNL sandbox protections in Apache Struts and Atlassian Confluence could be bypassed using AST nodes such as ASTEval, ASTMap, ASTChain, and ASTSequence, allowing an attacker who can inject OGNL expressions to achieve remote code execution. The author demonstrated bypasses of the isSafeExpression method and found new gadgets in Struts to execute arbitrary code.

Alvaro Muñoz Follow

Published on github.blog

Alvaro Munoz·@pwntester

Alvaro Munoz, on github.blog

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

The sandbox's AST-based inspection missed certain node types (ASTEval, ASTMap, ASTChain, ASTSequence) and allowed string concatenation to evade blocklists, enabling expression evaluation that led to code execution.

Impact

An attacker who can inject OGNL expressions could bypass sandbox protections and achieve remote code execution, though the author notes that no new OGNL injections are reported and the risk depends on the presence of such injections.

What the attacker needed

Ability to inject OGNL expressions; Target uses vulnerable Struts or Confluence

The fix

The bypasses were reported to Atlassian and fixed by blocking access to Class and ClassLoader properties, but the string concatenation issue was not fixed as it was considered a security-in-depth control.

How it was found

  1. Identify that the isSafeExpression method parses OGNL into an AST and blocks certain node types.
  2. Notice that ASTEval nodes are not checked and can evaluate a string as an OGNL expression.
  3. Use string concatenation to bypass blocklists on string literals.
  4. Combine ASTMap, ASTChain, and ASTSequence to avoid ASTAssign and call methods on a BeanMap.
  5. Use Unicode escapes to bypass curly bracket restrictions in the injection sink.
  6. For Struts, access the ActionInvocation object to force result creation and populate the request with new objects, then use gadgets like ObjectWrapper to execute 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.

OGNL is a way to write expressions that Java applications evaluate. If an attacker can inject their own expression, they might run code on the server. This article shows how protections that try to block dangerous expressions can be tricked, so the attacker can still run commands.

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 Alvaro Muñoz

View all

1 more disclosed report, 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.