When it comes to tuning IDS and customizing content for SIM, I definitely take my own medicine, or drink my own kool-aid, as it were. Today I am working on cleaning up the Snort rules on an IDS sensor. The rules on this sensor and the others in its group are managed via Oinkmaster. The down side to this is that researching rules and writing Oinkmaster directives can be slow and tedious. But here's some ugly shell script that makes it go faster.
In this example, I have decided that all of the rules related to Microsoft bulletins from 2003 do not apply to me because of patching. This script lets me isolate sid values from rules that contain the string "bulletins/MS03-" and put them into one big comma-delimted line for pasting into my oinkmaster.conf file.
$ for b in `for a in 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30; do grep bulletin/MS03- *.rules | cut -d\; -f$a |grep sid; done | cut -d: -f2`; do echo -n $b,; done; echo
If I want to be extra anal about it and only find those sid values for rules that aren't already disabled, I can use egrep to do this:
$ for b in `for a in 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30; do egrep ^alert *.rules |grep bulletin/MS03- | cut -d\; -f$a |grep sid; done | cut -d: -f2`; do echo -n $b,; done; echo
And finally, here's some ugly shell script that will count up all of your active rules. There's a way to do this while running Snort from the command-line as well.
$ for a in `egrep ^include /etc/snort/snort.conf |cut -d/ -f2 |grep \.rules`; do egrep ^alert $a; done |wc -l