
Lockdown UNix 审计与报告
当前版本 16.6.1
有关最新版本信息,请参阅 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|--checkenv)
Run a selected environment check (for example, shellcheck)
-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)
Docker image name, or Multipass release codename
-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|--shellcheck)
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。