Kingdom: Input Validation and Representation

Input validation and representation problems ares caused by metacharacters, alternate encodings and numeric representations. Security problems result from trusting input. The issues include: "Buffer Overflows," "Cross-Site Scripting" attacks, "SQL Injection," and many others.

OGNL Expression Injection

Abstract
The evaluation of unvalidated OGNL expressions can lead to remote code execution.
Explanation
Object-Graph Navigation Language (OGNL) is an open-source Expression Language (EL) for Java that enables the evaluation of EL expressions in the Struts 2 Value Stack context. Enabling evaluation of unvalidated expressions against the Value Stack can give an attacker access to modify system variables or execute arbitrary code.

In the following example, the application is using unvalidated user-controlled data to create an evaluate an OGNL expression:

OgnlContext ctx = new OgnlContext();
String expression = request.getParameter("input");
Object expr = Ognl.parseExpression(expression);
Object value = Ognl.getValue(expr, ctx, root);
System.out.println("Value: " + value);


An attacker may submit the following expression to execute arbitrary code in the application server context:

(#rt = @java.lang.Runtime@getRuntime(),#rt.exec("calc.exe"))
References
[1] Apache Commons OGNL - Object-Graph Navigation Library
[2] Meder Kydyraliev Milking a horse or executing remote code in modern Java frameworks
desc.dataflow.java.ognl_expression_injection