semx/aws-exposure-scanner
GitHub: semx/aws-exposure-scanner
一款轻量级只读的 AWS 账户安全暴露扫描工具,能够检测安全组、S3 和 IAM 的常见风险配置并输出多种格式的报告。
Stars: 0 | Forks: 0
# aws-exposure-scanner
[](https://github.com/semx/aws-exposure-scanner/actions/workflows/ci.yml)


一个轻量级、**只读**的命令行扫描工具,用于发现 AWS 账户中最常见的安全暴露风险,并以人类可读的表格、JSON 或
**SARIF 2.1.0** 格式输出报告,以便用于 GitHub 的代码扫描 / Security 标签页。
它主要检查在实际安全事件中最常涉及的三种服务:
| 服务 | 检查项 |
| --- | --- |
| **Security Groups** | 入站规则对 `0.0.0.0/0` / `::/0` 开放,针对管理/数据库端口(SSH、RDP、MySQL、Postgres、Redis、Mongo 等)进行升级提醒,广泛的端口范围,以及“所有端口”规则。 |
| **S3** | 公开 ACL 授权,缺失/部分配置 Block Public Access,通配符 principal 的 bucket 策略,缺失默认加密,禁用版本控制。 |
| **IAM** | 未启用 MFA 的控制台用户,超过 N 天未更换的 access key,具备管理员权限的用户,授予 `Action:* Resource:*` 权限的客户管理策略。 |
该扫描器仅调用 `Describe*`/`Get*`/`List*` API —— 它绝不会对任何资源进行修改。
## 安装
```
pipx install git+https://github.com/semx/aws-exposure-scanner
# 或者,从 clone 中:
pip install -e ".[dev]"
```
## 使用说明
```
# 扫描默认的 profile/region,以人类可读的 table 显示:
aws-exposure-scanner scan
# 指定 profile 和多个 region,仅扫描 Security Groups:
aws-exposure-scanner scan --profile prod -r us-east-1 -r eu-west-1 --only security-groups
# 机器可读的输出:
aws-exposure-scanner scan -o json --out-file findings.json
aws-exposure-scanner scan -o sarif --out-file results.sarif
# 仅报告 HIGH+ 并在任何 CRITICAL 项上 fail CI:
aws-exposure-scanner scan --min-severity HIGH --fail-on CRITICAL
```
`axs` 是该命令的一个简短别名。
### 输出示例
```
AWS exposure findings
┏━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Severity ┃ Service ┃ Region ┃ Resource ┃ Rule ┃ Finding ┃
┡━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ CRITICAL │ ec2 │ us-east-1 │ sg-0a1b2c3d │ SG_OPEN_ALL_PORTS │ …all ports… │
│ HIGH │ iam │ global │ deploy-bot │ IAM_ADMIN_USER │ …admin access │
│ MEDIUM │ s3 │ us-east-1 │ app-uploads │ S3_NO_PUBLIC_A… │ …no PAB… │
└──────────┴─────────┴───────────┴─────────────┴───────────────────┴───────────────┘
Summary: 1 CRITICAL, 1 HIGH, 1 MEDIUM
```
## GitHub Actions 集成
上传 SARIF 文件,以便扫描结果能够显示在代码库的 **Security → Code scanning** 标签页中:
```
- run: aws-exposure-scanner scan -o sarif --out-file results.sarif --fail-on NONE
- uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
```
## 退出代码
| 代码 | 含义 |
| --- | --- |
| `0` | 运行完成;在 `--fail-on` 设定级别或以上没有发现任何风险。 |
| `1` | 运行完成;在 `--fail-on` 设定级别或以上(默认为 `HIGH`)至少发现一项风险。 |
| `2` | 使用方式或 AWS 错误(参数错误、凭证缺失、API 错误)。 |
## 所需的 IAM 权限
只读权限。AWS 托管策略 `SecurityAudit`(或 `ReadOnlyAccess`)即可满足要求。
具体调用的 API 包括 `ec2:DescribeSecurityGroups`、`s3:ListAllMyBuckets`、
`s3:GetBucket*`、`s3:GetPublicAccessBlock`,以及 `iam:List*`/`iam:Get*`。
## 开发说明
```
python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"
ruff check src tests
mypy src
pytest # tests run fully offline against moto — no real AWS account needed
```
## 开源协议
MIT
标签:AWS, DPI, Python, 数据泄露, 无后门, 聊天机器人, 逆向工具, 配置核查