ubuntu15.10下Snort安装及配置

一、工作模式及原理

  • 嗅探器:嗅探器模式仅仅是从网络上读取数据包并作为连续不断的流显示在终端上。
  • 数据包记录器:数据包记录器模式把数据包记录到硬盘上。
  • 网络入侵检测系统:分析网络数据流以匹配用户定义的一些规则,并根据检测结果采取一定的动作。
  • 通常分为三层工作:传感器层、服务器层、管理员控制台层,分别对应上面的三个模式

二、工作工程

  1. 预处理
    a、Snort通过在网络TCP/IP的第5层结构的数据链路层进行抓取网络数据包;
    b、 将捕获的数据包送到包解码器进行解码。网络中的数据包有可能是以太网包、令牌环包、TCP/IP包c 802.11包等格式。在这一过程包解码器将其解码成Snort认识的统一的格式;
    c、将数据包送到预处理器进行处理,预处理包括能分片的数据包进行重 新组装,处理一些明显的错误等问题;
  2. 处理:规则的建立及根据规则进行检测
    规则检测是Snort中最重要的部分,作用是检测数据包中是否包含有入侵行为。处理规则文件的时候,用三维链表来存规则信息以便和后面的数据包进行匹配,三维链表一旦构建好了,就通过某种方法查找三维链表并进行匹配和发生响应。规则检测的处理能力需要根据规则的数量,运行Snort机器的性能,网络负载等因素决定.
  3. 输出
    经过检测后的数据包需要以各种形式将结果进行输出,输出形式可以是输出到alert文件、其它日志文件、数据库UNIX域或Socke

三、安装

  • 自动安装(可能需要安装依赖包)
    #apt-get update
    #apt-get dist-upgrade
    #apt-get install snort
    Configuring snort
    注:用ifconfig查看端口

  • 编译安装
    1)、依赖安装
    安装libpcap
    a、下载libpcap-1.5.3源码 并解压,然后编译安装
    tar xzf libpcap-1.5.3.tar.gz
    cd libpcap-1.5.3
    ./configure
    make
    sudo make install
    注:默认安装在/usr/local下
    b、设置路径: 将上面安装的libpcap的路径添加到path中
    sudo vim /etc/ld.so.conf
    Ctrl+G
    Ctrl+i
    /usr/local/lib
    /usr/local/bin
    退出vim然后执行命令 
    /sbin/ldconfig
    注:可以查看版本 /sbin/ldconfig -p | grep libcap
    c、安装Libpcre库
    sudo apt-get install libpcre3-dev
    d、安装dnet库
    sudo apt-get install libdumbnet-dev
    2)正式安装(也可参考snort.org)
    wget https://snot.org/downloads/snort/daq-2.0.6.tar.gz
    wget https://snort.org/downloads/snort/snort-2.9.8.0.tar.gz
    ./configure; make; sudo make install
    tar xvfz snort-2.9.8.0.tar.gz cd snort-2.9.8.0
    ./configure –enable-sourcefire; make; sudo make install
    3)配置
    a、执行复制脚本(脚本来自于互联网)
    首先将snort_srt变量设置为自己的源码路径然后执行脚本
    sudo sh snort_coyp_rule.sh
    b、下载规则库并安装
    tar zxf snortrules-snapshot-2980.tar.gz
    cd snortrules-snapshot-2980
    sudo cp -r preproc_rules /etc/snort
    sudo cp -r so_rules /etc/snort
    sudo cp rules/* /etc/snort/rules
    sudo cp etc/* /etc/snort/
    注:如果直接从网上下载规则库需要先注册(免费)
    c、下载下载社区规则并解压到指定位置
    wget https://snort.org/rules/community  
    sudo tar -xvfz community.tar.gz -C /etc/snort/rules
    d、配置个人规则
    sudo vim /etc/snort/snort.conf
    将第101行到110行由:
    #Path to your rules files (this can be a relative path)
    # Note for Windows users: You are advised to make this an absolute path,
    # such as: c:\snort\rules
    var RULE_PATH ../rules
    var SO_RULE_PATH ../so_rules
    var PREPROC_RULE_PATH ../preproc_rules

    # If you are using reputation preprocessor set these
    var WHITE_LIST_PATH ../rules
    var BLACK_LIST_PATH ../rules

    改为:
    # Path to your rules files (this can be a relative path)
    # Note for Windows users: You are advised to make this an absolute path,
    # such as: c:\snort\rules
    var RULE_PATH ./rules
    var SO_RULE_PATH ./so_rules
    var PREPROC_RULE_PATH ./preproc_rules

    # If you are using reputation preprocessor set these
    var WHITE_LIST_PATH ./rules
    var BLACK_LIST_PATH ./rules
    其他配置根据需要自行修改
    注:可以用命令查看配置情况:sudo snort -T -c /etc/snort/snort.conf

四、运行

  • sudo snort -i interface
    注:参数及使用见手册

五、分析

  • -d 将报警文件保存在 /var/log/snort/snort.log中,也可以用 -l 参数改变日志的输出文件,然后可以进一步对文件进行分析

六、参考文献

  1. 官网教程
  2. Snort中文手册
  3. 在Ubuntu 15.04中如何安装和使用Snort (有非常详细的步骤,脚本就来自于这篇文章)
  4. linux 下Snbort-2.9.22安装详解
  5. Snort使用手册,第二部分:配置

七、附件

#snrot_copy_rule.sh
#引用自:http://www.linuxdiyf.com/linux/13726.html
#nort源代码的路径
snort_src="/home/name/workspace/snort/snortrules-snapshot-2980"
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---"

你可能感兴趣的:(Linux)