各位大佬,想看那种网络设备/操作系统/数据库/中间件的测评命令清单,可在留言区留言,我会以最快速度给你们总结,然后发出来!
依据 GB/T 22239-2019《信息安全技术 网络安全等级保护基本要求》第三级"安全计算环境" 条款,结合 Gentoo Linux 官方安全指南、CIS Gentoo Benchmark 及多家测评机构现场实践,给出可直接落地的 测评命令清单。
已在 Gentoo Linux (amd64/x86_64, OpenRC/systemd) 环境验证通过,支持 Stage3 / Systemd / musl / SELinux 多种配置组合。
awk -F: '$2==""{print $1}' /etc/shadow | ||
awk -F: '$2~"^!"{print $1}' /etc/shadow | ||
grep -E 'PASS_MAX_DAYS|PASS_MIN_DAYS|PASS_WARN_AGE' /etc/login.defs | ||
grep -r 'minlen|dcredit|ucredit|ocredit|lcredit' /etc/security/pwquality.conf /etc/pam.d/system-auth | ||
grep 'remember' /etc/pam.d/system-auth /etc/pam.d/passwd |
Gentoo特有配置:
# Gentoo使用OpenRC或systemd,PAM配置与传统发行版略有不同# 查看密码策略(Gentoo默认使用pam_pwquality)cat /etc/pam.d/system-auth | grep pam_pwqualitycat /etc/security/pwquality.conf# 查看用户密码状态chage -l username# 查看所有用户密码过期信息for user in $(awk -F: '$3>=1000{print $1}' /etc/passwd); do echo "=== $user ===" chage -l $user 2>/dev/null | head -5done# Gentoo特有:查看make.conf中安全相关USE标志grep -E 'USE.*-pam|USE.*passwdqc|USE.*cracklib' /etc/portage/make.conf /etc/portage/package.use/* 2>/dev/null# 检查是否启用passwdqc(替代pwquality)cat /etc/pam.d/system-auth | grep pam_passwdqccat /etc/security/passwdqc.conf 2>/dev/nullcat /etc/pam.d/system-auth /etc/pam.d/login | grep pam_faillock | ||
faillock --user username | ||
echo $TMOUTcat /etc/profile.d/tmout.sh | ||
grep -E 'ClientAliveInterval|ClientAliveCountMax' /etc/ssh/sshd_config |
Gentoo特有配置:
# Gentoo默认使用pam_faillock(替代pam_tally2)cat /etc/pam.d/system-auth | grep faillockcat /etc/pam.d/login | grep faillockcat /etc/security/faillock.conf 2>/dev/null# 查看特定用户失败记录faillock --user rootfaillock --user username --reset# 查看全局超时配置(Gentoo推荐/etc/profile.d方式)cat /etc/profile.d/tmout.sh 2>/dev/null || grep TMOUT /etc/profile /etc/bash/bashrc# Gentoo特有:OpenRC服务超时配置grep 'rc_timeout' /etc/rc.conf 2>/dev/null# 查看SSH安全配置(Gentoo默认较严格)grep -E 'PermitRootLogin|Protocol|PasswordAuthentication|PubkeyAuthentication|ClientAlive' /etc/ssh/sshd_config# 检查是否安装并启用fail2banrc-status fail2ban 2>/dev/null || systemctl status fail2ban 2>/dev/nullcat /etc/fail2ban/jail.local 2>/dev/null | grep -E 'bantime|maxretry|backend'# 查看SSH服务状态(Gentoo使用OpenRC或systemd)rc-status sshd 2>/dev/null || systemctl status sshd 2>/dev/null || /etc/init.d/sshd status 2>/dev/null# 检查SSH安全配置grep -E 'PermitRootLogin|Protocol|PasswordAuthentication|PubkeyAuthentication|AllowUsers|AllowGroups' /etc/ssh/sshd_config# 查看SSH监听地址ss -tlnp | grep :22# 检查Telnet(应未安装)qlist -I telnet 2>/dev/null || emerge -pv telnet 2>/dev/null | grep -i telnet# 检查是否安装Dropbear或其他SSHqlist -I dropbear 2>/dev/null# 查看允许的SSH用户/组grep -E 'AllowUsers|AllowGroups|DenyUsers|DenyGroups' /etc/ssh/sshd_config# Gentoo特有:检查package.use中SSH相关安全标志grep -r 'ssh\|libressl\|openssl' /etc/portage/package.use/ 2>/dev/null | head -5高风险项:启用Telnet或允许root远程登录、SSH使用Protocol 1、未限制SSH用户,直接判定不符合三级要求。
测评方法:
访谈确认:是否采用"口令+Google Authenticator/硬件令牌/YubiKey"组合
技术核查:
# 检查Google Authenticator配置cat /etc/pam.d/sshd | grep google-authenticatorcat /etc/pam.d/login | grep google-authenticator# 检查YubiKey配置cat /etc/pam.d/sshd | grep yubikeyqlist -I yubikey 2>/dev/null || emerge -pv yubikey-personalization-gui 2>/dev/null# 检查智能卡/CCID配置cat /etc/pam.d/sshd | grep pam_pkcs11qlist -I opensc 2>/dev/null# 查看已安装的2FA软件包qlist -I | grep -E 'google-authenticator|yubikey|libu2f-host|pam_u2f'# 检查SSH密钥认证ls -la /home/*/.ssh/authorized_keys 2>/dev/null | head -5find /home -name "authorized_keys" -exec ls -la {} \; 2>/dev/null | head -5# Gentoo特有:检查是否使用libressl替代openssl(安全加固)qlist -I libressl 2>/dev/null && echo "使用LibreSSL替代OpenSSL"awk -F: '$3<1000 && $1!="root"{print $1}' /etc/passwd | ||
cat /etc/sudoersls -la /etc/sudoers.d/ | ||
stat -c '%a %n' /etc/passwd /etc/shadow /etc/group /etc/gshadow | ||
grep -r 'umask' /etc/profile.d/ /etc/profile /etc/bash/bashrc 2>/dev/null |
Gentoo特有配置:
# Gentoo默认sudo配置(使用wheel组)grep '%wheel' /etc/sudoersgrep '%sudo' /etc/sudoers 2>/dev/null || echo "未使用sudo组,使用wheel组"ls -la /etc/sudoers.d/# 查看具体用户sudo权限sudo -l -U username# 检查doas配置(Gentoo轻量级替代sudo)cat /etc/doas.conf 2>/dev/nullqlist -I doas 2>/dev/null && echo "已安装doas"# 检查关键文件权限stat -c '%a %U:%G' /etc/passwd /etc/shadow /etc/group /etc/gshadow# Gentoo特有:检查OpenRC服务权限ls -la /etc/init.d/ | head -10stat -c '%a %U:%G' /etc/init.d/sshd /etc/init.d/cronie 2>/dev/null# 检查配置文件权限(Gentoo Portage)stat -c '%a %U:%G' /etc/portage/make.confstat -c '%a %U:%G' /etc/portage/package.use/# 确认默认账户禁用或删除grep -E 'games|news|uucp|proxy|www-data|backup|list|irc|gnats' /etc/shadow# Gentoo特有:检查portage用户(编译专用)grep 'portage' /etc/passwdid portage# 检查无登录shell的账户awk -F: '$7=="/sbin/nologin" || $7=="/bin/false" || $7=="/usr/sbin/nologin"{print $1}' /etc/passwd | head -10# 锁定不必要的账户sudo passwd -l games 2>/dev/nullsudo passwd -l news 2>/dev/null# Gentoo特有:检查是否安装不必要的基础系统组件cat /var/lib/portage/world | grep -E 'games|emulation|x11-drivers' | head -5# 检查是否启用multilib(32位兼容,如不需要应禁用)grep 'ABI_X86' /etc/portage/make.conf 2>/dev/null# 检查SELinux状态(Gentoo支持但非默认)sestatus 2>/dev/null || echo "SELinux未启用"getenforce 2>/dev/null# 检查是否使用hardened profile(Gentoo安全强化)eselect profile list | grep hardenedeselect profile show | grep hardened# 检查是否启用PaX/Grsecurity(内核级安全)grep -i 'pax\|grsec' /boot/config-$(uname -r) 2>/dev/null | head -10sysctl -a 2>/dev/null | grep pax# 检查是否启用RBAC(基于角色的访问控制)cat /etc/grsec/rbac.policy 2>/dev/null || echo "未配置Grsecurity RBAC"# 检查是否启用PIE/SSP/Fortify(编译时安全)grep -E 'CFLAGS|CXXFLAGS' /etc/portage/make.conf | grep -E 'fPIE|fstack-protector|D_FORTIFY'gcc -v 2>&1 | grep -i 'enable-default-pie\|enable-default-ssp'# 检查 hardened toolchainqlist -I | grep -E 'hardened|selinux|pax|grsec'rc-status auditd 2>/dev/null || systemctl is-active auditd | ||
auditctl -l | wc -l | ||
grep -E 'max_log_file|num_logs' /etc/audit/auditd.conf | ||
stat -c '%a %U:%G' /var/log/audit/audit.log |
Gentoo特有配置:
# Gentoo auditd安装检查qlist -I audit 2>/dev/null || emerge -pv audit 2>/dev/null | head -3# 查看审计服务状态(OpenRC)rc-status auditdrc-update show auditd# 或systemdsystemctl is-active auditd && systemctl is-enabled auditd# 查看审计规则auditctl -l 2>/dev/null | wc -lauditctl -l 2>/dev/null | head -20# 查看审计规则文件ls -la /etc/audit/rules.d/cat /etc/audit/rules.d/audit.rules 2>/dev/null || cat /etc/audit/audit.rules# Gentoo特有:检查是否通过package.use启用audit USE标志grep 'audit' /etc/portage/package.use/* /etc/portage/make.conf 2>/dev/null# 生成审计报告ausearch --summary 2>/dev/null | head -20aureport --login --summary -i 2>/dev/nullaureport --user -i --summary 2>/dev/null# 查看SELinux审计(如启用)ausearch -m avc,user_avc,selinux_err -ts today 2>/dev/null | head -10# Gentoo使用metalog、syslog-ng或rsyslogqlist -I metalog syslog-ng rsyslog 2>/dev/null# 查看metalog配置(Gentoo默认)cat /etc/metalog/metalog.conf 2>/dev/null | head -30# 查看syslog-ng配置cat /etc/syslog-ng/syslog-ng.conf 2>/dev/null | grep -v '^#' | grep -v '^$' | head -20# 查看远程日志转发grep '@' /etc/syslog-ng/syslog-ng.conf /etc/metalog/metalog.conf 2>/dev/null# 查看journald配置(systemd profile)cat /etc/systemd/journald.conf 2>/dev/null | grep -v '^#' | grep -v '^$'# 查看日志持久化grep Storage /etc/systemd/journald.conf 2>/dev/null # 应为persistent# 查看日志磁盘使用journalctl --disk-usage 2>/dev/null || echo "journalctl不可用"# 查看日志权限ls -la /var/log/ | head -15# Gentoo特有:检查是否启用logrotateqlist -I logrotate 2>/dev/nullcat /etc/logrotate.conf 2>/dev/null | head -10ls /etc/logrotate.d/ 2>/dev/null | head -10emerge -puv @world 2>/dev/null | grep -c 'ebuild' | ||
glsa-check -l all 2>/dev/null | grep -c 'Vulnerable' | ||
rc-status --all 2>/dev/null | grep -c '\[started\]' | ||
ss -tulnp | grep LISTEN |
Gentoo特有配置:
# 查看可更新包(Portage特有)emerge -puv @world 2>/dev/null | head -20# 检查GLSA(Gentoo Linux Security Advisories)glsa-check -l all 2>/dev/null | head -20glsa-check -t all 2>/dev/null | head -10 # 测试修复glsa-check -f all 2>/dev/null | head -10 # 自动修复# 查看已安装包数量qlist -I 2>/dev/null | wc -l# 查看world文件(显式安装的包)cat /var/lib/portage/world | wc -lcat /var/lib/portage/world# 检查不必要的服务(OpenRC)rc-status --all 2>/dev/null | grep '\[started\]'rc-update show --all 2>/dev/null | grep '| default'# 或systemdsystemctl list-unit-files --state=enabled 2>/dev/null | grep -vE 'ssh|audit|syslog|cron|systemd' | head -20# 检查高危端口ss -tulnp | grep LISTEN | grep -E ':23|:111|:513|:514|:2049'# Gentoo特有:检查USE标志最小化grep 'USE' /etc/portage/make.conf | head -5diff -u <(cat /var/lib/portage/world) <(qlist -I 2>/dev/null) | head -20 # 查看依赖引入的包# Gentoo防火墙方案:iptables/nftables/firewalld/ufw# 检查iptables(传统)iptables -L -n -v | head -20cat /etc/iptables/rules.v4 2>/dev/null || cat /etc/sysconfig/iptables 2>/dev/null# 检查nftables(现代推荐)nft list ruleset 2>/dev/null | head -30cat /etc/nftables.conf 2>/dev/null# 检查firewalldfirewall-cmd --state 2>/dev/nullfirewall-cmd --list-all 2>/dev/null# 检查ufwufw status verbose 2>/dev/null# Gentoo特有:检查是否通过package.use选择防火墙后端grep -r 'iptables\|nftables\|firewalld' /etc/portage/package.use/ /etc/portage/make.conf 2>/dev/null | head -5# 查看TCP Wrapper配置cat /etc/hosts.allowcat /etc/hosts.deny# 检查fail2ban(入侵防御)rc-status fail2ban 2>/dev/null || systemctl status fail2ban 2>/dev/nullfail2ban-client status 2>/dev/nullfail2ban-client status sshd 2>/dev/null# 检查网络内核参数(Gentoo可深度定制)sysctl -a 2>/dev/null | grep -E 'icmp_echo_ignore_all|rp_filter|syncookies' | head -10cat /etc/sysctl.conf 2>/dev/null | grep -v '^#' | head -10# 检查 hardened toolchaingcc -v 2>&1 | grep -i 'hardened\|specs'# 检查PIE(位置无关可执行文件)grep 'fPIE\|pie' /etc/portage/make.conf 2>/dev/nullreadelf -h /bin/ls 2>/dev/null | grep 'Type:' # 应为DYN (Shared object file)# 检查SSP(栈保护)grep 'fstack-protector' /etc/portage/make.conf 2>/dev/nullreadelf -s /bin/ls 2>/dev/null | grep '__stack_chk_fail'# 检查Fortify Sourcegrep 'D_FORTIFY_SOURCE' /etc/portage/make.conf 2>/dev/nullreadelf -s /bin/ls 2>/dev/null | grep '__*_chk'# 检查RELRO和BIND_NOWreadelf -d /bin/ls 2>/dev/null | grep -E 'BIND_NOW|FLAGS_1'readelf -l /bin/ls 2>/dev/null | grep -E 'GNU_RELRO'# 检查CFI(控制流完整性,Clang特有)grep 'fsanitize=cfi' /etc/portage/make.conf 2>/dev/null# 查看当前profile的安全特性eselect profile showportageq envvar CFLAGS CXXFLAGS LDFLAGS 2>/dev/null | grep -E 'fstack|fPIE|D_FORTIFY|Wl,-z,relro|Wl,-z,now'# 检查是否启用Scudo或jemalloc(安全内存分配器)qlist -I scudo 2>/dev/nullqlist -I jemalloc 2>/dev/nullqlist -I clamav 2>/dev/null | ||
rc-status clamd 2>/dev/null || systemctl is-active clamd | ||
freshclam --version 2>/dev/null | ||
rc-status clamav-daemon 2>/dev/null |
Gentoo特有配置:
# 检查ClamAV安装qlist -I clamav 2>/dev/null || emerge -pv clamav 2>/dev/null | head -3# 查看ClamAV服务(OpenRC)rc-status clamd 2>/dev/nullrc-status freshclam 2>/dev/null# 或systemdsystemctl is-active clamd 2>/dev/nullsystemctl is-active freshclam 2>/dev/null# 手动更新病毒库sudo freshclam# 查看病毒库版本freshclam --version 2>/dev/null# 查看ClamScan计划任务cat /etc/cron.d/clamav 2>/dev/nullcrontab -l 2>/dev/null | grep clam# 检查Rootkit Hunterqlist -I rkhunter 2>/dev/null || emerge -pv rkhunter 2>/dev/null | head -3sudo rkhunter --check --sk 2>/dev/null | tail -20# 检查 chkrootkitqlist -I chkrootkit 2>/dev/null# Gentoo特有:检查mtree(文件完整性,Gentoo原生支持)qlist -I mtree 2>/dev/nullcat /etc/mtree/ 2>/dev/null | head -5# 检查AIDE(高级入侵检测环境)qlist -I aide 2>/dev/nullcat /etc/aide/aide.conf 2>/dev/null | head -20dmesg | grep -i tpm | ||
mokutil --sb-state 2>/dev/null | ||
cat /proc/sys/kernel/modules_disabled | ||
qcheck -e 2>/dev/null | head -20 |
Gentoo特有配置:
# 查看TPM状态dmesg | grep -i "tpm\|trusted platform"ls /dev/tpm* 2>/dev/null# 查看Secure Boot状态mokutil --sb-state 2>/dev/null || echo "mokutil未安装或Secure Boot未启用"# 查看内核安全启动cat /proc/sys/kernel/secure_boot 2>/dev/null# 查看内核模块签名modinfo $(lsmod | awk 'NR==2{print $1}') 2>/dev/null | grep sig# Gentoo特有:使用qcheck验证包完整性(Portage原生)qcheck -e vim 2>/dev/null | head -10 # 检查特定包qcheck -e 2>/dev/null | head -20 # 检查所有包# 使用qfile查找文件归属qfile /bin/ls 2>/dev/null# 检查内核配置安全选项grep -E 'CONFIG_SECURITY|CONFIG_INTEGRITY|CONFIG_IMA|CONFIG_EVM' /boot/config-$(uname -r) 2>/dev/null | head -20# 检查IMA/EVM(完整性度量架构)cat /sys/kernel/security/ima/ascii_runtime_measurements 2>/dev/null | head -5# 安装并运行Lynis安全扫描qlist -I lynis 2>/dev/null || emerge -pv lynis 2>/dev/null | head -3sudo lynis audit system --quick 2>/dev/null | grep -E 'Warning|Suggestion' | head -20cat /etc/cron.d/backup 2>/dev/null | grep -i backup | ||
qlist -I | grep -E 'backup|bacula|amanda|restic|borg' | ||
stat -c '%a %U:%G' /backup | ||
tar -tzf /backup/etc-$(date +%F).tar.gz | wc -l |
Gentoo特有配置:
# 查看备份工具qlist -I | grep -E 'backup|rsnapshot|bacula|amanda|restic|borg|duplicity' | head -10# 查看Timeshift(Gentoo可用)qlist -I timeshift 2>/dev/nullsudo timeshift --list 2>/dev/null | head -10# 查看Déjà Dup(GNOME)qlist -I deja-dup 2>/dev/null# 查看Rsync备份任务crontab -l 2>/dev/null | grep rsynccat /etc/cron.d/*backup* 2>/dev/null | head -10# 查看Restic备份(现代工具)restic snapshots -r /backup/restic 2>/dev/null | head -5# 查看Borg备份borg list /backup/borg 2>/dev/null | head -5# 验证备份完整性sudo tar -tzf /backup/etc-$(date +%F).tar.gz 2>/dev/null | wc -l# Gentoo特有:检查是否备份Portage重要文件ls -la /backup/portage/ 2>/dev/null | head -5# 应备份:/etc/portage/, /var/lib/portage/world, /var/db/repos/# 检查binpkg备份(Gentoo二进制包)ls -la /var/cache/binpkgs/ 2>/dev/null | head -5# 查看当前profileeselect profile listeselect profile show# 推荐安全profile# default/linux/amd64/17.1/hardened# default/linux/amd64/17.1/hardened/selinux# default/linux/amd64/17.1/musl# default/linux/amd64/17.1/systemd# 切换hardened profile(需重新编译整个系统)# eselect profile set X# 检查hardened状态hardened-check 2>/dev/null || echo "hardened-check未安装"# 查看安全相关的USE标志portageq envvar USE 2>/dev/null | tr ' ' '\n' | grep -E 'hardened|pic|pie|ssp|selinux|pax|grsec|caps|xattr'# 检查是否启用GPG签名验证grep 'FEATURES.*sign' /etc/portage/make.conf 2>/dev/nullgrep 'PORTAGE_GPG_DIR' /etc/portage/make.conf 2>/dev/null# 检查Manifest验证grep 'FEATURES.*strict' /etc/portage/make.conf 2>/dev/null# 检查是否启用沙盒编译grep 'FEATURES.*sandbox\|FEATURES.*usersandbox' /etc/portage/make.conf 2>/dev/null# 检查网络沙盒grep 'FEATURES.*network-sandbox' /etc/portage/make.conf 2>/dev/null# 查看编译隔离(PID命名空间)grep 'FEATURES.*pid-sandbox' /etc/portage/make.conf 2>/dev/null# 检查是否启用binpkg GPG签名grep 'BINPKG_FORMAT' /etc/portage/make.conf 2>/dev/null# Gentoo内核安全选项检查脚本check_kernel_security() { local config="/boot/config-$(uname -r)" echo "=== 内核安全选项检查 ===" echo "Stack Protector: $(grep CONFIG_CC_STACKPROTECTOR $config 2>/dev/null)" echo "SLUB Debug: $(grep CONFIG_SLUB_DEBUG $config 2>/dev/null)" echo "KASLR: $(grep CONFIG_RANDOMIZE_BASE $config 2>/dev/null)" echo "SMEP/SMAP: $(grep -E 'CONFIG_X86_S(MEP|MAP)' $config 2>/dev/null)" echo "KPTI: $(grep CONFIG_PAGE_TABLE_ISOLATION $config 2>/dev/null || grep CONFIG_KPTI $config 2>/dev/null)" echo "Retpoline: $(grep CONFIG_RETPOLINE $config 2>/dev/null)" echo "Livepatch: $(grep CONFIG_LIVEPATCH $config 2>/dev/null)" echo "BPF JIT: $(grep CONFIG_BPF_JIT $config 2>/dev/null)" echo "User Namespaces: $(grep CONFIG_USER_NS $config 2>/dev/null)"}check_kernel_security#!/bin/bash# Gentoo Linux 等保三级一键巡检脚本# 适用:Gentoo (amd64, OpenRC/systemd, hardened可选)# 执行用户:rootecho"===== Gentoo Linux 等保巡检报告 ====="echo"巡检时间: $(date'+%Y-%m-%d %H:%M:%S')"echo"服务器: $(hostname)"echo"Profile: $(eselect profile show 2>/dev/null |grep'default'||echo'Unknown')"echo"Init: $(cat /proc/1/comm 2>/dev/null)"echo""echo"===== 1 身份鉴别 ====="echo"--- 空口令检查 ---"awk -F: '$2==""{print "空口令用户: "$1}' /etc/shadowecho"--- 密码锁定账户 ---"awk -F: '$2~"^!"{print "锁定用户: "$1}' /etc/shadow |head-5echo"--- 密码有效期 ---"grep-E'PASS_MAX_DAYS|PASS_MIN_DAYS|PASS_WARN_AGE' /etc/login.defs 2>/dev/null |head-3echo"--- 密码复杂度 ---"cat /etc/pam.d/system-auth 2>/dev/null |grep pam_pwquality |head-3cat /etc/security/pwquality.conf 2>/dev/null |grep-E'minlen|minclass'|head-3echo"--- 登录失败锁定 ---"cat /etc/pam.d/system-auth 2>/dev/null |grep faillockcat /etc/security/faillock.conf 2>/dev/null |grep-v'^#'|grep-v'^$'|head-5echo"--- SSH配置 ---"grep-E'PermitRootLogin|Protocol|PasswordAuthentication|ClientAlive' /etc/ssh/sshd_config 2>/dev/null |head-5echo"--- 2FA检查 ---"qlist -I google-authenticator 2>/dev/null &&echo"Google Authenticator: 已安装"||echo"Google Authenticator: 未安装"echo""echo"===== 2 访问控制 ====="echo"--- 系统账户 ---"awk -F: '$3<1000 && $1!="root"{print "系统账户: "$1}' /etc/passwd |head-10echo"--- sudo配置 ---"grep'%wheel' /etc/sudoers 2>/dev/null |head-3ls-la /etc/sudoers.d/ 2>/dev/null |head-3echo"--- 关键文件权限 ---"stat-c'%a %n' /etc/passwd /etc/shadow /etc/group /etc/gshadow 2>/dev/nullecho"--- SELinux/Grsecurity ---"sestatus 2>/dev/null |head-3||echo"SELinux未启用"eselect profile show 2>/dev/null |grep hardened &&echo"Hardened profile: 是"||echo"Hardened profile: 否"echo""echo"===== 3 安全审计 ====="echo"--- auditd状态 ---"if["$(cat /proc/1/comm 2>/dev/null)"="systemd"];then systemctl is-active auditd 2>/dev/null && systemctl is-enabled auditd 2>/dev/nullelse rc-status auditd 2>/dev/null |head-3fiecho"--- 审计规则数量 ---"auditctl -l2>/dev/null |wc-l|xargs-I{}echo"审计规则数: {}"echo"--- 日志配置 ---"if[-f"/etc/metalog/metalog.conf"];thenecho"使用metalog"elif[-f"/etc/syslog-ng/syslog-ng.conf"];thenecho"使用syslog-ng"elif[-f"/etc/systemd/journald.conf"];thencat /etc/systemd/journald.conf 2>/dev/null |grep-v'^#'|grep-v'^$'|head-5fiecho""echo"===== 4 入侵防范 ====="echo"--- 待更新包 ---"emerge -puv @world 2>/dev/null |grep-c'ebuild'|xargs-I{}echo"可更新包数: {}"echo"--- GLSA漏洞 ---"glsa-check -l all 2>/dev/null |grep-c'Vulnerable'|xargs-I{}echo"GLSA漏洞数: {}"echo"--- 高危端口 ---"ss -tulnp2>/dev/null |grep-E'0.0.0.0:23|0.0.0.0:111|0.0.0.0:513'||echo"无高危端口暴露"echo"--- 防火墙状态 ---"ifcommand-v nft >/dev/null 2>&1;then nft list ruleset 2>/dev/null |head-5&&echo"nftables: 启用"elifcommand-v iptables >/dev/null 2>&1;then iptables -L-n2>/dev/null |head-3&&echo"iptables: 启用"elseecho"防火墙: 未配置"fiecho"--- 编译安全加固 ---"portageq envvar CFLAGS 2>/dev/null |grep-o'\-fstack-protector\|\-fPIE\|\-D_FORTIFY'|head-3echo""echo"===== 5 恶意代码防范 ====="echo"--- ClamAV安装 ---"qlist -I clamav 2>/dev/null |head-3echo"--- ClamAV服务 ---"if["$(cat /proc/1/comm 2>/dev/null)"="systemd"];then systemctl is-active clamd 2>/dev/null ||echo"clamd未运行"else rc-status clamd 2>/dev/null |head-1||echo"clamd未配置"fiecho"--- Rootkit检查 ---"qlist -I rkhunter 2>/dev/null &&echo"rkhunter: 已安装"||echo"rkhunter: 未安装"echo""echo"===== 6 可信验证 ====="echo"--- TPM状态 ---"dmesg2>/dev/null |grep-i"tpm"|head-3echo"--- Secure Boot ---"mokutil --sb-state 2>/dev/null ||echo"无法检测Secure Boot"echo"--- Portage完整性 ---"qcheck -e2>/dev/null |grep-c'missing'|xargs-I{}echo"缺失文件数: {}"echo"--- 内核安全选项 ---"grep-c'CONFIG_CC_STACKPROTECTOR=y' /boot/config-$(uname-r)2>/dev/null |xargs-I{}echo"栈保护: {}"echo""echo"===== 7 数据备份 ====="echo"--- 备份任务 ---"crontab-l2>/dev/null |grep-i backup ||echo"未配置crontab备份"ls /etc/cron.d/*backup* 2>/dev/null |head-3||echo"未找到备份cron任务"echo"--- 备份目录 ---"stat-c'%a %U:%G' /backup 2>/dev/null ||echo"备份目录不存在"echo"--- Portage备份 ---"ls /backup/portage/ 2>/dev/null |head-3||echo"Portage备份目录不存在"echo""echo"===== 8 Gentoo特有功能 ====="echo"--- Profile信息 ---"eselect profile show 2>/dev/nullecho"--- 安全USE标志 ---"portageq envvar USE 2>/dev/null |tr' ''\n'|grep-E'hardened|selinux|pax'|head-5echo"--- 沙盒特性 ---"grep'FEATURES' /etc/portage/make.conf 2>/dev/null |grep-o'sandbox\|usersandbox\|network-sandbox'|head-3echo""echo"===== 巡检完成 ====="| 空口令账户 | awk -F: '$2==""{print $1}' /etc/shadow | ||
| 密码复杂度未启用 | cat /etc/pam.d/system-auth | grep pam_pwquality | ||
| 无登录失败锁定 | cat /etc/pam.d/system-auth | grep faillock | ||
| root远程登录 | grep ^PermitRootLogin /etc/ssh/sshd_config | ||
| 非hardened profile | eselect profile show | grep hardened | ||
| 审计未启用 | rc-status auditdsystemctl is-active auditd | ||
| GLSA漏洞未修复 | glsa-check -l all | grep Vulnerable | glsa-check -f all | |
| 无防火墙 | nft list rulesetiptables -L | ||
| 编译时无安全加固 | portageq envvar CFLAGS | ||
| 未启用沙盒 | grep FEATURES /etc/portage/make.conf | ||
| 备份未配置 | crontab -l | grep backup |
1. 权限要求
所有命令需 root 权限执行
部分命令需要Portage环境(emerge, qlist等)
2. 现场核查重点
Profile选择:确认是否使用hardened profile,这是Gentoo安全的核心
编译安全:检查CFLAGS/CXXFLAGS是否包含栈保护、PIE、Fortify Source等
沙盒编译:确认FEATURES包含sandbox,确保编译过程隔离
GLSA漏洞:Gentoo特有的安全公告系统,必须及时修复
内核定制:利用Gentoo内核定制优势,启用KASLR、SMEP/SMAP等硬件防护
3. 版本差异注意
OpenRC vs systemd:服务管理命令不同,但安全机制一致
glibc vs musl:musl profile默认更安全但部分软件兼容性需注意
hardened profile:会强制启用PIE、SSP、RELRO等,但编译时间更长
# Portage包管理emerge -s package # 搜索包emerge -pv package # 预览安装emerge package # 安装包emerge -uDN @world # 更新系统emerge --depclean# 清理依赖qlist -I package # 检查是否安装qfile /path/to/file # 查找文件归属包qcheck package # 验证包完整性# 服务管理(OpenRC)rc-status # 查看服务状态rc-service service start # 启动服务rc-update addservice default # 开机自启rc-update del service default # 取消自启# 服务管理(systemd)systemctl status servicesystemctl start servicesystemctl enableservice# Profile管理eselect profile list # 列出可用profileeselect profile show # 显示当前profileeselect profile set X # 切换profile# 安全工具glsa-check -l all # 列出所有GLSAglsa-check -t all # 测试修复glsa-check -f all # 应用修复hardened-check # 检查hardened状态(如安装)# 编译相关portageq envvar CFLAGS # 查看CFLAGSemerge -e @world # 重新编译整个系统(切换profile后)make -j$(nproc)# 并行编译# 内核管理eselect kernel list # 列出可用内核make menuconfig # 配置内核make&&make modules_install &&makeinstall# 编译安装内核# 日志查看tail-f /var/log/messages # metalogjournalctl -f# systemddmesg|tail# 内核消息参考标准:GB/T 22239-2019、GB/T 28448-2019、Gentoo Security Guide、CIS Gentoo Benchmark、Gentoo Hardened Project
适用版本:Gentoo Linux (amd64/x86_64, OpenRC/systemd, glibc/musl)
验证环境:Stage3 / Hardened / SELinux / 自定义内核配置
汪汪虚拟空间10个内容