DunneSecurity/SecurityAuditScripts
GitHub: DunneSecurity/SecurityAuditScripts
一套面向多云与本地环境的模块化安全审计工具,生成可评分的执行摘要与合规映射报告。
Stars: 0 | Forks: 0
# 🛡️ 安全审计脚本
[](https://github.com/Decdd19/SecurityAuditScripts/actions/workflows/ci.yml)
适用于 AWS、Azure、M365、Windows/Linux 本地环境以及网络服务的独立安全审计脚本。无需代理、无需 SaaS — 运行并审查。
## 架构
```
graph TD
O["🎯 audit.py — Python Orchestrator\nRich progress UI · ThreadPoolExecutor · exec summary"]
P["⚡ Run-Audit.ps1 — PowerShell Orchestrator\nAzure · M365 · Windows · exec summary"]
subgraph AWS["☁️ AWS — 15 auditors (Python · boto3)"]
A["IAM · S3 · CloudTrail · SG · Root · EC2\nRDS · GuardDuty · VPC Flow Logs · Lambda\nSecurity Hub · KMS · ELB · Config · Backup"]
end
subgraph Linux["🐧 Linux — 5 auditors (Python · sudo)"]
L["Users · Firewall · Sysctl · Patch · SSH"]
end
subgraph Azure["🔷 Azure — 11 auditors (PowerShell · Az module)"]
AZ["Entra · Entra Password Policy · Hybrid Identity\nStorage · Activity Log · NSG · Subscription\nKey Vault · Defender · Policy · Backup"]
end
subgraph M365["📨 M365 — 6 auditors (PowerShell · Graph · ExO · SPO · Teams)"]
M["CA MFA · Legacy Auth · Mailbox Forwarding · OAuth Consent · MFA Coverage · Admin Roles\nSharePoint Sharing · Teams Federation · Intune Compliance · Exchange Transport Rules\nDefender for Endpoint (MDE onboarding · RTP · encryption · tamper · scan age)"]
end
subgraph Windows["🪟 Windows — 8 auditors (PowerShell)"]
W["AD · Local Users · Firewall · SMB Signing\nAudit Policy · BitLocker · LAPS · Patch"]
end
subgraph Email["📧 Email — 1 auditor (Python · dnspython)"]
E["SPF · DKIM · DMARC"]
end
subgraph Network["🌐 Network — 2 auditors (Python · stdlib)"]
N["SSL/TLS Certificates · HTTP Security Headers"]
end
O -->|"--aws"| AWS
O -->|"--linux"| Linux
O -->|"--email --domain"| Email
O -->|"--ssl / --http-headers --domain"| Network
P -->|"-Azure"| Azure
P -->|"-M365"| M365
P -->|"-Windows"| Windows
AWS --> S["📊 exec_summary.py\nCross-cloud HTML report · Security score 0–100"]
Linux --> S
Azure --> S
M365 -.->|"JSON reports"| S
Email --> S
Network --> S
Windows -.->|"JSON reports"| S
```
## 快速开始
### Python 编排器 — AWS · Linux · 邮件 · 网络
```
git clone https://github.com/Decdd19/SecurityAuditScripts.git
cd SecurityAuditScripts
pip install boto3 rich
# 完成完整的 AWS + Linux 审计,完成后打开 HTML 报告
sudo python3 audit.py --client "Acme Corp" --aws --linux --open --output ./reports/
```
### PowerShell 编排器 — Azure · M365 · Windows
```
git clone https://github.com/Decdd19/SecurityAuditScripts.git
cd SecurityAuditScripts
Connect-AzAccount
# 完成所有 Azure + M365 + Windows 审计,完成后打开 HTML 报告
.\Run-Audit.ps1 -Client "Acme Corp" -All -AllSubscriptions -Open
```
## 编排器
### audit.py
并行运行 AWS、Linux、邮件和网络审计器,并带有实时的 Rich 进度界面。
```
python3 audit.py --client "Acme Corp" --aws --linux --profile prod
python3 audit.py --client "Acme Corp" --aws --regions eu-west-1 us-east-1
python3 audit.py --client "Acme Corp" --email --ssl --http-headers --domain acme.ie
```
**标志:** `--aws` · `--linux` · `--all` · `--quick` · `--ssl` · `--http-headers` · `--email` · `--domain` · `--profile` · `--regions` · `--output` · `--workers` · `--open` · `--severity-threshold`
### Run-Audit.ps1
按顺序运行 Azure、M365 和 Windows 本地审计器,然后生成执行摘要。
```
.\Run-Audit.ps1 -Client "Acme Corp" -Azure -AllSubscriptions
.\Run-Audit.ps1 -Client "Acme Corp" -M365 -SkipSummary
.\Run-Audit.ps1 -Client "Acme Corp" -All -OutputDir C:\Reports -Open
```
**标志:** `-Azure` (11) · `-M365` (6) · `-Windows` (8) · `-All` · `-Quick` · `-AllSubscriptions` · `-OutputDir` · `-SkipSummary` · `-Open` · `-SeverityThreshold`
## 脚本
每个审计器都会生成 JSON + CSV + HTML 输出,并将发现映射到 CIS v8 控制项。请参阅各子目录的 README 以获取完整的检查详情。
### AWS (15 个审计器)
| 审计器 | 检查内容 |
|---------|----------------|
| [IAM](./AWS/iam-privilege-mapper/) | 权限提升路径、旧凭证、MFA 缺口 |
| [S3](./AWS/s3-auditor/) | 公开访问、加密、版本控制、日志记录 |
| [CloudTrail](./AWS/cloudtrail-auditor/) | 多区域覆盖、KMS 加密、云监控集成 |
| [安全组](./AWS/sg-auditor/) | 开放端口、无限制入口、未使用的组 |
| [根账户](./AWS/root-auditor/) | MFA、访问密钥、密码策略、备用联系人 |
| [EC2](./AWS/ec2-auditor/) | IMDSv2、EBS 加密、公网 IP、公网快照 |
| [RDS](./AWS/rds-auditor/) | 公开访问、加密、备份、多可用区 |
| [GuardDuty](./AWS/guardduty-auditor/) | 启用状态、发现数量、S3/EKS/恶意软件/RDS/运行时保护 |
| [VPC 流日志](./AWS/vpcflowlogs-auditor/) | 每个 VPC 覆盖、流量类型、保留策略 |
| [Lambda](./AWS/lambda-auditor/) | 公开 URL、IAM 角色、环境变量中的密钥、弃用的运行时 |
| [Security Hub](./AWS/securityhub-auditor/) | 启用状态、发现、CIS/PCI DSS/FSBP 合规性 |
| [KMS](./AWS/kms-auditor/) | CMK 轮换、密钥策略、状态、未别名密钥 |
| [ELB](./AWS/elb-auditor/) | 访问日志、TLS 策略、HTTP→HTTPS 重定向、WAF(ALB) |
| [Config](./AWS/config-auditor/) | 启用状态、规则、合规性、记录覆盖范围 |
| [备份](./AWS/backup-auditor/) | 金库覆盖、保留、加密 |
### Azure (11 个审计器)
| 审计器 | 检查内容 |
|---------|----------------|
| [Entra ID](./Azure/entra-auditor/) | MFA、访客角色、应用凭证、权限提升 |
| [Entra 密码策略](./Azure/entrapwd-auditor/) | 到期、SSPR、智能锁定、安全默认、禁止密码 |
| [混合身份](./Azure/hybrid-auditor/) | AAD Connect 同步陈旧、PHS、写回、意外删除、SSO |
| [存储](./Azure/storage-auditor/) | 公开访问、共享密钥认证、加密、软删除 |
| [活动日志](./Azure/activitylog-auditor/) | 诊断设置、保留、告警缺口 |
| [NSG](./Azure/nsg-auditor/) | 开放端口、面向互联网规则、孤立组 |
| [订阅](./Azure/subscription-auditor/) | Defender for Cloud、PIM、全局管理员健康 |
| [Key Vault](./Azure/keyvault-auditor/) | RBAC、清除保护、软删除、过期密钥/证书/密钥 |
| [Defender for Cloud](./Azure/defender-auditor/) | 计划启用、安全分数、安全联系人 |
| [策略](./Azure/policy-auditor/) | 分配、合规状态、豁免 |
| [备份](./Azure/backup-auditor/) | 金库覆盖、保留、冗余、软删除 |
### M365 (6 个审计器)
| 审计器 | 检查内容 |
|---------|----------------|
| [M365 核心](./M365/m365-auditor/) | CA MFA、旧版身份验证、邮箱转发、OAuth 同意、MFA 覆盖、管理员角色 |
| [SharePoint](./M365/sharepoint-auditor/) | 外部共享、匿名链接、OneDrive 设置、域限制 |
| [Teams](./M365/teams-auditor/) | 外部联合、访客访问、会议等候室、录制过期 |
| [Intune](./M365/intune-auditor/) | 设备合规策略、CA 强制执行、Windows 自动注册 |
| [Exchange](./M365/exchange-auditor/) | 传输规则、自动转发、委派、审计日志、SMTP AUTH |
| [Defender for Endpoint](./M365/mde-auditor/) | MDE 上线、实时保护、BitLocker、篡改保护、扫描陈旧 |
### Windows 本地 (8 个审计器)
| 审计器 | 检查内容 |
|---------|----------------|
| [Active Directory](./OnPrem/Windows/ad-auditor/) | 旧账户、可被 Kerberoast 的用户、弱策略、无约束委派 |
| [本地用户](./OnPrem/Windows/localuser-auditor/) | 本地账户、注册表自动登录、WDigest、NTLMv1、LAPS 检测 |
| [Windows 防火墙](./OnPrem/Windows/winfirewall-auditor/) | 已禁用配置文件、默认允许策略、危险开放端口 |
| [SMB 签名](./OnPrem/Windows/smbsigning-auditor/) | 服务器和客户端签名强制(NTLM 中继防护) |
| [审核策略](./OnPrem/Windows/auditpolicy-auditor/) | 15 个关键子类别与 CIS 基线对比 |
| [BitLocker](./OnPrem/Windows/bitlocker-auditor/) | 驱动器加密状态、方法强度、TPM 保护器 |
| [LAPS](./OnPrem/Windows/laps-auditor/) | 部署覆盖、密码年龄、过期配置 |
| [Windows 更新](./OnPrem/Windows/winpatch-auditor/) | 最近更新时间、重启状态、自动更新策略、待处理安全更新 |
### Linux 本地 (5 个审计器)
| 审计器 | 检查内容 |
|---------|----------------|
| [用户](./OnPrem/Linux/linux-user-auditor/) | 账户、sudo 规则、SSH 配置、密码策略、旧账户 |
| [防火墙](./OnPrem/Linux/linux-firewall-auditor/) | iptables/nftables/ufw/firewalld、auditd、syslog |
| [Sysctl](./OnPrem/Linux/linux-sysctl-auditor/) | 24 个 CIS 基准内核参数 |
| [补丁](./OnPrem/Linux/linux-patch-auditor/) | 可用更新、自动更新代理、内核版本(apt/yum/dnf/zypper) |
| [SSH](./OnPrem/Linux/linux-ssh-auditor/) | 通过 `sshd -T` 的 21 个 sshd 强化参数 |
### 邮件与网络
| 审计器 | 检查内容 |
|---------|----------------|
| [邮件安全](./Email/email-security-auditor/) | SPF、DKIM、DMARC — 仅 DNS 查询,不需凭证 |
| [SSL/TLS](./Network/ssl-tls-auditor/) | 证书到期、TLS 版本、弱密码套件、HSTS |
| [HTTP 头]( ) | X-Frame-Options、CSP、Referrer-Policy、Permissions-Policy |
| [网络暴露](./OnPrem/Windows/netexpose-auditor/) | LAN 端口扫描 — 每台主机的 RDP/SMB/WinRM/LDAP/MSSQL(位于 CIDR 范围内) |
### 跨云
| 脚本 | 功能 |
|--------|--------------|
| [执行摘要](./tools/) | 聚合所有 JSON 报告 → 生成 0–100 分的 HTML 报告,包含支柱卡片、主要发现、快速修复、复合攻击路径 |
| [关联分析](./tools/correlations.py) | 15 条跨支柱复合风险规则(CP-01–CP-15) — 当两种及以上发现类型同时出现时触发,揭示对单支柱评分不可见的攻击路径 |
| [MITRE 映射](./tools/mitre_map.py) | 将 67 种发现类型映射到 MITRE ATT&CK 战术与技术 — 自动丰富到发现中,并在执行摘要中以徽章形式呈现 |
## 要求
| 平台 | 运行时 | 关键依赖 |
|----------|---------|-----------------|
| AWS | Python 3.7+ | `pip install boto3 rich` · AWS 凭证 |
| Azure | PowerShell 7+ | `Install-Module Az.*` · `Connect-AzAccount` |
| M365 | PowerShell 7+ | `Install-Module Microsoft.Graph ExchangeOnlineManagement` |
| Windows 本地 | PowerShell 5.1+ | 以本地管理员运行 · RSAT 用于 ad-auditor |
| Linux 本地 | Python 3.7+ | 无依赖 · 仅 SSH 审计器需要 `sudo` |
| 邮件 | Python 3.7+ | `pip install dnspython` · 不需要凭证 |
| 网络 | Python 3.8+ | 无依赖 · 不需要凭证 |
## 说明
- 脚本均为 **只读** — 不会对你的环境做任何更改
- 输出文件使用所有者仅可读权限(模式 600)创建
- 所有 JSON 发现均包含 `cis_control` 字段,映射到 CIS v8 控制项
- 67 种发现类型会自动丰富 MITRE ATT&CK 战术与技术引用(在执行摘要中以徽章形式呈现)
- 执行摘要会检测 15 条跨支柱复合攻击路径(凭据窃取、横向移动、勒索软件、数据外泄、AD 接管等) — 对单支柱评分不可见的风险
- AWS/Linux 脚本输出到当前目录,除非设置了 `--output`;PowerShell 脚本默认输出到带时间戳的客户端文件夹
- AWS 脚本支持 `--profile` 和 `--regions`;Azure 脚本支持 `-AllSubscriptions`
### 本地测试设置
```
pip install -r requirements-test.txt
pytest AWS/ OnPrem/Linux/ Network/ Email/ tests/ -v --import-mode=importlib
```
## 免责声明
这些脚本仅供 **内部安全审计** 使用。在对任何环境运行安全工具之前,请确保已获得适当授权。
标签:AI合规, AWS审计, Azure审计, Az模块, BitLocker审计, boto3, CI审计, CloudTrail审计, Defender审计, DKIM, DMARC, Graph API, HTML报告, IAM审计, JSON报告, Key Vault审计, Linux审计, M365审计, Patch审计, PowerShell审计, Python审计, S3审计, SMB安全评估, SPF, SSH审计, SSL/TLS检查, Sysctl审计, Windows审计, 安全规则引擎, 执行摘要, 无代理审计, 离线审计, 网络服务审计, 评分摘要, 逆向工具, 邮件安全, 防火墙审计