WAF 与 SOC 建设
1. WAF 部署
1.1 ModSecurity 部署(Nginx)
# 安装 ModSecurity + Nginx 模块
apt install -y libmodsecurity3 libmodsecurity-dev gcc make git
git clone https://github.com/SpiderLabs/ModSecurity.git
cd ModSecurity && git checkout v3.0/release/3.0.x
./configure && make && make install
# Nginx 编译 ModSecurity 模块
./configure --add-dynamic-module=../ModSecurity-nginx --with-compat && make modules
cp objs/ngx_http_modsecurity_module.so /usr/lib/nginx/modules/
配置 ModSecurity:
# /etc/nginx/modsec_main.conf
Include /etc/nginx/modsec/*.conf
# nginx.conf
http {
modsecurity on;
modsecurity_rules_file /etc/nginx/modsec/rules.conf;
}
1.2 规则示例(OWASP Core Rule Set)
# 下载 CRS 规则
git clone https://github.com/coreruleset/coreruleset.git /etc/nginx/modsec/crs
mv /etc/nginx/modsec/crs/crs-setup.conf.example /etc/nginx/modsec/crs/crs-setup.conf
mv /etc/nginx/modsec/crs/rules/*.conf /etc/nginx/modsec/rules/
# 自定义规则 /etc/nginx/modsec/rules/custom.conf
SecRule REQUEST_URI "@rx (\.\./|\.\./\.\./)" "id:9001,phase:1,log,deny,status:403"
SecRule ARGS "@rx <script>|javascript:|onerror=" "id:9002,phase:2,log,deny,status:403"
SecRule REQUEST_HEADERS|REQUEST_BODY "@rx union.*select|insert.*into|drop.*table" "id:9003,phase:2,log,deny,status:403"
1.3 NLB + WAF 架构
Internet → AWS NLB(TCP 443)→ WAF(ModSecurity)→ ALB → ECS/EKS
# AWS WAF 规则示例(CLI)
aws wafv2 create-web-acl --name my-waf-acl --scope REGIONAL --default-action Block={} --rules '[{"name":"SQLInjection","statement":{"byteMatchStatement":{"searchString":"''","fieldToMatch":{"uriPath":{}},"textTransformations":[{"priority":0,"transformation":"URL_DECODE"}]}},"action":{"block":{}}}]'
2. SOC 安全运营中心建设
2.1 SOC 架构
┌─────────────────────────────────────────────────────┐
│ 数据采集层 │
│ IDS/IPS · WAF · HIDS · SIEM · 流量探针 · 云日志 │
└────────────────────────┬────────────────────────────┘
▼
┌─────────────────────────────────────────────────────┐
│ 数据存储层 │
│ ElasticSearch / Loki / ClickHouse / Kafka │
└────────────────────────┬────────────────────────────┘
▼
┌─────────────────────────────────────────────────────┐
│ 分析运营层 │
│ 关联分析引擎 · 威胁情报 · 机器学习检测 · 自动化响应 │
└────────────────────────┬────────────────────────────┘
▼
┌─────────────────────────────────────────────────────┐
│ 响应处置层 │
│ 告警分级 · 工单流转 · SOAR 自动化 · 通报预警 │
└─────────────────────────────────────────────────────┘
2.2 告警分级标准
| 级别 | 名称 | 响应时效 | 处置方式 |
|---|---|---|---|
| P0 | 紧急 | 15 分钟内 | 立即断网,通知 CSO,启动应急 |
| P1 | 高危 | 1 小时内 | 隔离受影响系统,分析溯源 |
| P2 | 中危 | 4 小时内 | 分析评估影响范围,跟踪修复 |
| P3 | 低危 | 24 小时内 | 记录观察,例行处置 |
2.3 告警规则示例(Sigma 格式)
# 入侵检测规则(密码暴力破解)
title: SSH Brute Force
logsource:
product: linux
service: auth
detection:
selection:
EventID: 6
pam|failure
condition: selection
timeframe: 5m
count: 10
level: high
2.4 自动化响应(SOAR)
# 当 WAF 封禁 IP 时自动通知
# 触发条件:WAF 某 IP 1 分钟内被 block 超过 100 次
# 动作:发送 Slack 告警 + 自动在防火墙添加 DROP 规则
# 示例:Python SOAR 脚本
import boto3, json, requests
waf = boto3.client('wafv2')
def handler(event):
ip = event['detail']['ruleMatchTuple']['ipAddress']['address']
requests.post(
'https://hooks.slack.com/services/xxx',
json={'text': f'🚨 WAF 封禁高危IP: {ip}'}
)
# 自动在 Security Group 封禁
ec2 = boto3.client('ec2')
ec2.authorize_security_group_ingress(
GroupId='sg-xxxx', IpProtocol='tcp', CidrIp=f'{ip}/32', FromPort=443, ToPort=443
)
3. 下一步
- 应急响应与溯源 — 安全事件处置全流程
- Kali Linux 快速上手 — 掌握渗透测试工具链