Snort安装与配置

获得 Snort

现在,您已经获得了 Snort?首先使用 Web 浏览器访问 Snort 的 Web 站点(参见 参考资料)。左侧有一个很显眼的 “GET SNORT” 链接,就在那只大鼻子猪的下方。(严格来说,Snort 的徽标就是一头大鼻子粉红色小猪,似乎在喷鼻息)。在本文撰写之时,最新的可付诸生产的版本是 2.8。本文的所有内容都同样适用于 Snort 的 2.x 版本,只需进行少许调整,甚至完全不需要调整。

如果您使用的是 Linux® 或 Windows,可以下载二进制文件。单击生产文件列表下的 “Click to view binaries >>” 链接即可下载这些文件。

  • 如果您使用的是 Windows,首先单击二进制文件的链接,随后单击 win32/ 链接。您将看到一个 .exe 文件,名为 Snort_2_8_0_2_installer.exe,单击即可开始下载 Snort。
  • 对于 Linux,选择二进制文件链接,然后单击 linux/。您可以在几个 RPM 中做出选择,有些 RPM 带有对 MySQL 和 PostreSQL 的预置支持。选择所需 RPM,这样就准备完毕了。

如果您希望专研得深入一些,或者如果您使用的不是 Windows、Linux 系统(如 Mac OS X),则应从主下载链接中选择下载 GZipped TAR 文件,其名称类似于 snort-2.8.0.2.tar.gz(如果在本文撰写发表之后,发布的版本出现变化,具体文件名可能会略有不同)。此文件是 Snort 的源代码,您可以通过此源代码为您的特定平台进行生成。

通过源代码安装 Snort

有三种基本安装类型:

  • 在 UNIX® 类型的平台上(UNIX、Linux、Mac OS X、Cygwin)通过源代码安装
  • 在 Linux 上通过 RPM 安装
  • 通过 Windows .exe 安装程序进行安装

如果您正在使用 UNIX 类型的平台,则可通过源代码生成 Snort。这是最灵活的一种选项,能够确保专为您的系统生成 Snort。这种方法要稍微多花一些功夫,也有一些命令行或终端体验,您很有可能能够顺利完成安装。

Snort 需要一些二进制文件,尤其是通过源代码安装时。因此,在开始处理 Snort 包本身之前,应准备好这些二进制文件。

Windows 用户,继续使用二进制文件

通过源代码安装 Snort 并不困难,它非常适合命令行环境,但需要使用 C 编译器和众多二进制文件。即便您已经在自己的 Windows 计算机上安装了 Cygwin,使用 GUI 安装程式来使 Snort 准备好正常运行也是非常简单的。如果您要访问 Mac OS X 或 Linux 计算机,那么就应该选择通过源代码进行安装,但若您正在保护一个 Windows 组件(假设是 Internet Information Server),那么就不要引入不必要的麻烦。

在 Mac OS X 上安装 C 编译器

要通过源代码安装 Snort,您需要使用 C 编译器。大多数 Linux 和 UNIX 平台都提供了一个 C 编译器,名为 gcc,因此无需进行额外的处理。对于 Mac OS X 用户,gcc 编译器在默认情况下不会安装。

要获得用于 Mac OS X 的 gcc,请访问 Apple Developer Connection(参见 参考资料),登录并选择 Downloads。您将在页面右侧看到许多分类。选择 Developer Tools,然后查找 Xcode,下载用于 Tiger 或 Mac OS X 的更早期版本(即 10.4.x 或更早的版本)的 Xcode 2.5 的磁盘镜像;如果您目前使用的是 Leopard(10.5.x 或更新版本),请选择 Xcode 3.0。要下载的文件都很大,绝不仅仅是一个 C 编译器,因此请耐心等待下载完成。

最后,打开磁盘镜像,浏览 Installer 文件夹。运行安装程序,按提示完成各个步骤即可。为了确定您已经成功安装了 gcc,运行命令 gcc 即可:

[bdm0509:~/Desktop] gcc
powerpc-apple-darwin8-gcc-4.0.1: no input files

这是一个错误(您并未给 gcc 提供任何需要编译的内容),但它指出了您的系统应该安装编译器。在 UNIX、Linux、Solaris 或 Cygwin on Windows 上也会获得类似的响应。

添加 PCRE 支持

Snort 需要 Perl Compatible Regular Expressions,也就是 PCRE。您可以在线免费下载该库(参见 参考资料 部分),它可用于多种平台。将 .tar.gz 文件解压缩到一个目录中,切换到此目录:

[bdm0509:~/Desktop] tar xzf pcre-7.6.tar.gz 
[bdm0509:~/Desktop] cd pcre-7.6

现在,通过 configure 脚本配置此安装(稍后对 Snort 也要进行相同的处理)。结果如清单 1 所示。

清单 1. 为安装配置 PCRE 包
[bdm0509:~/Desktop/pcre-7.6] ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
...
Lots more output here...
...
config.status: executing script-chmod commands
config.status: executing delete-old-chartables commands

pcre-7.6 configuration summary:

    Install prefix .................. : /usr/local
    C preprocessor .................. : gcc -E
    C compiler ...................... : gcc
    C++ preprocessor ................ : g++ -E
    C++ compiler .................... : g++
    Linker .......................... : /usr/libexec/gcc/powerpc-apple-darwin8/4.0.1/ld
    C preprocessor flags ............ : 
    C compiler flags ................ : -O2
    C++ compiler flags .............. : -O2
    Linker flags .................... : 
    Extra libraries ................. : 

    Build C++ library ............... : yes
    Enable UTF-8 support ............ : no
    Unicode properties .............. : no
    Newline char/sequence ........... : lf
    \R matches only ANYCRLF ......... : no
    EBCDIC coding ................... : no
    Rebuild char tables ............. : no
    Use stack recursion ............. : yes
    POSIX mem threshold ............. : 10
    Internal link size .............. : 2
    Match limit ..................... : 10000000
    Match limit recursion ........... : MATCH_LIMIT
    Build shared libs ............... : yes
    Build static libs ............... : yes
    Link pcregrep with libz ......... : no
    Link pcregrep with libbz2 ....... : no
    Link pcretest with libreadline .. : no

接下来您只需要完成用于生成和编译代码的程序,然后将其安装到系统恰当的位置上即可。大多数程序、工具和实用工具(包括 PCRE 和 Snort)都允许您通过一个命令完成所有这些步骤:make install。但在执行这条命令之前,您应作为 root 用户登录或使用 sudo 命令。Snort 和 PCRE 等大多数软件包都需要写入受保护的目录,而普通用户通常无法访问这样的目录。使用 root 用户的权限或 sudo 命令就能顺利完成。您应看到如清单 2 所示的结果。

清单 2. 安装 PCRE(使用 sudo)
[bdm0509:~/Desktop/pcre-7.6] sudo make install
Password:
test -z "/usr/local/lib" || ./install-sh -c -d "/usr/local/lib"
 /bin/sh ./libtool --mode=install /usr/bin/install -c  'libpcre.la' 
     '/usr/local/lib/libpcre.la'
/usr/bin/install -c &.libs/libpcre.0.0.1.dylib /usr/local/lib/libpcre.0.0.1.dylib
(cd /usr/local/lib && { ln -s -f libpcre.0.0.1.dylib libpcre.0.dylib || 
     { rm -f libpcre.0.dylib && ln -s libpcre.0.0.1.dylib libpcre.0.dylib; }; })
(cd /usr/local/lib && { ln -s -f libpcre.0.0.1.dylib libpcre.dylib || 
     { rm -f libpcre.dylib && ln -s libpcre.0.0.1.dylib libpcre.dylib; }; })
/usr/bin/install -c .libs/libpcre.lai /usr/local/lib/libpcre.la
/usr/bin/install -c .libs/libpcre.a /usr/local/lib/libpcre.a
chmod 644 /usr/local/lib/libpcre.a
ranlib /usr/local/lib/libpcre.a
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib
...
Lots more output here...
...
test -z "/usr/local/include" || ./install-sh -c -d "/usr/local/include"
 /usr/bin/install -c -m 644 'pcre.h' '/usr/local/include/pcre.h'
 /usr/bin/install -c -m 644 'pcrecpparg.h' '/usr/local/include/pcrecpparg.h'
 /usr/bin/install -c -m 644 'pcre_stringpiece.h' 
     '/usr/local/include/pcre_stringpiece.h'
test -z "/usr/local/lib/pkgconfig" || ./install-sh -c -d "/usr/local/lib/pkgconfig"
 /usr/bin/install -c -m 644 'libpcre.pc' '/usr/local/lib/pkgconfig/libpcre.pc'
 /usr/bin/install -c -m 644 'libpcrecpp.pc' '/usr/local/lib/pkgconfig/libpcrecpp.pc'

有了这些库和工具,您就可以转向核心的 Snort 配置和安装了。

配置 Snort

下载了 Snort 源代码的 .tar.gz 文件之后,将其解压缩到一个便于访问的目录中。可以使用这样的命令:

[bdm0509:~/Desktop] tar xzf snort-2.8.0.2.tar.gz

在 Mac OS X 中,也可以双击文件,由 GUI 解压工具来处理解压缩的工作。您将获得一个类似于 snort-2.8.0.2 的文件夹,内容应如清单 3 所示。

清单 3. Snort 安装文件夹的目录列表
[bdm0509:~/Desktop/snort-2.8.0.2] ls
COPYING
ChangeLog
LICENSE
Makefile.am
Makefile.in
RELEASE.NOTES
aclocal.m4
config.guess
config.h.in
config.sub
configure
configure.in
contrib
depcomp
doc
etc
install-sh
ltmain.sh
m4
missing
mkinstalldirs
preproc_rules
rpm
schemas
snort.8
src
templates
verstuff.pl
ylwrap

现在,切换到刚刚创建的目录。运行 configure,这是一个脚本命令,尝试为您自动配置安装。您的输出应如清单 4 所示。

清单 4. 为安装配置 Snort 包
[bdm0509:~/Desktop/snort-2.8.0.2] ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific 
   portions of Makefiles... no
checking for style of include used by make... GNU
checking for gcc... gcc
...
lots more output...
...
config.status: creating doc/Makefile
config.status: creating contrib/Makefile
config.status: creating schemas/Makefile
config.status: creating rpm/Makefile
config.status: creating preproc_rules/Makefile
config.status: creating m4/Makefile
config.status: creating etc/Makefile
config.status: creating templates/Makefile
config.status: creating src/win32/Makefile
config.status: creating config.h
config.status: executing depfiles commands

在您的系统上安装 Snort

在安装了 PCRE 之后,下一步就是:再次运行 make install,同样以 root 用户的身份或使用 sudo 命令运行。您的输出应如清单 5 所示。

清单 5. 在 Snort 目录上运行 make install
[bdm0509:~/Desktop/snort-2.8.0.2] sudo make install
Password:
Making install in src
Making install in sfutil
gcc -DHAVE_CONFIG_H -I. -I../.. -I../.. -I../../src -I../../src/sfutil 
  -I/sw/include -I../../src/output-plugins -I../../src/detection-plugins 
  -I../../src/dynamic-plugins -I../../src/preprocessors 
  -I../../src/preprocessors/flow -I../../src/preprocessors/portscan  
  -I../../src/preprocessors/flow/int-snort  -I../../src/preprocessors/HttpInspect/include 
  -I../../src/preprocessors/Stream5 -I../../src/target-based  -I/usr/local/include 
  -fno-strict-aliasing  -g -O2 -Wall -DDYNAMIC_PLUGIN -fno-strict-aliasing 
  -c sfghash.c
...
Lots more output...
...
Making install in preproc_rules
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Nothing to be done for `install-exec-am'.
test -z "/usr/local/share/man/man8" || ./install-sh -c -d "/usr/local/share/man/man8"
 /usr/bin/install -c -m 644 './snort.8' '/usr/local/share/man/man8/snort.8'

如果在运行 configure 和 make 的解压缩目录中未看到很多变化,也不必担心。这里的大多数工作都是在系统用于二进制文件、库和可执行文件的目录中完成的。

在 Linux 上通过 RPM 安装 Snort

RPM 表示 RPM Package Manager。(没错,这个缩写实际上是循环的。并不是很有意义,但符合事实。)RPM on Linux 是可以轻松安装的软件包,因为 RPM 支持是市面上所有 Linux 发布版的核心。从 Snort Web 站点下载了一个 RPM 之后,只需将您下载的文件名作为参数运行 rpm命令即可,如清单 6 所示。

清单 6. 在 Snort RPM 上调用 rpm
[bdm0509@pegasus]# rpm -ivh snort-2.8.0.2-1.RH5.i386.rpm
Preparing...     ################################################ [100%]
   1:snort       ################################################ [100%]

ivh 选项代表安装、详尽和井号,它会安装软件包,同时告诉您所有细节(还会为您提供井号状态指标)。在本例中,安装是在 Red Hat 上进行的,但您会在任何 Linux 发布版上看到类似的结果。

与通过源代码安装 Snort 类似,您可能需要作为 root 用户登录来运行此命令,或使用 sudo 命令来作为超级用户安装 RPM。Snort 希望其二进制文件能够置于受保护的目录中,如 /usr/bin、/usr/local/bin,因此标准系统上的安装需要高于大多数普通用户账户的权限。

测试安装

在完成安装之后,您需要采取几个步骤,确保 Snort 可在系统上正常运行。一切都很简单,但在每次安装新版本的 Snort 或在新机器上安装 Snort 时都需要执行这些步骤。

运行 Snort 二进制文件

可以执行的最简单的测试就是运行 snort 命令。要开始测试,请切换到机器上的任意随机目录。但为了安全起见,请不要在 Snort 安装目录中执行此命令。您应得到类似于清单 7 所示的输出结果。

清单 7. 测试 Snort 二进制文件
[bdm0509:~] snort
   ,,_     -*> Snort! <*-
  o"  )~   Version 2.8.0.2 (Build 75)  
   ''''    By Martin Roesch & The Snort Team: http://www.snort.org/team.html
           (C) Copyright 1998-2007 Sourcefire Inc., et al.
           Using PCRE version: 7.6 2008-01-28

USAGE: snort [-options] <filter options>
Options:
   -A         Set alert mode: fast, full, console, test or none  (alert file alerts only)
              "unsock" enables UNIX socket logging (experimental).
   -b         Log packets in tcpdump format (much faster!)
   -B <mask>  Obfuscated IP addresses in alerts and packet dumps using CIDR mask
   -c <rules> Use Rules File <rules>
   -C         Print out payloads with character data only (no hex)
   -d         Dump the Application Layer
   -D         Run Snort in background (daemon) mode
   -e         Display the second layer header info
   -f         Turn off fflush() calls after binary log writes
   -F <bpf>   Read BPF filters from file <bpf>
   -g <gname> Run snort gid as <gname> group (or gid) after initialization
   -G <0xid>  Log Identifier (to uniquely id events for multiple snorts)
   -h <hn>    Home network = <hn>
   -H         Make hash tables deterministic.
   -i <if>    Listen on interface <if>
   -I         Add Interface name to alert output
   -k <mode>  Checksum mode (all,noip,notcp,noudp,noicmp,none)
   -K <mode>  Logging mode (pcap[default],ascii,none)
   -l <ld>    Log to directory <ld>
   -L <file>  Log to this tcpdump file
   -M         Log messages to syslog (not alerts)
   -m <umask> Set umask = <umask>
   -n <cnt>   Exit after receiving <cnt> packets
   -N         Turn off logging (alerts still work)
   -o         Change the rule testing order to Pass|Alert|Log
   -O         Obfuscate the logged IP addresses
   -p         Disable promiscuous mode sniffing
   -P <snap>  Set explicit snaplen of packet (default: 1514)
   -q         Quiet. Don't show banner and status report
   -r <tf>    Read and process tcpdump file <tf>
   -R <id>    Include 'id' in snort_intf<id>.pid file name
   -s         Log alert messages to syslog
   -S <n=v>   Set rules file variable n equal to value v
   -t <dir>   Chroots process to <dir> after initialization
   -T         Test and report on the current Snort configuration
   -u <uname> Run snort uid as <uname> user (or uid) after initialization
   -U         Use UTC for timestamps
   -v         Be verbose
   -V         Show version number
   -w         Dump 802.11 management and control frames
   -X         Dump the raw packet data starting at the link layer
   -y         Include year in timestamp in the alert and log files
   -Z <file>  Set the performonitor preprocessor file path and name
   -?         Show this information
<Filter Options> are standard BPF options, as seen in TCPDump
Longname options and their corresponding single char version
   --logid <0xid>                  Same as -G
   --perfmon-file <file>           Same as -Z
   --pid-path <path>               Specify the path for the Snort PID file
   --snaplen <snap>                Same as -P
   --help                          Same as -?
   --version                       Same as -V
   --alert-before-pass             Process alert, drop, sdrop, or reject before pass, 
                                   default is pass before alert, drop,...
   --treat-drop-as-alert           Converts drop, sdrop, and reject rules into alert 
                                   rules during startup
   --process-all-events            Process all queued events (drop, alert,...), 
                                   default stops after 1st action group
   --dynamic-engine-lib <file>     Load a dynamic detection engine
   --dynamic-engine-lib-dir <path> Load all dynamic engines from directory
   --dynamic-detection-lib <file>  Load a dynamic rules library
   --dynamic-detection-lib-dir <path> Load all dynamic rules libraries from 
                                   directory
   --dump-dynamic-rules <path>     Creates stub rule files of all loaded rules libraries
   --dynamic-preprocessor-lib <file>  Load a dynamic preprocessor library
   --dynamic-preprocessor-lib-dir <path> Load all dynamic preprocessor libraries from 
                                   directory
   --dump-dynamic-preproc-genmsg <path>  Creates gen-msg.map files of all loaded 
                                   preprocessor libraries
   --create-pidfile                Create PID file, even when not in Daemon mode
   --nolock-pidfile                Do not try to lock Snort PID file
   --disable-inline-initialization Do not perform the IPTables initialization in inline 
                                   mode.
   --loop <count>                  In combination with the -r <tf> option, 
                                   this will read the tcpdump file continuously
                                   for <count> times.  A value of 0 will read the pcap 
                                   until Snort is killed.
ERROR: 

Uh, you need to tell me to do something...

Fatal Error, Quitting..

最后出现了错误,但在这个过程中完成了一些重要的事情:

  1. 它确认了 Snort 二进制文件已正确安装到了您的路径中。这也就是说,您可以从计算机的任何目录运行它。
  2. 它为您提供了关于 Snort 版本及其相关库的重要信息。请注意靠近输出顶端的这段输出内容:
       ,,_     -*> Snort! <*-
      o"  )~   Version 2.8.0.2 (Build 75)  
       ''''    By Martin Roesch & The Snort Team: http://www.snort.org/team.html
               (C) Copyright 1998-2007 Sourcefire Inc., et al.
               Using PCRE version: 7.6 2008-01-28

    这使您可以轻而易举地看到正在运行的 Snort 和 PCRE 的版本。
  3. 它为您提供了可向 Snort 发送的简单命令纲要。

使用 Snort 进行嗅探

您知道,Snort 是一种入侵检测系统,但它是如何检测入侵的呢?Snort(和大多数高端 IDS)都会嗅探 网络流量。嗅探器是一种工具或设备(带有网卡),用于监控计算机之间的网络流量。有些嗅探器是 “第三方”,嗅探外部机器与嗅探器本身之间的流量。也有一些嗅探器会嗅探网络和嗅探器本身所在计算机之间的流量。在下一期的文章中,我们将进一步介绍嗅探,如果您目前对嗅探有不明确的地方,请不要担心。

目前,嗅探是一种简单而有用的方法,能够确保 Snort 已安装且能够正常工作,能够监控网络流量。使用 -v 标记运行 snort 命令,这告知 Snort 嗅探网络流量,将信息输出到控制台。清单 8 展示了在 Mac OS X 机器上运行 snort -v 的输出结果。

清单 8. 使用 Snort 进行嗅探
[bdm0509:~] snort -v
Running in packet dump mode

        --== Initializing Snort ==--
Initializing Output Plugins!
Verifying Preprocessor Configurations!
***
*** interface device lookup found: en0
***

Initializing Network Interface en0
ERROR: You don't have permission to sniff.
Try doing this as root.
Fatal Error, Quitting..

是的,这是一个错误,在这里输出有一个重要的目的:Snort 需要广泛的权限来完成大量工作。嗅探是一项基本操作,但毫无疑问,如果没有 root 权限,没有使用 sudo 的能力,就很难充分利用 Snort。

尝试相同的命令,但这一次在超级用户的账户下运行。您应看到类似于清单 9 的输出结果。必须使用 Ctrl+C 退出,否则 Snort 将一直运行。

清单 9. 使用 Snort 进行嗅探(成功的结果)
[bdm0509:~] sudo snort -v
Password:
Running in packet dump mode

        --== Initializing Snort ==--
Initializing Output Plugins!
Verifying Preprocessor Configurations!
***
*** interface device lookup found: en0
***

Initializing Network Interface en0
Decoding Ethernet on interface en0

        --== Initialization Complete ==--

   ,,_     -*> Snort! <*-
  o"  )~   Version 2.8.0.2 (Build 75)  
   ''''    By Martin Roesch & The Snort Team: http://www.snort.org/team.html
           (C) Copyright 1998-2007 Sourcefire Inc., et al.
           Using PCRE version: 7.6 2008-01-28

Not Using PCAP_FRAMES
03/31-08:55:12.179192 192.168.1.102:64862 -> 239.255.255.253:427
UDP TTL:1 TOS:0x0 ID:10292 IpLen:20 DgmLen:64
Len: 36
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

03/31-08:55:12.179498 192.168.1.102:64863 -> 239.255.255.253:427
UDP TTL:1 TOS:0x0 ID:10293 IpLen:20 DgmLen:64
Len: 36
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

03/31-08:55:12.180121 192.168.1.102:64864 -> 239.255.255.253:427
UDP TTL:1 TOS:0x0 ID:10294 IpLen:20 DgmLen:64
Len: 36
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

03/31-08:55:12.180278 192.168.1.102:64865 -> 239.255.255.253:427
UDP TTL:1 TOS:0x0 ID:10295 IpLen:20 DgmLen:64
Len: 36
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

03/31-08:55:12.247880 192.168.1.102:64866 -> 192.168.1.255:137
UDP TTL:64 TOS:0x0 ID:10296 IpLen:20 DgmLen:78
Len: 50
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

03/31-08:55:12.248297 192.168.1.103:137 -> 192.168.1.102:64866
UDP TTL:64 TOS:0x0 ID:8075 IpLen:20 DgmLen:90
Len: 62
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

03/31-08:55:12.599248 192.168.1.102:55381 -> 192.168.1.101:139
TCP TTL:64 TOS:0x0 ID:10297 IpLen:20 DgmLen:64 DF
******S* Seq: 0x42127B5E  Ack: 0x0  Win: 0xFFFF  TcpLen: 44
TCP Options (8) => MSS: 1460 NOP WS: 0 NOP NOP TS: 1428368232 0 
TCP Options => SackOK EOL 
...
LOTS more output here
...
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

03/31-08:55:21.976018 0.0.0.0:68 -> 255.255.255.255:67
UDP TTL:64 TOS:0x0 ID:48134 IpLen:20 DgmLen:328
Len: 300
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

03/31-08:55:21.976800 ARP who-has 192.168.1.104 tell 192.168.1.1

03/31-08:55:22.968515 192.168.1.1:67 -> 255.255.255.255:68
UDP TTL:150 TOS:0x0 ID:6040 IpLen:20 DgmLen:576
Len: 548
=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+

03/31-08:55:22.977578 ARP who-has 192.168.1.104 tell 192.168.1.104

^C*** Caught Int-Signal
Run time prior to being shutdown was 14.231224 seconds
===============================================================================
Packet Wire Totals:
   Received:           78
   Analyzed:           78 (100.000%)
    Dropped:            0 (0.000%)
Outstanding:            0 (0.000%)
===============================================================================
Breakdown by protocol (includes rebuilt packets):
      ETH: 78         (100.000%)
  ETHdisc: 0          (0.000%)
     VLAN: 0          (0.000%)
     IPV6: 0          (0.000%)
  IP6 EXT: 0          (0.000%)
  IP6opts: 0          (0.000%)
  IP6disc: 0          (0.000%)
      IP4: 71         (91.026%)
  IP4disc: 0          (0.000%)
    TCP 6: 0          (0.000%)
    UDP 6: 0          (0.000%)
    ICMP6: 0          (0.000%)
  ICMP-IP: 0          (0.000%)
      TCP: 57         (73.077%)
      UDP: 14         (17.949%)
     ICMP: 0          (0.000%)
  TCPdisc: 0          (0.000%)
  UDPdisc: 0          (0.000%)
  ICMPdis: 0          (0.000%)
     FRAG: 0          (0.000%)
   FRAG 6: 0          (0.000%)
      ARP: 3          (3.846%)
    EAPOL: 0          (0.000%)
  ETHLOOP: 0          (0.000%)
      IPX: 0          (0.000%)
    OTHER: 4          (5.128%)
  DISCARD: 0          (0.000%)
InvChkSum: 0          (0.000%)
  Upconvt: 0          (0.000%)
  Up fail: 0          (0.000%)
   S5 G 1: 0          (0.000%)
   S5 G 2: 0          (0.000%)
    Total: 78        
===============================================================================
Action Stats:
ALERTS: 0
LOGGED: 0
PASSED: 0
===============================================================================
Snort exiting

目前看来,这很可能没有太多意义,但没有关系。在本系列结束前,您将了解更多相关内容。目前,我们的任务是确保 Snort 已正确安装。如果您能够将 Snort 作为嗅探器运行,也就做好了继续使用 Snort 的准备,而不仅仅是向它发送令人迷惑的命令。

但我没有 root 访问权限!

至此为止,您已经了解到,Snort 需要的权限超过大多数普通用户账户的能力。即使您能够说服网络或系统管理员安装 Snort —— 并且为他们没有安装 Snort 而惋惜 —— 但如果没有获得额外的特权,您依然是只利用了 Snort 的部分功能。

然而,在普通的用户账户和 root 用户(或通过 sudo 命令授予的特权)之间仍然存在显著差异。大多数管理员都愿意帮助您缩短一点这个的差距。下面介绍了一种合理的方法,能使您的管理员允许您使用 Snort,并授予您使用 Snort 所需的权限:

安装 Snort

首先,安装 Snort。同样,某些管理员已经使用了 Snort。切记,Snort 不必运行在您希望保护和嗅探的机器之上。例如,您可能在几台服务器上管理几个 Web 站点。如果 Snort 能在所有服务器上运行并访问,并且您能够轻松通过远程登录使用它,这当然更好;但您也可以在您自己的机器上运行 Snort,并将其指向运行站点的服务器,从而获得大量信息。因此,您将能够使用 Snort 在您自己的桌面或笔记本电脑上为所欲为(重申一下,这并不是理想的做法,但至少可以算是朝着正确方向发展的一个步骤)。

如果管理员对您提起 Snort 毫无动情,请为他们推荐本文或 参考资料 中提到的某些 Snort 书籍。如果您能帮助保护他们负责的服务器,那么他们可能会更乐于为您提供所需的更多权限。

确保您可以运行 Snort

下一项优先任务就是确保您能够运行 snort 命令。因为 Snort 安装在 /usr/local/bin 中(默认目录),因此这非常简单,只需为所有用户或您的用户账户开放此目录,或者允许您的用户(或一个可以添加用户账户的组)使用该特定的二进制文件。最好的方法是首先提出最具体的请求。询问您的管理员,他们能否使您的特定用户账户可以运行 /usr/local/bin/snort。

实际上,大多数管理员都有较重的工作压力,往往十分忙碌。他们授予您的权限通常会超过您所要求的权限,但希望您不会提出一些在他们看来十分荒谬的要求,例如为您的账户授予对其负责的服务器上所有重要可执行程序的访问权限。您通常会得到居中的权限,例如进入可访问 Snort 等并不通用的程序的组,但这些程序并不存在像更改用户密码或删除用户账户那样的危险。

确保您能够使用 Snort

遗憾的是,Snort 需要写入大量受限的目录,并且要在其中运行。这也就是说,即便您可以运行 Snort,通常也无法使用它来做任何有生产意义的事情。参考下面的步骤,并坚持阅读本系列文章,我们将提供解决方法。

首先,默认情况下,Snort 所做的许多工作都要在受限目录中完成,它可以请求不受保护的目录。因此,您可以选择使 Snort 登录您已经有权访问的目录,减少部分权限问题。但最终,您依然会看到错误,如清单 10 所示。

清单 10. 权限错误
[bdm0509:~] snort -v
Running in packet dump mode

        --== Initializing Snort ==--
Initializing Output Plugins!
Verifying Preprocessor Configurations!
***
*** interface device lookup found: en0
***

Initializing Network Interface en0
ERROR: You don't have permission to sniff.
Try doing this as root.
Fatal Error, Quitting..

坏消息是:不存在好的规避方法,它需要通常与 root 用户相关联的权限。但也有好消息:也是这篇文章对 Web 开发人员而不仅仅是系统和网络管理员都有意义 —— 您在本地机器上配置和运行的一切都适用于在生产机器上运行的 Snort。因此,在您生成配置文件时,了解如何记录警报,为 Snort 开发规则,而这一切都在您的本地安装上完成(甚至可能是一台笔记本电脑),这样,您就是在构建一个可在任何位置检测入侵的系统。

虽然大多数管理员不会允许您自由支配,但许多管理员会准许您为他们提供脚本和规则文件(在下一期的文章中,我们将进一步介绍规则),由他们来替您运行 —— 往往是在您小心谨慎的时候。这是最好的情况吗?或许不是,但仍然会提供站点保护,这也是底线。

使日志和警报通过邮件发送给您

对于大多数 IDS 和管理员来说,最遗憾的事实莫过于常常发现很多问题,也忽略了很多问题。管理员有繁重的工作,即便您已经很好地设置了 Snort,为它提供了可靠的规则,仍然不代表您将得到一个安全的系统。大多数入侵都需要操作。因而,如果有可能,您应该要求管理员通过邮件为您发送日志和警报文件,不久之后,您的 Snort 将可以生成此类文件。您可以每周要求一次,作为自动化作业完成,但还可能需要配置 Snort,在问题出现时,自动为您和管理员发送邮件。同样,弄清楚在您的机器上完成此任务的配置,然后将其提交给管理员,帮助管理员完成此工作。

这样,无论您是 root 用户、具有超级用户特权的网络管理员,还是因系统管理员保护过度而为安装 PHP 脚本据理力争的 Web 开发人员,您都将受益于对 Snort 的深入理解。

试用三项功能

至此,您应已得到了可正常工作的 Snort 安装,也对使 Snort 运行(即便在半受限的环境中)有了一些深入的理解。在本文结束之前,我们有机会来观察和试用 Snort 的三项基本功能。这使您能够为下一篇文章做好准备,并具体了解 Snort 能够为您的系统带来怎样的影响。

Snort 是一种包嗅探器

 就是一组格式化的数据。网络不习惯于用较大的数据块或较小的字节来表示数据,而习惯于以包为单位。包不仅提供了数据,还提供了关于数据的简单信息。这允许包的发送方表明所发送的数据类型,也使包的接收方能够在研究数据本身之前对包的数据略有认识(称为有效负载)。

我的 IP 地址是什么?

有多种方法可用于确定您的计算机的 IP 地址。大多数 GUI 都提供了以可视化方法查找计算机 IP 地址的手段。Windows 中的网络控制面板提供了相关报告(在 TCP/IP 协议下);在 Mac OS X 上,System Preferences 中的 Network 面板将告诉您 IP 地址。还可利用一些命令。在 Windows 中,从命令行中运行 ipconfig。在 Mac OS X 、Linux 和 UNIX 中,ifconfig 的变体将完成此任务。

包嗅探器是一种工具,它会嗅探或调查包。使用 Snort,您可以在包的级别检查网络流量,这允许您查看原始数据,以及包的接收方附加到原始数据之上的信息。这是您使用带有 -v 标记的 snort 命令时获得的结果,将 Snort 作为包嗅探器运行时,您会获得三方面的信息:

  1. 关于 Snort 将信息记录到何处及其所检查的网络接口的信息。
  2. Snort 所嗅探的包,发送到指定网络接口,或从指定网络接口发出。
  3. Snort 在本次运行中完成的所有任务的汇总(在您结束嗅探时输出,通常要使用 Ctrl+C 控制)。

在下一篇文章中,您将了解到这些包中究竟有哪些内容,如何开始对这些包进行基本分析。目前,只需思考一下,对于各包来说,所有信息是都是针对该包报告的。这里是一个包的输出结果:

03/31-08:55:12.180121 192.168.1.102:64864 -> 239.255.255.253:427
UDP TTL:1 TOS:0x0 ID:10294 IpLen:20 DgmLen:64
Len: 36

如果您不确定,可尝试在您自己的机器上嗅探包,使用您自己的 Snort 安装,作为辅助,您还需要查看自己的 IP 地址。这将允许您将尚不确定的内容整理在一起。

Snort 是一种包记录器

包嗅探非常出色,但如您所见,Snort 的包嗅探模式假设您一直关注着显示器,急切地查看数千行网络数据。当然,您已经有了需要设计的站点和需要掌控的世界,所以这显然不理想。通过为 Snort 添加 -l 开关,就能告诉它将包记录到您选定的目录中(如清单 11 所示)。

清单 11: 告诉 Snort 在何处记录包
[bdm0509:~/Documents/developerworks/snort_1] sudo snort -l myLogDir/
Password:
Running in packet logging mode
Log directory = myLogDir/

        --== Initializing Snort ==--
Initializing Output Plugins!
Verifying Preprocessor Configurations!
***
*** interface device lookup found: en0
***

Initializing Network Interface en0
Decoding Ethernet on interface en0

        --== Initialization Complete ==--

   ,,_     -*> Snort! <*-
  o"  )~   Version 2.8.0.2 (Build 75)  
   ''''    By Martin Roesch & The Snort Team: http://www.snort.org/team.html
           (C) Copyright 1998-2007 Sourcefire Inc., et al.
           Using PCRE version: 7.6 2008-01-28

Not Using PCAP_FRAMES

请注意,这条命令在前台启动 Snort;如果此时按下 Ctrl+C,重新调出终端提示符,也就中止了 Snort 的记录。因此,应将 Snort 作为包记录器在一个可最小化、可忽略的窗口中运行,更好的方法是,将其作为长期运行的进程(作为守护进程或系统进程)。

退出此进程时,Snort 会为您提供与前述相同的汇总数据。但也会在您指定的目录中创建一个文件,列举所嗅探过的包:

[bdm0509:~/Documents/developerworks/snort_1] ls myLogDir/
snort.log.1206998502

打开这个文件,您将看到 Snort 运行时嗅探过的包的更多具体信息。但务必牢记,如果必须作为超级用户(使用 sudo)或 root 用户运行 Snort,也就必须使用相同的权限打开此文件。

查看该文件,它与上文列出的嗅探器输出略有不同。实际上,它的用处更小 —— 除非您想了解 Snort 如何分析自己的文件。这也是另一篇文章的主题,现在您尝试了使用 Snort、使用命令行版本、包嗅探器,但包记录器的更多内容不在此处赘述。

Snort 是 IDS(或 NIDS)

从根本上来说,包嗅探和包记录(以及对这些记录的分析)都是入侵检测系统(或者说 Snort 的另一种称呼:NIDS,即网络入侵检测系统)的子系统。这是 Snort 最杰出的领域。也是涉猎广泛、讲究技巧的方面。由于入侵的类型不断迅速变化,Snort 有一组规则,您可从 Snort 的站点下载这些规则,它们详细阐述了这些入侵,允许 Snort 观察入侵。规则频繁更改,保证(至少是尝试保证)与最新攻击的各种类型保持一致。

此外,您需要配置 Snort,告诉它在感知到攻击时应采取怎样的措施。这是您此前与之建立良好合作关系的网络和系统管理员出面拯救您的站点的时机……让他们来负责采取措施应对攻击。但如果您能通过提交配置和规则文件来使他们注意到攻击,那么您就已经在这场游戏中占据了领先地位。

如果您耐心不足,或者无法等待尝试将 Snort 作为 IDS 使用,请尝试运行 snort -A,这会将 Snort 切换为警报 模式。您必须付出一定的努力,才能使它正常运作,但在等待下一篇文章发表期间,这是一项不错的 Snort 试验。


原文章:http://www.ibm.com/developerworks/cn/web/wa-snort1/

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值