Linux Tips

Menu

DJB Tools
  > daemontools, tcpserver, tcpanalog, djbdns,
Qmail
  > qmail, qmailanalog, APOP, SMTP認証, アンチウィルス, アンチスパム,
Open SSL
  > OpenSSL, Apache/mod_ssl, SSLWrap,
Cron
AirH" PHONE対応
analog, ipchains, NTP, WebMailer, SSH, BIND, namazu, seti@home,
Libsafe, ★References

analog

/etc/analog.cfg

analog.cfgは以下のパラメータを追加

# append by YANO
MONTHLY         OFF             # 月毎レポート
WEEKLY          ON              # 週毎レポート
DAILYREP        ON              # 日毎レポート
DAYREPROWS      7               # 日毎レポートは1週間分(7days)
HOURLYREP       ON              # 時間毎レポート
HOURREPROWS     168             # 時間毎レポートは1週間分(7days*24H)
DIRECTORY       OFF             # ディレクトリレポート
FILETYPE        OFF             # ファイルタイプレポート
SEARCHQUERY     OFF             # 検索語句レポート
SEARCHWORD      ON              # 検索語レポート
FULLBROWSER     OFF             # ブラウザーレポート
BROWSER         OFF             # ブラウザーの概要
OSREP           OFF             # OSレポート
REFERRER        ON              # リンク元レポート
REFSITE         ON              # リンク元サイトレポート
VHOST           OFF             # 仮想ホストレポート

REQINCLUDE      pages           # リクエストレポートはページだけを含めるようにする
#FILEEXCLUDE    *.jpg           # jpegファイルは統計対象外
#FILEEXCLUDE    *.png           # pngファイルは統計対象外
#FILEEXCLUDE    *.gif           # gifファイルは統計対象外

SUBDOMAIN       *.*.*           # サブドメインは階層表示
HOSTEXCLUDE     iron.bravotouring.com   # 自分のアクセスは統計対象外
ARGSEXCLUDE     /*/*.cgi,/*/*.pl        # CGIの引数は無視して統計
/etc/cron.3hourly/analog.cron

analogを自動実行させるスクリプト。但しnkfの1.92以前はUTF-8をサポートしていない為、下記リンクから2.00以降か、UTF-8対応版を貰ってくるべし。

#!/bin/sh
cd /usr/share/analog

# referer_logに含まれる検索語をURLデコードする
perl -e 'while (<>){ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; print;}' \
/var/log/httpd/referer_log* | nkf -e >./referer_log

# DNSキャッシュ
./dnstran /var/log/httpd/access_log

# analog
./analog >/dev/null 2>&1
参照
Analoghttp://www.analog.cx/
日本 Analog ユーザ会http://www.jp.analog.cx/
nkfhttp://www.ie.u-ryukyu.ac.jp/~kono/nkf/
nkf UTF-8(Rei FURUKAWA)http://www01.tcp-ip.or.jp/~furukawa/nkf_utf8/

ipchains

ftp,sshはtcpserverでlocalとinfoweb.ne.jp、plala.or.jp以外は拒否。nfsの穴あけはわかんなかったんで、使う時は全部開ける。

/etc/sysconfig/ipchains
:input ACCEPT
:forward ACCEPT
:output ACCEPT
-A input -s 0/0 -d 0/0 -i lo -j ACCEPT
# http
-A input -s 0/0 -d 0/0 http -p tcp -j ACCEPT
-A input -s 0/0 -d 0/0 https -p tcp -j ACCEPT
# smtp - guard by tcpserver
-A input -s 0/0 -d 0/0 smtp -p tcp -j ACCEPT
-A input -s 0/0 -d 0/0 smtps -p tcp -j ACCEPT
# pop3 - guard by tcpserver
-A input -s 0/0 -d 0/0 pop3 -p tcp -j ACCEPT
-A input -s 0/0 -d 0/0 pop3s -p tcp -j ACCEPT
# DNS
-A input -s 0/0 -d 0/0 domain -p tcp -j ACCEPT
-A input -s 0/0 -d 0/0 domain -p udp -j ACCEPT
#-A output -s 192.168.199.0/24 -d 0/0 domain -p tcp -j ACCEPT
#-A output -s 192.168.199.0/24 -d 0/0 domain -p udp -j ACCEPT
# ftp - guard by tcpserver
-A input -s 0/0 -d 0/0 ftp -p tcp -j ACCEPT
-A input -s 0/0 -d 0/0 ftps -p tcp -j ACCEPT
-A input -s 0/0 -d 0/0 ftps-data -p tcp -j ACCEPT
# ssh - guard by tcpserver
-A input -s 0/0 -d 0/0 ssh -p tcp -j ACCEPT
# telnet
#-A input -s 192.168.199.0/255.255.255.0 -d 0/0 telnet -p tcp -j ACCEPT
#
# NFS # NFSを使う時はlocalアドレスを全ポート開ける
#
#-A input -s 192.168.199.0/255.255.255.0 -d 192.168.199.0/255.255.255.0 -j ACCEPT
# ntp
-A input -s 0/0 -d 0/0 ntp -p udp -j ACCEPT
# syslog
-A input -s 0/0 -d 0/0 syslog -p udp -j ACCEPT
# spamd
-A input -s 127.0.0.1/24 -d 0/0 5783 -p tcp -j ACCEPT
-A input -s 0/0 -d 0/0 5783 -p tcp -j REJECT -l
#
-A input -s 0/0 -d 0/0 0:1023 -p tcp -j REJECT -y -l
-A input -s 0/0 -d 0/0 2049:2049 -p tcp -j REJECT -y
-A input -s 0/0 -d 0/0 0:1023 -p udp -j REJECT
-A input -s 0/0 -d 0/0 2049:2049 -p udp -j REJECT
-A input -s 0/0 -d 0/0 6000:6009 -p tcp -j REJECT -y
-A input -s 0/0 -d 0/0 7100:7100 -p tcp -j REJECT -y

ntp

NetGenesis SuperOPT70のNTP機能を有効にしているので、routerのNTPに同期させる。

/etc/ntp.conf
#
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available. The
# default stratum is usually 3, but in this case we elect to use stratum
# 0. Since the server line does not have the prefer keyword, this driver
# is never used for synchronization, unless no other other
# synchronization source is available. In case the local host is
# controlled by some external source, such as an external oscillator or
# another protocol, the prefer keyword would cause the local host to
# disregard all other synchronization sources, unless the kernel
# modifications are in use and declare an unsynchronized condition.
#
#server 127.127.1.0 # local clock
#fudge 127.127.1.0 stratum 10
server router # NetGenesis SuperOPT70のNTP機能を使用する
#server ntp1.jst.mfeed.ad.jp # NetGenesis SuperOPT70に設定
#server ntp2.jst.mfeed.ad.jp
#server ntp3.jst.mfeed.ad.jp

#
# Drift file. Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
#
driftfile /etc/ntp/drift
logfile /var/log/ntpd.log
#multicastclient # listen on default 224.0.1.1
#broadcastdelay 0.008

#
# Authentication delay. If you use, or plan to use someday, the
# authentication facility you should make the programs in the auth_stuff
# directory and figure out what this number should be on your machine.
#
authenticate no
restrict 192.168.1.0 mask 255.255.255.0

#
# Keys file. If you want to diddle your server at run time, make a
# keys file (mode 600 for sure) and define the key number to be
# used for making requests.
#
# PLEASE DO NOT USE THE DEFAULT VALUES HERE. Pick your own, or remote
# systems might be able to reset your clock at will. Note also that
# ntpd is started with a -A flag, disabling authentication, that
# will have to be removed as well.
#
#keys /etc/ntp/keys
参照
NTPhttp://www.matsusaka-u.ac.jp/~okumura/networking/ntp.html

WebMailer

タダでHTTPによるメールアクセス(いわゆるWebメール)を実現すべく、qmailのMailDir対応でフリーなソフトを探しまくってウェブメーラーを発見。CGIで軽いにも関わらずアドレス帳や署名のサポートは当然ながら添付ファイルまでも扱え文句無し。インストールも超簡単。

参照
ウェブメーラー Ver0.954http://www.ai.is.saga-u.ac.jp/~takeda/software.phtml

SSH

"OpenSSHにセキュリティホール"の報を読んで、遅ればせながらssh(Secure SHell) 3.1p1をrpmでインストール。tcpserverのtelnet環境もsshd環境に移行。WindowsクライアントにもTeraTermのSSH対応版を展開して、telnetを全面的に停止する。

OpenSSH 3.9p1はソースからインストール。

$ cd software/openssh-3.9p1
$ ./configure --sysconfdir=/etc/ssh
$ make
$ sudo make install
実行モジュールがrpmでは/usr/bin,/usr/sbinだったのに対して、/usr/local/bin,/usr/local/sbinに変るので要注意。

/etc/ssh/sshd_config

sshからrootでのログインを禁止、yano以外のssh接続を禁止。(suで昇格するのはOK)

#PermitRootLogin yes
PermitRootLogin no
 : 
#
AllowUsers yano

【備忘録】sshかコンソールかを問わず、リモート側にログインしている時にscpしようとすると失敗する。

参照
OpenSSHhttp://www.openssh.com/ja/
OpenSSH portableftp://ftp.jp.openbsd.org/pub/OpenBSD/OpenSSH/portable/
Tera Term Home Pagehttp://www.vector.co.jp/authors/VA002416/
Tera Term Pro for Windows 日本語版http://www.sakurachan.org/soft/teraterm-j/
TTSSH 日本語版http://www.sakurachan.org/soft/teraterm-j/ttssh/

bind

"lame server resolving 'xx.xx.xxx.xx.xxx.in-addr.arpa'"のログ抑制

/etc/named.conf

IPアドレスからホスト名を逆引きできなかった場合に出力される「lame server resolving …」というログを出力しないように設定。

logging {
  category lame-servers { null; };
};

namazu

build & install

詳細はhttp://www.ki.nu/software/namazu/tutorial/purpose.htmlを参照。

$ cd namazu-2.0.14/File-MMagic
$ perl Makefile.PL
$ make
$ sudo make install
$ cd ..
$ ./configure
$ make
$ make check
$ sudo make install

mknmzの環境設定

$ADDRESSにメールアドレス、$EXCLUDE_PATHに検索除外パス/portal/と/cv/を設定。

~/.mknmzrc

$ADDRESS = 'mail-mknmz@bravotouring.com';

$EXCLUDE_PATH = '\/portal\/|\/cv\/'; ←正規表現

毎日namazuのindexを更新するスクリプト

/etc/namazu/mknmzuserに列挙されたユーザーがmknmzの対象となる。また各ユーザー毎に~/.mknmzrcも反映させる。

/etc/cron.daily/mknmz.cron
#!/bin/sh
# 自動インデックス更新.shファイル
#
#PERL_BADLANG=0
LANG=ja_JP.eucJP
export LANG

#
# /etc/namazu/mknmzuserにmknmzを行うユーザーを列挙する
# ユーザー毎に~/.mknmzrcを置いて$ADDRESSを書換えるべき
#
for username in `cat /etc/namazu/mknmzuser`;

do
 uhome="/home/$username";
 rcfile="$uhome/.mknmzrc";
 if [ -f /usr/local/bin/mknmz ] &&
    [ -d $uhome/namazu/index ] &&
    [ -d $uhome/public_html ] ; then

   # ユーザー毎~/.mknmzrcがあれば指定
   if [ -f $rcfile ] ; then rcfile="-f $rcfile"; else rcfile=""; fi

   /usr/local/bin/mknmz $rcfile -O $uhome/namazu/index $uhome/public_html;
 fi
done
参照
全文検索システム Namazuhttp://www.namazu.org/
Namazu 2.0 入門http://www.ki.nu/software/namazu/tutorial/purpose.html

seti@home

rcスクリプトを作成

/etc/init.d/setiathome
#!/bin/sh
#
# setiathome  Start setiathome.
#
# Author: YANO (yano@bravotouring.com)
#
# chkconfig: 2345 99 50
# description: setiathome starts of services.
#
# processname: setiathome
# service directory: /usr/local/setiathome

# Source function library.
. /etc/rc.d/init.d/functions

PATH="/usr/local/bin:$PATH"
prog=setiathome
SVDIR=/usr/local/setiathome
RETVAL=0
export PATH SVDIR


start() {
  echo -n $"Starting $prog: "
  cd $SVDIR
  ./setiathome -nice 19 >/dev/null 2>1 &
  SETI_PS=`ps aux | grep setia | grep -v grep | awk '{print $2}'`;
  if [ -z "$SETI_PS" ]; then
    echo_failure
    RETVAL=1
  else
    echo_success
    RETVAL=0
  fi
  echo
  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/setiathome
}

stop() {
  echo -n $"Stopping $prog: "
  killproc setiathome
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/setiathome
}


case "$1" in
start)
  start
  ;;
stop)
  stop
  ;;
restart|reload)
  stop
  start
  ;;
*)
  echo $"Usage: $prog {start|stop|restart|reload}"
  exit 1
esac

exit $RETVAL
参照
seti@homehttp://setiathome.ssl.berkeley.edu/

Libsafe

スタックバッファオーバフローやフォーマットストリングによる攻撃を未然に防止するツールLibsafeを導入する。完璧ではないらしいが、取り敢えず気休め程度と言う事でそのへんはご愛敬。

build & install

http://www.avayalabs.com/project/libsafe/から最新版(2.0-16)を落して展開する。

$ tar zxvf ~/archives/libsafe-2.0-16.tgz

violation検出時にメールによる通知を行わせるよう、Makefileに下記オプションを追加。

libsafe-2.0-16/src/Makefile
CCFLAGS += -DNOTIFY_WITH_EMAIL

build & install

$ make
$ sudo make install

setup

violation通知メールの宛先アドレスを設定

/etc/libsafe.notify
# echo yano@bravotouring.com > /etc/libsafe.notify

/etc/init.d以下のすべての起動スクリプトのみに適用させるので、/etc/init.d/functionsに下記設定を追加する。

/etc/init.d/functions
# append by YANO 2002/12/25
# setup for libsafe - http://www.avayalabs.com/project/libsafe/
export LD_PRELOAD=/lib/libsafe.so.2
参照
Libsafehttp://www.avayalabs.com/project/libsafe/
脆弱性を回避するための対策
参考(Libsafeの導入事例)
http://www.atmarkit.co.jp/fsecurity/rensai/iprotect03/iprotect02.html

References

日本の Linux 情報
 -- JF Project
 -- JM Project
Red Hat
 -- オフィシャル Red Hat Linux 7.3リファレンスガイド
FreeBSD
 -- FreeBSD ハンドブック
TurboLinux
 -- TurboLinux マニュアル・ドキュメント
日経 ITPro
 -- 日経Linux : Linuxカーネル設定パラメータ一覧 : index
@IT Linux Square

★Linux Square全記事インデックス★
http://www.atmarkit.co.jp/flinux/index/indexfiles/index-linux.html
・Linux管理者への道
http://www.atmarkit.co.jp/flinux/index/indexfiles/rootindex.html
・ApacheによるWebサーバ構築
http://www.atmarkit.co.jp/flinux/index/indexfiles/apacheindex.html
・実用qmailサーバ運用・管理術
http://www.atmarkit.co.jp/flinux/index/indexfiles/qmailindex.html
・BINDで作るDNSサーバ
http://www.atmarkit.co.jp/flinux/index/indexfiles/bindindex.html

ITmedia HelpDesk
 ☆ Howto
  ・いちばん近道なLinuxマスター術
   3. アクセスコントロールを知ってサーバ運用の基本を理解しよう
   4. システムログの読み方を理解しよう
   5. Webサーバのアクセス解析をしよう
  ・IDSで不正アクセスを監視したい〜swatch編〜 (swatch)
  ・ウイルスからLinuxサーバを守る (Sophos Anti-Virus)
 ☆ Tips
 -- ブート時のメッセージをゆっくりと確認したい
 -- ユーザーごとに使用容量制限をしたい
 -- root権限を持つことが可能な一般ユーザーを限定させたい
ASCII24
 -- Linux.com
みっきーのネットワーク研究所
 -- Snortを使おう

software関連
qmail
djbdns
DJB's software maniacs
daemontools
relay-ctrl
qlogtools
qlogselect


Topに戻る

Copyright (c) 1998-2004 by YANO
All rights reserved.