EL - Expression Language

Bsic Info

Expression Language (EL) is integral in JavaEE for bridging the presentation layer (e.g., web pages) and application logic (e.g., managed beans), enabling their interaction. It's predominantly used in:

  • JavaServer Faces (JSF): For binding UI components to backend data/actions.

  • JavaServer Pages (JSP): For data access and manipulation within JSP pages.

  • Contexts and Dependency Injection for Java EE (CDI): For facilitating web layer interaction with managed beans.

Usage Contexts:

  • Spring Framework: Applied in various modules like Security and Data.

  • General Use: Through SpEL API by developers in JVM-based languages like Java, Kotlin, and Scala.

EL's is present in JavaEE technologies, standalone environments, and recognizable through .jsp or .jsf file extensions, stack errors, and terms like "Servlet" in headers. However, its features and the use of certain characters can be version-dependent.

Depending on the EL version some features might be On or Off and usually some characters may be disallowed.

Basic Example

(You can find another interesting tutorial about EL in https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=sponsblog/exploiting-ognl-injection-in-apache-struts/)

Download from the Maven repository the jar files:

  • commons-lang3-3.9.jar

  • spring-core-5.2.1.RELEASE.jar

  • commons-logging-1.2.jar

  • spring-expression-5.2.1.RELEASE.jar

And create a the following Main.java file:

Next compile the code (if you don't have javac installed, install sudo apt install default-jdk):

Execute the application with:

Note how in the previous example the term {5*5} was evaluated.

CVE Based Tutorial

Check it in this post: https://xvnpw.medium.com/hacking-spel-part-1-d2ff2825f62a

Payloads

Basic actions

Detection

  • Burp detection

  • J2EE detection

  • Sleep 10 secs

Remote File Inclusion

Directory Listing

RCE

  • Basic RCE explanation

  • RCE linux

  • RCE Windows (not tested)

  • More RCE

Inspecting the environment

  • applicationScope - global application variables

  • requestScope - request variables

  • initParam - application initialization variables

  • sessionScope - session variables

  • param.X - param value where X is the name of a http parameter

You will need to cast this variables to String like:

Authorization bypass example

The application can also use custom variables like:

WAF Bypass

Check https://h1pmnh.github.io/post/writeup_spring_el_waf_bypass/

References

Last updated