如何在 snort 警报上运行 shell 脚本?

Ser*_*ult 5 linux iptables snort syslog-ng

我在监听 cisco 交换机的 SPAN 端口时哼了一声。我希望能够在我的网络服务器上添加一个 iptables DROP 规则以用于特定的 snort 警报,但很难找到确切的方法。我希望阻塞实时发生,而不是通过 cron 启动脚本来定期拖网 snort 日志。

我在 Seclists 上找到了一个示例,它使用 syslog-ng 运行 shell 脚本,但它必须用于旧版本的 syslog-ng,因为我在重新启动 syslog-ng 时收到有关不推荐使用的语法的错误。

我对 syslog-ng 过滤器了解不多,因此我打算对此进行更多研究,因为它看起来很有希望,但我想我会在这里提出问题,以防有更好的方法。当 snort 警报通过我的 snort 框的 SPAN 端口时,运行 shell 脚本的好方法是什么?

Ser*_*ult 3

我已经拼凑了足够的文档来让某些东西发挥作用。解决方案包括告诉 snort 记录到 syslog,然后设置 syslog-ng 以触发 snort syslog 流量来运行给定的 shell 脚本。将 Snort 假脱机到磁盘或运行脚本对于高流量负载来说并不理想,因此请注意。如果您将 Snort 配置为仅对某些流量发出警报以降低负载,那么应该没问题。设置和调试 syslog-ng 可能是一件麻烦事,所以我已经包含了使其正常工作所需的部分。只需将它们添加到 syslog-ng.conf 的底部即可。希望它对其他人有帮助。请注意,由于某种原因,系统日志会记录每条消息的 3 个副本。不知道为什么。

我在这里使用了一些信息:http://www.mad-hacking.net/documentation/linux/reliability/logging/email-notification.xml

/etc/snort/snort.conf - configure snort to log to syslog
------------------------------------------------------------
# syslog
output alert_syslog: LOG_LOCAL6 LOG_ALERT


/etc/syslog/syslog-ng.conf  - setup filters/destinations for alerts
------------------------------------------------------------
# snort filter - this only pays attention to syslog messages sent by the 'snort' program
filter f_snort
{
  facility(local6) and match("snort" value ("PROGRAM"));                                                
};

# optionally, this would send the snort message to a remote host running a syslog listener.
# I was running tcpdump to debug the whole setup so I use UDP protocol here so the
# message is just blasted out over the ether without needing to actually have a syslog
# listener setup anywhere
destination d_net
{
  udp("10.10.10.1" port(514) log_fifo_size(1000) template(t_snort));   
};

# this one sends the syslog message consisting of priority,time_in_seconds,host and syslog meesage.
# 
destination d_prog
{
  program("/root/bin/snort_script" template("<$PRI>$UNIXTIME $HOST $MSGONLY\n") );
};

# ..or use a pipe if you don't want syslog running scripts
destination d_prog_pipe
{
  pipe("/root/bin/syslog-pipe" template("<$PRI>$DATE $HOST $MSGONLY\n") );
};

# finally, log the message out the snort parsing mechanism
log
{
   source(s_src);
   filter(f_snort);
   destination(d_prog);
   #destination(d_net); 
};



/root/bin/snort_script
------------------------------------------------------------
#!/bin/bash
while read line; do
   echo "$line" >> /tmp/snort.log
done
Run Code Online (Sandbox Code Playgroud)