Installed anti-virus software (Clam AntiVirus).
Install Clam AntiVirus.
[root@www ~]# dnf -y install clamav clamav-update
[root@www ~]# vi /etc/freshclam.conf
#Example
[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 ~]# 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://www.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)
Introduced a file tampering detection system (Tripwire).
Install Tripwire.
[root@www ~]# dnf -y install tripwire
[root@www ~]# tripwire-setup-keyfiles
Enter the site keyfile passphrase: Site key file passphrase (alphanumeric) Verify the site keyfile passphrase: Site key file passphrase (alphanumeric)
Enter the local keyfile passphrase: Local key file passphrase (alphanumeric) Verify the local keyfile passphrase: Local key file passphrase (alphanumeric)
Please enter your site passphrase: Site key file passphrase
Please enter your site passphrase: Site key file passphrase
[root@www ~]# cd /etc/tripwire
[root@www tripwire]# vi twcfg.txt
REPORTLEVEL = 4
[root@www tripwire]# twadmin -m F -c tw.cfg -S site.key twcfg.txt
Please enter your site passphrase: Site key file passphrase
Wrote configuration file: /etc/tripwire/tw.cfg
[root@www 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} # ---------------------------------------------------------------- # #Create a line without "#" at the beginning of the line, and do the following. $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) = /^HOSTNAMEs*=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 tripwire]# perl twpolmake.pl twpol.txt > twpol.txt.new [root@www tripwire]# twadmin -m P -c tw.cfg -p tw.pol -S site.key twpol.txt.new
Please enter your site passphrase: Passphrase for your site key file
Wrote configuration file: /etc/tripwire/tw.pol
[root@www tripwire]# tripwire -m i -s -c tw.cfg
Please enter your local passphrase: Local key file passphrase
[root@www 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: Local key file passphrase
Rootkit detection system introduced (RkHunter).
Install RKHunter.
[root@www ~]# dnf -y install rkhunter
[root@www ~]# vi /etc/sysconfig/rkhunter
#Destination to send the report to
MAILTO=root@localhost
#Scan mode
DIAG_SCAN=no
[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.
Settings for SSH server public key authentication method connections.
Create a public key for the server.
Start TeraTerm, log in as a user, and create public and private keys.
[webmaster@www ~]$ ssh-keygen -t ecdsa
Generating public/private ecdsa key pair.
Enter file in which to save the key (/home/webmaster/.ssh/id_ecdsa):
Enter passphrase (empty for no passphrase):Passphrase
Enter same passphrase again:Passphrase
[webmaster@www ~]$ mv ~/.ssh/id_ecdsa.pub ~/.ssh/authorized_keys
[webmaster@www ~]$ chmod 700 .ssh/
[root@www ~]# mv /home/webmaster/.ssh/id_ecdsa /samba/share [root@www ~]# chmod 777 /samba/share/id_ecdsa
Connection test.
Select “New Connection”.
[webmaster@www ~]$ su - Password:
Authenticated connection with private key.
Create a backup.
[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
コメント