第24章 网络安全架构
学习目标
- 理解网络安全架构的设计原则
- 掌握防火墙、零信任等安全技术
- 了解DDoS防护和入侵检测
- 能够设计安全的网络架构
前置知识
24.1 网络安全概述
24.1.1 网络安全威胁
1. 外部威胁
- DDoS攻击:分布式拒绝服务攻击
- 恶意软件:病毒、木马、勒索软件
- 网络入侵:未授权访问
- 数据泄露:敏感信息泄露
2. 内部威胁
- 内部攻击:员工恶意行为
- 权限滥用:过度权限使用
- 数据泄露:内部人员泄露
- 配置错误:安全配置错误
24.1.2 安全架构原则
1. 纵深防御
- 多层安全防护
- 每层都有安全措施
- 单一防护失效不影响整体
2. 最小权限
- 用户只获得必要权限
- 定期审查权限
- 及时撤销不需要的权限
3. 零信任
- 不信任任何用户或设备
- 持续验证身份
- 动态调整权限
24.2 防火墙架构
24.2.1 防火墙类型
1. 包过滤防火墙
# iptables规则示例
# 允许SSH
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# 允许HTTP/HTTPS
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# 拒绝其他流量
iptables -A INPUT -j DROP
2. 状态检测防火墙
# 允许已建立连接
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# 允许新连接
iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
3. 应用层防火墙
# 使用mod_security
# 检测SQL注入
SecRule ARGS "@detectSQLi" "id:1,phase:2,block,msg:'SQL Injection Attack'"
# 检测XSS
SecRule ARGS "@detectXSS" "id:2,phase:2,block,msg:'XSS Attack'"
24.2.2 防火墙部署
1. 边界防火墙
┌─────────────────────────────────────────────────────────────┐
│ Network Topology │
├─────────────────────────────────────────────────────────────┤
│ Internet │
│ │ │
│ ┌──────┐ │
│ │ Border Firewall │ │
│ └───┬───┘ │
│ │ │
│ ┌──────┐ │
│ │ DMZ │ │
│ └───┬───┘ │
│ │ │
│ ┌──────┐ │
│ │ Internal Firewall │ │
│ └───┬───┘ │
│ │ │
│ ┌──────┐ │
│ │ Internal Network │ │
│ └───────┘ │
└─────────────────────────────────────────────────────────────┘
2. 分布式防火墙
# 在每个服务器上部署防火墙
# 使用iptables或firewalld
systemctl enable firewalld
systemctl start firewalld
# 配置防火墙规则
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
24.3 零信任网络
24.3.1 零信任原则
1. 永不信任,始终验证
- 所有用户和设备都需要验证
- 持续验证身份和权限
- 动态调整访问权限
2. 最小权限访问
- 只授予必要的权限
- 基于角色的访问控制
- 定期审查权限
3. 假设违规
- 假设网络已被入侵
- 持续监控和检测
- 快速响应和恢复
24.3.2 零信任架构
1. 身份验证
# 多因子认证配置
authentication:
primary: password
secondary:
- sms
- totp
- biometric
session_timeout: 3600
max_attempts: 3
2. 设备信任
# 设备信任配置
device_trust:
certificate_validation: true
device_fingerprinting: true
compliance_check: true
risk_assessment: true
3. 网络分段
# 网络分段配置
network_segmentation:
micro_segmentation: true
policy_enforcement: true
traffic_inspection: true
encryption: true
24.4 DDoS防护
24.4.1 DDoS攻击类型
1. 网络层攻击
- SYN Flood:大量SYN请求
- UDP Flood:大量UDP包
- ICMP Flood:大量ICMP包
2. 应用层攻击
- HTTP Flood:大量HTTP请求
- Slowloris:慢速HTTP请求
- DNS Amplification:DNS放大攻击
24.4.2 DDoS防护方案
1. 硬件防护
# 使用专用DDoS防护设备
# 配置流量清洗
# 配置黑洞路由
2. 软件防护
# 使用iptables限制连接数
iptables -A INPUT -p tcp --dport 80 -m connlimit --connlimit-above 10 -j DROP
# 使用fail2ban防护
# 配置fail2ban规则
[apache-ddos]
enabled = true
port = http,https
filter = apache-ddos
logpath = /var/log/apache2/access.log
maxretry = 300
findtime = 300
bantime = 600
3. 云防护
# 使用云服务商DDoS防护
# AWS Shield
# Cloudflare DDoS Protection
# 阿里云DDoS防护
24.5 入侵检测
24.5.1 IDS/IPS系统
1. 网络入侵检测(NIDS)
# 使用Suricata
# 配置规则
alert tcp any any -> any 80 (msg:"HTTP Request"; content:"GET"; http_method; sid:1;)
# 配置日志
alert tcp any any -> any 22 (msg:"SSH Login Attempt"; content:"SSH"; sid:2;)
2. 主机入侵检测(HIDS)
# 使用OSSEC
# 配置规则
<rule id="1001" level="7">
<if_sid>1000</if_sid>
<regex>failed password</regex>
<description>SSH Failed Password</description>
</rule>
24.5.2 安全监控
1. 日志监控
# 配置syslog
# 集中收集日志
# 实时分析日志
2. 行为分析
# 使用机器学习
# 检测异常行为
# 预测安全威胁
24.6 加密和认证
24.6.1 网络加密
1. IPsec VPN
# 配置IPsec
# 使用strongSwan
# 配置证书认证
2. TLS/SSL
# 配置HTTPS
# 使用Let's Encrypt
# 配置证书自动更新
24.6.2 身份认证
1. 多因子认证
# 配置MFA
mfa:
enabled: true
methods:
- totp
- sms
- email
- push
backup_codes: true
2. 单点登录(SSO)
# 配置SSO
sso:
provider: saml
entity_id: https://example.com/saml
sso_url: https://example.com/saml/sso
certificate: /path/to/cert.pem
24.7 实验:安全架构设计
24.7.1 实验环境
环境要求:
- 三台Linux主机
- 网络互通
- 支持iptables
网络拓扑:
┌─────────────────────────────────────────────────────────────┐
│ Security Lab │
├─────────────────────────────────────────────────────────────┤
│ Internet │
│ │ │
│ ┌──────┐ │
│ │ Firewall │ │
│ └───┬───┘ │
│ │ │
│ ┌──────┐ │
│ │ Web Server │ │
│ └───┬───┘ │
│ │ │
│ ┌──────┐ │
│ │ Database │ │
│ └───────┘ │
└─────────────────────────────────────────────────────────────┘
24.7.2 实验步骤
步骤1:配置防火墙
# 在防火墙上配置规则
# 允许SSH
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# 允许HTTP/HTTPS
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# 允许已建立连接
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# 拒绝其他流量
iptables -A INPUT -j DROP
步骤2:配置Web服务器
# 安装Apache
apt-get update
apt-get install apache2
# 配置SSL
a2enmod ssl
a2ensite default-ssl
# 配置防火墙
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
步骤3:配置数据库
# 安装MySQL
apt-get install mysql-server
# 配置防火墙
ufw allow from 192.168.1.0/24 to any port 3306
# 配置用户权限
mysql -u root -p
CREATE USER 'webuser'@'192.168.1.0/24' IDENTIFIED BY 'password';
GRANT SELECT, INSERT, UPDATE, DELETE ON webdb.* TO 'webuser'@'192.168.1.0/24';
FLUSH PRIVILEGES;
24.8 安全监控
24.8.1 安全事件监控
1. 日志收集
# 配置rsyslog
# 集中收集日志
# 实时分析日志
2. 威胁检测
# 使用Snort
# 配置规则
# 实时检测威胁
24.8.2 安全响应
1. 事件响应
# 配置自动响应
# 隔离受感染设备
# 通知安全团队
2. 恢复计划
# 制定恢复计划
# 定期备份数据
# 测试恢复流程
24.9 故障排查
24.9.1 安全事件诊断
问题1:防火墙规则不生效
# 检查iptables规则
iptables -L -n
# 检查规则顺序
iptables -L -n --line-numbers
# 检查日志
tail -f /var/log/iptables.log
问题2:VPN连接失败
# 检查IPsec状态
ipsec status
# 检查证书
ipsec showcerts
# 检查日志
tail -f /var/log/ipsec.log
问题3:DDoS攻击
# 检查连接数
netstat -an | grep :80 | wc -l
# 检查流量
iftop -i eth0
# 检查日志
tail -f /var/log/apache2/access.log
24.9.2 排错工具
# 使用nmap扫描端口
nmap -sS -O 192.168.1.1
# 使用tcpdump抓包
tcpdump -i eth0 -n
# 使用wireshark分析
wireshark -i eth0
# 使用netstat查看连接
netstat -tuln
24.10 排错清单
24.10.1 安全配置检查
- [ ] 防火墙规则是否正确
- [ ] 访问控制是否配置
- [ ] 加密是否启用
- [ ] 认证是否配置
- [ ] 监控是否正常
24.10.2 安全事件检查
- [ ] 日志是否正常收集
- [ ] 威胁检测是否正常
- [ ] 响应机制是否有效
- [ ] 恢复计划是否可行
- [ ] 安全培训是否完成
24.11 延伸阅读
下一章:第25章 系统级调优
返回目录:README