変奏現実

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

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

パソコン

入れ替え

ブログサーバーをVMPlayerからベタなPCに変えました。
反応は多少良くなったハズです。
今度のPCスペックは

  • CPU: Intel Celeron G540
  • メモリ: 4GB (DDR3- 13333MHz CL9 2GB × 2個)
  • SSD: Samsung 830Series (128GB)
  • LAN: 1Gbps

です。
電源はKRPW-PT500W/92+ 500Wなせいか 排気が熱くありません。
CPU温度が30度(室温)ってどうなってるんでしょうね?
これで暫く様子を見ることにします。
んじゃ英訳してみるか。
I replace blog’PC  from VMPlayer to generic-PC.
Would PC performance have been better?
New-PC SpecList

  • CPU: Intel Celeron G540
  • Memory: 4GB (DDR3- 13333MHz CL9 2GB × 2個)
  • SSD: Samsung 830Series (128GB)
  • LAN: 1Gbps

I have been observing to work blog’ server .
やっぱり英単語で書いた日本語にしか見えないなぁ~



PCにそのままCentOS6.2をインスト(8)

Apacheをいんすと

yum -y install httpd
Package httpd-2.2.15-15.el6.centos.1.i686 already installed and latest version Nothing to do
きにするなと返事が返ってきた。
PHPをインストール
yum -y install php php-mbstring
MYSQLをいんすと
yum -y install mysql-server
起動
 /etc/rc.d/init.d/mysqld start
 chkconfig mysqld on
MySQL初期設定
mysql_secure_installation 
MySQLデータベースバックアップスクリプト作成
 mysql-backup.sh

ーーーココからーーー
#!/bin/bash
PATH=/usr/local/sbin:/usr/bin:/bin
# バックアップ先ディレクトリ
BACKDIR=/backup/mysql
# MySQLrootパスワード
ROOTPASS=xxxxxxxx
# バックアップ先ディレクトリ再作成
rm -rf $BACKDIR
mkdir -p $BACKDIR
# データベース名取得
DBLIST=`ls -p /var/lib/mysql | grep / | tr -d /`
# データベースごとにバックアップ
for dbname in $DBLIST
do
 table_count=`mysql -u root -p$ROOTPASS -B -e "show tables" $dbname|wc -l`
 [ $table_count -ne 0 ] &&
 mysqlhotcopy $dbname -u root -p $ROOTPASS $BACKDIR | logger -t mysqlhotcopy
done
ーーーココまでーーー
chmod 700 mysql-backup.sh
実行してみる
./mysql-backup.sh
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
外部から実行できなくしてあったせい
とりあえずパスワードも追加
mysql -u root -p
SET PASSWORD FOR root@localhost=PASSWORD('********************');
quit
たぶんエラーになるので修正しておく
vi /usr/bin/mysqlhotcopy

my @dbh_tables = eval { $dbh->tables() };
の下に
map { s/^.*?\.//o } @dbh_tables; ← 追加

phpMyAdminインストール

yum install phpmyadmin
/etc/httpd/conf.d/phpMyAdmin.conf を編集
<Location /phpmyadmin>
Order deny,allow
Deny from all
Allow from 127.0.0.1
Allow from 192.168.1 ← 内部ネットワークアドレスを指定
</Location>
を追加
 
 
 


 mysql_secure_installation ← MySQL初期設定


PCにそのままCentOS6.2をインスト(7)

NTPサーバーインストール

 yum -y install ntp
/etc/ntp.conf ← ntp設定ファイル編集
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap を追加
#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サーバー※
手動調整
1回目
ntpdate ntp.nict.jp
8 Jul 18:16:40 ntpdate[2352]: step time server 133.243.238.163 offset -28219.469647 sec
2回目
ntpdate ntp.nict.jp
8 Jul 18:17:01 ntpdate[2354]: adjust time server 133.243.238.244 offset 0.002021 sec
実行
/etc/rc.d/init.d/ntpd start
自動実行設定
chkconfig ntpd on
暫くして確認
[root@ssiscirine ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ntp-b2.nict.go. .NICT.           1 u   31   64    3   44.138    1.780   3.033
 ntp1.jst.mfeed. 210.173.160.86   2 u   29   64    3   34.625    3.007  35.681
 ns5.rdc1.kt.hom .INIT.          16 u    -   64    0    0.000    0.000   0.000
ダメっぽい


PCにそのままCentOS6.2をインスト(6)

ファイアウォール構築(iptables)
 
スクリプト作成
 

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
ーーーココまでーーー
ファイアウォール設定スクリプト外部関数作成
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
}
ーーーココまでーーー
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=9999
[ $# -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
ーーーココまでーーー
実行属性を追加
chmod +x /etc/cron.daily/iplist_check.sh
実行してみる
モジュールを取り外しに結構時間がかかるようだ。
自動起動設定
chkconfig iptables on

    


PCにそのままCentOS6.2をインスト(5)

アンチウィルスソフト導入(Clam AntiVirus)
Clam AntiVirusインストール
/etc/clamd.conf を clamd設定ファイル編集

#User clam とコメントアウトする

起動してみる

/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  ]

clamd自動起動設定
 

chkconfig clamd on

ウィルス定義ファイル更新機能の有効化

sed -i ‘s/Example/#Example/g’ /etc/freshclam.conf
 
ウィルス定義ファイル最新化

freshclam
ClamAV update process started at Mon Jul  9 01:33:45 2012
WARNING: DNS record is older than 3 hours.
WARNING: Invalid DNS reply. Falling back to HTTP mode.
Reading CVD header (main.cvd): OK
main.cvd is up to date (version: 54, sigs: 1044387, f-level: 60, builder: sven)
Reading CVD header (daily.cvd): OK
WARNING: getfile: daily-13811.cdiff not found on remote server (IP: 211.10.155.48)
WARNING: getpatch: Can't download daily-13811.cdiff from db.jp.clamav.net
WARNING: getfile: daily-13811.cdiff not found on remote server (IP: 203.212.42.128)
WARNING: getpatch: Can't download daily-13811.cdiff from db.jp.clamav.net
WARNING: getfile: daily-13811.cdiff not found on remote server (IP: 27.96.54.66)
WARNING: getpatch: Can't download daily-13811.cdiff from db.jp.clamav.net
WARNING: Incremental update failed, trying to download daily.cvd
connect_error: getsockopt(SO_ERROR): fd=5 error=110: Connection timed out
Can't connect to port 80 of host db.jp.clamav.net (IP: 219.106.242.51)
Downloading daily.cvd [100%]
daily.cvd updated (version: 15117, sigs: 228019, f-level: 63, builder: guitar)
Downloading bytecode.cvd [100%]
bytecode.cvd updated (version: 187, sigs: 37, f-level: 63, builder: neo)
Database updated (1272443 signatures) from db.jp.clamav.net (IP: 211.10.155.48)
大丈夫なのか?
 freshclam
ClamAV update process started at Mon Jul  9 01:34:50 2012
WARNING: DNS record is older than 3 hours.
WARNING: Invalid DNS reply. Falling back to HTTP mode.
Reading CVD header (main.cvd): OK
main.cvd is up to date (version: 54, sigs: 1044387, f-level: 60, builder: sven)
Reading CVD header (daily.cvd): OK (IMS)
daily.cvd is up to date (version: 15117, sigs: 228019, f-level: 63, builder: guitar)
Reading CVD header (bytecode.cvd): OK (IMS)
bytecode.cvd is up to date (version: 187, sigs: 37, f-level: 63, builder: neo)
2度目でOKらしい。
ではテスト
 clamscan --infected --remove --recursive
----------- SCAN SUMMARY -----------
Known viruses: 1267143
Engine version: 0.97.3
Scanned directories: 5
Scanned files: 12
Infected files: 0
Data scanned: 1.70 MB
Data read: 0.57 MB (ratio 2.95:1)
Time: 4.153 sec (0 m 4 s)
実行スクリプト作成
virusscan
ーーーココからーーー
#!/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
# 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 virusscan
echo "/proc/" >> clamscan.exclude
echo "/sys/" >> clamscan.exclude
移動
mv virusscan /etc/cron.daily/


PCにそのままCentOS6.2をインスト(4)

rootkit検知ツール導入(chkrootkit)をインストする前に
 
EPELリポジトリ導入(EPEL)

yum -y install yum-plugin-priorities
/etc/yum.repos.d/CentOS-Base.repo を編集
全セクションに
priority=1 を追加するだけ
パッケージをインストール
rpm -ivh http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-5.noarch.rpm
するとそのパッケージはなかったので
rpm -ivh http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-7.noarch.rpm
そしてアップデート
yum -y update epel-release
失敗したら、何度もやり直す。
chkrootkitインストール
yum -y install chkrootkit
chkrootkitを実行してみる
chkrootkit | grep INFECTED
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
ーーーココまでーーー
実行モードを設定して
chmod 700 chkrootkit
移動
mv chkrootkit /etc/cron.daily/
バックアップを作成する
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
uuencodeコマンドインストール
yum -y install sharutils
ルート宛に送ってみる
uuencode chkrootkitcmd.zip chkrootkitcmd.zip|mail root
rm -f chkrootkitcmd.zip



PCにそのままCentOS6.2をインスト(3)

1.ファイル改竄検知システム導入(Tripwire)をインスト
http://sourceforge.net/projects/tripwire/files/OldFiles/ で最新版をチェックすると、
Download tripwire-2.4.2.2-src.tar.bz2 (716.6 kB) となっていた。
ダウンロードして、
> wget   http://sourceforge.net/projects/tripwire/files/latest/download?source=files
> 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]
license agreement. [do not accept] [accept]
※ここでDELキーで修正したりするとエラーでインスト中止になる。
Continue with installation? [y/n] [y]
Enter the site keyfile passphrase: [xxxxxxxx]
Verify the site keyfile passphrase:
・・・
The installation succeeded.
後始末
> cd
> rm -rf tripwire-2.4.2.2-src
> rm -rf tripwire-2.4.2.2-src.tar.bz2
パスを通す
> echo PATH=$PATH:/usr/local/tripwire/sbin >> .bashrc ; source .bashrc
/etc/tripwire/twcfg.txt を修正
REPORTLEVEL   =  3 => 4
Tripwire設定ファイル(暗号署名版)作成
> twadmin -m F -c /etc/tripwire/tw.cfg -S /etc/tripwire/site.key /etc/tripwire/twcfg.txt
Tripwire設定ファイル(テキスト版)削除
> rm -f /etc/tripwire/twcfg.txt
ポリシーファイルを作る
/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) ;
---ココまで---
最適化する
perl /etc/tripwire/twpolmake.pl /etc/tripwire/twpol.txt > /etc/tripwire/twpol.txt.new
(暗号署名版)作成
twadmin -m P -c /etc/tripwire/tw.cfg -p /etc/tripwire/tw.pol -S /etc/tripwire/site.key /etc/tripwire/twpol.txt.new
後始末
rm -f /etc/tripwire/twpol.txt*
データベース作成
tripwire -m i -s -c /etc/tripwire/tw.cfg
動作確認
tripwire -m c -s -c /etc/tripwire/tw.cfg
定期自動実行スクリプト作成
tripwire.sh
---ココから---
#!/bin/bash
PATH=/usr/sbin:/usr/bin:/bin:/usr/local/tripwire/sbin
# パスフレーズ設定
LOCALPASS=xxxxxxxx # ローカルパスフレーズ
SITEPASS=xxxxxxxx  # サイトパスフレーズ
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
---ココまで---
実行設定&CRON登録
chmod 700 tripwire.sh
echo "0 3 * * * root /root/tripwire.sh" > /etc/cron.d/tripwire



PCにそのままCentOS6.2をインスト(2)

1.パッケージを最新状態にする。
> yum -y update
2.yum-cronをインストする。
> yum -y install yum-cron
> /etc/rc.d/init.d/yum-cron start
> chkconfig yum-cron on
3.開発ツールの類をインストール
> yum -y groupinstall "Base" "Development tools"
4.SELinuxの無効化
> getenforce
> setenforce 0
/etc/sysconfig/selinux を修正
enforcing -> disabled
5.一応コード変換も入れる
> yum -y install nkf
6.リブート。

パッケージ自動更新自動起動設定


PCにそのままCentOS6.2をインスト(1)

なかなか起動しない
Machine Check Error
が出る等
安物買いらしい状況に・・・
症状1:インストーラのハードウェアチェックなど全般に処理が遅すぎ
原因1:SATAをAHCIモードに変えたせい
対処1:IDEモードに戻すとウソのように速くなった
症状2:インストールできそうなHDDが見つからない
原因2:追加チップで実装しているSATA(6Gbps)のコネクタにSSDをつないだせい
対処2:SATA(3GBps)に差し替えると認識できた
そして無事CentsOS6.2をインストールできた。
しかし、ここからが長く面倒な設定が続く・・・
 
 



無駄使い

ブログ鯖用VMPlayerが調子が悪いのでPCを新調することにしました。
【目標優先度】低予算、低消費電力、低発熱
【購入品】

  1. ケース
    • メーカー:SCYTHE
    • 型番:SARA3  (訳ありもの:5個限定)
    • ¥1,900-
    • ワゴンセール品。サイドパネルが外しにくいとのころ。非力な50過ぎのボクには難しいかな?と思いましたが、立て付けが悪かっただけでした。
  2. 電源
    • メーカー:玄人志向
    • 型番:KRPW-PT500W/92+ 500W
    • ¥5,480-
    • ワゴンセール品。
  3. CPU
    • メーカー:INTEL製
    • 型番:CELERON PROCESSOR G540 (LGA1155)
    • ¥3,480-
  4. マザーボード
    • メーカー:MSI製
    • 型番:PH61A-P35(B3)
    • 価格:¥3,480-
  5. SSD
    • メーカー:SAMSUN
    • 型番:MZ-7PC128
    • 説明:SSD 830Series for PC(SATA 6Gb/s) 128GB
    • 価格:¥8,480-
  6. メモリ
    • メーカー:KINGMAX製
    • 型番:KM-LD3-1333-4GD
    • 説明:DDR3 1333MHz CL9 4GB
    • 価格:¥1,750-

合計 ¥24,650- (OSなし)
今Windows-7を買うとWindows-8が¥1,280円で買える筈ですが、
CENT-OS用なのでその分SSDに回しました。
SSDを除けば、¥1,6170-
これでもダメなら、もうMac Miniでいいのかもしれない。(笑)




top