前のページ « | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | » 次のページ

chkrootkitのアラーム

2010, 07, 11

先日、以下のメールが来るようになった。
Checking `bindshell'... INFECTED (PORTS: 1008)

bindshellが仕掛けられたのかと思い、色々調べたら、どうもポート1008がrpc.statdのプロセスによって使用されていることが分かり、bindshellではなかったようなので、まずは一安心。

ポート1008が使ってるプロセスを確認
[root@server ~]# lsof -i:1008
COMMAND    PID    USER   FD   TYPE DEVICE SIZE NODE NAME
rpc.statd 2098 rpcuser    7u  IPv4   5737       TCP *:1008 (LISTEN)

rpc.statdが、rpcuserによって起動している。

バックアップしてあったchkrootkitで使用するコマンド群使って再検査を行うことに。
[root@server ~]# shutdown -r now

クライアントマシンにバックアップしてあったchkrootkitcmd.zipを、/home/higo/にアップロードしてから以下の作業を行う。
[root@server ~]# cd /home/higo/
[root@server higo]# mv -v chkrootkitcmd.zip /root
`chkrootkitcmd.zip' -> `/root/chkrootkitcmd.zip'
[root@server higo]# cd
[root@server ~]# unzip chkrootkitcmd.zip
Archive:  chkrootkitcmd.zip
   creating: chkrootkitcmd/
  inflating: chkrootkitcmd/id
  inflating: chkrootkitcmd/egrep
  inflating: chkrootkitcmd/sed
  inflating: chkrootkitcmd/netstat
  inflating: chkrootkitcmd/echo
  inflating: chkrootkitcmd/find
  inflating: chkrootkitcmd/awk
  inflating: chkrootkitcmd/head
  inflating: chkrootkitcmd/strings
  inflating: chkrootkitcmd/ps
  inflating: chkrootkitcmd/uname
  inflating: chkrootkitcmd/ls
  inflating: chkrootkitcmd/cut
[root@server ~]# ls -l ./chkrootkitcmd/
合計 1084
-rwxr-xr-x 1 root root 320416  7月 12 09:20 awk
-rwxr-xr-x 1 root root  34408  7月 12 09:20 cut
-rwxr-xr-x 1 root root  19852  7月 12 09:20 echo
-rwxr-xr-x 1 root root  85060  7月 12 09:20 egrep
-rwxr-xr-x 1 root root 151244  7月 12 09:20 find
-rwxr-xr-x 1 root root  31660  7月 12 09:20 head
-rwxr-xr-x 1 root root  22600  7月 12 09:20 id
-rwxr-xr-x 1 root root  95116  7月 12 09:20 ls
-rwxr-xr-x 1 root root 121300  7月 12 09:20 netstat
-r-xr-xr-x 1 root root  79004  7月 12 09:20 ps
-rwxr-xr-x 1 root root  51764  7月 12 09:20 sed
-rwxr-xr-x 1 root root  25892  7月 12 09:20 strings
-rwxr-xr-x 1 root root  20024  7月 12 09:20 uname

/root/chkrootkitcmd/の外部コマンドで、chkrootkitを実行。
[root@server ~]# which chkrootkit
/usr/sbin/chkrootkit
[root@server ~]# chkrootkit -p /root/chkrootkitcmd/

INFECTEDは無いようだが、INFECTEDのみ表示させてみる。
[root@server ~]# chkrootkit -p /root/chkrootkitcmd/ | grep INFECTED

INFECTEDは無かった。

rpc.statdの待ち受けポートを確認してみる。
[root@server ~]# netstat -anp|grep rpc.statd
tcp        0      0 0.0.0.0:1006                0.0.0.0:*                   LISTEN      2096/rpc.statd
udp        0      0 0.0.0.0:1000                0.0.0.0:*                               2096/rpc.statd
udp        0      0 0.0.0.0:1003                0.0.0.0:*                               2096/rpc.statd
unix  2      [ ]         DGRAM                    5427   2096/rpc.statd

rpc.statdが使ってた1008はすでに違うものになってる。

ポート1008番は、どのプロセスも使用してないことを確認。
[root@server ~]# lsof -i:1008
[root@server ~]#

再検査で使ったファイル群を削除。
[root@server ~]# rm -v -f -R ./chkrootkitcmd/
removed `./chkrootkitcmd//id'
removed `./chkrootkitcmd//egrep'
removed `./chkrootkitcmd//sed'
removed `./chkrootkitcmd//netstat'
removed `./chkrootkitcmd//echo'
removed `./chkrootkitcmd//find'
removed `./chkrootkitcmd//awk'
removed `./chkrootkitcmd//head'
removed `./chkrootkitcmd//strings'
removed `./chkrootkitcmd//ps'
removed `./chkrootkitcmd//uname'
removed `./chkrootkitcmd//ls'
removed `./chkrootkitcmd//cut'
removed directory: `./chkrootkitcmd/'

zipファイルも削除
[root@server ~]# rm -v chkrootkitcmd.zip
rm: remove 通常ファイル `chkrootkitcmd.zip'? y
removed `chkrootkitcmd.zip'

以前のコマンドでchkrootkitを実行
[root@server ~]# chkrootkit | grep INFECTED
[root@server ~]#
rootkitは検出されなかった。

SMTPサーバ(Postfix)

2010, 04, 14

メールサーバーを構築するためには、まずメール配送を行うためのSMTPサーバーが必要となる。 SMTPサーバーとして動作するソフトウェアの代表的なものにはPostfix、sendmail、qmailがある。 Postfixはsendmailやqmailより後に開発されたため、それぞれの良い部分を反映して開発されており、簡単に設定することが可能なので、ここではsendmailとの互換性が優れているPostfixを使用する。

■sendmailを停止する
デフォルトでインストールされているsendmailをPostfixをインストールする前に停止しておく
[root@linux ~]# /etc/rc.d/init.d/sendmail stop
sendmail を停止中:                                         [  OK  ]
sm-client を停止中:                                        [  OK  ]

sendmail自動起動設定解除
[root@linux ~]# chkconfig sendmail off

sendmail自動起動設定解除確認
[root@linux ~]# chkconfig --list sendmail
sendmail        0:off   1:off   2:off   3:off   4:off   5:off   6:off
                (ランレベル2〜5のoffを確認)


■Postfixのインストール
[root@linux ~]# yum -y install postfix


■sendmail環境からPostfix環境へ移行する
CentOSでは、利用するMTAプログラムの選択にalternativesという仕組みを利用しており、このalternativesコマンドを実行することにより、簡単にsendmail環境からPostfix環境へ移行することが出来る。
[root@linux ~]# alternatives --config mta

2 プログラムがあり 'mta' を提供します。

  選択       コマンド
-----------------------------------------------
*+ 1           /usr/sbin/sendmail.sendmail
   2           /usr/sbin/sendmail.postfix

Enter を押して現在の選択 [+] を保持するか、選択番号を入力:2
postfixを使うので選択番号[2]を入力


■Postfixの設定
Postfixの基本的な設定は、/etc/postfix/main.cfで行う
[root@linux ~]# vi /etc/postfix/main.cf ← viエディタでmain.cfを開く
# The myhostname parameter specifies the internet hostname of this
# mail system. The default is to use the fully-qualified domain name
# from gethostname(). $myhostname is used as a default value for many
# other configuration parameters.
#
#myhostname = host.domain.tld
↓
myhostname = linux.yokensaka.com ← #を外して、サーバーのホスト名を設定
#myhostname = virtual.domain.tld

# The mydomain parameter specifies the local internet domain name.
# The default is to use $myhostname minus the first component.
# $mydomain is used as a default value for many other configuration
# parameters.
#
#mydomain = domain.tld
↓
mydomain = yokensaka.com ← #を外して、ドメイン名を設定

# For the sake of consistency between sender and recipient addresses,
# myorigin also specifies the default domain name that is appended
# to recipient addresses that have no @domain part.
#
#myorigin = $myhostname
#myorigin = $mydomain
↓
myorigin = $mydomain ← #を外して、設定を有効に
      (メールアドレスの「@」以下に付加する文字列を指定)

# See also the proxy_interfaces parameter, for network addresses that
# are forwarded to us via a proxy or network address translator.
#
# Note: you need to stop/start Postfix when this parameter changes.
#
メールの受信を許可するネットワークインターフェースを設定
#inet_interfaces = all
↓ #を外して、設定を有効にする(自サーバーからのメールだけを受信する場合は設定しない)
inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces = localhost
↓ 行頭に#を追加(自サーバーからのメールだけを受信する場合は設定しない)
#inet_interfaces = localhost

# Specify a list of host or domain names, /file/name or type:table
# patterns, separated by commas and/or whitespace. A /file/name
# pattern is replaced by its contents; a type:table is matched when
# a name matches a lookup key (the right-hand side is ignored).
# Continue long lines by starting the next line with whitespace.
#
# See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS".
#
受信したメールを拒否するかどうかを設定
mydestination = $myhostname, localhost.$mydomain, localhost
↓
#mydestination = $myhostname, localhost.$mydomain, localhost ← 行頭に#を追加
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
↓
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain ← #を外す
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
#       mail.$mydomain, www.$mydomain, ftp.$mydomain

# Specify "mynetworks_style = host" when Postfix should "trust"
# only the local machine.
#
#mynetworks_style = class
#mynetworks_style = subnet
↓
mynetworks_style = subnet ← #を外す
#mynetworks_style = host

# You can also specify the absolute pathname of a pattern file instead
# of listing the patterns here. Specify type:table for table-based lookups
# (the value on the table right-hand side is not used).
#
内部ネットワークアドレスとローカルホストアドレスを指定
#mynetworks = 168.100.189.0/28, 127.0.0.0/8
↓
mynetworks = 192.168.1.0/24, 127.0.0.0/8 ← #を外して書き換える
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table

# NOTE: Postfix will not automatically forward mail for domains that
# list this system as their primary or backup MX host. See the
# permit_mx_backup restriction description in postconf(5).
#
#relay_domains = $mydestination
↓
relay_domains = $mydestination ← #を外す

# DELIVERY TO MAILBOX
#
# The home_mailbox parameter specifies the optional pathname of a
# mailbox file relative to a user's home directory. The default
# mailbox file is /var/spool/mail/user or /var/mail/user.  Specify
# "Maildir/" for qmail-style delivery (the / is required).
#
#home_mailbox = Mailbox
#home_mailbox = Maildir/
↓
home_mailbox = Maildir/ ← #を外してメールボックス格納形式をMaildir形式にする

SMTP Authを有効にする。設定ファイルの最終行まで移動して、以下のように設定を追記。
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

relays.ordb.org が、2006/12/18で正式な活動を停止した為以下は設定しない。
メール不正中継ホストからの接続を拒否する場合以下を最終行へ追加する。
smtpd_client_restrictions = reject_rbl_client relays.ordb.org

送信するメール1通当たりのサイズはデフォルトで10MByte、
受信するメール合計の総容量はデフォルトで50MByteに設定されている。
それぞれ100MByteと500MByteに変更するには以下を最終行へ追加。
message_size_limit = 102400000
mailbox_size_limit = 512000000

変更を有効にする為、postfixを再起動。
[root@server ~]# /etc/rc.d/init.d/postfix reload
postfix を再読み込み中:                                    [  OK  ]


■SMTP Auth設定
SMTP AuthではCyrus SASLと呼ばれる認証プログラムを利用している。 PostfixでCyrus SASLを利用出来るように設定する必要がある。
[root@linux ~]# vi /usr/lib/sasl2/smtpd.conf ← smtpd.confを開く
設定ファイルの最後に追記
mech_list: plain login cram-md5 digest-md5

saslauthdの起動
[root@linux ~]# /etc/init.d/saslauthd start
saslauthd を起動中:                                        [  OK  ]

saslauthdの自動起動設定
[root@linux ~]# chkconfig saslauthd on

saslauthdの自動起動設定確認
[root@linux ~]# chkconfig --list saslauthd
saslauthd       0:off   1:off   2:on    3:on    4:on    5:on    6:off
                (ランレベル2〜5のonを確認)


■root宛メールを一般ユーザ(webmaster)へ転送
システムからroot宛に送られてくるメールを、一般ユーザ(webmaster)へ転送するようにする。
管理者ユーザ宛メールのroot宛転送設定を解除
[root@linux ~]# sed -i 's/^webmaster/#webmaster/g' /etc/aliases

管理者ユーザ宛メールのroot宛転送設定解除を確認
[root@linux ~]# grep ^webmaster /etc/aliases ← 結果がなにも表示されないことを確認

root宛メールを管理者ユーザ(webmaster)へ転送するように設定
[root@linux ~]# sed -i 's/^root/#root/g' /etc/aliases

root宛メールを管理者ユーザ(webmaster)へ転送するように設定
[root@linux ~]# echo "root: webmaster" >> /etc/aliases

root宛メールが管理者ユーザ(webmaster)宛へ転送されるかの確認
[root@linux ~]# grep ^root /etc/aliases
root: webmaster ← root宛メールが管理者ユーザ(webmaster)へ転送されるように設定されている

転送先を反映させる
[root@linux ~]# postalias /etc/aliases


■一般ユーザー(webmaster)の作成
webmasterへメールが届くようにするためには一般ユーザー(webmaster)の作成が必要。
一般ユーザ(webmaster)を追加。
[root@linux ~]# useradd webmaster

一般ユーザーでログインするためにはパスワードを設定する必要がある
[root@linux ~]# passwd webmaster

パスワードの入力(入力したパスワードは表示されない)
Changing password for user webmaster.
New UNIX password:パスワード

再入力を促されるので、もう一度入力。(上記のパスワードと同じ物を入れる)
Retype new UNIX password:パスワード
passwd: all authentication tokens updated successfully.


■Postfixの起動
Postfixの起動 
[root@linux ~]# /etc/rc.d/init.d/postfix start
postfix を起動中:                                          [  OK  ]


■Postfixの自動起動設定
Postfixの自動起動設定
[root@linux ~]# chkconfig postfix on

Postfixの自動起動設定確認
[root@linux ~]# chkconfig --list postfix
postfix         0:off   1:off   2:on    3:on    4:on    5:on    6:off
                (ランレベル2〜5のonを確認)


■sendmailのアンインストール
不要になったSendmailは、念のためアンインストールしておく。
[root@linux ~]# yum remove sendmail


■sendmailパスの確認
掲示板などで投稿があったらメール通知する設定をしている時は CGIのsendmailパスの設定を変更しないと送信エラーになる場合がある。
一般ユーザーでsendmailパスの確認をする
[root@linex ~]# su - higo
[higo@linux ~]$ which sendmail ← sendmailパスの確認
/usr/bin/which: no sendmail in (/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/higo/bin)

sendmailパスが見つからないときは
以下のようにすれば一般ユーザーでもsendmailパスがみえるようになる。
[higo@linux ~]$ su - ← ルートになる
パスワード(P): ← ルートのパスワードを入力

[root@linux ~]# ln -s /usr/sbin/sendmail /usr/bin/sendmail

[root@linux ~]# su - higo ← 一般ユーザーになる

[higo@linux ~]$ which sendmail ← sendmailパスの確認
/usr/bin/sendmail


joyful.cgiではsendmailパスがデフォルトで「/usr/lib/sendmail」になっているので、上記で確認したsendmailパス「/usr/bin/sendmail」に直さないと投稿時に送信エラーになる。
# sendmailパス(メール通知する時)
$sendmail = '/usr/lib/sendmail';
 ↓
# sendmailパス(メール通知する時)
$sendmail = '/usr/bin/sendmail'; ← libをbinに変更


※SMTPサーバーを使うには、ルーターの設定が必要なので25番のポートを開ける。

■ ポートチェック【ポート開放確認】
「管理しているサーバーが外部から接続アクセスできるか?」「ポートは開放されているか?」「portは閉じているか?」「ルータのポートは開放されているか」等の
ポートチェック・ポートの疎通確認テストはこちらで

Postfixをインストールしただけでは、メールの読み出しは出来ない。 Postfixはメールを配信するためのSMTPサーバーとしての機能しか持たないので、dovecotをインストールすることにより、POP3/IMAP4どちらでもメールを読み出せるようにする。

ウィルス対策(Clam Antivirus)

2010, 04, 02

Clam AntivirusはGPLライセンスに従って利用することができるオープンソースのソフトウェアであり、LinuxやBSD、Mac OS Xなど各種UNIX系のシステムで動作するアンチウイルスソフト。しかしyumではなかなか最新版にアップデートされないのでwgetでソースからインストールすることにする。

■古いバージョンのclamavがある場合はアンインストールしておく
アンインストール用にバックアップしてあったモジュールを展開。
[root@server ~]# tar zxvf clamav-0.95.3_self.tar.gz

clamav-0.95.3のディレクトリへ移動
[root@server ~]# cd clamav-0.95.3

clamav-0.95.3のアンインストール
[root@server clamav-0.95.3]# make uninstall

clamav-0.95.3のファイルとディレクトリーを削除
[root@server clamav-0.95.3]# cd
[root@server ~]# rm -f clamav-0.95.3_self.tar.gz
[root@server ~]# rm -rf clamav-0.95.3

古いバージョンのディレクトリーの削除
[root@server ~]# rm -rf /usr/local/clamav


■ユーザとグループの作成
clamavはインストールする前に
「clamav」という名前のユーザとグループを作成しておく必要がある。
[root@linux ~]# groupadd clamav
[root@linux ~]# useradd -g clamav -s /bin/false clamav


■最新版のClamAVをダウンロード (最新版は公式サイトで確認できる
[root@server ~]# wget http://downloads.sourceforge.net/clamav/clamav-0.96.tar.gz
--2010-04-02 06:55:13--  http://downloads.sourceforge.net/clamav/clamav-0.96.tar.gz
downloads.sourceforge.net をDNSに問いあわせています... 216.34.181.59
downloads.sourceforge.net|216.34.181.59|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 302 Found
場所: http://jaist.dl.sourceforge.net/project/clamav/clamav/0.96/clamav-0.96.tar.gz [続く]
--2010-04-02 06:55:14--  http://jaist.dl.sourceforge.net/project/clamav/clamav/0.96/clamav-0.96.tar.gz
jaist.dl.sourceforge.net をDNSに問いあわせています... 150.65.7.130
jaist.dl.sourceforge.net|150.65.7.130|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 39792593 (38M) [application/x-gzip]
`clamav-0.96.tar.gz' に保存中

100%[==========================================================>] 39,792,593  4.76M/s 時間 9.4s

2010-04-02 06:55:23 (4.05 MB/s) - `clamav-0.96.tar.gz' へ保存完了 [39792593/39792593]

clamav-0.96を展開
[root@server ~]# tar zxvf clamav-0.96.tar.gz

ダウンロードしたファイルを削除
[root@server ~]# rm -f clamav-0.96.tar.gz

clamav-0.96ディレクトリーへ移動
[root@server ~]# cd clamav-0.96

Makefileを自動作成するためのツール「configure」を実行。
[root@server clamav-0.96]# ./configure --prefix=/usr/local/clamav

makeを実行し、clamavをインストール
[root@server clamav-0.96]# make
[root@server clamav-0.96]# make install


■アンインストール用にバックアップしておく
[root@server clamav-0.96]# cd
[root@server ~]# tar cvf clamav-0.96_self.tar ./clamav-0.96
[root@server ~]# gzip clamav-0.96_self.tar


■設定ファイル変更
インストールが正常に完了したらまず、二つの設定ファイル
/usr/local/clamav/etc/freshclam.conf
/usr/local/clamav/etc/clamd.conf
をエディタで開きExampleと書かれた行をコメントアウトし、保存。
[root@server ~]# vi /usr/local/clamav/etc/freshclam.conf

# Comment or remove the line below.
Example
↓
#Example

[root@server ~]# vi /usr/local/clamav/etc/clamd.conf

# Comment or remove the line below.
Example
↓
#Example


■「freshclam」を使用してVirusDBをアップデート
[root@server ~]# /usr/local/clamav/bin/freshclam
ClamAV update process started at Fri Apr  2 07:16:41 2010
main.cvd is up to date (version: 52, sigs: 704727, f-level: 44, builder: sven)
Downloading daily-10678.cdiff [100%]
Downloading daily-10679.cdiff [100%]
Downloading daily-10680.cdiff [100%]
Downloading daily-10681.cdiff [100%]
Downloading daily-10682.cdiff [100%]
Downloading daily-10683.cdiff [100%]
Downloading daily-10684.cdiff [100%]
Downloading daily-10685.cdiff [100%]
Downloading daily-10686.cdiff [100%]
Downloading daily-10687.cdiff [100%]
Downloading daily-10688.cdiff [100%]
Downloading daily-10689.cdiff [100%]
Downloading daily-10690.cdiff [100%]
Downloading daily-10691.cdiff [100%]
daily.cld updated (version: 10691, sigs: 49537, f-level: 44, builder: neo)
Downloading bytecode.cvd [100%]
bytecode.cvd updated (version: 5, sigs: 2, f-level: 44, builder: nervous)
Database updated (754266 signatures) from database.clamav.net (IP: 193.1.193.64)


■ウィルススキャン確認(/etc/passwdをスキャンしてみる)
[root@server ~]# /usr/local/clamav/bin/clamscan --infected --remove --recursive /etc/passwd

----------- SCAN SUMMARY -----------
Known viruses: 753570
Engine version: 0.96
Scanned directories: 0
Scanned files: 1
Infected files: 0
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 0.00:1)
Time: 3.654 sec (0 m 3 s)

version: 0.96でスキャンされてることを確認


■Clam AntiVirusの定期自動実行設定
毎日自動的にウィルス定義ファイル最新化して、全てのファイルのウィルススキャンを行うスプリクトの作成 
[root@linux ~]# vi clamav.sh
#!/bin/bash

PATH=/usr/bin:/bin
# excludelist
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
CLAMSCANTMP=`mktemp`
/usr/local/clamav/bin/freshclam > /dev/null
/usr/local/clamav/bin/clamscan --recursive --remove ${excludeopt} / > $CLAMSCANTMP 2>&1
[ ! -z "$(grep FOUND$ $CLAMSCANTMP)" ] && \
grep FOUND$ $CLAMSCANTMP | mail -s "Virus Found in `hostname`" root
rm -f $CLAMSCANTMP


■Clam AntiVirus定期自動実行スクリプトに実行権限付加
[root@linux ~]# chmod 700 clamav.sh


■cron編集
[root@linux ~]# crontab -e
00 03 * * * /root/clamav.sh ← 追加(毎日3:00にClam AntiVirusの定期自動実行)


■スキャン除外設定
backupディレクトリをスキャン対象外にするように設定
[root@linux ~]# echo "/backup/" >> clamscan.exclude


Tripwire、/backupディレクトリーのチェック対象外設定

2010, 01, 30

下記のようなTripwireのエラーメールが届いた。
### Warning: File system error.
### Filename: /backup/backup.tar.bz2
### Value too large for defined data type
### Continuing...


/backup/backup.tar.bz2のファイルサイズが2Gを超えてしまったため、2Gを超えるファイルに対応してないtripwireがエラーを出したようだ。なので、/backupのディレクトリーをチェック対象外にすることにした。
ポリシーファイル(テキスト版)の復活
[root@server ~]# twadmin -m p -c /etc/tripwire/tw.cfg -p /etc/tripwire/tw.pol -S /etc/tripwire/site.key > /etc/tripwire/twpol.txt

ポリシーファイル(テキスト版)の編集
[root@server ~]# vi /etc/tripwire/twpol.txt
  ################################################
 #                                              ##
################################################ #
#                                              # #
#  Monitor Filesystems                         # #
#                                              ##
################################################
(
  rulename = "Monitor Filesystems",
)
{
  /                             -> $(ReadOnly) ;
  /home                         -> $(ReadOnly) ;  # Modify as needed
  /usr                          -> $(ReadOnly) ;
  /var                          -> $(ReadOnly) ;
  !/backup; ← /backupをチェック対象外にするので追加
}

ポリシーファイル(暗号署名版)を作成
[root@server ~]# twadmin -m P -c /etc/tripwire/tw.cfg -p /etc/tripwire/tw.pol -S /etc/tripwire/site.key /etc/tripwire/twpol.txt

Please enter your site passphrase: ← サイトパスフレーズを入力
Wrote policy file: /etc/tripwire/tw.pol

ポリシーファイル(テキスト版)を削除
[root@server ~]# rm -f /etc/tripwire/twpol.txt

ポリシーファイルよりデータベースを作成
[root@server ~]# tripwire -m i -s -c /etc/tripwire/tw.cfg
Please enter your local passphrase: ← ローカルパスフレーズを入力
※データベースを作成するには結構時間がかかる

MySQL管理(phpMyAdmin)

2010, 01, 11

phpMyAdminはWebブラウザからMySQLデータベースを管理するためのPHPで記述されたソフトウェア。WebブラウザからMySQLのテーブル操作、インポート・エクスポートすることが出来る。

■ phpMyAdminインストール
こちらで最新版 を確認すること
(最新版を確認してダウロード 10/01/11 時点では phpMyAdmin 3.2.5)
[root@linux ~]# wget http://prdownloads.sourceforge.net/phpmyadmin/phpMyAdmin-3.2.5-all-languages.tar.bz2

ダウンロードしたphpMyAdminを展開
[root@linux ~]# tar jxvf phpMyAdmin-3.2.5-all-languages.tar.bz2

古いphpMyAdminを削除
[root@linux ~]# rm -rf /var/www/phpmyadmin

phpMyAdmin展開先ディレクトリを所定の場所へコピー
[root@linux ~]# mv phpMyAdmin-3.2.5-all-languages/ /var/www/phpmyadmin

ダウンロードしたphpMyAdminを削除
[root@linux ~]# rm -f phpMyAdmin-3.2.5-all-languages.tar.bz2


■ php-mysqlインストール
phpMyAdminはPHPで動作するため、PHPからMySQLデータベースへアクセスするためのパッケージ「php-mysql」をインストールする
[root@linux ~]# yum -y install php-mysql


■ mbstringモジュールインストール
phpMyAdmin は mbstring 拡張なしでは文字列を正確に分割することができないのでmbstringモジュールをインストールする
[root@linux ~]# yum -y install php-mbstring


■ phpMyAdmin設定
phpmyadmin/libraries/config.default.phpを名前変更して/var/www/phpmyadmin/の直下にコピー
[root@linux ~]# cp /var/www/phpmyadmin/libraries/config.default.php /var/www/phpmyadmin/config.inc.php

設定ファイルのパーミッションを変更
[root@linux ~]# chmod 660 /var/www/phpmyadmin/config.inc.php

設定ファイル編集
[root@linux ~]# vi /var/www/phpmyadmin/config.inc.php
$cfg['blowfish_secret'] = 'xxxxxxxxxxxx'; ← 46文字以内の適当な文字列を指定
※上記はロiグイン時のパスワード暗号化の際に内部的に利用されるパスフレーズであり、ユーザに入力要求されるものではない

phpMyAdminの所有者を変更
[root@linux ~]# chown -R root.apache /var/www/phpmyadmin/


■ Apache設定
phpMyAdmin用Apache設定ファイル作成
[root@linux ~]# vi /etc/httpd/conf.d/phpmyadmin.conf
Alias /phpmyadmin /var/www/phpmyadmin

内部と特定の外部IPからのみアクセスできるように指定する
<Location /phpmyadmin>
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1 ← サーバー自身からのアクセスを許可
    Allow from 192.168.1. ← 内部ネットワークからのアクセスを許可
    Allow from xxx.xxx.xxx.xxx ← 特定の外部IP(xxx.xxx.xxx.xxx)からのアクセスを許可
</Location>

[root@linux ~]# /etc/rc.d/init.d/httpd reload ← Apache設定反映
httpd を再読み込み中:                                      [  OK  ]

会社等からアクセスする場合、自分の会社の接続環境(IPアドレス)を調べ、/etc/hosts.allowへ登録する必要がある。そんな時は診断くんで確認できる。

■ phpMyAdmin確認
http://サーバー名/phpmyadmin/へアクセスして、phpMyAdminのログイン画面が表示されること
MySQLに登録されているアカウントでログインできること

※アクセスしてみると「PHP を 5.2 以降にアップグレードしてください」というエラーメッセージが出てきた。

■ インストールされてるphpバージョン確認
[root@linux ~]# yum list installed php*
php.i386                                 5.1.6-20.el5_2.1       installed
php-cli.i386                             5.1.6-20.el5_2.1       installed
php-common.i386                          5.1.6-20.el5_2.1       installed
php-gd.i386                              5.1.6-20.el5_2.1       installed
php-mbstring.i386                        5.1.6-20.el5_2.1       installed
php-mysql.i386                           5.1.6-20.el5_2.1       installed
php-pdo.i386                             5.1.6-20.el5_2.1       installed


■ phpを5.2以降のバージョンにアップグレード
[root@linux ~]# rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

リポジトリを追加
[root@linux ~]# vi /etc/yum.repos.d/utterramblings.repo
[utterramblings]
name=Jason’s Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka


■ phpのアップグレード
[root@linux ~]# yum update php


http://サーバー名/phpmyadmin/へアクセスしてみると
「mcrypt 拡張をロードできません。PHP の設定を確認してください」というエラーメッセージが出てきた。

■ php-mcryptをインストール
[root@linux ~]# yum install php-mcrypt


■ phpバージョン確認
[root@linux ~]# yum list installed php*

php.i386                                 5.2.6-jason.1          installed
php-cli.i386                             5.2.6-jason.1          installed
php-common.i386                          5.2.6-jason.1          installed
php-gd.i386                              5.2.6-jason.1          installed
php-mbstring.i386                        5.2.6-jason.1          installed
php-mcrypt.i386                          5.2.6-jason.1          installed
php-mysql.i386                           5.2.6-jason.1          installed
php-pdo.i386                             5.2.6-jason.1          installed



■ リポジトリを無効にする
[root@linux ~]# vi /etc/yum.repos.d/utterramblings.repo
enabled=1
 ↓
enabled=0


■ Apacheの再起動
[root@linux ~]# /etc/rc.d/init.d/httpd restart



■ PHP の初期設定の変更
リストアで利用できるバックアップデータの最大サイズは2,048KB と書かれているとおり、 デフォルト では2 MB になっている。これはphpMyAdminの制限ではなく、 PHP の初期設定での制限。 これを変更するには、 "/etc/php.ini" を開き、 "upload_max_filesize" ディレクティブ を修正。

/etc/php.iniを cp コマンドでバックアップを作成してから作業するようにする。

[root@server ~]# cp -p /etc/php.ini /etc/php.ini.org
[root@server ~]# vi /etc/php.ini

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
;upload_tmp_dir =

; Maximum allowed size for uploaded files.
upload_max_filesize = 2M
↓
upload_max_filesize = 30M ← 30Mに変更


前のページ « | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | » 次のページ