アンチウィルスソフトの導入(Clam AntiVirus)。
Clam AntiVirus をインストールします。
root@www:~# apt -y install clamav
root@www:~# sed -i -e "s/^NotifyClamd/#NotifyClamd/g" /etc/clamav/freshclam.conf
root@www:~# systemctl stop clamav-freshclam
root@www:~# freshclam ClamAV update process started at Sun Jun 30 23:51:01 2019 main.cvd is up to date (version: 58, sigs: 4566249, f-level: 60, builder: sigmgr) daily.cld is up to date (version: 25496, sigs: 1606212, f-level: 63, builder: raynman) bytecode.cvd is up to date (version: 328, sigs: 94, f-level: 63, builder: neo)
root@www:~# systemctl start clamav-freshclam
root@www:~# clamscan --infected --remove --recursive /home ----------- SCAN SUMMARY ----------- Known viruses: 6163086 Engine version: 0.101.2 Scanned directories: 38 Scanned files: 23 Infected files: 0 Data scanned: 0.00 MB Data read: 0.00 MB (ratio 0.00:1) Time: 179.738 sec (2 m 59 s)
root@www:~# wget http://eicar.org/download/eicar.com
root@www:~# clamscan --infected --remove --recursive ./ ----------- SCAN SUMMARY ----------- Known viruses: 6163097 Engine version: 0.101.2 Scanned directories: 3 Scanned files: 10 Infected files: 1 Data scanned: 0.00 MB Data read: 0.00 MB (ratio 0.00:1) Time: 179.738 sec (2 m 59 s)
ファイル改竄検知システムの導入(Tripwire)。
Tripwire をインストールします。
root@www:~# apt -y install tripwire
root@www:~# cd /etc/tripwire
root@www:/etc/tripwire# vi twcfg.txt
REPORTLEVEL = 4
root@www:/etc/tripwire# twadmin -m F -c tw.cfg -S site.key twcfg.txt
Please enter your site passphrase: サイトキーファイルのパスフレーズ
Wrote configuration file: /etc/tripwire/tw.cfg
root@www:/etc/tripwire# vi 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} # ---------------------------------------------------------------- # #ここまでを1回目で作成して行頭に「#」の無い行を挿入して、以下を作成します。 $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) ; root@www:/etc/tripwire# perl twpolmake.pl twpol.txt > twpol.txt.new root@www:/etc/tripwire# twadmin -m P -c tw.cfg -p tw.pol -S site.key twpol.txt.new
Please enter your site passphrase: サイトキーファイルのパスフレーズ
Wrote configuration file: /etc/tripwire/tw.pol
root@www:/etc/tripwire# tripwire -m i -s -c tw.cfg
Please enter your local passphrase: ローカルキーファイルのパスフレーズ
root@www:/etc/tripwire# cd
root@www:~# tripwire -m c -s -c /etc/tripwire/tw.cfg Open Source Tripwire(R) 2.4.2.2 Integrity Check Report Report generated by: root ... ... ... All rights reserved.
root@www:~# ll /var/lib/tripwire/report total 4 -rw-r--r-- 1 root root 1821526 6月 29 07:58 server.jp-20190629-075230.twr -rw-r--r-- 1 root root 1830182 6月 30 06:09 server.jp-20190630-060029.twr -rw-r--r-- 1 root root 1829590 7月 1 09:29 server.jp-20190701-092314.twr -rw-r--r-- 1 root root 1828518 7月 1 17:27 server.jp-20190701-171400.twr
root@www:~# tripwire -m u -a -s -c /etc/tripwire/tw.cfg -r /var/lib/tripwire/report/server.jp-20190701-171400.twr
Please enter your local passphrase: ローカルキーファイルのパスフレーズ
rootkit検知システム導入(RkHunter)。
RKHunter をインストールします。
root@www:~# apt -y install rkhunter
root@www:~# vi /etc/default/rkhunter
CRON_DAILY_RUN="true"
CRON_DB_UPDATE="true"
DB_UPDATE_EMAIL="true"
root@www:~# rkhunter --update
root@www:~# rkhunter --propupd
root@www:~# rkhunter --check --sk [ Rootkit Hunter version 1.4.2 ] Checking system commands... ... ... No warnings were found while checking the system.
SSHサーバー公開鍵認証方式接続の設定。
windows PCの任意の場所に「SSH鍵」フォルダを作成し、その中に「公開鍵」フォルダ、「秘密鍵」フォルダを作成します。
windows PCのTeraTermを起動し、「設定」→「SSH鍵生成」を選択します。
サーバーの公開鍵の作成。
webmaster@www:~$ mkdir .ssh webmaster@www:~$ chmod 700 .ssh/ webmaster@www:~$ touch .ssh/authorized_keys webmaster@www:~$ chmod 600 .ssh/authorized_keys
「ファイル」→「SSH SCP…」を選択します。
webmaster@www:~$ cat id_rsa.pub >> .ssh/authorized_keys
接続テスト。
「新しい接続」を選択します。
webmaster@www:~$ su - パスワード:
秘密鍵での認証接続。
バックアップを作成します。
root@www:~# cp -p /etc/ssh/sshd_config /etc/ssh/sshd_config_bck
root@www:~# vi /etc/ssh/sshd_config
PasswordAuthentication no
root@www:~# systemctl restart sshd
コメント