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

## 安装
使用我们的安装脚本安装 cnspec:
**Linux 和 macOS**```bash
bash -c "$(curl -sSL https://install.mondoo.com/sh)"
Windows```powershell 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;
如果你更喜欢手动安装,可以在我们的[发布页面](https://github.com/mondoohq/cnspec/releases)中找到 cnspec 软件包。
## 使用策略运行扫描
使用 `cnspec scan` 子命令检查本地和远程目标的错误配置和漏洞。
### 本地扫描
此命令评估你本地机器的安全性:```bash
cnspec scan local
你也可以指定要扫描的远程目标。例如:```bash
cnspec scan docker image ubuntu:22.04
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
cnspec scan aws
cnspec scan aws ec2 instance-connect root@i-1234567890abcdef0
cnspec scan k8s cnspec scan k8s manifest.yaml
export GITHUB_TOKEN=<personal_access_token> cnspec scan github repo <org/repo>
[:books: 要了解更多信息,请阅读 cnspec 文档。](https://mondoo.com/docs/cnspec)
### 策略
cnspec 策略基于策略即代码的概念构建。cnspec 自带针对所有受支持目标的默认安全策略。默认策略可在本仓库的 `content` 目录中找到。
## 漏洞扫描
cnspec 可扫描多种平台中的漏洞。漏洞扫描不仅限于容器镜像;它同样适用于构建和运行时。

注意:漏洞扫描要求客户端登录 Mondoo Platform。
### 示例```bash
# 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
cnspec 还提供了一个交互式 shell 来探索断言。它可以帮助你理解安全策略所使用的断言,以及编写你自己的策略。它也是即时与本地和远程目标进行交互的绝佳方式。
cnspec shell local
shell 提供了一个 `help` 命令,用于获取有关为 cnspec 提供支持的资源的信息。不带任何参数运行 `help` 会列出所有可用资源及其字段。你也可以运行 `help <resource>` 来获取特定资源的更多详细信息。例如:```bash
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 断言:```coffeescript
ports.listening.none( port == 23 )
要清空终端,请输入 `clear`。
要退出,请按 CTRL + D 或输入 `exit`。
## 使用 Mondoo Platform 优先处理重要风险
Mondoo 统一安全平台能够发现并优先处理对您的业务构成最高风险的漏洞和错误配置。Mondoo 的安全数据架构会在您基础设施的独特上下文中分析每个发现的威胁和暴露情况。Mondoo 不会向您推送大量无关的安全警报,而是向您展示如何对您的安全态势产生即时且显著的影响。
要开始使用,请[联系我们](https://mondoo.com/contact)。
要了解 Mondoo Platform,请阅读 [Mondoo Platform 文档](https://mondoo.com/docs) 或访问 [mondoo.com](https://mondoo.com)。
### 将 cnspec 注册到 Mondoo Platform
要将 cnspec 与 Mondoo Platform 配合使用,请[在 Mondoo App 中生成令牌](https://mondoo.com/docs/cnspec/install/registration),然后运行:```bash
cnspec login --token TOKEN
认证后,你可以扫描任意目标:```bash cnspec scan
cnspec 将扫描结果返回到 `STDOUT` 和 Mondoo Platform。
在 Mondoo Platform 上拥有账户后,您可以上传策略:```bash
cnspec bundle upload mypolicy.mql.yaml
cnspec 策略就是一个 YAML 文件,让你能够为你的设备集群表达任何安全规则或最佳实践。
一些示例可以在本仓库的 examples 文件夹中找到。你可以运行以下任意策略:```bash
cnspec scan local -f examples/example.mql.yaml
如果你有兴趣编写自己的策略或将策略回馈给 cnspec 社区,请阅读 Mondoo 的[策略编写指南](https://mondoo.com/docs/cnspec/write-policies/write-intro)。
## 支持的目标| 目标 | 提供程序 | 示例 |
| ------------------------------ | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| Active Directory 域 | `activedirectory` | `cnspec scan activedirectory --dc DC_HOSTNAME --user USER --password PASSWORD` |
| 阿里云账户 | `alicloud` | `cnspec scan alicloud --access-key-id KEY_ID --access-key-secret KEY_SECRET` |
| Ansible playbook | `ansible` | `cnspec shell ansible YOUR_PLAYBOOK.yml` |
| Apache Cassandra 集群 | `cassandra` | `cnspec scan cassandra HOST --user USER --ask-pass` |
| Arista 网络设备 | `arista` | `cnspec scan arista DEVICE_PUBLIC_IP --ask-pass` |
| Atlassian 组织 | `atlassian admin` | `cnspec shell atlassian admin --admin-token YOUR_TOKEN` |
| Auth0 租户 | `auth0` | `cnspec scan auth0 --domain TENANT_DOMAIN --client-id CLIENT_ID --client-secret CLIENT_SECRET` |
| AWS 账户 | `aws` | `cnspec scan aws` |
| AWS CloudFormation 模板 | `cloudformation` | `cnspec scan cloudformation cloudformation_file.json` |
| AWS EC2 EBS 快照 | `aws ec2 ebs snapshot` | `cnspec scan aws ec2 ebs snapshot SNAPSHOTID` |
| AWS EC2 EBS 卷 | `aws ec2 ebs volume` | `cnspec scan aws ec2 ebs volume VOLUMEID` |
| AWS EC2 Instance Connect | `aws ec2 instance-connect` | `cnspec scan aws ec2 instance-connect ec2-user@INSTANCEID` |
| AWS EC2 实例 | `ssh` | `cnspec scan ssh user@host` |
| Bicep 文件和 ARM 模板 | `bicep` | `cnspec scan bicep BICEP_FILE_OR_PATH` |
| Bitwarden 组织 | `bitwarden` | `cnspec scan bitwarden --client-id organization.UUID --client-secret CLIENT_SECRET` |
| 块设备 | `device` | `cnspec scan device --lun LOGICAL_UNIT_NUMBER` |
| Check Point 管理服务器 | `checkpoint` | `cnspec scan checkpoint --hostname HOSTNAME --api-key API_KEY` |
| Cisco Catalyst 设备 | `ciscocatalyst` | `cnspec scan ciscocatalyst HOSTNAME --user USER --ask-pass` |
| Claude AI 平台账户 | `claude` | `cnspec scan claude --admin-token ADMIN_API_KEY` |
| ClickHouse Cloud 组织 | `clickhousecloud` | `cnspec scan clickhousecloud --organization-id ORG_ID --api-key KEY_ID --ask-secret` |
| ClickHouse 服务器 | `clickhousedb` | `cnspec scan clickhousedb HOST --user USER --ask-pass` |
| Cloudflare 账户 | `cloudflare` | `cnspec scan cloudflare --token ACCESS_TOKEN` |
| Confluence 用户 | `atlassian confluence` | `cnspec shell atlassian confluence --host YOUR_HOST_URL --user USER --user-token YOUR_TOKEN` |
| 容器镜像 | `container`, `docker` | `cnspec scan container ubuntu:latest` |
| 容器注册表 | `container registry` | `cnspec scan container registry index.docker.io/library/rockylinux:8` |
| Databricks 账户 | `databricks` | `cnspec scan databricks --account-id ACCOUNT_ID --client-id CLIENT_ID --client-secret CLIENT_SECRET` |
| Datadog 账户 | `datadog` | `cnspec scan datadog --api-key API_KEY --app-key APP_KEY` |
| DigitalOcean 账户 | `digitalocean` | `cnspec scan digitalocean --token API_TOKEN` |
| DNS 记录 | `host` | `cnspec scan host mondoo.com` |
| Dockerfile | `docker` | `cnspec shell docker file FILENAME` |
| Dropbox Business 团队 | `dropbox` | `cnspec scan dropbox --token TEAM_ACCESS_TOKEN` |
| Elasticsearch 集群 | `elasticsearch` | `cnspec scan elasticsearch HOST --user USER --ask-pass` |
| F5 BIG-IP 系统 | `bigip` | `cnspec scan bigip --hostname HOSTNAME --username USER --ask-pass` |
| 文件系统 | `filesystem` | `cnspec scan filesystem MOUNT_PATH` |
| FortiOS 设备 | `fortios` | `cnspec scan fortios --hostname HOSTNAME --token API_TOKEN` |
| GitHub 组织 | `github org` | `cnspec scan github org mondoohq` |
| GitHub 仓库 | `github repo` | `cnspec scan github repo mondoohq/cnspec` |
| GitLab 群组 | `gitlab` | `cnspec scan gitlab --group mondoohq` |
| Google Cloud 项目 | `gcp` | `cnspec scan gcp` |
| Google Workspace | `google-workspace` | `cnspec scan google-workspace --customer-id CUSTOMER_ID --impersonated-user-email EMAIL --credentials-path JSON_FILE` |
| Grafana 组织 | `grafana` | `cnspec scan grafana --url GRAFANA_URL --token API_TOKEN` |
| HashiCorp Cloud Platform | `hcp` | `cnspec scan hcp --client-id CLIENT_ID --client-secret CLIENT_SECRET` |
| Helm chart | `helm` | `cnspec scan helm CHART_PATH` |
| Hetzner Cloud 项目 | `hetzner` | `cnspec scan hetzner --token API_TOKEN` |
| Hugging Face 命名空间 | `huggingface` | `cnspec scan huggingface --token API_TOKEN --namespace NAMESPACE --namespace-type org` |
| IBM Db2 数据库 | `db2` | `cnspec scan db2 HOST --database DATABASE --user USER --ask-pass` |
| IoT 设备 | `opcua` | `cnspec shell opcua` |
| IP 地址信息 | `ipinfo` | `cnspec shell ipinfo` |
| IPMI 接口 | `ipmi` | `cnspec scan ipmi user@host` |
| Iru 租户 | `iru` | `cnspec scan iru --subdomain SUBDOMAIN --token API_TOKEN` |
| Jamf Pro 账户 | `jamf` | `cnspec scan jamf --client-id CLIENT_ID --client-secret CLIENT_SECRET --instance-domain INSTANCE_URL` |
| JFrog Artifactory 实例 | `artifactory` | `cnspec scan artifactory --url ARTIFACTORY_URL --token ACCESS_TOKEN` |
| Jira 项目 | `atlassian jira` | `cnspec shell atlassian jira --host YOUR_HOST_URL --user USER --user-token YOUR_TOKEN` |
| JumpCloud 组织 | `jumpcloud` | `cnspec scan jumpcloud --api-key API_KEY` |
| Juniper Junos 设备 | `junos` | `cnspec scan junos --hostname DEVICE_IP --username USER_NAME --identity-file SSH_IDENTITY_FILE` |
| Keycloak 服务器 | `keycloak` | `cnspec scan keycloak --url KEYCLOAK_URL --realm REALM --client-id CLIENT_ID --client-secret CLIENT_SECRET` |
| Kubernetes 集群节点 | `local`, `ssh` | `cnspec scan ssh user@host` |
| Kubernetes 集群 | `k8s` | `cnspec scan k8s` |
| Kubernetes 清单 | `k8s` | `cnspec scan k8s manifest.yaml` |
| Kubernetes 工作负载 | `k8s` | `cnspec scan k8s --discover pods,deployments` |
| Kustomize 覆盖层 | `kustomize` | `cnspec scan kustomize OVERLAY_PATH` |
| Linux 主机 | `local`, `ssh` | `cnspec scan local` 或<br></br>`cnspec scan ssh user@host` |
| macOS 主机 | `local`, `ssh` | `cnspec scan local` 或<br></br>`cnspec scan ssh user@IP_ADDRESS` |
| Microsoft 365 租户 | `ms365` | `cnspec scan ms365 --tenant-id TENANT_ID --client-id CLIENT_ID --certificate-path PEM_FILE` |
| Microsoft Azure 实例 | `ssh` | `cnspec scan ssh user@host` |
| Microsoft Azure 订阅 | `azure` | `cnspec scan azure --subscription SUBSCRIPTION_ID` |
| Microsoft SQL Server 实例 | `mssql` | `cnspec scan mssql HOST --user USER --ask-pass` |
| MikroTik RouterOS 设备 | `mikrotik` | `cnspec scan mikrotik user@host --ask-pass` |
| Mistral AI 工作区 | `mistral` | `cnspec scan mistral --token API_KEY --workspace WORKSPACE_ID` |
| Model Context Protocol 服务器 | `mcp` | `cnspec scan mcp http http://localhost:8080/mcp` |
| Mondoo Platform | `mondoo` | `cnspec scan mondoo` |
| MongoDB Atlas 组织 | `mongodbatlas` | `cnspec scan mongodbatlas --org-id ORG_ID --public-key PUBLIC_KEY --private-key PRIVATE_KEY` |
| MongoDB 服务器 | `mongo` | `cnspec scan mongo HOST --user USER --ask-pass` |
| MySQL 和 MariaDB 服务器 | `mysqldb` | `cnspec scan mysqldb HOST --user USER --ask-pass` |
| Neon 组织 | `neon` | `cnspec scan neon --token API_KEY` |
| Netlify 账户 | `netlify` | `cnspec scan netlify --token ACCESS_TOKEN` |
| 通过 SSH 访问的网络设备 | `nd-ssh` | `cnspec scan nd-ssh user@host --ask-pass` |
| NextDNS 账户 | `nextdns` | `cnspec scan nextdns --api-key API_KEY` |
| Nmap 网络扫描 | `nmap` | `cnspec shell nmap host IP_ADDRESS` |
| Nutanix Prism Central | `nutanix` | `cnspec scan nutanix --endpoint ENDPOINT --user USER --ask-pass` |
| Okta 组织 | `okta` | `cnspec scan okta --token TOKEN --organization ORGANIZATION` |
| Ollama 实例 | `ollama` | `cnspec scan ollama --host OLLAMA_URL` |
| OpenAI 账户 | `openai` | `cnspec scan openai --token ADMIN_API_KEY --organization ORG_ID` |
| OpenSearch 集群 | `opensearch` | `cnspec scan opensearch HOST --user USER --ask-pass` |
| OpenStack 项目 | `openstack` | `cnspec scan openstack --cloud CLOUDS_YAML_ENTRY` |
| Oracle Cloud Interface (OCI) | `oci` | `cnspec scan oci` |
| Oracle Database | `oracledb` | `cnspec scan oracledb HOST --service SERVICE_NAME --user USER --ask-pass` |
| PAN-OS 防火墙 | `panos` | `cnspec scan panos --hostname HOSTNAME --username USER --ask-pass` |
| Portainer 实例 | `portainer` | `cnspec scan portainer PORTAINER_URL --access-token ACCESS_TOKEN` |
| PostgreSQL 服务器 | `postgresdb` | `cnspec scan postgresdb HOST --user USER --ask-pass` |
| Proxmox VE 虚拟机监控程序 | `proxmox` | `cnspec scan proxmox --host PROXMOX_URL --token API_TOKEN` |
| Redfish 管理控制器 | `redfish` | `cnspec scan redfish user@host --ask-pass` |
| Redis 和 Valkey 服务器 | `redisdb` | `cnspec scan redisdb HOST --ask-pass` |
| 运行中的容器 | `docker` | `cnspec scan docker CONTAINER_ID` |
| Shodan 搜索引擎 | `shodan` | `cnspec shell shodan` |
| Slack 团队 | `slack` | `cnspec scan slack --token TOKEN` |
| Snowflake 账户 | `snowflake` | `cnspec scan snowflake --account ACCOUNT_ID --region REGION --user USER --role ROLE --token TOKEN` |
| 软件依赖 | `depsdev` | `cnspec scan depsdev PATH_TO_GO_MOD` |
| 网站上的 SSL 证书 | `host` | `cnspec scan host mondoo.com` |
| STACKIT 项目 | `stackit` | `cnspec scan stackit --project-id PROJECT_ID --service-account-key-path KEY_FILE` |
| 子域名 | `networkdiscovery` | `cnspec scan networkdiscovery mondoohq.com --discover subdomains` |
| Tailscale 网络 | `tailscale` | `cnspec scan tailscale --token ACCESS_TOKEN` |
| Terraform HCL | `terraform` | `cnspec scan terraform HCL_FILE_OR_PATH` |
| Terraform plan | `terraform plan` | `cnspec scan terraform plan plan.json` |
| Terraform state | `terraform state` | `cnspec scan terraform state state.json` |
| Together AI 账户 | `together` | `cnspec scan together --token API_KEY` |
| Ubiquiti UniFi 控制器 | `unifi` | `cnspec scan unifi --hostname HOSTNAME --username USER --ask-pass` |
| Vagrant 虚拟机 | `vagrant` | `cnspec scan vagrant HOST` |
| Vercel 账户 | `vercel` | `cnspec scan vercel --token ACCESS_TOKEN` |
| vLLM 推理服务器 | `vllm` | `cnspec scan vllm ENDPOINT` |
| VMware Cloud Director | `vcd` | `cnspec shell vcd --user USER --host HOST --ask-pass` |
| VMware vSphere | `vsphere` | `cnspec scan vsphere user@domain@host --ask-pass` |
| Weaviate 向量数据库 | `weaviate` | `cnspec scan weaviate HOST --api-key API_KEY` |
| Windows 主机 | `local`, `ssh`, `winrm` | `cnspec scan local`、<br></br>`cnspec scan ssh Administrator@IP_ADDRESS --ask-pass` 或<br></br>`cnspec scan winrm Administrator@IP_ADDRESS --ask-pass` |
| Zoom 账户 | `zoom` | `cnspec scan zoom --account-id ACCOUNT_ID --client-id CLIENT_ID --client-secret CLIENT_SECRET` |## Agent 技能
cnspec 包含代理技能,为编码代理提供 MQL 专业知识和策略导航能力。这些技能适用于 Claude Code、Cursor、Gemini CLI 和 Codex。
| 技能 | 描述 |
|-------|-------------|
| [mql](https://github.com/mondoohq/cnspec/blob/main/skills/mql) | MQL 查询开发,包含语法指导、平台特定模式和模式发现 |
| [policy-graph](https://github.com/mondoohq/cnspec/blob/main/skills/policy-graph) | 使用图命令导航策略包 — 搜索、追踪合规映射、探索结构 |
有关安装说明和详细信息,请参阅 [skills/README.md](https://github.com/mondoohq/cnspec/blob/main/skills/README.md)。
## 下一步是什么?
cnspec 能做的事情非常多,从测试整个机群的漏洞到收集信息并为审计人员创建报告。借助其自定义策略,cnspec 可以扫描你关心的任何组件!
探索我们的:
- [cnspec 文档](https://mondoo.com/docs/cnspec)
- [策略即代码](https://mondoo.com/docs/cnspec/write-policies/write-intro)
- [MQL](https://github.com/mondoohq/mql),我们的开源、云原生资产清单框架
- [MQL 介绍](https://mondoohq.github.io/mql-intro/index.html)
- [MQL 资源包](https://mondoo.com/docs/mql/resources)
- [HashiCorp Packer 插件](https://github.com/mondoohq/packer-plugin-mondoo),用于将 cnspec 与 HashiCorp Packer 集成!
## 加入社区!
我们的目标是保护你基础设施的所有层面。如果你需要支持或想参与 cnspec 的开发,请立即加入我们的[社区](https://github.com/orgs/mondoohq/discussions),让我们一起壮大它!
## 开发
有关构建和贡献 cnspec 的信息,请参阅我们的[开发文档](https://github.com/mondoohq/cnspec/blob/main/docs/development.md)。
## 法律
- **版权:** 2018-2026, Mondoo, Inc.
- **许可证:** BUSL 1.1
- **作者:** Christoph Hartmann, Dominik Richter
| 平台 | 版本 |
|---|
| Alpine | 3.10 - 3.24 |
| AlmaLinux | 8, 9, 10 |
| Amazon Linux | 1, 2, 2023 |
| Arch Linux | Rolling |
| 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 |