IPLOGでTCP/IPトラフィックを記録する



●概要

 IPLOGはTCP/IPのトラフィックを片っ端から記録してくれるツールです。これを使うと、ポートスキャンを仕掛けられたり、ftpポートをこっそり調べられたりしても記録することができる。
 IPLOGの主な機能は、iplog's documentにもあるように、

 ・TCP、UDP、ICMP のトラフィックを記録する
 ・TCP の connect、scan、FIN、SYN、Xmas および UDP スキャンの検出
 ・smurf、flagment 攻撃の検出
 ・OS の検出に使用される bogus TCP flag の検出

などです。snort などと比べると機能がかなりと少ない気がするが、トラフィックの検出機能は snort に備わっていない機能なので、ぜひ組合わせて使ってほしい。

●IPLOGのインストール

 IPLOGをhttp://ojnk.sourceforge.net/からダウンロードします。
 しかし、最近のOSではconfigureができません。下記のようなエラーが表示されます。
Please remember to use GNU make to build iplog.
iplog will not build with BSD (or any other) make.
You can get GNU make from any GNU mirror in /pub/gnu/make
 このため、パッチもダウンロードします。それぞれ/usr/local/srcに保存します。
 展開後、パッチ(iplog-2.2.3-make.patch.gz)を適用します。
# cd /usr/local/src
# tar zxvf iplog-2.2.3.tar.gz
# cd iplog-2.2.3
# patch -p1 < iplog-2.2.3-make.patch
# ./configure
# make
# make install
 これでインストール完了です。

●起動スクリプトの作成

 デーモンとして動作するように作成します。
# chkconfig: 345 58 74
# description:iplog
#!/bin/sh
#
# iplog This start and stops the iplog utility
#
# chkconfig: 345 97 03
# description: iplog's capabilities include the ability to detect \
# TCP port scans, TCP null scans, FIN scans, UDP and \
# ICMP "smurf" attacks, bogus TCP flags (used by \
# scanners to detect the operating system in use), \
# TCP SYN scans, TCP "Xmas" scans, ICMP ping floods, \
# UDP scans, and IP fragment attacks.
# Source function library.
. /etc/rc.d/init.d/functions
  if [ -z /var/run/iplog/iplog.pid ] ; then
#        pidfile=`/bin/cat /var/run/iplog/iplog.pid`
       exit 0
  fi
case "$1" in
  start)
    echo -n "Starting iplog:"
    /usr/local/sbin/iplog
    daemon $pidfile
    RETVAL=$?
    echo
    [ $RETVAL = 0 ]
    ;;
  stop)
    echo -n "Shutting down iplog:"
    killproc iplog
    echo
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac
exit 0

●IPLOG起動用のアカウント・グループの作成

 IPLOG起動用のアカウント・グループを作成します。
# groupadd nobody
# adduser -g nobody -d /dev/null -s /bin/false iplog

●PIDディレクトリの作成

 PIDディレクトリを作成します。
# mkdir /var/run/iplog
# chown iplog:nobody /var/run/iplog

●/etc/iplog.confの編集

 iplog.confを編集します。自分の環境に合わせる必要があります。
/*
** $Id: example-iplog.conf,v 1.2 2000/12/31 18:40:40 odin Exp $
**
** Example iplog configuration file.
** Edit me and copy me to /etc/iplog.conf
**
** See iplog.conf(5) for details on syntax and a full description
** of available options.
*/
# Run as an unprivileged account with the login "iplog"
user iplog
# Run with group "nobody"
group nobody
# User "iplog" has write permission for the directory "/var/run/iplog"
pid-file /var/run/iplog/iplog.pid
# Log to /var/log/iplog
logfile /var/log/iplog
# Use the syslog(3) facility log_daemon.
facility log_daemon
# Use the syslog(3) priority (level) log_info.
priority log_info
# Log the IP address as well as the hostname of packets. 
set log_ip true
# Do not log the destination of packets.
set log_dest false
# Ignore DNS traffic from nameservers in /etc/resolv.conf.
set ignore_dns
# Listen on eth0 and eth1
interface eth0
# Operate in promiscuous mode and watch the 192.168.0.x network
#promisc 192.168.0.0/24
/*
** Ignore DNS traffic from nameservers.
** Using the -d option will add similar rules for all nameservers
** listed in /etc/resolv.conf
*/
#ignore udp from 192.168.0.1 sport 53
#ignore udp from 192.168.0.2 sport 53
# Example log statement. 
#log tcp dport 1045:1055 sport ftp-data
# Ignore ftp-data connections from to ports 1024 and above.
ignore tcp dport 1024: sport 20
# Ignore WWW connections, if you're running a WWW server.
ignore tcp dport 80
# Ignore ICMP unreach.
ignore icmp type unreach
# Ignore all ICMP except ICMP echo packets.
ignore icmp type !echo
# Ignore UDP traffic from the 127.1.2 network
#ignore udp from 127.1.2/24
# or
#ignore udp from 127.1.2/255.255.255.0
ignore tcp dport 443     # https
ignore tcp dport 993     # imaps
ignore tcp dport 1984    # bb
ignore tcp dport 3551    # apcupsd
 自動起動の設定をします。
# chmod 755 /etc/rc.d/init.d/iplog
# chkconfig --add iplog
# chkconfig --level 345 iplog on
# chkconfig --list iplog
 これにより、サーバが再起動してもIPLOGは自動的に起動するようになります。

●ログローテーションの設定

 IPLOGのログはかなり肥大化するので、ログローテーションをする必要があります。
# vi /etc/logrotate.d/iplog
/var/log/iplog {
  weekly
  rotate 4
  missingok
  create 0600 root root
  postrotate
        /bin/killall -HUP `cat /var/run/iplog/iplog.pid 2>/dev/null` 2> /dev/null
  endscript
}
 これで自動的にログがローテートします。

●旧設定方法

rpmfind.netからダウンロードしてきた最新版のrpmファイルをインストールする。
# rpm -ivh iplog-2.2.3-fr2.i386.rpm
 iplog には libpcap が必要になるので、libpcap-0.6.2-9vl1.i386.rpm も併せてインストールする。設定ファイルは、/etc/iplog.conf だ。

 iplogデーモンのスタート及び停止は以下のとおり。
# /etc/rc.d/init.d/iplog start(スタート)
# /etc/rc.d/init.d/iplog stop (停止)
 iplog.conf の中身

 デフォルトでは以下のようになっている。
/*
** iplog configuration file.
**
** See iplog.conf(5) for details on syntax and a full description
** of available options.
*/
# Run as user "nobody."
user nobody  ←  実行ユーザは nobody
# Run with group "nobody."
group nobody  ←  実行グループは nobody
# Log to /var/log/iplog
logfile /var/log/iplog  ←  ログファイルを指定
# Log the IP address as well as the hostname of packets.
set log_ip true  ←  IP アドレスでも記録する
# Do not log the destination of packets.
set log_dest false
# Ignore DNS traffic from nameservers in /etc/resolv.conf.
set ignore_dns  ←  /etc/rosolv.conf のネームサーバからのDNSパケットは記録しない
# Listen on eth0
interface eth0  ←  eth0 のパケットを記録
# Example log statement.
#log tcp dport 1045:1055 sport ftp-data
# Ignore ftp-data connections from to ports 1024 and above.
#ignore tcp dport 1024: sport 20
# Ignore WWW connections, SMB and ICQ.
ignore tcp dport 80  ←  HTTP パケットを記録しない
ignore tcp dport 137  ←  SMB(TCP) パケットを記録しない
ignore tcp dport 138  ←  SMB(TCP) パケットを記録しない
ignore tcp dport 139  ←  SMB(TCP) パケットを記録しない
ignore udp dport 137  ←  SMB(UDP) パケットを記録しない
ignore udp dport 138  ←  SMB(UDP) パケットを記録しない
ignore udp dport 139  ←  SMB(UDP) パケットを記録しない
ignore udp dport 2049  ←  ICQ パケットを記録しない
ignore udp sport 4000  ←  ICQ パケットを記録しない
ignore udp dport 4000  ←  ICQ パケットを記録しない
# Ignore ICMP unreach.
#ignore icmp type unreach
# Ignore all ICMP except ICMP echo packets.
ignore icmp type !echo  ←  ICMP(ICMP echo を除く) パケットを記録しない
# Ignore UDP traffic from the 127.1.2 network
#ignore udp from 127.1.2/24
# or
#ignore udp from 127.1.2/255.255.255.0
 iplog を運用していると、気づくと思うが、NTP、SMTP、POP3 等を利用している場合、これらのパケットが大量にロギングされてしまう。これらを記録したくないときは iplog.conf に以下を加えればよい。
ignore udp dport ntp
ignore tcp dport 25
ignore tcp dport 110
 iplog.confを変更したら、必ずリロードする事。
# /etc/rc.d/init.d/iplog reload
 iplog.conf のマニュアルはこちらです。