変奏現実

パソコンやMMORPGのことなどを思いつくまま・・・記載されている会社名・製品名・システム名などは、各社の商標、または登録商標です。

この画面は、簡易表示です

Linux

dovecot

元ネタはココ。

/etc/postfix/main.cf

以下を追記

myhostname=ssiscirine.perma.jp

mydomain=ssiscirine.perma.jp

myorigin = $mydomain

inet_interfaces = all

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

home_mailbox = Maildir/

smtpd_banner = $myhostname ESMTP unknown

 

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain = $myhostname

smtpd_recipient_restrictions =

permit_mynetworks

permit_sasl_authenticated

reject_unauth_destination

message_size_limit = 10485760


認証サービス起動

# /etc/rc.d/init.d/saslauthd start

# chkconfig saslauthd on

# mkdir -p /etc/skel/Maildir/{new,cur,tmp}

# chmod -R 700 /etc/skel/Maildir/

(1)dovecotをインスト

# yum -y install dovecot

(2)設定を修正

/etc/dovecot/conf.d/10-mail.conf

以下を追記

mail_location = maildir:~/Maildir

disable_plaintext_auth = no                          ← SSL接続なしを許可

(3)サービス起動

# service dovecot start

(4)自動起動設定

# chkconfig dovecot on

(5)メールアカウント作成

# adduser ユーザー名

# saslpasswd2 -f /var/lib/qpidd/qpidd.sasldb -u ssiscirine.perma.jp ユーザー名

# service saslauthd restart

状況

メール受信はOK。

しかしメール送信は認証ではじかれたが、暫くたったら通るようになった。



vmtoolbox

まだvmwareツールを入れてなかった。
これを入れておかないとVMDKファイルを圧縮できなくなる。
(1)X-WINDOWをインスト

# yum -y groupinstall “X Window System”

# yum -y groupinstall “Desktop”

# yum -y groupinstall “General Purpose Desktop”

このまま startx するとマウスもキーボードも使えなかったから
(2)日本語化パッチも入れる。

# yum -y groupinstall “Japanese Support”

もしTeraTermやWinSCPなどで接続しているならこの時点で全てオフラインにする。
ここから先はVMwareの画面で行う。
(3)vmtoolをインストールする
VMPlayer画面下の【ツールのインスト-ル】ボタンを押す。
(4)CD-ROMをマウント

# mkdir /mnt/cdrom

# mount /dev/cdrom /mnt/cdrom

mount: ブロックデバイス /dev/sr0 は書き込み禁止です、読込み専用でマウントします

(5)解凍しインスト。

# tar xvf /mnt/cdrom/VMwareTools-8.8.1-528969.tar.gz

# cd vmware-tools-distrib/

# ./vmware-install.pl

しばらく【Enter】応答を繰り返す

(6)X-Window起動

# startx

(7)キーボードを日本語に設定

画面上のSystem⇒Preferences⇒Keyboardで、Keyboard Preferencesを開き

Layoutsを選択し、画面下の【Add…】ボタンを押し、リストからJapanを選択して【OK】ボタンを押す。

リストのJapaneseにデフォルトを切り替える。

(8)VMware Toolを起動しディスク圧縮を行う。

画面上のApplication⇒System Tools ⇒ Terminalでコマンドラインを開き

# su –

# vmware-toolbox &

VMware Tools Properties 以外のウインドウを全て閉じる。

VMware Tools Properties画面のShrinkを選択し、リストの/をクリックして画面左下の【Shirink】ボタンを押す。

確認メッセージで【Yes】ボタンを押す。

Please Wait… のプログレスバーが進むのを待つ。

Shirink Diskメッセージで【Yes】ボタンを押す。

<暫く処理待ち>

Informationメッセージで【Yes】ボタンを押す。

画面上のApplication⇒System Tools ⇒ ShutDown…で【ShutDown】ボタンを押し停止させる。

2.84GバイトあったVMDKファイルが2.7Gバイトと若干小さくなっていた。

 
 



phpmyadmin

phpmyadminをインストする。

# yum -y install phpmyadmin

/etc/htpd/conf.dにphpMyAdmin.confが出来ているので
ブラウザから繋いでみる。

http://192.168.***.***/phpMyAdmin

しかし403エラーなので、設定をちょっと修正してLANの中ならOKにする。

/etc/htpd/conf.d/phpMyAdmin.conf

<Directory /usr/share/phpMyAdmin/>

の中に1行追加
Allow from 192.168

ブラウザから繋いでみる。

http://192.168.***.***/phpMyAdmin

パスワード応答は root と先に設定したパスワードでもいい。

※後で調整。

デザインが替わった様だ。

このままでも動くが

一応、

/usr/share/phpMyAdmin/の

config.sample.inc.phpをコピーしてconfig.inc.phpを作り、0666にモードを変えておく。

$cfg[‘blowfish_secret’] = ”; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

にパスワードを入れるため

パスワード作成ツールをインストし、

# yum -y install expect
# mkpasswd -l 46

で作ったパスワードを貼り付けてapache再起動。



mysql

mysqlをインストする。
元ネタはココ。
(1)パッケージをインスト。

# yum -y install mysql-server

(2)WinSCPで /etc/my.cnf を修正

[mysqld]

default-character-set = utf8

[mysql]

default-character-set = utf8

(3)起動

# /etc/rc.d/init.d/mysqld start

(4)自動起動設定。

# chkconfig mysqld on

# chkconfig –list mysqld

mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

(5)セキュリティを強化。

# mysql_secure_installation

Enter current password for root (enter for none):  【Enter】

OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

Set root password? [Y/n]  【Enter】

New password:  mysqlでのrootパスワード

Re-enter new password:  mysqlでのrootパスワード

Password updated successfully!

Reloading privilege tables..

… Success!

・・・

Remove anonymous users? [Y/n]  【Enter】

・・・

Disallow root login remotely? [Y/n]  【Enter】

・・・

Remove test database and access to it? [Y/n]  【Enter】

・・・

Reload privilege tables now? [Y/n]  【Enter】

… Success!

Cleaning up…

All done! If you’ve completed all of the above steps, your MySQL

installation should now be secure.

Thanks for using MySQL!



apache

apacheのインスト
元ネタはここ。
# yum -y install httpd
# yum -y install php php-mbstring
# /etc/rc.d/init.d/httpd start
# chkconfig httpd on
# chkconfig –list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
あとで以下のフォルダを元サーバーからコピー。
/etc/httpd/conf/*
/etc/httpd/conf.d/*
/etc/php.ini
/var/www/*
 



ntpd

ntpdをインストする
元ネタはココ。
(1)ntpdをインスト。
# yum -y install ntp
(2)ntpdサーバーを設定。

/etc/ntp.conf
#server 0.centos.pool.ntp.org
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org
server ntp.nict.jp # 日本標準時を提供しているNTPサーバー(stratum 1)
server ntp.jst.mfeed.ad.jp # 上記サーバーと直接同期しているNTPサーバー(stratum 2)
server <プロバイダのNTPサーバー名> # プロバイダのNTPサーバー※

(3)手動調整

# ntpdate ntp.nict.jp

19 Jan 13:20:06 ntpdate[18063]: step time server 133.243.238.243 offset -32401.513872 sec

(4)自動起動設定

# /etc/rc.d/init.d/ntpd start
ntpd を起動中:                                             [  OK  ]
# chkconfig ntpd on

# chkconfig –list ntpd

ntpd            0:off   1:off   2:on    3:on    4:on    5:on    6:off



iptables

元ネタはここ。
(1)WinSCPでiptablesのスクリプトを作成する。

/root/iptables.sh


#!/bin/bash



#—————————————#


# 設定開始 #


#—————————————#



# インタフェース名定義


LAN=eth0



#—————————————#


# 設定終了 #


#—————————————#



# 内部ネットワークのネットマスク取得


LOCALNET_MASK=`ifconfig $LAN|sed -e ‘s/^.*Mask:\([^ ]*\)$/\1/p’ -e d`



# 内部ネットワークアドレス取得


LOCALNET_ADDR=`netstat -rn|grep $LAN|grep $LOCALNET_MASK|cut -f1 -d’ ‘`


LOCALNET=$LOCALNET_ADDR/$LOCALNET_MASK




# ファイアウォール停止(すべてのルールをクリア)


/etc/rc.d/init.d/iptables stop



# デフォルトルール(以降のルールにマッチしなかった場合に適用するルール)設定


iptables -P INPUT DROP # 受信はすべて破棄


iptables -P OUTPUT ACCEPT # 送信はすべて許可


iptables -P FORWARD DROP # 通過はすべて破棄



# 自ホストからのアクセスをすべて許可


iptables -A INPUT -i lo -j ACCEPT



# 内部からのアクセスをすべて許可


iptables -A INPUT -s $LOCALNET -j ACCEPT



# 内部から行ったアクセスに対する外部からの返答アクセスを許可


iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT



# SYN Cookiesを有効にする


# ※TCP SYN Flood攻撃対策


sysctl -w net.ipv4.tcp_syncookies=1 > /dev/null


sed -i ‘/net.ipv4.tcp_syncookies/d’ /etc/sysctl.conf


echo “net.ipv4.tcp_syncookies=1” >> /etc/sysctl.conf



# ブロードキャストアドレス宛pingには応答しない


# ※Smurf攻撃対策


sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1 > /dev/null


sed -i ‘/net.ipv4.icmp_echo_ignore_broadcasts/d’ /etc/sysctl.conf


echo “net.ipv4.icmp_echo_ignore_broadcasts=1” >> /etc/sysctl.conf



# ICMP Redirectパケットは拒否


sed -i ‘/net.ipv4.conf.*.accept_redirects/d’ /etc/sysctl.conf


for dev in `ls /proc/sys/net/ipv4/conf/`


do


sysctl -w net.ipv4.conf.$dev.accept_redirects=0 > /dev/null


echo “net.ipv4.conf.$dev.accept_redirects=0” >> /etc/sysctl.conf


done



# Source Routedパケットは拒否


sed -i ‘/net.ipv4.conf.*.accept_source_route/d’ /etc/sysctl.conf


for dev in `ls /proc/sys/net/ipv4/conf/`


do


sysctl -w net.ipv4.conf.$dev.accept_source_route=0 > /dev/null


echo “net.ipv4.conf.$dev.accept_source_route=0” >> /etc/sysctl.conf


done



# フラグメント化されたパケットはログを記録して破棄


iptables -A INPUT -f -j LOG –log-prefix ‘[IPTABLES FRAGMENT] : ‘


iptables -A INPUT -f -j DROP



# 外部とのNetBIOS関連のアクセスはログを記録せずに破棄


# ※不要ログ記録防止


iptables -A INPUT ! -s $LOCALNET -p tcp -m multiport –dports 135,137,138,139,445 -j DROP


iptables -A INPUT ! -s $LOCALNET -p udp -m multiport –dports 135,137,138,139,445 -j DROP


iptables -A OUTPUT ! -d $LOCALNET -p tcp -m multiport –sports 135,137,138,139,445 -j DROP


iptables -A OUTPUT ! -d $LOCALNET -p udp -m multiport –sports 135,137,138,139,445 -j DROP



# 1秒間に4回を超えるpingはログを記録して破棄


# ※Ping of Death攻撃対策


iptables -N LOG_PINGDEATH


iptables -A LOG_PINGDEATH -m limit –limit 1/s –limit-burst 4 -j ACCEPT


iptables -A LOG_PINGDEATH -j LOG –log-prefix ‘[IPTABLES PINGDEATH] : ‘


iptables -A LOG_PINGDEATH -j DROP


iptables -A INPUT -p icmp –icmp-type echo-request -j LOG_PINGDEATH



# 全ホスト(ブロードキャストアドレス、マルチキャストアドレス)宛パケットはログを記録せずに破棄


# ※不要ログ記録防止


iptables -A INPUT -d 255.255.255.255 -j DROP


iptables -A INPUT -d 224.0.0.1 -j DROP



# 113番ポート(IDENT)へのアクセスには拒否応答


# ※メールサーバ等のレスポンス低下防止


iptables -A INPUT -p tcp –dport 113 -j REJECT –reject-with tcp-reset



# ACCEPT_COUNTRY_MAKE関数定義


# 指定された国のIPアドレスからのアクセスを許可するユーザ定義チェイン作成


ACCEPT_COUNTRY_MAKE(){


for addr in `cat /tmp/cidr.txt|grep ^$1|awk ‘{print $2}’`


do


iptables -A ACCEPT_COUNTRY -s $addr -j ACCEPT


done


}



# DROP_COUNTRY_MAKE関数定義


# 指定された国のIPアドレスからのアクセスを破棄するユーザ定義チェイン作成


DROP_COUNTRY_MAKE(){


for addr in `cat /tmp/cidr.txt|grep ^$1|awk ‘{print $2}’`


do


iptables -A DROP_COUNTRY -s $addr -m limit –limit 1/s -j LOG –log-prefix ‘[IPTABLES DENY_COUNTRY] : ‘


iptables -A DROP_COUNTRY -s $addr -j DROP


done


}



# IPアドレスリスト取得


. /root/iptables_functions


IPLISTGET



# 日本からのアクセスを許可するユーザ定義チェインACCEPT_COUNTRY作成


iptables -N ACCEPT_COUNTRY


ACCEPT_COUNTRY_MAKE JP


# 以降,日本からのみアクセスを許可したい場合はACCEPTのかわりにACCEPT_COUNTRYを指定する



# 中国・台湾・ロシア※からのアクセスをログを記録して破棄


# ※全国警察施設への攻撃元上位3カ国(日本・アメリカを除く)


# http://www.cyberpolice.go.jp/detect/observation.htmlより


iptables -N DROP_COUNTRY


DROP_COUNTRY_MAKE CN


DROP_COUNTRY_MAKE TW


DROP_COUNTRY_MAKE RU


iptables -A INPUT -j DROP_COUNTRY



#———————————————————-#


# 各種サービスを公開する場合の設定(ここから) #


#———————————————————-#



# 外部からのTCP22番ポート(SSH)へのアクセスを日本からのみ許可


# ※SSHサーバーを公開する場合のみ


iptables -A INPUT -p tcp –dport 22 -j ACCEPT_COUNTRY



# 外部からのTCP/UDP53番ポート(DNS)へのアクセスを許可


# ※外部向けDNSサーバーを運用する場合のみ


iptables -A INPUT -p tcp –dport 53 -j ACCEPT


iptables -A INPUT -p udp –dport 53 -j ACCEPT



# 外部からのTCP80番ポート(HTTP)へのアクセスを許可


# ※Webサーバーを公開する場合のみ


iptables -A INPUT -p tcp –dport 80 -j ACCEPT



# 外部からのTCP443番ポート(HTTPS)へのアクセスを許可


# ※Webサーバーを公開する場合のみ


iptables -A INPUT -p tcp –dport 443 -j ACCEPT



# 外部からのTCP21番ポート(FTP)へのアクセスを日本からのみ許可


# ※FTPサーバーを公開する場合のみ


iptables -A INPUT -p tcp –dport 21 -j ACCEPT_COUNTRY



# 外部からのPASV用ポート(FTP-DATA)へのアクセスを日本からのみ許可


# ※FTPサーバーを公開する場合のみ


# ※PASV用ポート60000:60030は当サイトの設定例


iptables -A INPUT -p tcp –dport 60000:60030 -j ACCEPT_COUNTRY



# 外部からのTCP25番ポート(SMTP)へのアクセスを許可


# ※SMTPサーバーを公開する場合のみ


iptables -A INPUT -p tcp –dport 25 -j ACCEPT



# 外部からのTCP465番ポート(SMTPS)へのアクセスを日本からのみ許可


# ※SMTPSサーバーを公開する場合のみ


iptables -A INPUT -p tcp –dport 465 -j ACCEPT_COUNTRY



# 外部からのTCP110番ポート(POP3)へのアクセスを日本からのみ許可


# ※POP3サーバーを公開する場合のみ


iptables -A INPUT -p tcp –dport 110 -j ACCEPT_COUNTRY



# 外部からのTCP995番ポート(POP3S)へのアクセスを日本からのみ許可


# ※POP3Sサーバーを公開する場合のみ


iptables -A INPUT -p tcp –dport 995 -j ACCEPT_COUNTRY



# 外部からのTCP143番ポート(IMAP)へのアクセスを日本からのみ許可


# ※IMAPサーバーを公開する場合のみ


iptables -A INPUT -p tcp –dport 143 -j ACCEPT_COUNTRY



# 外部からのTCP993番ポート(IMAPS)へのアクセスを日本からのみ許可


# ※IMAPSサーバーを公開する場合のみ


iptables -A INPUT -p tcp –dport 993 -j ACCEPT_COUNTRY



# 外部からのUDP1194番ポート(OpenVPN)へのアクセスを日本からのみ許可


# ※OpenVPNサーバーを公開する場合のみ


iptables -A INPUT -p udp –dport 1194 -j ACCEPT_COUNTRY



# VPNインタフェース用ファイアウォール設定


# ※OpenVPNサーバーを公開する場合のみ


[ -f /etc/openvpn/openvpn-startup ] && /etc/openvpn/openvpn-startup




#———————————————————-#


# 各種サービスを公開する場合の設定(ここまで) #


#———————————————————-#



# 拒否IPアドレスからのアクセスはログを記録せずに破棄


# ※拒否IPアドレスは/root/deny_ipに1行ごとに記述しておくこと


# (/root/deny_ipがなければなにもしない)


if [ -s /root/deny_ip ]; then


for ip in `cat /root/deny_ip`


do


iptables -I INPUT -s $ip -j DROP


done


fi



# 上記のルールにマッチしなかったアクセスはログを記録して破棄


iptables -A INPUT -m limit –limit 1/s -j LOG –log-prefix ‘[IPTABLES INPUT] : ‘


iptables -A INPUT -j DROP


iptables -A FORWARD -m limit –limit 1/s -j LOG –log-prefix ‘[IPTABLES FORWARD] : ‘


iptables -A FORWARD -j DROP



# サーバー再起動時にも上記設定が有効となるようにルールを保存


/etc/rc.d/init.d/iptables save



# ファイアウォール起動


/etc/rc.d/init.d/iptables start


/root/iptables_functions

# IPアドレスリスト取得関数定義

IPLISTGET(){

# http://nami.jp/ipv4bycc/から最新版IPアドレスリストを取得する

wget -q http://nami.jp/ipv4bycc/cidr.txt.gz

gunzip cidr.txt.gz

# 最新版IPアドレスリストが取得できなかった場合

if [ ! -f cidr.txt ]; then

if [ -f /tmp/cidr.txt ]; then

# バックアップがある場合はその旨をroot宛にメール通知して処理を打ち切る

echo cidr.txt was read from the backup! | mail -s $0 root

return

else

# バックアップがない場合はその旨をroot宛にメール通知して処理を打ち切る

echo cidr.txt not found!|mail -s $0 root

exit 1

fi

fi

# 最新版IPアドレスリストを /tmpへバックアップする

/bin/mv cidr.txt /tmp/cidr.txt

}

(2)IPアドレスリスト更新チェックを作成

/etc/cron.daily/iplist_check.sh

#!/bin/bash

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# 新旧IPLIST差分チェック件数(0を指定するとチェックしない)

# ※新旧IPLIST差分がSABUN_CHKで指定した件数を越える場合はiptables設定スクリプトを実行しない

# ※新旧IPLIST差分チェック理由はhttp://centossrv.com/bbshtml/webpatio/1592.shtmlを参照

SABUN_CHK=100

[ $# -ne 0 ] && SABUN_CHK=${1}

# チェック国コード

COUNTRY_CODE=’JP CN TW RU’

# iptables設定スクリプトパス

IPTABLES=/root/iptables.sh

# iptables設定スクリプト外部関数取り込み

. /root/iptables_functions

# IPアドレスリスト最新化

rm -f IPLIST.new

IPLISTGET

for country in $COUNTRY_CODE

do

if [ -f /tmp/cidr.txt ]; then

grep ^$country /tmp/cidr.txt >> IPLIST.new

else

grep ^$country /tmp/IPLIST >> IPLIST.new

fi

done

[ ! -f /tmp/IPLIST ] && cp IPLIST.new /tmp/IPLIST

# IPアドレスリスト更新チェック

diff -q /tmp/IPLIST IPLIST.new > /dev/null 2>&1

if [ $? -ne 0 ]; then

if [ ${SABUN_CHK} -ne 0 ]; then

if [ $(diff /tmp/IPLIST IPLIST.new | egrep -c ‘<|>’) -gt ${SABUN_CHK} ]; then

(

diff /tmp/IPLIST IPLIST.new

echo

echo “$IPTABLES not executed.”

) | mail -s ‘IPLIST UPDATE’ root

rm -f IPLIST.new

exit

fi

fi

/bin/mv IPLIST.new /tmp/IPLIST

sh $IPTABLES > /dev/null

else

rm -f IPLIST.new

fi

(3)起動

# sh iptables.sh
iptables: ファイアウォールルールを消去中:                  [  OK  ]
iptables: チェインをポリシー ACCEPT へ設定中filter         [  OK  ]
iptables: モジュールを取り外し中:                          [  OK  ]

<10分ぐらい>
iptables: ファイアウォールのルールを /etc/sysconfig/iptable[  OK  ]中:
iptables: ファイアウォールルールを適用中:                  [  OK  ]
#

(4)自動起動設定

# chkconfig iptables on



Clam AntiVirus

Clam AntiVirusをインストする

元ネタはここ。
(1)パッケージをインスト。
# yum -y install clamd
(2)設定を編集。

/etc/clamd.conf

#User clamav

(3)サービス実行。※元ネタと若干替わっている。

# /etc/rc.d/init.d/clamd start

Starting Clam AntiVirus Daemon: LibClamAV Warning: **************************************************
LibClamAV Warning: ***  The virus database is older than 7 days!  ***
LibClamAV Warning: ***   Please update it as soon as possible.    ***
LibClamAV Warning: **************************************************
                                                           [  OK  ]

(4)自動実行を設定。※元ネタと若干替わっている。

# chkconfig clamd on
# chkconfig –list clamd
clamd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

(5)ウィルス定義ファイル更新機能の有効化し実行してみる

# sed -i ‘s/Example/#Example/g’ /etc/freshclam.conf

# freshclam

・・・

bytecode.cvd updated (version: 163, sigs: 39, f-level: 63, builder: edwin)
Database updated (1120560 signatures) from db.jp.clamav.net (IP: 203.212.42.128)

(6)一応テストしてみる

# clamscan –infected –remove –recursive

———– SCAN SUMMARY ———–
Known viruses: 1119275
Engine version: 0.97.3
Scanned directories: 1
Scanned files: 10
Infected files: 0
Data scanned: 0.02 MB
Data read: 0.01 MB (ratio 2.00:1)
Time: 11.014 sec (0 m 11 s)

 (7)スキャンスプリプトをcromに登録しておく

/root/clamscan

#!/bin/bash

PATH=/usr/bin:/bin

# clamd update

yum -y update clamd > /dev/null 2>&1

# excludeopt setup

excludelist=/root/clamscan.exclude

if [ -s $excludelist ]; then

for i in `cat $excludelist`

do

if [ $(echo “$i”|grep \/$) ]; then

i=`echo $i|sed -e ‘s/^\([^ ]*\)\/$/\1/p’ -e d`

excludeopt=”${excludeopt} –exclude-dir=^$i”

else

excludeopt=”${excludeopt} –exclude=^$i”

fi

done

fi

# signature update

freshclam > /dev/null

# virus scan

CLAMSCANTMP=`mktemp`

clamscan –recursive –remove ${excludeopt} / > $CLAMSCANTMP 2>&1

[ ! -z “$(grep FOUND$ $CLAMSCANTMP)” ] && \

# report mail send

grep FOUND$ $CLAMSCANTMP | mail -s “Virus Found in `hostname`” root

rm -f $CLAMSCANTMP

# chmod +x clamscan
# echo “/proc/” >> clamscan.exclude
# echo “/sys/” >> clamscan.exclude
# mv clamscan /etc/cron.daily/

 



chkrootkitインストール

元ネタはココ
# yum -y install chkrootkit
No package chkrootkit available.
Error: Nothing to do
なので


EPELリポジトリ導入(EPEL)
(1)yumのプライオリティのパッケージをインスト
# yum -y install yum-plugin-priorities
ちょっと訂正を入れる。

 /etc/yum.repos.d/CentOS-Base.repo

 priority=1を[base][updates][extras]の各ブロックに追加。

(2)EPELリポジトリインストール

# rpm -ivh http://download.fedora.redhat.com/pub/epel/6/i386/epel-release-6-5.noarch.rpm

(3)epel-releaseアップデートして最新にしておく

 # yum -y update epel-release


再び、
(1)chkrootkitをインスト

# yum -y install chkrootkit
(2)実行してみて失敗がないか確認する。
# chkrootkit | grep INFECTED
(3)chkrootkit実行スクリプト作成する。

/root/chkrootkit

#!/bin/bash

PATH=/usr/bin:/bin

TMPLOG=`mktemp`

# chkrootkit実行

chkrootkit > $TMPLOG

# ログ出力

cat $TMPLOG | logger -t chkrootkit

# SMTPSのbindshell誤検知対応

if [ ! -z “$(grep 465 $TMPLOG)” ] && \

[ -z $(/usr/sbin/lsof -i:465|grep bindshell) ]; then

sed -i ‘/465/d’ $TMPLOG

fi

# rootkit検知時のみroot宛メール送信

[ ! -z “$(grep INFECTED $TMPLOG)” ] && \

grep INFECTED $TMPLOG | mail -s “chkrootkit report in `hostname`” root

rm -f $TMPLOG

(4)chkrootkit実行スクリプトへ実行権限付加

# chmod 700 chkrootkit

(5)chkrootkit実行スクリプトを毎日自動実行されるディレクトリへ移動

# mv chkrootkit /etc/cron.daily/

 (6)クラッシュした時のためにコマンドをメールで送る

作業フォルダを作り

# mkdir chkrootkitcmd

対象コマンドをコピし

# cp `which –skip-alias awk cut echo egrep find head id ls netstat ps strings sed uname` chkrootkitcmd/

一応改ざんチェックもしておく

# chkrootkit -p /root/chkrootkitcmd|grep INFECTED

圧縮し

# zip -r chkrootkitcmd.zip chkrootkitcmd/

作業フォルダは削除、

# rm -rf chkrootkitcmd

メールで送信する。

# yum -y install sharutils

# uuencode chkrootkitcmd.zip chkrootkitcmd.zip|mail root

元ファイルは消しておく

# rm -f chkrootkitcmd.zip



Tripwire

まずはTripwireか
1.ソースをダウンロード。
大元をみると
Looking for the latest version? Download tripwire-2.4.2.2-src.tar.bz2 (716.6 kB)
と書いてあったので、2.4.2.2をダウンロードしてWinSCPを使ってCentOS6.2の/rootにコピーする。
2.インスト

実際にインストするならココを見たほうがいい。

どうやらWordPress3.3.1の編集機能には問題があり改行が勝手に削除されるので、

ソースコード部分は手作業で修正したから信頼性はかなり低い。

(1)tar解凍し、インストール開始。

# tar jxvf tripwire-2.4.2.2-src.tar.bz2
# cd tripwire-2.4.2.2-src

# ./configure --prefix=/usr/local/tripwire sysconfdir=/etc/tripwire && make && make install

 Press ENTER to view the License Agreement.
【Enter】
ライセンス表示は【Space】で次頁へ移動できる。何度も【Space】
license agreement. [do not accept] accept
Continue with installation? [y/n] y
Enter the site keyfile passphrase: ++++++++++ ← サイトパスフレーズ(パスワード1みたいなもの)
Verify the site keyfile passphrase: ++++++++++
Enter the local keyfile passphrase: ********** ← ローカルパスフレーズ(パスワード2みたいなもの)
Verify the local keyfile passphrase: **********
Please enter your site passphrase: ++++++++++
Please enter your site passphrase: ++++++++++

———————————————-
The installation succeeded.

Please refer to
for release information and to the printed user documentation
for further instructions on using Tripwire 2.4 Open Source.

make[3]: ディレクトリ `/root/tripwire-2.4.2.2-src’ から出ます
make[2]: ディレクトリ `/root/tripwire-2.4.2.2-src’ から出ます
make[1]: ディレクトリ `/root/tripwire-2.4.2.2-src’ から出ます

(2)不要なファイルを削除

# cd
# rm  -rf  tripwire-2.4.2.2-src
# rm  tripwire-2.4.2.2-src.tar.bz2
rm: remove 通常ファイル `tripwire-2.4.2.2-src.tar.bz2′?  y

(3)tripwireが実行できる様にPATH環境変数を変更 .bashrcの構成に注意

# echo PATH=$PATH:/usr/local/tripwire/sbin >> .bashrc ; source .bashrc

 
3.設定。
(1)Tripwire設定ファイルの変更

WinSCPで/etc/tripwire の twcfg.txt をエディタで開く。

LOOSEDIRECTORYCHECKING =false  true に変更

REPORTLEVEL   =3 を 4 に変更して保存。

(2)Tripwire設定ファイル(暗号署名版)作成

# twadmin -m F -c /etc/tripwire/tw.cfg -S /etc/tripwire/site.key /etc/tripwire/twcfg.txt
Please enter your site passphrase: ++++++++++
Wrote configuration file: /etc/tripwire/tw.cfg

<不要なテキストを削除>

# rm -f /etc/tripwire/twcfg.txt

(3)ポリシーファイルを最適化するPerlスクリプトを作成

/etc/tripwire/twpolmake.pl

#!/usr/bin/perl

# Tripwire Policy File customize tool

# —————————————————————-

# Copyright (C) 2003 Hiroaki Izumi

# This program is free software; you can redistribute it and/or

# modify it under the terms of the GNU General Public License

# as published by the Free Software Foundation; either version 2

# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,

# but WITHOUT ANY WARRANTY; without even the implied warranty of

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License

# along with this program; if not, write to the Free Software

# Foundation, Inc., 59 Temple Place – Suite 330, Boston, MA 02111-1307, USA.

# —————————————————————-

# Usage:

# perl twpolmake.pl {Pol file}

# —————————————————————-

#

$POLFILE=$ARGV[0];

open(POL,”$POLFILE”) or die “open error: $POLFILE” ;

my($myhost,$thost) ;

my($sharp,$tpath,$cond) ;

my($INRULE) = 0 ;

while (<POL>) {

chomp;

if (($thost) = /^HOSTNAME\s*=\s*(.*)\s*;/) {

$myhost = `hostname` ; chomp($myhost) ;

if ($thost ne $myhost) {

$_=”HOSTNAME=\”$myhost\”;” ;

}

}

elsif ( /^{/ ) {

$INRULE=1 ;

}

elsif ( /^}/ ) {

$INRULE=0 ;

}

elsif ($INRULE == 1 and ($sharp,$tpath,$cond) = /^(\s*\#?\s*)(\/\S+)\b(\s+->\s+.+)$/) {

$ret = ($sharp =~ s/\#//g) ;

if ($tpath eq ‘/sbin/e2fsadm’ ) {

$cond =~ s/;\s+(tune2fs.*)$/; \#$1/ ;

}

if (! -s $tpath) {

$_ = “$sharp#$tpath$cond” if ($ret == 0) ;

}

else {

$_ = “$sharp$tpath$cond” ;

}

}

print “$_\n” ;

}

close(POL) ;

(4)ポリシーファイルの最適化

# perl /etc/tripwire/twpolmake.pl /etc/tripwire/twpol.txt > /etc/tripwire/twpol.txt.new

(5)最適化済ポリシーファイルを元にポリシーファイル(暗号署名版)作成

# twadmin -m P -c /etc/tripwire/tw.cfg -p /etc/tripwire/tw.pol -S /etc/tripwire/site.key /etc/tripwire/twpol.txt.new

Please enter your site passphrase: ++++++++++

Wrote policy file: /etc/tripwire/tw.pol

(6)ポリシーファイル(テキスト版)削除

# rm -f /etc/tripwire/twpol.txt*

(7)データベース作成

# tripwire -m i -s -c /etc/tripwire/tw.cfg
Please enter your local passphrase: ++++++++++

<結構長いAMD E350で2分ぐらい>

(8)実行してみる

# tripwire -m c -s -c /etc/tripwire/tw.cfg

<結構長いAMD E350で2分ぐらい>

 ===============================================================================
Error Report:
===============================================================================

No Errors

——————————————————————————-
*** End of report ***

Open Source Tripwire 2.4 Portions copyright 2000 Tripwire, Inc. Tripwire is a registered
trademark of Tripwire, Inc. This software comes with ABSOLUTELY NO WARRANTY;
for details use –version. This is free software which may be redistributed
or modified only under certain conditions; see COPYING for details.
All rights reserved.

(9)定期自動実行の設定

 /root/tripwire.sh

#!/bin/bash

PATH=/usr/sbin:/usr/bin:/bin:/usr/local/tripwire/sbin

# パスフレーズ設定

LOCALPASS=”**********” # ローカルパスフレーズ

SITEPASS=”++++++++++” # サイトパスフレーズ

cd /etc/tripwire

# Tripwireチェック実行

tripwire -m c -s -c tw.cfg|mail -s “Tripwire(R) Integrity Check Report in `hostname`” root

# ポリシーファイル最新化

twadmin -m p -c tw.cfg -p tw.pol -S site.key > twpol.txt

perl twpolmake.pl twpol.txt > twpol.txt.new

twadmin -m P -c tw.cfg -p tw.pol -S site.key -Q $SITEPASS twpol.txt.new > /dev/null

rm -f twpol.txt* *.bak

# データベース最新化

rm -f /usr/local/tripwire/lib/tripwire/*.twd*

tripwire -m i -s -c tw.cfg -P $LOCALPASS

<実行モード設定>

#chmod 700 tripwire.sh

<cron設定>

#echo “0 3 * * * root /root/tripwire.sh” > /etc/cron.d/tripwire

(10)とりあえず実行してみよう。

その前に内容確認。

# vi  tripwire.sh

LOCALPASS=”**********” # ローカルパスフレーズ

SITEPASS=”++++++++++” # サイトパスフレーズ

のままだったら、**********と++++++++++を正しい内容に書き換えよう。

# ./tripwire.sh

### Error: File could not be opened.
### Filename: /usr/local/tripwire/lib/tripwire/****************.twd

と出るかもしれない、その場合はもう一回やってみよう。




top