背景
漏洞描述:2020年12月29日,Nacos官方在github发布的issue中披露Alibaba Nacos 存在一个由于不当处理User-Agent导致的未授权访问漏洞。通过该漏洞,攻击者可以进行任意操作,包括创建新用户并进行登录后操作,以读取系统用户密码为例,如下:
访问接口:http://xxx/nacos/v1/auth/users?pageNo=1&pageSize=9
{
"totalCount": 2,
"pageNumber": 1,
"pagesAvailable": 1,
"pageItems": [
{
"username": "1513",
"password": "$2a$10$89d9KiYtiAhAj7P8EyxLl.vR.YC8uGDuYtzo8JDE9oEz3gl/7fky6"
},
{
"username": "nacos",
"password": "$2a$10$n6uOQweBlQP8mahgzSef7.aYP37e/8FM3xRZvsV4we1Sk.JZ3YTcy"
}
]
}
修复方法
1. nacos服务端开启鉴权
非Docker环境
application.properties中的配置信息新增如下配置:
### If turn on auth system:
nacos.core.auth.system.type=nacos
nacos.core.auth.enabled=true
### 1. 文档中提供的密钥为公开密钥,在实际部署时请更换为其他密钥内容,防止密钥泄漏导致安全风险。
### 2. 在2.2.0.1版本后,社区发布版本将移除以文档如下值作为默认值,需要自行填充,否则无法启动节点。
### 3. 密钥需要保持节点间一致,长时间不一致可能导致403 invalid token错误。
### The default token(Base64 String):
nacos.core.auth.default.token.secret.key=your_secret_key
### 2.1.0 版本后
nacos.core.auth.plugin.nacos.token.secret.key=your_secret_key
Docker环境
如果使用官方镜像,请在启动docker容器时,添加如下环境变量:
NACOS_AUTH_ENABLE=true
参考官方文档:Authorization (nacos.io)
2. 客户端鉴权配置
此处以Java客户端为例,其他客户端类似。
Nacos Spring Cloud
注册中心和配置中心的依赖版本需要 >=2.1.4.RELEASE 或者 >=2.2.4.RELEASE
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>${latest.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>${latest.version}</version>
</dependency>
application.yml中的配置中心和服务发现,新增加username和password的配置项。
spring:
cloud:
nacos:
config:
server-addr: ${NACOS_URL}
username: xxxx
password: xxxx
discovery:
server-addr: ${NACOS_URL}
username: xxxx
password: xxxx
其中用户名和密码可以在nacos服务端控制台获取,nacos服务端控制台:
注意: 用户一定要有相应服务命名空间的读写权限。
Nacos Springboot
注册中心和配置中心的依赖版本需要 >=0.1.8 或者 >=0.2.8
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>${latest.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-discovery-spring-boot-starter</artifactId>
<version>${latest.version}</version>
</dependency>
application.properties中的配置中心和服务发现,新增加username和password的配置项。
nacos.config.server-addr=127.0.0.1:8848
nacos.config.username=xxxx
nacos.config.password=xxxx
nacos.discovery.server-addr=127.0.0.1:8848
nacos.discovery.username=xxxx
nacos.discovery.password=xxxx
参考官方文档:
Releases · nacos-group/nacos-spring-boot-project · GitHub
Nacos Dubbo
dubbo的依赖版本需要 >=2.7.11
<!-- Dubbo Spring Boot Starter -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo.version}</version>
</dependency>
<!--curator-recipes-->
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>${dubbo.version}</version>
</dependency>
<!-- dubbo-registry-nacos -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-nacos</artifactId>
<version>${dubbo.version}</version>
</dependency>
application.properties中的配置中心和服务发现,新增加username和password的配置项。
dubbo.registry.address=nacos://127.0.0.1:8848?username=xxx&password=xxx
如果这篇文章帮助到了你,欢迎评论、点赞、转发。