
Lockdown UNix 审计与报告
当前版本 15.9.3
有关最新版本信息,请参阅 lunar.sh 和 CHANGELOG.md
CC BY-NC-SA: https://creativecommons.org/licenses/by-nc-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 VM 用于测试:
./lunar.sh --action create --machine multipass --osver 24.04
有关更多信息,请参阅 wiki:
添加了一个简单的测试框架,用于调试 lunar 脚本本身。 它使用 docker compose 启动容器,挂载 lunar 目录并运行 lunar。