Debian Apache安全审计实施指南
sudo apt update && sudo apt list --upgradable确认系统及Apache(apache2包)是否有未安装的安全更新,及时修补已知漏洞。/etc/apache2/conf-enabled/security.conf文件,确保以下配置生效(隐藏版本信息和服务器签名):ServerTokens Prod
ServerSignature Off
重启Apache使配置生效:sudo systemctl restart apache2。同时,通过curl -I http://localhost验证响应头中无版本信息。sudo apache2ctl -M,禁用不必要的模块(如autoindex防止目录列表、mod_php若使用PHP-FPM替代):sudo a2dismod autoindex
sudo systemctl restart apache2
/var/log/apache2/access.log(记录所有请求)/var/log/apache2/error.log(记录配置或运行错误)/var/log/auth.log(记录SSH、sudo等登录尝试)。/etc/logwatch/conf/services/apache.conf,设置*OnlyService = apache2。#!/bin/bash
grep "Failed password" /var/log/auth.log | awk '{print $11}' | sort | uniq -c | sort -nr | mail -s "SSH Failed Login Attempts" admin@example.com
ufw status确认仅允许HTTP(80端口)、HTTPS(443端口)流量,拒绝其他入站连接:sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
/etc/apache2/sites-available/000-default.conf),限制敏感目录(如/admin)仅允许特定IP访问:<Directory "/var/www/html/admin">
Require ip 192.168.1.100
</Directory>
openssl验证证书有效期和配置:sudo openssl x509 -in /etc/ssl/certs/apache-selfsigned.crt -noout -dates # 检查有效期
sudo apache2ctl -t -D DUMP_VHOSTS # 确认虚拟主机配置了SSL
/etc/apache2/mods-enabled/ssl.conf,禁用弱加密套件(如SSLv2、SSLv3),仅启用TLS 1.2及以上:SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite HIGH:!aNULL:!MD5
/etc/fail2ban/jail.local,确保Apache相关规则启用(如apache-auth针对401错误、apache-noscript针对500错误),并设置封禁时间(如bantime = 3600秒):[apache-auth]
enabled = true
port = http,https
filter = apache-auth
logpath = /var/log/apache2/error.log
maxretry = 3
bantime = 3600
查看被封禁IP:sudo fail2ban-client status apache-auth。libapache2-mod-security2),检查/etc/modsecurity/modsecurity.conf中的SecRuleEngine设置为On(启用入侵检测),并定期查看/var/log/apache2/modsec_audit.log中的拦截记录。lynis或OpenVAS),测试SSL配置(如通过SSL Labs的测试工具),备份日志并归档。