Text of securitylab.github.com › research › apache-struts-CVE-2018-11776 as Styx crawled it on Nov 20, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

CVE-2018-11776: How to find 5 RCEs in Apache Struts with CodeQL | GitHub Security Lab

skip to content Resources Open Source Community Enterprise / Security Lab Research Advisories CodeQL Wall of Fame Resources Open Source Community Enterprise Events Get Involved In April 2018, I reported a new remote code execution vulnerability in Apache Struts and to the Struts Security Team. The vulnerability has been assigned CVE-2018-11776 ( S2-057 ), is exposed on servers running Struts under certain configurations and can be triggered by visiting a specially crafted URL.

This discovery is part of my continuing security research into Apache Struts. In this post I’ll walk through the process that led me to find the vulnerability. I’ll explain how I used information on previous vulnerabilities to gain knowledge of the internal working of Struts and to create queries that encapsulate Struts-specific concepts. Running these queries produced results that highlighted the problematic code.

These queries are hosted on GitHub , and over time, as research continues, we’ll be adding more queries and libraries to this repository to aid security research for Struts and other projects. Mapping the attack surface Many security vulnerabilities involve data flowing from an untrusted source —for example, user input—to some specific location (a sink ) where the data gets used in a way that is dangerous—for example, an SQL query, deserialization, some other interpreted language, etc… CodeQL makes it easy to search for this type of vulnerability.

You simply need to describe the various sources and sinks, and then let the DataFlow library do all the hard work. A good way to start an investigation into this kind of problem, for a particular project, is to look at known vulnerabilities for older versions of the software. This can give you good insight into the sorts of sources and sinks you want to look for. For this investigation, I started by looking at the RCE vulnerabilities S2-032 ( CVE-2016-3081 ), S2-033 ( CVE-2016-3687 ) and S2-037 ( CVE-2016-4438 ).

Like many other RCEs in Struts, these involve untrusted input being evaluated as an OGNL expression, which allows the attacker to run arbitrary code on the server. These three vulnerabilities are particularly interesting, not only because they give us some insights into the internal working of Struts, but also because what is effectively the same issue took three attempts to fix! All three issues were the result of remote inputs being passed via the variable methodName as an argument to the method OgnlUtil::getValue() .

String methodName = proxy . getMethod (); //<--- untrusted source, but where from? LOG . debug ( "Executing action method = {}" , methodName ); String timerKey = "invokeAction: " + proxy . getActionName (); try { UtilTimerStack . push ( timerKey ); Object methodResult ; try { methodResult = ognlUtil . getValue ( methodName + "()" , getStack (). getContext (), action ); //<--- RCE The field proxy has the type ActionProxy , which is an interface.

Looking at its definition, I see that in addition to the method getMethod() (which is used in the code above in the assignment of the tainted variable methodName ) there are also various methods like getActionName() and getNamespace() . These methods looked like they may return information from the URL. So I began with the assumption that all of these methods could potentially return untrusted input. (In later posts, I will dig deeper into my investigation of where these inputs come from.) Now we can start modeling these untrusted sources using CodeQL’s language, named QL: class ActionProxyGetMethod extends Method { ActionProxyGetMethod() { getDeclaringType().getASupertype*().hasQualifiedName("com.opensymphony.xwork2", "ActionProxy") and ( hasName("getMethod") or hasName("getNamespace") or hasName("getActionName") ) } } predicate isActionProxySource(DataFlow::Node source) { source.asExpr().(MethodAccess).getMethod() instanceof ActionProxyGetMethod } Identifying the OGNL sinks Now that we’ve identified and described some untrusted sources, the next step is to do the same for the sinks.

As mentioned before, many Struts RCEs involve remote input being parsed as OGNL expressions. There are many functions in Struts that ultimately evaluate their arguments as OGNL expressions under the hood; in the case of the three vulnerabilities we started with in this post, OgnlUtil::getValue() was used, however in the vulnerability S2-045 ( CVE-2017-5638 ), TextParseUtil::translateVariables() was used. Instead of describing each of these methods as separate sinks, we can look for common functions that they use to execute OGNL expressions.

I decided that OgnlUtil::compileAndExecute() and OgnlUtl::compileAndExecuteMethod() look like promising sinks. I described them both in a single QL predicate like so: predicate isOgnlSink(DataFlow::Node sink) { exists(MethodAccess ma | ma.getMethod().hasName("compileAndExecute") or ma.getMethod().hasName("compileAndExecuteMethod") | ma.getMethod().getDeclaringType().getName().matches("OgnlUtil") and sink.asExpr() = ma.getArgument(0) ) } First attempt at taint tracking Now that we have our sources and sinks defined with CodeQL, we can use these definitions in a taint-tracking query.

We use the DataFlow library to do this, by defining a DataFlow Configuration : class OgnlTaintTrackingCfg extends DataFlow::Configuration { OgnlTaintTrackingCfg() { this = "mapping" } override predicate isSource(DataFlow::Node source) { isActionProxySource(source) } override predicate isSink(DataFlow::Node sink) { isOgnlSink(sink) } override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) { TaintTracking::localTaintStep(node1, node2) or exists(Field f, RefType t | node1.asExpr() = f.getAnAssignedValue() and node2.asExpr() = f.getAnAccess() and node1.asExpr().getEnclosingCallable().getDeclaringType() = t and node2.asExpr().getEnclosingCallable().getDeclaringType() = t ) } } from OgnlTaintTrackingCfg cfg, DataFlow::Node source, DataFlow::Node sink where cfg.hasFlow(source, sink) select source, sink Here I use the previously defined isActionProxySource and isOgnlSink predicates.

Note that I also override a predicate called isAdditionalFlowStep . This predicate allows me to include extra steps where tainted data can be propagated. This allows me, for example, to incorporate project-specific information in the flow configuration. For example, if I had components that communicated via some network layer, I could describe with CodeQL what the code of those various network endpoints looked like, allowing the DataFlow library to track data being tainted through that abstraction.

For this particular query, I added two extra flow steps for the DataFlow library to use. The first one: TaintTracking::localTaintStep(node1, node2) includes the standard CodeQL TaintTracking library steps that track through standard Java library calls, string operations etc. The second addition is an approximation that allows me to track taint data via field accesses: exists(Field f, RefType t | node1.asExpr() = f.getAnAssignedValue() and node2.asExpr() = f.getAnAccess() and node1.asExpr().getEnclosingCallable().getDeclaringType() = t and node2.asExpr().getEnclosingCallable().getDeclaringType() = t ) This says that if a field is assigned to some tainted value, then an access to that field will also be considered tainted, as long as both expressions are called by methods of the same type.

Roughly speaking, this incorporates the following case: public void foo ( String taint ) { this . field = taint ; } public void bar () { String x = this . field ; //x is tainted because field is assigned to tainted value in `foo` } As you can see, the access of this.field in bar() may not always be tainted. For example if foo() is not called before bar() . Because of this, we don’t include this flow step in the default DataFlow::Configuration , as we cannot guarantee that data will always flow in this manner.

For hunting vulnerabilities however, I find this addition t

The rest of this page is on the live site.