Spring Boot应用安全加固实战:Actuator未授权与ScriptEngine注入漏洞修复

Spring Boot Actuator 未授权访问:3种利用手法与2种加固方案对比 本文深入探讨了Spring Boot Actuator未授权访问的安全风险,详细演示了三种高危漏洞利用手法,包括环境信息泄露、配置属性注入和内存敏感数据提取。同时对比分析了两种企业级防护方案(端点路径修改与Spring Security集成)的优劣,并提供了渗透测试环境搭建与加固建议,帮助开发者有效防范此类安全威胁。 阅读详情

1. 项目概述:一次典型的Spring Boot应用安全加固实战

最近在帮一个朋友的公司做内部系统的安全评估,他们用的是基于 nbcio-boot 这个开源框架搭建的后台管理系统。这个框架本身功能挺全,整合了Spring Boot、MyBatis-Plus、Flowable工作流这些主流技术栈,开发效率很高。但在做代码审计时,我发现了两个比较典型且危险的安全漏洞:一个是Actuator端点的未授权访问,另一个是ScriptEngine的代码注入风险。这两个问题在Spring Boot生态里其实挺常见的,但很多开发团队在追求功能快速上线时,很容易忽略掉。今天我就把这次审计和修复的过程详细拆解一下,尤其是针对 nbcio-boot 这个具体框架的上下文,希望能给正在使用类似技术栈或者关心应用安全的同学一些直接的参考。你不需要是安全专家,只要对Spring Boot开发有基本了解,就能看懂并应用到自己的项目里。

简单来说,这次要处理的核心就两件事:第一,防止任何人不用登录就能访问到 /actuator 下面的健康检查、内存信息、线程堆栈等敏感接口,这些信息泄露可能导致攻击者摸清系统底细;第二,堵住通过ScriptEngine执行任意代码的口子,这相当于给攻击者开了一个在服务器上直接运行命令的后门,危害极大。修复的思路并不复杂,关键是理解漏洞产生的原理,以及如何在 nbcio-boot 现有的项目结构中找到最合适、侵入性最小的修补点。

2. 漏洞原理深度剖析:为什么会出现这些问题?

在动手修复之前,我们必须先把这两个漏洞的来龙去脉搞清楚。知其然更要知其所以然,这样以后遇到类似问题,你才能举一反三。

2.1 Actuator未授权访问:便利性与安全性的失衡

Spring Boot Actuator是个非常棒的生产就绪特性模块,它提供了一系列HTTP或JMX端点(Endpoints),让你能监控和管理正在运行的应用。比如查看健康状态( /actuator/health )、查看环境变量( /actuator/env )、查看映射的URL( /actuator/mappings ),甚至能优雅关闭应用( /actuator/shutdown ,默认关闭)。

在 nbcio-boot 的默认配置或者很多快速启动的教程里,为了图方便,开发者可能会在 application.yml 里简单地写上:

management:
  endpoints:
    web:
      exposure:
        include: "*" # 暴露所有端点

或者直接依赖了 spring-boot-starter-actuator 但没有做任何安全配置。问题就出在这里: 这些暴露的端点默认是没有接入应用自身的安全框架(如Spring Security)的 。它们运行在一个独立的管理上下文里。

这意味着,即使你的业务接口 /api/user/login 有严格的JWT或Session校验,攻击者依然可以直接访问 http://你的服务器:端口/actuator/env ,拿到数据库连接密码、第三方API密钥等所有环境变量;访问 /actuator/heapdump 可以下载整个JVM堆内存快照,用MAT等工具分析能还原出敏感数据; /actuator/mappings 会泄露所有控制器路径,相当于给了攻击者一份完整的API地图。

漏洞的本质 :Actuator端点的暴露范围( management.endpoints.web.exposure.include )和对其的访问控制(认证与授权)是两件独立的事情。只配置了暴露,没配置保护,就等于把后门敞开了。

2.2 ScriptEngine注入漏洞:动态执行的“双刃剑”

nbcio-boot 框架中,为了支持动态流程表达式或者某些灵活的脚本配置功能,可能会引入或使用Java的 ScriptEngineManager 。例如,允许在流程定义中写一段Groovy或JavaScript逻辑来判断审批条件。

一个存在风险的代码片段可能长这样:

@PostMapping("/eval")
public String evaluateScript(@RequestParam String script) {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("javascript");
    try {
        // 危险!直接执行用户传入的脚本
        return engine.eval(script).toString();
    } catch (ScriptException e) {
        return "Error: " + e.getMessage();
    }
}

或者更隐蔽一些,从数据库、配置文件、前端传入的某个参数,最终被拼接成脚本字符串交给了 ScriptEngine 执行。

漏洞的本质 : ScriptEngine.eval() 或 engine.createScript().eval() 这类方法,如果其输入源(参数、请求体、数据库字段)完全或部分由用户控制,且没有经过严格的净化和沙箱隔离,就等同于允许攻击者在服务器上执行任意代码。JavaScript引擎可以调用Java类,Groovy引擎功能更强大,几乎能完成任何操作,比如 “java.lang.Runtime.getRuntime().exec(‘rm -rf /’)“ 。

在 nbcio-boot 的上下文中,需要重点审计与工作流(Flowable)、规则引擎、动态报表生成相关的服务类,查找所有使用 javax.script.ScriptEngine 或 org.springframework.scripting 包的地方。

3. 修复方案设计与实施:精准施策,最小化改动

理解了漏洞原理,修复目标就明确了:对Actuator,我们要么限制暴露的端点,要么给暴露的端点加上安全锁;对ScriptEngine,我们要彻底杜绝不可信数据流入执行引擎。下面我结合 nbcio-boot 的项目结构,给出具体的修复步骤。

3.1 Actuator未授权访问漏洞修复

对于Actuator的修复,通常有四种策略,按推荐度排序:

  1. 策略一:严格限制暴露的端点(最推荐) 。只暴露真正需要的、不敏感的端点。
Spring Boot FatJar文件写入漏洞到RCE攻击链深度剖析 在Java应用安全领域,文件写入漏洞常被视为中低风险,但其与特定框架机制结合可能引发严重后果。Spring Boot的FatJar打包方式通过LaunchedURLClassLoader实现自包含部署,这种类加载机制在特定配置下会扫描外部目录。当应用存在目录遍历或未授权文件写入漏洞时,攻击者可植入恶意JAR文件。结合Spring Boot的loader.path系统属性或DevTools重启机制,恶意类可能被加载执行,实现远程代码执行。这种攻击链利用了FatJar运行原理与框架热加载特性的安全盲区,在配置不 阅读详情

相关推荐

Mythos如何重塑AI安全:从漏洞扫描到自主攻防的范式跃迁

AI安全正经历从静态检测到动态攻防的根本性转变。传统SAST/DAST工具依赖规则匹配,难以应对逻辑漏洞与零日风险;而以Claude Mythos为代表的新型AI安全模型,依托长程规划能力、推理时强化学习(RL)编排与百万级token沙盘推演,实现了从‘解题’到‘造局’的跨越。其核心价值在于将软件安全升维为端到端攻击链建模——涵盖侦察、横向移动、提权与持久化,直击FreeBSD、FFmpeg、OpenBSD等真实系统中的陈年漏洞。这种能力不仅刷新了CVE发现效率,更倒逼防御体系转向‘漏洞免疫’‘红蓝对抗即服

aocaiti5781的博客 395

Spring Boot Actuator未授权访问安全指南:从原理到修复

Spring Boot Actuator作为应用监控与运维管理组件,提供了大量运行时端点,用于查看健康状态、环境配置、JVM堆快照等。若这些端点未受访问控制,将形成严重的安全隐患,即未授权访问。攻击者只需请求/actuator/env、/actuator/heapdump等路径即可获取敏感配置与内存数据。因此,必须理解Actuator端点暴露原理、配置分层以及常见风险。在生产环境中,开发者需要结合Spring Security、独立管理端口、细粒度ID过滤等方式,对Actuator端点进行安全加固,确保服务

weixin_31648507的博客 249

吃透 AM32 无人机电调:从源码架构到工作原理的全方位解析(附实践指南)(上)

本文深入解析了AM32电调固件的源码架构与核心模块实现。文章首先介绍了AM32电调作为开源无人机;动力心脏的重要地位,随后从硬件基础、源码目录、模块划分三个维度构建解析框架。重点剖析了系统初始化模块的时钟配置、GPIO初始化和定时器设置,以及FOC控制模块的坐标变换算法、角度估算和SVPWM生成等关键技术实现。通过逐行代码解析,揭示了电调如何将飞控指令转换为电机驱动的完整过程,为开发者理解AM32电调工作原理提供了系统性指导。

bother3000的博客 6613

瑞芯微RK3576开发板实战:6TOPS NPU如何加速你的AIoT项目(附性能测试)

本文以瑞芯微RK3576开发板为核心,深入探讨其6TOPS NPU在AIoT项目中的实战应用。通过详细的性能测试对比,展示了NPU如何将AI模型推理速度提升15倍以上,并大幅降低CPU负载。文章涵盖从环境搭建、模型转换优化到多屏异显与系统级调优的全流程,为开发者提供了将硬件算力转化为实际项目加速效果的完整指南。

oauth7security的博客 826

STM32H743 LAN8720网口配置避坑指南:用CubeMX v6.5.0快速搞定LWIP+FreeRTOS

本文详细介绍了使用CubeMX v6.5.0配置STM32H743与LAN8720网口的LWIP+FreeRTOS方案,涵盖硬件连接、时钟配置、ETH外设初始化及LWIP协议栈调优等关键步骤。特别针对常见陷阱提供解决方案,帮助开发者快速实现稳定网络通信,适用于嵌入式网络开发场景。

weixin_33739523的博客 362

Android Studio运行报错: failed to load include path ……\platforms\android-35\android.jar的最细解决方案

【代码】Android Studio运行报错: failed to load include path ……\platforms\android-35\android.jar的最细解决方案。

2401_86789230的博客 2万+

《哥谭神话-工程篇》02.Palantir的Ontology层(语义层) -企业操作系统的大脑

Ontology(语义层) 是Foundry 的核心层。Ontology 位于集成到 Foundry 中的数字资产(数据集和模型)之上,并将其连接到现实世界的对应物,从工厂、设备和产品等物理资产到客户订单或金融交易等概念。本篇将详细拆解Ontology(语义层)。

917

深入解析 ReDoc:从零构建高性能 API 文档的终极指南

ReDoc 是一个强大的开源工具,用于将 OpenAPI 规范转换为高质量、响应式的 API 文档。本文详细介绍了如何使用 ReDoc 构建和自定义 API 文档,包括如何编写支持 OpenAPI 的 API 注解、配置 HTML 页面以加载文档,以及如何利用 ReDoc 的高级功能进行定制。通过实例代码,您将学会如何灵活地展示 API 文档,提升用户体验。无论是初学者还是经验丰富的开发者,都能从本文中获得实用的技巧与方案,帮助快速搭建符合需求的 API 文档界面。

楠搏万的博客 4654

PCL 改进的RANSAC算法实现点云粗配准【2024最新版】

一种改进的RANSAC点云粗配准算法,具体改进见论文:“Pose Estimation using Local Structure-Specific Shape and Appearance Context”

点云侠的博客 37万+

数仓建模—数据语义层

如今,企业产生大量数据,需要以正确的方式进行分析才能做出重要决策。数据可能来自多个来源并采用不同的格式,这使得清楚地了解其含义和重要性成为一项挑战。这就是语义层的用武之地。语义层存在于数据仓库和最终用户使用的应用程序之间。它为用户提供了简化且一致的数据视图,无论其基础数据源的复杂性如何。该逻辑层有助于映射物理数据结构以创建概念数据模型。它定义了数据元素之间的所有规则和关系,并以业务术语提供了数据的通用词汇表。然后,用户可以轻松地与数据进行交互,而无需了解其数据源的技术知识。

7万+

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

上一篇: PSoC62与HS3003实现超低功耗温湿度监测方案
下一篇: Ubuntu安装搜狗输入法及Qt Creator中文输入优化指南
aaa1231722
博客等级 码龄12年 6粉丝 425原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值