WatchAD攻防实战
字数 1517 2025-08-09 13:33:38
WatchAD攻防实战教学文档
一、WatchAD简介
WatchAD是一款基于Python开发的Active Directory(AD)安全监控系统,由奇安信团队开发。它通过采集Windows事件日志,结合Elasticsearch、MongoDB等组件,实现对AD域环境的实时监控和安全分析。
二、环境准备
1. 系统要求
- Windows Server(作为域控制器)
- Linux服务器(用于部署WatchAD分析平台)
- Python 3.6+
- Elasticsearch 6.x/7.x
- MongoDB 4.x
- RabbitMQ(可选)
2. 组件说明
- Winlogbeat:负责从域控制器收集Windows事件日志
- Elasticsearch:存储和索引日志数据
- MongoDB:存储检测规则和配置信息
- WatchAD:核心分析引擎
三、安装部署
1. Winlogbeat安装配置
- 下载Winlogbeat(版本需与Elasticsearch兼容)
- 解压到域控制器(如
C:\Program Files\Winlogbeat) - 配置
winlogbeat.yml文件:
winlogbeat.event_logs:
- name: Security
ignore_older: 72h
output.logstash:
hosts: ["10.10.10.12:5044"] # 修改为WatchAD服务器IP
- 启动Winlogbeat:
.\winlogbeat.exe -e -c .\winlogbeat.yml
常见问题解决:
- 连接被拒绝错误(如文档中的
Failed to connect: dial tcp 10.10.10.12:5044):- 检查目标服务器防火墙是否开放5044端口
- 确认Logstash服务是否正常运行
- 验证IP地址是否正确
2. WatchAD安装
- 克隆项目:
git clone https://github.com/0Kee-Team/WatchAD.git
cd WatchAD
- 安装Python依赖:
pip3 install -r requirements.txt
- 初始化安装:
python3 WatchAD.py --install -d 域名 -s 域控IP -u 用户名 -p 密码
示例:
python3 WatchAD.py --install -d Motoo.nc -s 192.168.159.149 -u motoo\\administrator -p "Motoo123!@#45"
常见问题解决:
ModuleNotFoundError: No module named 'simplejson':pip3 install simplejson- 域连接问题:
- 确保域名解析正确
- 检查用户名格式(需包含域,如
domain\user) - 验证密码中的特殊字符是否转义
四、配置详解
1. WatchAD配置文件
configs/config.py主要配置项:
ELASTICSEARCH_HOST = '127.0.0.1' # ES地址
ELASTICSEARCH_PORT = 9200 # ES端口
MONGO_HOST = '127.0.0.1' # MongoDB地址
MONGO_PORT = 27017 # MongoDB端口
RABBITMQ_HOST = '127.0.0.1' # RabbitMQ地址(可选)
2. 规则配置
规则存储在MongoDB的watchad.rules集合中,支持以下检测类型:
- 异常登录
- 权限提升
- 黄金票据攻击
- DCShadow攻击
- 密码喷洒攻击
五、功能使用
1. 启动WatchAD
python3 WatchAD.py
2. 数据查询
通过Elasticsearch API或Kibana查询日志数据:
GET /winlogbeat-*/_search
{
"query": {
"match": {
"event_id": "4624"
}
}
}
3. 告警查看
告警信息存储在MongoDB的watchad.alerts集合中,可通过Web界面或API查看。
六、攻防对抗技巧
1. 攻击检测
- 黄金票据攻击:检测异常的Kerberos TGT请求
- DCShadow攻击:检测异常的域控制器复制请求
- 密码喷洒攻击:检测短时间内大量失败登录
2. 防御措施
- 确保Winlogbeat日志收集完整
- 定期审核检测规则
- 监控关键事件ID(如4769、5136等)
七、维护与优化
- 日志轮转:配置Elasticsearch索引生命周期管理
- 性能优化:根据日志量调整Elasticsearch和MongoDB资源配置
- 规则更新:定期更新检测规则以应对新型攻击
八、故障排查
-
Winlogbeat连接问题:
- 检查网络连通性
- 验证端口开放情况
- 查看Winlogbeat日志(
logs/winlogbeat)
-
WatchAD运行问题:
- 检查Python依赖是否完整
- 验证数据库连接配置
- 查看WatchAD日志(
logs/watchad.log)
通过以上步骤,您可以成功部署和使用WatchAD进行Active Directory安全监控。根据实际环境调整配置,并定期维护系统以确保其有效性。