开源、云原生安全与策略项目
cnspec 评估你整个基础设施的安全性与合规性。它能在公有云和私有云环境、Kubernetes 集群、容器、容器镜像仓库、服务器、终端、SaaS 产品、基础设施即代码、API 等各类环境中发现漏洞和错误配置。
作为一款强大的策略即代码引擎,cnspec 构建于 Mondoo 的安全数据织构之上。它预置了开箱即用的默认安全策略,既快速又易于使用!
bash -c "$(curl -sSL https://install.mondoo.com/sh)"
cnspec scan local

使用我们的安装脚本安装 cnspec:
Linux 和 macOS
bash -c "$(curl -sSL https://install.mondoo.com/sh)"
Windows
Set-ExecutionPolicy Unrestricted -Scope Process -Force;
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
iex ((New-Object System.Net.WebClient).DownloadString('https://install.mondoo.com/ps1'));
Install-Mondoo;
如果你更倾向于手动安装,可以在我们的 releases 中找到 cnspec 软件包。
使用 cnspec scan 子命令检查本地和远程目标是否存在错误配置和漏洞。
此命令评估本地机器的安全性:
cnspec scan local
你也可以指定要扫描的远程目标。例如:
# to scan a docker image:
cnspec scan docker image ubuntu:22.04
# scan public ECR registry
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/r6z5b8t4
cnspec scan docker image public.ecr.aws/r6z5b8t4
# to scan an AWS account using the local AWS CLI config
cnspec scan aws
# scan an EC2 instance with EC2 Instance Connect
cnspec scan aws ec2 instance-connect root@i-1234567890abcdef0
# to scan a Kubernetes cluster via your local kubectl config or a local manifest file
cnspec scan k8s
cnspec scan k8s manifest.yaml
# to scan a GitHub repository
export GITHUB_TOKEN=<personal_access_token>
cnspec scan github repo <org/repo>
cnspec 策略基于策略即代码(policy as code)的概念构建。cnspec 自带针对所有受支持目标的默认安全策略。默认策略可在本仓库的 content 目录中找到。
cnspec 可对多种平台进行漏洞扫描。漏洞扫描并不局限于容器镜像;它同样适用于构建和运行时环境。

注意:漏洞扫描要求客户端登录 Mondoo Platform。
# scan container image
cnspec vuln docker debian:12
# scan aws instance via EC2 instance connect
cnspec vuln aws ec2 instance-connect root@i-1234567890abcdef0
# scan instance via SSH
cnspec vuln ssh user@host
# scan windows via SSH or Winrm
cnspec vuln ssh user@host --ask-pass
cnspec vuln winrm user@host --ask-pass
# scan VMware vSphere ESXi hosts
cnspec vuln vsphere user@host --ask-pass
# scan Linux, Windows
cnspec vuln local
| 平台 | 版本 |
|---|---|
| Alpine | 3.10 - 3.24 |
| AlmaLinux | 8, 9, 10 |
| Amazon Linux | 1, 2, 2023 |
| Arch Linux | 滚动更新 |
| CentOS | 6, 7, 8, Stream |
| Debian | 8, 9, 10, 11, 12, 13 |
| Fedora | 30 - 44 |
| openSUSE | Leap 15, Leap 16 |
| Oracle Linux | 6, 7, 8, 9, 10 |
| Photon Linux | 2, 3, 4, 5 |
| Red Hat Enterprise Linux | 6, 7, 8, 9, 10 |
| Rocky Linux | 8, 9, 10 |
| SUSE Linux Enterprise | 12, 15, 16 |
| Ubuntu | 18.04, 20.04, 22.04, 24.04, 26.04 |
| VMware vSphere ESXi | 6, 7, 8, 9 |
| Windows | 10, 11, 2016, 2019, 2022, 2025 |
cnspec 还提供了一个交互式 shell 来探索断言。它可以帮助你理解安全策略所使用的断言,也可以帮助你编写自己的策略。它也是即时与本地和远程目标进行交互的绝佳方式。
cnspec shell local
shell 提供了一个 help 命令,用于获取有关为 cnspec 提供支持的资源的信息。不带任何参数运行 help 会列出所有可用资源及其字段。你也可以运行 help <resource> 来获取特定资源的更多详细信息。例如:
cnspec> help ports
ports: TCP/IP ports on the system
list []port: List of all TCP/IP ports
listening []port: All listening ports
该 shell 使用自动补全功能,便于探索。
进入 shell 后,你可以输入如下 MQL 断言:
> ports.listening.none( port == 23 )
要清空终端,请输入 clear。
要退出,请按 CTRL + D 或输入 exit。
Mondoo 统一安全平台可发现并优先处理对您的业务构成最高风险的漏洞和错误配置。Mondoo 的安全数据织构会在您基础设施的独特上下文中分析每一项发现的威胁和暴露情况。Mondoo 不会向您推送大量无关的安全警报,而是向您展示如何对您的安全态势产生即时且显著的影响。
要开始使用,请联系我们。
要了解 Mondoo Platform,请阅读 Mondoo Platform 文档或访问 mondoo.com。
要将 cnspec 与 Mondoo Platform 配合使用,请在 Mondoo App 中生成令牌,然后运行:
cnspec login --token TOKEN
认证成功后,你可以扫描任意目标:
cnspec scan <target>
cnspec 将扫描结果返回到 STDOUT 和 Mondoo Platform。
在 Mondoo Platform 上拥有账户后,你可以上传策略:
cnspec bundle upload mypolicy.mql.yaml
cnspec 策略就是一个简单的 YAML 文件,让你能够为你的设备群表达任何安全规则或最佳实践。
在本仓库的 examples 文件夹中可以找到一些示例。你可以运行其中任意一个策略:
cnspec scan local -f examples/example.mql.yaml
如果你有兴趣编写自己的策略,或将策略贡献回 cnspec 社区,请阅读 Mondoo 的策略编写指南。