开源安全审计工具Lynis简单介绍
Lynis是一款Linux系统的安全审计以及加固工具,能够进行深层次的安全扫描,其目的是检测潜在的时间并对未来的系统加固提供建议。
这款软件会扫描一般系统信息,脆弱软件包以及潜在的错误配置,执行全面的运行状况扫描,以支持系统强化和合规性测试
下面介绍使用Lynis扫描CentOS7系统并进行安全加固
1、配置lynis的源,并安装lynis
vi /etc/yum.repos.d/cisofy-lynis.repo [lynis] name=CISOfy Software - Lynis package baseurl=https://packages.cisofy.com/community/lynis/rpm/ enabled=1 gpgkey=https://packages.cisofy.com/keys/cisofy-software-rpms-public.key gpgcheck=1 priority=2 yum install lynis
2、使用用lynis扫描系统
lynis -h lynis audit system
3、根据上面安全加固建议进行安全加固
例如扫描出来的SSH的加固建议有如下加固项
修改之前的CentOS7安全加固脚本中ssh加固部分,可以参考之前文章
修改成如下
sec_ssh() { echo "============= sec ssh =============" >> ${LOCK} 2>&1 echo -en "${RGB_WAIT}Configuring...${RGB_END}" sed -i 's/#UseDNS.*$/UseDNS no/' /etc/ssh/sshd_config sed -i 's/^#LoginGraceTime.*$/LoginGraceTime 60/' /etc/ssh/sshd_config sed -i 's/^#PermitEmptyPasswords.*$/PermitEmptyPasswords no/' /etc/ssh/sshd_config sed -i 's/^#PubkeyAuthentication.*$/PubkeyAuthentication yes/' /etc/ssh/sshd_config sed -i 's/^#MaxAuthTries.*$/MaxAuthTries 3/' /etc/ssh/sshd_config sed -i "s/#ClientAliveInterval 0/ClientAliveInterval 30/g" /etc/ssh/sshd_config sed -i "s/#ClientAliveCountMax 3/ClientAliveCountMax 3/g" /etc/ssh/sshd_config sed -i "s/X11Forwarding yes/X11Forwarding no/g" /etc/ssh/sshd_config sed -i "s/#AllowAgentForwarding yes/AllowAgentForwarding no/g" /etc/ssh/sshd_config sed -i "s/#AllowTcpForwarding yes/AllowTcpForwarding no/g" /etc/ssh/sshd_config sed -i "s/#TCPKeepAlive yes/TCPKeepAlive no/g" /etc/ssh/sshd_config sed -i "s/#Compression delayed/Compression no/g" /etc/ssh/sshd_config sed -i "s/#MaxSessions 10/MaxSessions 2/g" /etc/ssh/sshd_config sed -i "s/#LogLevel INFO/LogLevel VERBOSE/g" /etc/ssh/sshd_config sed -i "s/#Banner none/Banner \/etc\/issue.net/g" /etc/ssh/sshd_config echo "Authorized users only. All activity may be monitored and reported.">/etc/issue.net systemctl restart sshd.service >> ${LOCK} 2>&1 cat /etc/ssh/sshd_config >> ${LOCK} 2>&1 echo -e "\r${RGB_SUCCESS}Configuration Success${RGB_END}" }
然后执行CentOS7安全加固脚本后,再进行lynis扫描
可以看到目前SSH安全基线只剩下3个安全加固建议