Snort 集成¶
本文档描述了如何将 OS-Ken 与 Snort 集成。
概述¶
有两种方法可以将警报发送到 OS-Ken 控制器。选项 1 更容易,如果您只想演示或测试。由于 Snort 需要非常大的计算能力来分析数据包,您可以选择选项 2 来分离它们。
[选项 1] OS-Ken 和 Snort 在同一台机器上
+------------------------+
| unixsock |
| OS-Ken == snort |
+----eth0-----eth1-------+
| |
+-------+ +----------+ +-------+
| HostA |---| OFSwitch |---| HostB |
+-------+ +----------+ +-------+
以上图示了 OS-Ken 和 Snort 的架构。OS-Ken 通过 Unix 域套接字 接收 Snort 警报数据包。要监控 HostA 和 HostB 之间的数据包,请安装一个镜像数据包到 Snort 的流。
[选项 2] OS-Ken 和 Snort 在不同的机器上
+---------------+
| Snort eth0--|
| Sniffer | |
+-----eth1------+ |
| |
+-------+ +----------+ +-----------+
| HostA |---| OFSwitch |---| LAN (*CP) |
+-------+ +----------+ +-----------+
| |
+----------+ +-------------+
| HostB | | OS-Ken |
+----------+ +-------------+
*CP: 控制平面
以上图示了 OS-Ken 和 Snort 的架构。OS-Ken 通过 网络套接字 接收 Snort 警报数据包。要监控 HostA 和 HostB 之间的数据包,请安装一个镜像数据包到 Snort 的流。
安装 Snort¶
Snort 是一个开源的网络入侵防御和检测系统,由 Sourcefire 开发。如果您不熟悉安装/设置 Snort,请参考 snort 设置指南。
配置 Snort¶
以下是配置示例
将一个 snort 规则文件添加到
/etc/snort/rules,命名为Myrules.rulesalert icmp any any -> any any (msg:"Pinging...";sid:1000004;) alert tcp any any -> any 80 (msg:"Port 80 is accessing"; sid:1000003;)
在
/etc/snort/snort.conf中添加自定义规则include $RULE_PATH/Myrules.rules
将网卡配置为混杂模式。
$ sudo ifconfig eth1 promisc
用法¶
[选项 1]
修改
simple_switch_snort.pysocket_config = {'unixsock': True} # True: Unix Domain Socket Server [Option1] # False: Network Socket Server [Option2]
使用示例应用程序运行 OS-Ken
$ sudo osken-manager os_ken/app/simple_switch_snort.py
传入的数据包将全部镜像到 端口 3,该端口应连接到 Snort 网络接口。您可以修改镜像端口,方法是在 simple_switch_snort.py 的 self.snort_port = 3 中分配一个新值。
运行 Snort
$ sudo -i $ snort -i eth1 -A unsock -l /tmp -c /etc/snort/snort.conf
从 HostA (192.168.8.40) 向 HostB (192.168.8.50) 发送一个 ICMP 数据包
$ ping 192.168.8.50
您可以在下一节中查看结果。
[选项 2]
修改
simple_switch_snort.pysocket_config = {'unixsock': False} # True: Unix Domain Socket Server [Option1] # False: Network Socket Server [Option2]
使用示例应用程序运行 OS-Ken (在控制器上)
$ osken-manager os_ken/app/simple_switch_snort.py
运行 Snort (在 Snort 机器上)
$ sudo -i $ snort -i eth1 -A unsock -l /tmp -c /etc/snort/snort.conf
运行
pigrelay.py(在 Snort 机器上)$ sudo python pigrelay.py
该程序监听 snort 警报消息,并通过网络套接字将其发送到 OS-Ken。
您可以从这个仓库克隆源代码。 https://github.com/John-Lin/pigrelay
从 HostA (192.168.8.40) 向 HostB (192.168.8.50) 发送一个 ICMP 数据包
$ ping 192.168.8.50
您可以在下面看到警报消息
alertmsg: Pinging... icmp(code=0,csum=19725,data=echo(data=array('B', [97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 97, 98, 99, 100, 101, 102, 103, 104, 105]),id=1,seq=78),type=8) ipv4(csum=42562,dst='192.168.8.50',flags=0,header_length=5,identification=724,offset=0,option=None,proto=1,src='192.168.8.40',tos=0,total_length=60,ttl=128,version=4) ethernet(dst='00:23:54:5a:05:14',ethertype=2048,src='00:23:54:6c:1d:17') alertmsg: Pinging... icmp(code=0,csum=21773,data=echo(data=array('B', [97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 97, 98, 99, 100, 101, 102, 103, 104, 105]),id=1,seq=78),type=0) ipv4(csum=52095,dst='192.168.8.40',flags=0,header_length=5,identification=7575,offset=0,option=None,proto=1,src='192.168.8.50',tos=0,total_length=60,ttl=64,version=4)