#!/bin/bash# # snort源代码的路径 snort_src="/home/test/Downloads/snort-2.9.7.3" echo"adding group and user for snort..." groupadd snort &> /dev/null useradd snort -r -s /sbin/nologin -d /var/log/snort -c snort_idps -g snort &> /dev/null#snort configuration echo"Configuring snort..."mkdir -p /etc/snort mkdir -p /etc/snort/rules touch /etc/snort/rules/black_list.rules touch /etc/snort/rules/white_list.rules touch /etc/snort/rules/local.rules mkdir /etc/snort/preproc_rules mkdir /var/log/snort mkdir -p /usr/local/lib/snort_dynamicrules chmod -R 775 /etc/snort chmod -R 775 /var/log/snort chmod -R 775 /usr/local/lib/snort_dynamicrules chown -R snort:snort /etc/snort chown -R snort:snort /var/log/snort chown -R snort:snort /usr/local/lib/snort_dynamicrules ###copy configuration and rules from etc directory under source code of snort echo"copying from snort source to /etc/snort ....." echo$snort_src echo"-------------" cp$snort_src/etc/*.conf* /etc/snort cp$snort_src/etc/*.map /etc/snort##enable rules sed -i 's/include \$RULE\_PATH/#include \$RULE\_PATH/' /etc/snort/snort.conf echo"---DONE---"
改变脚本中的snort源目录路径并运行。下面是成功的输出。
上面的脚本从snort源中复制下面的文件和文件夹到/etc/snort配置文件中
snort的配置非常复杂,要让IDS能正常工作需要进行下面必要的修改。
1 2
ipvar HOME_NET 192.168.1.0/24# LAN side
1 2
ipvar EXTERNAL_NET !$HOME_NET# WAN side
1 2 3 4 5 6
var RULE_PATH /etc/snort/rules # snort signature path var SO_RULE_PATH /etc/snort/so_rules #rules in shared libraries var PREPROC_RULE_PATH /etc/snort/preproc_rules # Preproces path var WHITE_LIST_PATH /etc/snort/rules # dont scan var BLACK_LIST_PATH /etc/snort/rules # Must scan
1 2
include$RULE_PATH/local.rules # file for custom rules