网络安全 频道

Bro NIDS的安装与配置

Bro是一个目前比较活跃的开源NIDS系统,差不多两年前我写过一个有关它特性的帖子。

Bro:一个开放源码的高级NIDS系统
http://www.xfocus.net/articles/200310/624.html

近些日子陆续收到一些要求详细介绍如何使用的反馈,因此也就起了写个Bro相关系列文章的意,本篇作为此系列的第一篇,先从最基本的安装和配置讲起。


安装
----

由于Bro有一些其他开源NIDS所没有的高级特性(主要在于对策略脚本的支持),因此安装和配置上可能相对麻烦一些,这个帖子希望能提供一些有用的参考。

Bro的官方网站是:
http://www.bro-ids.org/

上面有基本的介绍信息和下载指示,网站的一些栏目内容还待完善中。相对Snort来说,使用Bro的人还是非常少的,因此Bro的邮件列表是一个得以获取帮助非常重要的资源,建议加入这个列表或经常浏览一下邮件列表的Web Archive,相关的信息在如下的链接:
http://www.bro-ids.org/mailing-list.html

最新版本Bro的下载地址:
ftp://bro-ids.org/bro-0.9-current.tar.gz

截止到写这个帖子的时候,Bro软件包的最新版本是0.9a10,在FTP服务器上还可以找到一些老版本。在我的RedHat 7.3测试系统上,0.9a9版本在编译完成后“make install”时会出错,这个问题在Bro的邮件列表上有人提过,没看到Bro的维护团队给出有效的解决方案,但安装0.9a10版本时倒是没碰上什么麻烦,应该算是解决了。

Bro软件需要libpcap库完成抓包功能,也自带了libpcap库,当然也可以在configure的时候指定使用外部已安装的libpcap。顺利的话,安装过程非常简单,就是标准的Unix软件安装四步曲:

# tar zxvf bro-0.9a10.tar.gz
# cd bro-0.9a10
# ./configure
# make
# make install

默认情况下,安装完成以后Bro所有安装文件位于 /usr/local/bro 目录下,目录结构与相应的说明如下:

bro
|-- archive                       # 用于存储归档文件的目录
|-- bin                           # 可执行文件目录
|   |-- bro                       # 主执行程序
|   |-- cf                        # 转换时间显示格式的工具
|   |-- ef
|   |-- hf
|   |-- nf
|   |-- pf
|   `-- rst                       # 用于切断TCP软件的工具,可以在脚本里调用
|-- doc                           # 使用及帮助文档目录
|   |-- Bro-Ref-Manual.pdf        # Bro脚本语言参考手册,PDF格式文档
|   |-- Bro-quick-start           # Bro快速使用指南目录,HTML格式的文档
.   .
.   .
.   .
|   |-- Bro-quick-start.pdf       # Bro快速使用指南,PDF格式文档
|   |-- Bro-reference-manual      # Bro脚本语言参考手册目录,HTML格式文档
.   .
.   .
.   .
|   |-- Bro-user-manual           # Bro使用手册目录,HTML格式文档
.   .
.   .
.   .
|   `-- Bro-user-manual.pdf       # Bro使用手册,PDF格式文档
|-- etc                           # 配置信息目录,Bro的配置文件bro.cfg可以放在这里
|   |-- VERSION
|   |-- alert_scores
|   `-- signature_scores
|-- logs                          # 日志目录,将来存储Bro的各类日志文件
|-- policy                        # Bro策略脚本目录,存储Bro自带的各种强大的功能脚本
|   |-- OS-fingerprint.bro
|   |-- active.bro
|   |-- alarm.bro
.   .
.   .
.   .
|   |-- sig-addendum.sig
|   |-- sig-functions.bro
|   |-- signatures.bro
|   |-- sigs                      # 规则文件目录,存放各个规则文件      
|   |   |-- ex.web-rules.sig
|   |   |-- p0fsyn.osf
|   |   |-- snort-default.sig
|   |   |-- ssl-worm.sig
|   |   `-- worm.sig
.   .
.   .
.   .
|   `-- worm.bro
|-- reports                       # 生成的告警文件存储目录
|-- scripts                       # 脚本目录,用于存放各种维护操作的脚本
|   |-- bro-logchk.pl
|   |-- bro_log_compress.sh
|   |-- frontend-mail-reports.sh
|   |-- frontend-site-report.sh
|   |-- host-grep
|   |-- host-to-addrs
|   |-- mail_notice.sh
|   |-- mvlog
|   `-- push_logs.sh
|-- site                          # 用于存放各类自定义规则和脚本的目录,定制自己的Bro功能
|   `-- signatures.sig
`-- var                           # 存放Bro执行过程中生成的临时文件,比如进程ID记录文件等

Bro软件包带的Bro脚本语言参考手册、Bro快速使用指南、Bro使用手册几个文档非常重要,涵盖了从使用入门到编写检测脚本等高级功能的几乎所有细节,如果仔细阅读了这几个文档就没有读本帖子的必要了。


运行
----

如果只是简单测试一下Bro的可用性、调试脚本,Bro可以通过在命令行直接指定参数的方法启动。

Bro程序支持如下的命令行参数:

[root@redhat7 bin]# ./bro -h
bro version 0.9a10
usage: ./bro [options] [file ...]
                 | policy file, or read stdin
    -d                 | activate policy file debugging
    -e       | augment loaded policies by given code
    -f         | tcpdump filter
    -g                 | dump current config into .state dir
    -h                 | command line help
    -i      | read from given interface
    -p         | add given prefix to policy file resolution
    -r       | read from given tcpdump file
    -s       | read rules from given file
    -t      | activate execution tracing
    -w      | write to given tcpdump file
    -v                 | print version and exit
    -z       | run the specified policy file analysis
    -A      | write transformed trace to given tcpdump file
    -C                 | ignore checksums
    -D           | DFA state cache size
    -F                 | force DNS
    -K        | set key for keyed hashing
    -L                 | benchmark for rules
    -O                 | optimize policy script
    -P                 | prime DNS
    -R     | replay events
    -S                 | enable rule debugging
    -T          | set ''RE_level'' for rules
    -W                 | activate watchdog timer
    -x       | print contents of state file
    -I            | print ID
    $BROPATH           | file search path (.:policy:policy/local:policy/sigs:/usr/local/bro/lib/)
    $BRO_PREFIXES      | prefix list ()

其中比较重要的参数有:
                 | 所要加载的策略脚本,如果不指定,从标准输入读取脚本代码
    -f         | tcpdump格式的BPF过滤器,用于从网络接口过滤读取特定的报文进行分析
    -i      | 指定监听的网络接口
    -p         | 增加对以''prefix''开头的脚本的加载解释执行
    -r       | 从''readfile''文件中读取报文记录
    -s       | 从''rulefile''文件读取检测规则,也就是使用这个参数指定规则文件
    -F                 | 强制使用缓存的
域名信息
    -O                 | 优化策略脚本的执行
    -P                 | 不执行策略脚本,而是提取脚本中出现的
域名,解析以后把结果缓存起来
    $BROPATH           | 环境变量,指定脚本和规则文件的搜索路径,此变量是必要的,命令行中指定的脚本都从这个路径中搜索

定义环境变量,执行Bro程序:    
[root@redhat7 bro]# export BROPATH=/usr/local/bro/policy
[root@redhat7 bro]# bin/bro -i eth0 -f ''tcp or udp'' mt
/usr/local/bro/policy/hot.bro, line 30: warning: no such host: ph33r.the.eleet.com
  .
  .
  .
/usr/local/bro/policy/portmapper.bro, line 139: warning: no such host: sun-rpc.mcast.net
pcap bufsize = 8192
listening on eth0

在进程正式进入监听之前,Bro会试图解析脚本中所有出现的
域名并对有问题的域名报错,这个过程可能会花费不少时间,可以先指定''-P''参数缓存一下脚本中的域名,那么在以后的启动命令中通过指定''-F''标记强制使用缓存的记录来加快启动过程。

[root@redhat7 bro]# bin/bro -i eth0 -P -f ''tcp or udp'' mt
[root@redhat7 bro]# bin/bro -i eth0 -F -f ''tcp or udp'' mt
/usr/local/bro/policy/hot.bro, line 30: warning: no such host: ph33r.the.eleet.com
/usr/local/bro/policy/scan.bro, line 96: warning: no such host: j5004.inktomisearch.com
  .
  .
  .
/usr/local/bro/policy/ftp.bro, line 74: warning: no such host: gvaona1.cns.hp.com
/usr/local/bro/policy/portmapper.bro, line 139: warning: no such host: sun-rpc.mcast.net
pcap bufsize = 8192
listening on eth0
Reading .state/state.bst ...



普通配置
--------

在生产环境中使用Bro,最好采用配置文件加脚本的方式来启动进程,这样做的好处是方便管理。Bro软件包提供了相应的配置和管理脚本,具体的配置过程简述如下:

进入软件包的scripts子目录,执行bro_config脚本

[root@redhat7 scripts]# ./bro_config

Running Bro Configuration Utility

Values enclosed in ''[ ]''s are the default value set if you hit return.

Automode not enabled
Using defaults from bro.cfg.example
Checking interfaces ....Done.
Log archive directory [/usr/local/bro/archive]
User id to install and run Bro under [root]
Interface name to listen on.  The default is to use the busiest one found. [lo]
eth0
Site name for reports (i.e. LBNL, FOO.COM, BAZ.ORG) [2]
Starting time for a report run (0001 is 12:01 am and 1201 is 12:01pm) [0000]
How often (in hours) to generate an activity report [24]
Email local reports? (YES/NO)  [NO]
Do you want to send external reports to a incident reporting org (e.g.: CERT, CIAC, etc) [NO]
Do you want to encrypt email reports (YES/NO) [NO]
May I guess your network configuration for you?  [YES]
Checking network
Running localnets script to determine the local network range ...
This will take about 20 seconds
Capturing packets .... done.
Analyzing dump file..... done.
Your network appears to contain the following networks:
Edit local.site.bro by hand if this is not correct
Press any key to now to continue.
[root@redhat7 scripts]# ls /usr/local/bro/etc

alert_scores  signature_scores  VERSION
0
相关文章