网络通信 频道

LINUX下的IDS测试

 //当时做这个实验是为了参加学院举行的学生学术论坛,文章有点长,请提出你的宝贵意见
  
  LINUX下的IDS测试实验
  2000级计算机一班:王维
  IDS(Instrusion Detection System),也就是大家平时所说的入侵检测系统,广泛的被运用于各种操作系统的安全检测和安全防御,以及探测网络受攻击的程度和次数。为以后的网络安全管理提供详实的资料和证据。
  由于条件的限制,我们只能够采取SNORT做为本次实验的IDS使用。
  Snort的一些功能:
  1.实时通讯分析和信息包记录
     2.包装有效载荷检查
     3.协议分析和内容查询匹配
     4.探测缓冲溢出、秘密端口扫描、CGI攻击、SMB探测、操作系统侵入尝试
     5.对系统日志、指定文件、Unix socket或通过Samba的WinPopus 进行实时报警
  下面,我将以REDHAT 7.3为例,讲述一个完整的入侵检测系统的调试和测试报告
  一,本机环境
  OS:REDHAT 7.3
  HardWare:CPU:P3 800 .256MB--SDRAM .20G/7200 --HARDDISC
  IDS:SNORT-1.9+Libpcap
  二.调试方法
  首先将在本机环境中安装SNORT。SNORT是一个免费的IDS软件,我们这次将利用他来做系统检测
  本机已经获得了SNORT-1.9这个版本。
  首先,为了更方便的定制后面的探测规则和调试需要,我们将采取手工编译源文件(scorcus)的方法安装。(版本说明:SNORT-1.9.0.tar.gz )
  本地安装的权限必须是:ROOT。如果不是ROOT。则必须采取SU指令,切换成本地系统管理员|:ROOT
  #su
  #passwd:************
  当确定从ROOT登陆以后,我们必须将源文件释放出来,因为在使用snort的时候,我们需要Libpcap这个包文件,所以在本机测试前,我们必须保证系统中有Libpcap。如果不清楚localhost是否已经有Libacap的话,可以用下面的指令查询:
  $ locate Libacap
  如果出现:
  /usr/lib/Libacap.1.9.0
  /usr/lib/Libpcap.a
  等提示信息的话,证明本机已经有了Libpcap.如果没有任何提示的话,则说明还没有Libpcap库文件,需要安装。那么进行下列操作:(我获取的Libpcap0.6.2.tar.gz)
  cd /usr/src/ids
  [root@kykin-L-linux ids]# tar –zxvf libpcap-0.6.2.tar.gz
  [root@kykin-L-linux ids]# ls
  libpcap-0.6.2 libpcap-0.6.2.tar.gz snort-1.9.0 snort-1.9.0.tar.gz
  这样的操作,将libpcap完全的释放到了本地文件夹中
  继续:
  [root@kykin-L-linux ids]# cd libpcap-0.6.2
  [root@kykin-L-linux libpcap-0.6.2]# ls
  aclocal.m4 configure.in lbl pcap-enet.c README.linux
  bpf CREDITS libpcap.a pcap.h savefile.c
  bpf_dump.c CVS LICENSE pcap-int.h savefile.o
  bpf_dump.o etherent.c llc.h pcap-linux.c scanner.c
  bpf_filter.c etherent.o Makefile pcap-linux.o scanner.l
  bpf_filter.o ethertype.h Makefile.in pcap-namedb.h scanner.o
  bpf_image.c FILES mkdep pcap-nit.c sll.h
  bpf_image.o gencode.c nametoaddr.c pcap-nit.h SUNOS4
  CHANGES gencode.h nametoaddr.o pcap-null.c TODO
  config.cache gencode.o net pcap.o tokdefs.h
  config.guess grammar.c nlpid.h pcap-pf.c VERSION
  config.h grammar.o optimize.c pcap-pf.h version.c
  config.h.in grammar.y optimize.o pcap-snit.c version.o
  config.log inet.c pcap.3 pcap-snoop.c
  config.status inet.o pcap-bpf.c ppp.h
  config.sub INSTALL pcap.c README
  configure install-sh pcap-dlpi.c README.aix
  这些源文件也就是我们即将进行编译的Libpcap文件,继续:
  [root@kykin-L-linuxlibpcap-0.6.2]# ./configure --prefix=/usr/local/libpcap-0.6.2
  (这句话的意思是:编译Libpcap文件到/usr/local/libpcap-0.6.2 目录)
  [root@kykin-L-linuxlibpcap-0.6.2]# make
  [root@kykin-L-linuxlibpcap-0.6.2]# makeinstall
  执行完上面的,我们已经完整的将Libpcap安装到了本系统中
  下面,我们将完成SNORT的安装和调试
  (为了测试的需要,我们不需要把SNORT的日志文件写入本地MYSQL数据库,那么对MYSQL数据库的操作步骤暂时省略)
  [root@kykin-L-linux ids]#tar –zxvf snort-1.9.0.tar.gz
  [root@kykin-L-linux ids]# cd snort-1.9.0
  [root@kykin-L-linux snort-1.9.0]# ls
  acconfig.h config.h.in contrib Makefile snort.8
  aclocal.m4 config.log COPYING Makefile.am src
  ChangeLog config.status doc Makefile.in stamp-h
  config.cache config.sub etc missing stamp-h.in
  config.guess configure install-sh mkinstalldirs templates
  config.h configure.in LICENSE rules
  [root@kykin-L-linux snort-1.9.0]# ./configure --prefix=/usr/local/snort19
  [root@kykin-L-linux snort-1.9.0]#make
  [root@kykin-L-linux snort-1.9.0]#makeinstall
  (这几个操作的含义和Libpcap相同)
  然后,我们将对SNORT作一系列的调试,使其正常运行,也方便管理
  [root@kykin-L-linux snort-1.9.0]# cp etc /usr/local/snort19 –r
  (复制当前文件夹下的ETC目录到SNORT19下面)
  [root@kykin-L-linux snort-1.9.0]# cp rules /usr/local/snort19 –r
  (复制全部规则文件)
  [root@kykin-L-linux snort-1.9.0]# cp etc/classification.config /root/
  [root@kykin-L-linux snort-1.9.0]# cp etc/snort.conf /root/.snortrc
  (将调用的文件属性修改)
  做完这一些,我们的工作已经完成了一大部分。下面我们将完成比较重要的一部分。入侵检测的规则定制
  [root@kykin-L-linux snort-1.9.0]#vi /root/.snortrc
  # This file contains a sample snort configuration.
  # You can take the following steps to create your
  # own custom configuration:
  #
  # 1) Set the network variables for your network
  # 2) Configure preprocessors
  # 3) Configure output plugins
  # 4) Customize your rule set
  #
  ###################################################
  # Step #1: Set the network variables:
  #
  # You must change the following variables to reflect
  # your local network. The variable is currently
  # setup for an RFC 1918 address space.
  #
  # You can specify it explicitly as:
  #
  # var HOME_NET 10.1.1.0/24
  。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
  (内容太多,暂时省略)
  首先。我们在整个config文件的102行找到:
  var RULE_PATH ../rules
  这个是本地存放规则的路径,我们必须根据自己的情况,完整写出来
  我的文件是这样的:
  var RULE_PATH /usr/local/snort19/rules
  然后,在config文件的590行。我们将会看见:
  include $RULE_PATH/bad-traffic.rules
  从这里开始,一直到后面,就是SNORT的整个规则集合。我们必须根据自己的情况作出详细的调试
  include $RULE_PATH/bad-traffic.rules
  include $RULE_PATH/exploit.rules
  include $RULE_PATH/scan.rules
  include $RULE_PATH/finger.rules
  include $RULE_PATH/ftp.rules
  include $RULE_PATH/telnet.rules
  include $RULE_PATH/rpc.rules
  include $RULE_PATH/rservices.rules
  include $RULE_PATH/dos.rules
  (文件的内容太多,暂时省略)
  你可以针对自己的系统的具体环境做出详细的规则说明,不需要的规则,就采取#注释的方法来去掉
  为了可执行指令:SNORT的方便调用,我们将做出连接说明
  [root@kykin-L-linuxsnort-1.9.0]#ln –s /usr/local/snort19/bin/snort /usr/sbin/snort
  然后。我们将建立一个新的目录来存放SNORT日志文件
  [root@kykin-L-linux snort-1.9.0]#cd /var/log
  [root@kykin-L-linux snort-1.9.0]#mkdir snort
  做完上面的一切,基本上完成了整个IDS的初步设定,下面我们将测试是否成功
  [root@kykin-L-linux snort-1.9.0]#snort
  Initializing Output Plugins!
  Log directory = /var/log/snort
  
  Initializing Network Interface eth0
  using config file /root/.snortrc
  Initializing Preprocessors!
  Initializing Plug-ins!
  Parsing Rules file /root/.snortrc
  
  +++++++++++++++++++++++++++++++++++++++++++++++++++
  Initializing rule chains...
  No arguments to frag2 directive, setting defaults to:
   Fragment timeout: 60 seconds
   Fragment memory cap: 4194304 bytes
   Fragment min_ttl: 0
   Fragment ttl_limit: 5
   Fragment Problems: 0
  Stream4 config:
  (文件太长,省略)
  当你看到这些输出信息的话,那么在你的系统中已经有了一套IDS
  下面我们来看看SNORT的一些使用方法
  [root@kykin-L-linux snort]#snort –help
  Initializing Output Plugins!
  snort: invalid option -- -
  
  -*> Snort! <*-
  Version 1.9.0 (Build 209)
  By Martin Roesch (roesch@sourcefire.com, www.snort.org)
  USAGE: snort [-options]
  Options:
   -A Set alert mode: fast, full, console, or none (alert file alerts only)
   "unsock" enables UNIX socket logging (experimental).
   -a Display ARP packets
   -b Log packets in tcpdump format (much faster!)
   -c Use Rules File
   -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 Read BPF filters from file
   -g Run snort gid as group (or gid) after initialization
   -G Add reference ids back into alert msgs (modes: basic, url)
   -h Home network =
   -i Listen on interface
   -I Add Interface name to alert output
   -l Log to directory
   -m Set umask =
   -n Exit after receiving 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 set explicit snaplen of packet (default: 1514)
   -q Quiet. Don''t show banner and status report
   -r Read and process tcpdump file
   -R Include ''id'' in snort_intf.pid file name
   -s Log alert messages to syslog
   -S Set rules file variable n equal to value v
   -t
  
   Chroots process to
  after initialization
   -T Test and report on the current Snort configuration
   -u Run snort uid as 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 Set assurance mode, match on established sesions (for TCP)
   -? Show this information
  are standard BPF options, as seen in TCPDump
  下面我将对这个文件做一些说明,我个人认为下列的这些参数比较重要:
  -A 设置报警模式,是快速,完全,或者是控制台,亦或是不报警
  -a 捕获ARP包
  -b 使用tcpdump的格式来写入日志
  -c 指定配置文件路径
  -d 捕获应用层数据
  -D 后台运行snort
  -e 显示第二层头信息
  -h 设置监听主机
  -m 设置掩码
  -z 只匹配已经完全建立链接的会话
  就我个人来说,我一般使用的是:snort -A fast -D-e –z来启动整个IDS系统。如果你有了MYSQL的数据库的话,你可以在这里选择是否将LOG文件存入本地数据库,甚至可以通过WEB的方法发布出来,供读取和分析
  到了这一部。IDS也建立成功了,那么我们来随机的选择一个时间段,测试本机在整个INTERNET上受到恶意扫描和攻击的情况分析
  [root@kykin-L-linux snort]# cd /var/log/snort
  [root@kykin-L-linux snort]ls
  [root@kykin-L-linux snort] 142.179.18.144 202.115.196.200 202.115.198.214 202.196.65.149 scan.log
  202.115.196.156 202.115.198.188 202.115.199.9 211.66.23.205 snort.log.1037336221
  202.115.196.167 202.115.198.213 202.115.32.61 alert
  我们任意的抽取了一个时间段的LOG文件,从中选取一个部分分析
  11/13-5:29:27.429801 UDP src: 142.179.18.144 dst: 202.115.198.188 sport: 1028 dport: 137 tgts: 6 ports: 6 event_id: 0
  11/13-5:29:27.759801 UDP src: 142.179.18.144 dst: 202.115.198.188 sport: 1028 dport: 137 tgts: 7 ports: 7 event_id: 471
  11/13-5:29:34.279801 UDP src: 142.179.18.144 dst: 202.115.198.188 sport: 1028 dport: 137 tgts: 8 ports: 8 event_id: 471
  11/13-5:29:34.449801 UDP src: 142.179.18.144 dst: 202.115.198.188 sport: 1028 dport: 137 tgts: 9 ports: 9 event_id: 471
  11/13-5:29:37.549801 UDP src: 142.179.18.144 dst: 202.115.198.188 sport: 1028 dport: 137 tgts: 10 ports: 10 event_id: 471
  11/13-5:29:41.989801 UDP src: 142.179.18.144 dst: 202.115.198.188 sport: 1028 dport: 137 tgts: 11 ports: 11 event_id: 471
  11/13-5:29:42.139801 UDP src: 142.179.18.144 dst: 202.115.198.188 sport: 1028 dport: 137 tgts: 12 ports: 12 event_id: 471
  通过这段日志文件的简单分析,我们可以得出下列结论
  这段日志说明了
  今天5点左右,有个IP是142.179.18.1444的朋友,在扫描202.115.198网段的共享或者是在使用一些低级的操作系统鉴别工具来鉴别这个网段的操作系统类型(因为高级的系统指纹鉴别系统是不会扫描137端口的)
  详细的分析一条日志吧
  再来详细分析一条
  11/13-5:29:27.429801 UDP src: 142.179.18.1444 dst: 202.115.198.188 sport: 1028 dport: 137 tgts: 6 ports: 6 event_id: 0
  UDP是使用的协议
  SRC是源IP
  DST是目标IP
  SPORT是源端口
  DPORT是目标端口
  有了这些日志的分析,再结合自己对网络协议的了解,我们很明白的知道了对方在针对你的系统在做什么了。。。。

 

转载地址:http://www.netsp.com.cn/Article/netsafe/idsips/200506/20050602135651.html

0
相关文章