Und3r__Score__

Spring Boot Actuator Misconfiguration 본문

취약점진단/WEB

Spring Boot Actuator Misconfiguration

_underscore_ 2024. 2. 20. 14:07

해당 게시글은 아래의 페이지를 번역하여 정리 및 참고하였습니다.

Expoting Spring Boot Actuators

 

Exploiting Spring Boot Actuators | Veracode

This post was updated May 1, 2019 The Spring Boot Framework includes a number of features called actuators to help you monitor and manage your web application when you push it to production. Intended to be used for auditing, health, and metrics gathering,

www.veracode.com

Sprint Boot Actuator

 

Production-ready Features

You can enable recording of HTTP exchanges by providing a bean of type HttpExchangeRepository in your application’s configuration. For convenience, Spring Boot offers InMemoryHttpExchangeRepository, which, by default, stores the last 100 request-response

docs.spring.io

Application Security Cheat Sheet - Spring Boot Actuators

 

 

Spring Boot Actuator?

Spring Boot Framework에는 웹 애플리케이션을 모니터링하고 관리하는데 도움이 되는 Actuator라는 다양한 기능이 포함된 도구를 제공하고 있습니다. 감사, health check, metrics gathering 등에 사용되는 Actuator가 잘못 구성될 경우 취약점이 발생할 수 있습니다.

 

Spring Boot  애플리케이션이 실행 중일 경우 자동으로 /health, /trace, /beans, /env와 같은 엔드포인트를 라우팅 프로세스에 등록합니다. Spring Boot 1 ~ 1.4의 경우 이러한 엔드포인트에 인증 없이 액세스가 가능하여 보안에 심각한 문제가 발생합니다. Spring Boot 1.5부터는 /health, /info를 제외한 모든 엔드포인트는 기본적으로 인증 없이 액세스가 불가능하지만, 개발자가 이러한 보안 설정을 비활성화하는 경우가 존재합니다.

 

 

Spring Boot Actuator endpoints 

각 endpoint는 enable/disable하고 HTTP 또는 JMX를 통해 expose(원격 접근)할 수 있습니다. 대부분의 애플리케이션은 /actuator에 endpoint ID를 이어 붙인 URL을 사용하여 HTTP를 통한 expose (원격 접근)을 할 수 있도록 설정되어 있습니다. 예를 들어 health endpoint는 /actutator/health에 매핑됩니다. (Spring 1x의 경우에는 root URL에 매핑됩니다.)

 

아래는 endpoint list 입니다. enable 되고 expose 될 경우 취약점이 존재할 수 있는 endpoint는 음영 처리로 표기하였습니다.

ID Description
auditevents Exposes audit events information for the current application. Requires an AuditEventRepository bean.
beans Displays a complete list of all the Spring beans in your application.
caches Exposes available caches.
conditions Shows the conditions that were evaluated on configuration and auto-configuration classes and the reasons why they did or did not match.
configprops Displays a collated list of all @ConfigurationProperties. Subject to sanitization.
env Exposes properties from Spring’s ConfigurableEnvironment. Subject to sanitization.
flyway Shows any Flyway database migrations that have been applied. Requires one or more Flyway beans.
health Shows application health information.
httpexchanges Displays HTTP exchange information (by default, the last 100 HTTP request-response exchanges). Requires an HttpExchangeRepository bean.
info Displays arbitrary application info.
integrationgraph Shows the Spring Integration graph. Requires a dependency on spring-integration-core.
loggers Shows and modifies the configuration of loggers in the application.
liquibase Shows any Liquibase database migrations that have been applied. Requires one or more Liquibase beans.
metrics Shows “metrics” information for the current application.
mappings Displays a collated list of all @RequestMapping paths.
quartz Shows information about Quartz Scheduler jobs. Subject to sanitization.
scheduledtasks Displays the scheduled tasks in your application.
sessions Allows retrieval and deletion of user sessions from a Spring Session-backed session store. Requires a servlet-based web application that uses Spring Session.
shutdown Lets the application be gracefully shutdown. Only works when using jar packaging. Disabled by default.
startup Shows the startup steps data collected by the ApplicationStartup. Requires the SpringApplication to be configured with a BufferingApplicationStartup.
threaddump Performs a thread dump.

 

만약 애플리케이션이 웹 애플리케이션(Spring MVC, Spring WebFlux, Jersey)인 경우에는 아래와 같은 추가 endpoint 사용이 가능합니다.

ID Description
heapdump Returns a heap dump file. On a HotSpot JVM, an HPROF-format file is returned. On an OpenJ9 JVM, a PHD-format file is returned.
logfile Returns the contents of the logfile (if the logging.file.name or the logging.file.path property has been set). Supports the use of the HTTP Range header to retrieve part of the log file’s content.
prometheus Exposes metrics in a format that can be scraped by a Prometheus server. Requires a dependency on micrometer-registry-prometheus.

 

 

진단 예시 CASE

heapdump endpoints는 heap dump file을 return합니다. HotSpot JVM의 경우 HPROF 포맷의 파일을, OpenJ9 JVM의 경우 PHD 포맷의 파일을 return 합니다. 중요정보가 메모리에 존재하는 경우 문제가 될 수 있습니다.

 

"env endpoint - 중요 정보 노출"

/actuator/env 로 접근하여 Spring의 ConfigurableEnvironment 속성을 확인합니다. 아래 사진과 같이 datasource와 관련된 중요 정보가 노출되고 있었습니다.  actuator에서는 다소 민감할 수 있는 특정 패턴(ex. password)과 일치하는 키는 기본적으로 *로 대체시킵니다. 

 

"heapdump endpoint - 중요 정보 노출"

/actuator/heapdump로 접근하여 heap dump file을 다운로드합니다. HotSpot JVM의 경우 HPROF 포맷의 파일을, OpenJ9 JVM의 경우 PHD 포맷의 파일을 return 합니다. 진단 시 다운로드된 파일은 HPROF 포맷의 파일이었습니다. 해당 포맷의 파일은 Eclipse Memory Analyzer로 확인이 가능합니다. Eclipse Memory Analyzer를 이용하면 OQL(Object Query Language)를 이용하여 다운로드된 파일 분석이 가능합니다. OQL은 메모리 분석용 언어이며 사용법이  SQL과 유사합니다.

 

Eclipse Memory Analyzer로 env endpoint에서 확인이 불가능했던 spring.datasource.password 키의 값을 확인할 수 있었습니다.

 

env endpoint 결과 사진에는 없지만 다양한 token 값들도 * 처리가 되어있었는데 그중 slack.token 값도 있었습니다. heap dump file에서 slack.token 값을 확인하였으며, 실제로 해당 token 값으로 slack 메시지 전송이 가능했습니다.