スポンサードリンク

スポンサードリンク

キーワードに合ったホームページを自動的に作っちゃおうツール

キーワードに合ったホームページを自動的に作っちゃおうツール

最新版のダウンロードはこちら↓
EXCEL版
BlogHPEditTool.exe

※実行ファイル版を作成中の為、
 今後、修正やバージョンアップはありません。m(__)m

EXCEL版の最新版の説明はこちら

最新情報 (RSS)

ご意見・ご感想などはこちらにコメントくださいm(__)m

キーワードに合ったホームページを自動的に作っちゃおうツール

CentOS 5.1 Clam AntiVirusでウィルス対策

さて前回は、iptablesでファイアーウォールを設定しました

今回はClam AntiVirusでウィルス対策です


前回「CentOS 5.1 iptablesでファイアーウォール


ウィルス。。。

脅威ですよねぇ。。。(汗



って事で

Clam AntiVirus をインストールします

CentOS の場合
リポジトリってヤツをインストールしなくちゃならないらしいので

リポジトリをダウンロード

# wget http://apt.sw.be/redhat/el5/en/i386/RPMS.dag/rpmforge-release-0.3.6-1.el5.rf.i386.rpm



でもってインストール

# rpm -Uvh rpmforge-release-0.3.6-1.el5.rf.i386.rpm



でもってダウンロードしたファイルを削除

# rm -f rpmforge-release-0.3.6-1.el5.rf.i386.rpm



でもって
基本リポジトリとのパッケージ競合を避けるため、デフォルトは無効にしておく

# sed -i 's/enabled = 1/enabled = 0/g' /etc/yum.repos.d/rpmforge.repo



ここまでやって
ようやくインストール

# yum -y --enablerepo=rpmforge install clamd







では、設定ファイルを編集

# vi /etc/clamd.conf





##
## Example config file for the Clam AV daemon
## Please read the clamd.conf(5) manual before editing this file.
##


# Comment or remove the line below.
#Example

# Uncomment this option to enable logging.
# LogFile must be writable for the user running daemon.
# A full path is required.
# Default: disabled

LogFile /var/log/clamav/clamd.log

# By default the log file is locked for writing - the lock protects against
# running clamd multiple times (if want to run another clamd, please
# copy the configuration file, change the LogFile variable, and run
# the daemon with --config-file option).
# This option disables log file locking.
# Default: no
#LogFileUnlock yes

# Maximum size of the log file.
# Value of 0 disables the limit.
# You may use 'M' or 'm' for megabytes (1M = 1m = 1048576 bytes)
# and 'K' or 'k' for kilobytes (1K = 1k = 1024 bytes). To specify the size
# in bytes just don't use modifiers.
# Default: 1M

LogFileMaxSize 0

# Log time with each message.
# Default: no

LogTime yes

# Also log clean files. Useful in debugging but drastically increases the
# log size.
# Default: no
#LogClean yes

# Use system logger (can work together with LogFile).
# Default: no

LogSyslog yes

# Specify the type of syslog messages - please refer to 'man syslog'
# for facility names.
# Default: LOG_LOCAL6
#LogFacility LOG_MAIL

# Enable verbose logging.
# Default: no
#LogVerbose yes

# This option allows you to save a process identifier of the listening
# daemon (main thread).
# Default: disabled

PidFile /var/run/clamav/clamd.pid

# Optional path to the global temporary directory.
# Default: system specific (usually /tmp or /var/tmp).

TemporaryDirectory /var/tmp

# Path to the database directory.
# Default: hardcoded (depends on installation options)

DatabaseDirectory /var/clamav

# The daemon works in a local OR a network mode. Due to security reasons we
# recommend the local mode.

# Path to a local socket file the daemon will listen on.
# Default: disabled (must be specified by a user)

LocalSocket /tmp/clamd.socket

# Remove stale socket after unclean shutdown.
# Default: yes

FixStaleSocket yes

# TCP port address.
# Default: no

TCPSocket 3310

# TCP address.
# By default we bind to INADDR_ANY, probably not wise.
# Enable the following to provide some degree of protection
# from the outside world.
# Default: no

TCPAddr 127.0.0.1

# Maximum length the queue of pending connections may grow to.
# Default: 15

MaxConnectionQueueLength 30

# Clamd uses FTP-like protocol to receive data from remote clients.
# If you are using clamav-milter to balance load between remote clamd daemons
# on firewall servers you may need to tune the options below.

# Close the connection when the data size limit is exceeded.
# The value should match your MTA's limit for a maximum attachment size.
# Default: 10M
#StreamMaxLength 20M

# Limit port range.
# Default: 1024
#StreamMinPort 30000
# Default: 2048
#StreamMaxPort 32000

# Maximum number of threads running at the same time.
# Default: 10

MaxThreads 50

# Waiting for data from a client socket will timeout after this time (seconds).
# Value of 0 disables the timeout.
# Default: 120

ReadTimeout 300

# Waiting for a new job will timeout after this time (seconds).
# Default: 30
#IdleTimeout 60

# Maximum depth directories are scanned at.
# Default: 15
#MaxDirectoryRecursion 20

# Follow directory symlinks.
# Default: no
#FollowDirectorySymlinks yes

# Follow regular file symlinks.
# Default: no
#FollowFileSymlinks yes

# Perform a database check.
# Default: 1800 (30 min)
#SelfCheck 600

# Execute a command when virus is found. In the command string %v will
# be replaced with the virus name.
# Default: no
#VirusEvent /usr/local/bin/send_sms 123456789 "VIRUS ALERT: %v"

# Run as another user (clamd must be started by root for this option to work)
# Default: don't drop privileges

User clamav
↓変更(コメントアウト)root権限で動作させる
#User clamav

# Initialize supplementary group access (clamd must be started by root).
# Default: no

AllowSupplementaryGroups yes

# Stop daemon when libclamav reports out of memory condition.
#ExitOnOOM yes

# Don't fork into background.
# Default: no
#Foreground yes

# Enable debug messages in libclamav.
# Default: no
#Debug yes

# Do not remove temporary files (for debug purposes).
# Default: no
#LeaveTemporaryFiles yes

# Detect Possibly Unwanted Applications.
# Default: no
#DetectPUA yes

# In some cases (eg. complex malware, exploits in graphic files, and others),
# ClamAV uses special algorithms to provide accurate detection. This option
# controls the algorithmic detection.
# Default: yes
#AlgorithmicDetection yes


##
## Executable files
##

# PE stands for Portable Executable - it's an executable file format used
# in all 32 and 64-bit versions of Windows operating systems. This option allows
# ClamAV to perform a deeper analysis of executable files and it's also
# required for decompression of popular executable packers such as UPX, FSG,
# and Petite.
# Default: yes

ScanPE yes

# Executable and Linking Format is a standard format for UN*X executables.
# This option allows you to control the scanning of ELF files.
# Default: yes

ScanELF yes

# With this option clamav will try to detect broken executables (both PE and
# ELF) and mark them as Broken.Executable.
# Default: no

DetectBrokenExecutables yes


##
## Documents
##

# This option enables scanning of OLE2 files, such as Microsoft Office
# documents and .msi files.
# Default: yes

ScanOLE2 yes

# This option enables scanning within PDF files.
# Default: no
#ScanPDF yes


##
## Mail files
##

# Enable internal e-mail scanner.
# Default: yes

ScanMail yes

# If an email contains URLs ClamAV can download and scan them.
# WARNING: This option may open your system to a DoS attack.
# Never use it on loaded servers.
# Default: no
#MailFollowURLs no

# Recursion level limit for the mail scanner.
# Default: 64
#MailMaxRecursion 128

# With this option enabled ClamAV will try to detect phishing attempts by using
# signatures.
# Default: yes
#PhishingSignatures yes

# Scan URLs found in mails for phishing attempts using heuristics.
# Default: yes
#PhishingScanURLs yes

# Use phishing detection only for domains listed in the .pdb database. It is
# not recommended to have this option turned off, because scanning of all
# domains may lead to many false positives!
# Default: yes
#PhishingRestrictedScan yes

# Always block SSL mismatches in URLs, even if the URL isn't in the database.
# This can lead to false positives.
#
# Default: no
#PhishingAlwaysBlockSSLMismatch no

# Always block cloaked URLs, even if URL isn't in database.
# This can lead to false positives.
#
# Default: no
#PhishingAlwaysBlockCloak no


##
## HTML
##

# Perform HTML normalisation and decryption of MS Script Encoder code.
# Default: yes
#ScanHTML yes


##
## Archives
##

# ClamAV can scan within archives and compressed files.
# Default: yes

ScanArchive yes

# The options below protect your system against Denial of Service attacks
# using archive bombs.

# Files in archives larger than this limit won't be scanned.
# Value of 0 disables the limit.
# Default: 10M
#ArchiveMaxFileSize 15M

# Nested archives are scanned recursively, e.g. if a Zip archive contains a RAR
# file, all files within it will also be scanned. This options specifies how
# deeply the process should be continued.
# Value of 0 disables the limit.
# Default: 8
#ArchiveMaxRecursion 10

# Number of files to be scanned within an archive.
# Value of 0 disables the limit.
# Default: 1000
#ArchiveMaxFiles 1500

# If a file in an archive is compressed more than ArchiveMaxCompressionRatio
# times it will be marked as a virus (Oversized.ArchiveType, e.g. Oversized.Zip)
# Value of 0 disables the limit.
# Default: 250

ArchiveMaxCompressionRatio 300

# Use slower but memory efficient decompression algorithm.
# only affects the bzip2 decompressor.
# Default: no
#ArchiveLimitMemoryUsage yes

# Mark encrypted archives as viruses (Encrypted.Zip, Encrypted.RAR).
# Default: no

ArchiveBlockEncrypted no

# Mark archives as viruses (e.g. RAR.ExceededFileSize, Zip.ExceededFilesLimit)
# if ArchiveMaxFiles, ArchiveMaxFileSize, or ArchiveMaxRecursion limit is
# reached.
# Default: no

ArchiveBlockMax no
↓変更(コメントアウト)
↓大きな圧縮ファイルなどをウィルス感染ファイルとしない
#ArchiveBlockMax no


##
## Clamuko settings
## WARNING: This is experimental software. It is very likely it will hang
## up your system!!!
##

# Enable Clamuko. Dazuko (/dev/dazuko) must be configured and running.
# Default: no
#ClamukoScanOnAccess yes

# Set access mask for Clamuko.
# Default: no
#ClamukoScanOnOpen yes
#ClamukoScanOnClose yes
#ClamukoScanOnExec yes

# Set the include paths (all files inside them will be scanned). You can have
# multiple ClamukoIncludePath directives but each directory must be added
# in a seperate line.
# Default: disabled
#ClamukoIncludePath /home
#ClamukoIncludePath /students

# Set the exclude paths. All subdirectories are also excluded.
# Default: disabled
#ClamukoExcludePath /home/bofh

# Don't scan files larger than ClamukoMaxFileSize
# Value of 0 disables the limit.
# Default: 5M
#ClamukoMaxFileSize 10M








もう一つ編集


# vi /etc/freshclam.conf





##
## Example config file for freshclam
## Please read the freshclam.conf(5) manual before editing this file.
##


# Comment or remove the line below.

Example
↓変更(コメントアウト)
#Example

# Path to the database directory.
# WARNING: It must match clamd.conf's directive!
# Default: hardcoded (depends on installation options)

DatabaseDirectory /var/clamav

# Path to the log file (make sure it has proper permissions)
# Default: disabled

UpdateLogFile /var/log/clamav/freshclam.log

# Maximum size of the log file.
# Value of 0 disables the limit.
# You may use 'M' or 'm' for megabytes (1M = 1m = 1048576 bytes)
# and 'K' or 'k' for kilobytes (1K = 1k = 1024 bytes).
# in bytes just don't use modifiers.
# Default: 1M
#LogFileMaxSize 2M

# Log time with each message.
# Default: no
#LogTime yes

# Enable verbose logging.
# Default: no
#LogVerbose yes

# Use system logger (can work together with UpdateLogFile).
# Default: no

LogSyslog yes

# Specify the type of syslog messages - please refer to 'man syslog'
# for facility names.
# Default: LOG_LOCAL6
#LogFacility LOG_MAIL

# This option allows you to save the process identifier of the daemon
# Default: disabled
#PidFile /var/run/freshclam.pid

# By default when started freshclam drops privileges and switches to the
# "clamav" user. This directive allows you to change the database owner.
# Default: clamav (may depend on installation options)

DatabaseOwner clamav

# Initialize supplementary group access (freshclam must be started by root).
# Default: no
#AllowSupplementaryGroups yes

# Use DNS to verify virus database version. Freshclam uses DNS TXT records
# to verify database and software versions. With this directive you can change
# the database verification domain.
# WARNING: Do not touch it unless you're configuring freshclam to use your
# own database verification domain.
# Default: current.cvd.clamav.net
#DNSDatabaseInfo current.cvd.clamav.net

# Uncomment the following line and replace XY with your country
# code. See http://www.iana.org/cctld/cctld-whois.htm for the full list.
#DatabaseMirror db.XY.clamav.net

# database.clamav.net is a round-robin record which points to our most
# reliable mirrors. It's used as a fall back in case db.XY.clamav.net is
# not working. DO NOT TOUCH the following line unless you know what you
# are doing.

DatabaseMirror db.local.clamav.net

※追加
DatabaseMirror db.jp.clamav.net


# How many attempts to make before giving up.
# Default: 3 (per mirror)
#MaxAttempts 5

# With this option you can control scripted updates. It's highly recommended
# to keep it enabled.
#ScriptedUpdates yes

# Number of database checks per day.
# Default: 12 (every two hours)
#Checks 24

# Proxy settings
# Default: disabled
#HTTPProxyServer myproxy.com
#HTTPProxyPort 1234
#HTTPProxyUsername myusername
#HTTPProxyPassword mypass

# If your servers are behind a firewall/proxy which applies User-Agent
# filtering you can use this option to force the use of a different
# User-Agent header.
# Default: clamav/version_number
#HTTPUserAgent SomeUserAgentIdString

# Use aaa.bbb.ccc.ddd as client address for downloading databases. Useful for
# multi-homed systems.
# Default: Use OS'es default outgoing IP address.
#LocalIPAddress aaa.bbb.ccc.ddd

# Send the RELOAD command to clamd.
# Default: no

NotifyClamd /etc/clamd.conf

# Run command after successful database update.
# Default: disabled
#OnUpdateExecute command

# Run command when database update process fails.
# Default: disabled
#OnErrorExecute command

# Run command when freshclam reports outdated version.
# In the command string %v will be replaced by the new version number.
# Default: disabled
#OnOutdatedExecute command

# Don't fork into background.
# Default: no
#Foreground yes

# Enable debug messages in libclamav.
# Default: no
#Debug yes

# Timeout in seconds when connecting to database server.
# Default: 30
#ConnectTimeout 60

# Timeout in seconds when reading from database server.
# Default: 30
#ReceiveTimeout 60







ここまで出来たら
Clam AntiVirus を起動

# service clamd start
Starting Clam AntiVirus Daemon: [ OK ]



OS起動時に起動するように設定

# chkconfig clamd on



自動起動の確認

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







次にウィルス定義ファイルを更新します

# freshclam
ClamAV update process started at Thu Apr 17 16:42:46 2008
WARNING: Your ClamAV installation is OUTDATED!
WARNING: Local version: 0.92.1 Recommended version: 0.93
DON'T PANIC! Read http://www.clamav.net/support/faq
main.inc is up to date (version: 46, sigs: 231834, f-level: 26, builder: sven)
WARNING: getfile: daily-6752.cdiff not found on remote server (IP: 203.178.137.175)
ERROR: getpatch: Can't download daily-6752.cdiff from db.jp.clamav.net
WARNING: getfile: daily-6752.cdiff not found on remote server (IP: 61.205.61.201)
ERROR: getpatch: Can't download daily-6752.cdiff from db.jp.clamav.net
WARNING: getfile: daily-6752.cdiff not found on remote server (IP: 219.117.246.122)
ERROR: getpatch: Can't download daily-6752.cdiff from db.jp.clamav.net
WARNING: Incremental update failed, trying to download daily.cvd
Downloading daily.cvd [100%]
daily.cvd updated (version: 6807, sigs: 28060, f-level: 26, builder: ccordes)
Database updated (259894 signatures) from db.jp.clamav.net (IP: 219.106.242.51)
Clamd successfully notified about the update.



これでウィルス定義が新しくなりました



ウィルス定義ファイルのアップデートは
今後、/etc/cron.daily/freshclam で
自動的に毎日行われます





お試しウィルススキャン

お試しは /root/ です

# clamscan --infected --remove --recursive /root/

----------- SCAN SUMMARY -----------
Known viruses: 259179
Engine version: 0.92.1
Scanned directories: 59
Scanned files: 60
Infected files: 0
Data scanned: 0.32 MB
Time: 5.652 sec (0 m 5 s)




テスト用の無害なウィルスをダウンロードしてテストしてみます

ダウンロード

# wget http://www.eicar.org/download/eicar.com.txt



スキャン

# clamscan --infected --remove --recursive /root/
/root/eicar.com.txt: Eicar-Test-Signature FOUND
/root/eicar.com.txt: Removed

----------- SCAN SUMMARY -----------
Known viruses: 259179
Engine version: 0.92.1
Scanned directories: 59
Scanned files: 60
Infected files: 1 ← 感染ファイル 1 件
Data scanned: 0.32 MB
Time: 5.652 sec (0 m 5 s)



きちんと動いているようです
削除もされてます





ウィルススキャン定期実行スクリプトの作成

さっ作るぞ!


# vi /root/clamscan




#!/bin/bash

PATH=/usr/bin:/bin

# clamd update
yum -y --enablerepo=rpmforge 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



ダウンロードURL
https://afexcel.up.seesaa.net/CentOS/clamcsan


これは、/root/clamscan.exclude を読込んで

その中にあるディレクトリやファイルは
スキャンしないって事になります


# vi /root/clamscan.exclude




/mnt/
/media/
/root/file.txt



など、
ディレクトリの場合は最後を「/」で終わる
ファイルの場合はファイルを指定





ファイルを移動
作成したスクリプトを
毎日実行するように cron.daily に移動します

# mv /root/clamscan /etc/cron.daily/




実行権限を付ける

# chmod +x /etc/cron.daily/clamscan





これで毎日ウィルススキャンが実行され
発見時にはroot宛てにメールが届きます


この記事へのコメント
コメントを書く
お名前: [必須入力]

メールアドレス:

ホームページアドレス:

コメント: [必須入力]

認証コード: [必須入力]


※画像の中の文字を半角で入力してください。

この記事へのトラックバック

キーワードに合ったホームページを自動的に作っちゃおうツール

キーワードに合ったホームページを自動的に作っちゃおうツール

最新版のダウンロードはこちら↓
EXCEL版
BlogHPEditTool.exe

※実行ファイル版を作成中の為、
 今後、修正やバージョンアップはありません。m(__)m

EXCEL版の最新版の説明はこちら

最新情報 (RSS)

ご意見・ご感想などはこちらにコメントくださいm(__)m

キーワードに合ったホームページを自動的に作っちゃおうツール