
锁定 Unix 审计与报告
当前版本 15.9.1
请参考 lunar.sh 和更新日志以获取最新版本信息
CC BY-SA:https://creativecommons.org/licenses/by-sa/4.0/
在此赞助我:https://ko-fi.com/richardatlateralblast
请仅以审计模式运行此脚本,例如使用 -a 或 --audit 参数。 自行承担锁定风险。如同任何系统更改,请做好备份。 我正在改进恢复模式,但仍可能存在缺陷。
我已尽可能使用 shellcheck 清理此脚本, 并启用了 -e(errexit)和 -u(nounset)shell 标志 以帮助防范错误。通过使用 -Q 或 --debug 标志可启用 -x(xtrace)shell 标志。
进行中:
此脚本生成 Unix 主机安全性的评分审计报告。 它基于 CIS 及其他框架。在可能的情况下, 代码文档中引用了 CIS 和其他基准。
为什么选择 shell 脚本?我希望有一个工具能够在其他工具可能不可用的锁定系统上运行。 我还希望该工具能在所有版本的 UNIX 上运行。 尽管如此,sh 和 bash 之间存在一些差异, 因此我只使用了 sh 中的函数。
此脚本不提供任何明示或暗示的保证。 我建议仅以审计模式使用此脚本, 并通过策略、文档和配置管理单独处理每个警告。
我绝不是编码人员,因此脚本中必定存在缺陷和更好的处理方法, 衷心感谢为此代码中缺陷/功能提供反馈、更新和补丁的人们。
它也可以执行锁定。与其他一些脚本不同,我添加了 回滚更改的功能。文件使用 cpio 备份到基于日期的目录中。
虽然它可以执行锁定,但如前所述,我建议您 通过策略、文档和配置管理来处理警告。 这就是我使用该工具的方式。AWS 服务审计仅支持报告, 不提供锁定功能。
支持以下操作系统:
Windows 支持需要安装额外软件,因此我尚未研究。 尽管如此,未来可能通过 bash 提供 Windows 支持。
支持以下服务:
AWS 服务审计使用 AWS CLI,因此需要具有适当权限的用户。 它目前不支持锁定功能,仅支持根据 CIS 基准生成审计报告。
有一些检查只能通过 GUI 完成或解决。 例如启用计费。有关更多信息,请参阅 CIS 基准。
在可能的情况下,我已在详细审计输出中放置了建议的修复命令。 同样,在某些情况下,这些只能通过 CLI 完成。请参阅 CIS 基准了解更多信息。
此外,我添加了推荐模式,用于根据 Cloud Conformity 等公司公开提供的最佳实践检查 AWS。
支持以下配置管理输出:
此选项输出示例 Ansible 配置管理代码/代码段,用于实施建议。
对于 UNIX:
对于 AWS:
对于 Azure:
Usage: ./lunar.sh -switch|--switch
switch(es):
-----------
-1|--list)
List changes/backups
-2|--tests)
Print tests
-3|--printfunct)
Print function
-4|--dryrun)
Run in dryrun mode
-6|--format)
Outpt format/type
-7|--file)
Output file
-8|--usesudo)
Use sudo
-9|--shellcheck)
Run shellcheck against script
-0|--force)
Force action
-a|--audit)
Run in audit mode (for Operating Systems - no changes made to system)
-A|--fullaudit)
Run in audit mode and include filesystems (for Operating Systems - no changes made to system)
-b|--backups|--listbackups)
List backups
-B|--basedir)
Set base directory
-c|--codename|--distro)
Distro/Code name (used with docker/multipass)
-C|--shell)
Run docker-compose testing suite (drops to shell in order to do more testing)
-d|--dockeraudit)
Run in audit mode (for Docker - no changes made to system)
-D|--dockertests)
List all Docker functions available to selective mode
-e|--host)
Run in audit mode on external host (for Operating Systems - no changes made to system)
-E|--hash|--passwordhash)
Password hash
-f|--action)
Action (e.g delete - used with multipass)
-F|--tempfile)
Temporary file to use for operations
-g|--giturl)
Git URL for code to copy to container
-G|--wheelgroup)
Set wheel group
-h|--help)
Display help
-H|--usage)
Display usage
-i|--anacron)
Enable/Disable anacron
-I|--type)
Audit type
-k|--kubeaudit)
Run in audit mode (for Kubernetes - no changes made to system)
-K|--function|--test)
Do a specific function
-l|--lockdown)
Run in lockdown mode (for Operating Systems - changes made to system)
-L|--fulllockdown|fulllock)
Run in lockdown mode (for Operating Systems - changes made to system)
-m|--machine|--vm)
Set virtualisation type
-M|--workdir)
Set work directory
-n|--ansible)
Output ansible
-N|--nocat)
Do output cat in score
-o|--os|--osver)
Set OS version
-O|--osinfo|--systeminfo)
Print OS/System information
-p|--previous)
Print previous audit information
-P|--sshsandbox|--sandbox)
Enable/Disabe SSH sandbox
-q|--quiet|--nostrict)
Run in quiet mode
-Q|--debug)
Run in debug mode
-r|--awsregion|--region)
Set AWS region
-R|--moduleinfo|--testinfo)
Print information about a module
-s|--select|--check)
Run in selective mode (only run tests you want to)
-S|--unixtests|--unix)
List UNIX tests
-t|--tag|--name)
Set docker tag
-T|--tempdir)
Set temp directoru
-u|--undo)
Undo lockdown (for Operating Systems - changes made to system)
-U|--dofiles)
Include filesystems
-v|--verbose)
Run in verbose mode
-V|--version)
Print version
-w|--awsaudit)
Run in audit mode (for AWS - no changes made to system)
-W|--awstests|--aws)
List all AWS functions available to selective mode
-x|--awsrec)
Run in recommendations mode (for AWS - no changes made to system)
-X|--strict)
Run shellcheck against script
-z)
Run specified audit function in lockdown mode
-Z|--changes|--listchanges)
List changes
执行完整审计(不含递归文件系统检查):
./lunar.sh --audit
列出测试:
./lunar.sh --tests
列出 AWS 测试:
./lunar.sh --tests aws
执行特定测试:
./lunar.sh --audit --select remote_shell
为测试创建 Ubuntu 24.04 multipass 虚拟机:
./lunar.sh --action create --machine multipass --osver 24.04
更多信息请参阅 Wiki:
添加了一个简单的测试框架,用于调试 lunar 脚本本身。 它使用 docker compose 启动一个容器,挂载 lunar 目录并运行 lunar。