阅读量:332
grep -i "script\|eval\|base64" /var/log/apache2/access.log
异常表现:
出现大量带有 `eval()` 或 `base64` 解码的请求,可能是WebShell攻击
3. 被修改的系统文件
find /bin /sbin /usr/bin /usr/sbin -type f -mtime -1
异常表现:
系统核心二进制文件被修改,可能意味着Rootkit攻击
四、实时监控与自动化安全响应
1. 部署Prometheus与Node Exporter
wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
tar xvfz node_exporter-*.tar.gz
cd node_exporter-*
创建systemd服务:
cat > /etc/systemd/system/node_exporter.service << EOF
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=node_exporter
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start node_exporter
这样可以通过Prometheus和Grafana实现服务器安全态势的实时可视化。
2. 自动封禁恶意IP
使用Python脚本检测SSH暴力攻击并自动封禁:
#!/usr/bin/python3
import subprocess
import re
def block_ip(ip):
cmd = f"iptables -A INPUT -s {ip} -j DROP"
subprocess.run(cmd.split())
with open('/var/log/auth.log', 'r') as f:
for line in f:
if 'Failed password' in line:
ip = re.search(r'\d+\.\d+\.\d+\.\d+', line)
if ip:
block_ip(ip.group())
五、入侵后的紧急响应
1. 隔离服务器
立即阻止所有非必要流量
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
2. 获取攻击现场证据
创建内存转储
dd if=/proc/kcore of=/forensics/memory-$(date +%Y%m%d).dump bs=1024
记录当前进程信息
ps auxf > /forensics/processes-$(date +%Y%m%d).txt
归档所有日志
tar czf /forensics/logs-$(date +%Y%m%d).tar.gz /var/log/
六、预防性安全措施
1. SSH安全加固
cat >> /etc/ssh/sshd_config << EOF
PermitRootLogin no
PasswordAuthentication no
MaxAuthTries 3
EOF
2. 自动化安全更新
apt install unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades
3. 配置防火墙
ufw default deny incoming
ufw default allow outgoing
ufw allow ssh
ufw allow http
ufw allow https
ufw enable
七、安全策略
实施零信任架构,限制服务器访问权限采用容器化技术,隔离关键业务部署机器学习入侵检测,识别异常行为定期进行渗透测试,确保安全策略有效
在洛杉矶服务器租用环境中,服务器安全需要综合的策略,包括主动监控、日志分析、自动化响应和紧急恢复。通过实施本指南中的检测与防御措施,系统管理员可以有效减少服务器遭受攻击的风险,并在发生入侵时快速应对,保障业务的稳定运行。