clamav: clamscanとclamdscanの違いってなんなんだよ
clamavはフリーのアンチウイルスソフトウェア
最近はOS Xとかでも有名ですな。
公式サイト
http://www.clamav.net/lang/en/
インストールはportsから。
概要
一部モジュールのみ以下にまとめます。
- clamscan
- clamdscan
- clamd
- freshclam
・clamscan
単品で動くウイルススキャナ。
一回だけのスキャンに使用する。
遅い。
・clamd
ウイルススキャナデーモン
後述のclamdscanとセットで使う。
あるいはメールのスキャンなどに。
・clamdscan
clamdとセットで動くウイルススキャナ。
指定されたファイルのパスをclamdに教えると、clamdがスキャンしてくれる。
clamdは定義ファイルをメモリ展開しているのでclamscan(clam*d*scanじゃなく)よりもスキャンが断然速い。
・freshclam
定義ファイルのダウンローダ。
オンデマンドで実行もできるし、常駐化させておいて定期的にダウンロードさせることもできる。
使い方: ウイルスデータベース更新
インストールすれば、すぐに使える。
まずは念のためウイルスデータベースを更新。freshclamを実行するだけ。
# freshclam ClamAV update process started at Wed Feb 29 14:22:04 2012 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 Downloading daily-14555.cdiff [100%] daily.cld updated (version: 14555, sigs: 108764, f-level: 63, builder: guitar) Reading CVD header (bytecode.cvd): OK bytecode.cvd is up to date (version: 167, sigs: 40, f-level: 63, builder: edwin) Database updated (1153191 signatures) from database.clamav.net Clamd successfully notified about the update.
使い方: スキャン: clamscan
あとはclamscanにファイル名を引数で渡せばよい。
$ clamscan <file>
$ clamscan -r <dir>
そのほか、よく使用するオプションとしては、
-i: 感染したファイルのみ表示 --move <dirA> : 感染したファイルを<dirA>に移動 --copy <dirB> : 感染したファイルを<dirB>に移動 -d [<file>|<dir>] : デフォルトと異なる場所に置いたウイルスデータベースを指定。 -l <logfile> : スキャンログを<logfile>に書き出し。 -f <filelist> : <filelist>にリストされたファイルをスキャン
clamscanとclamdscan
先述の通り、clamscanとclamdscanではスピードが違う。
実験をしてみるとその差は歴然。
というより、clamscanが遅すぎる。
定期的にスキャンするなら、絶対にclamdscanがよい。
注意点はあるが、それは後述。
$ clamscan ./messages ./lpd-errs ./messages: OK ./lpd-errs: OK ----------- SCAN SUMMARY ----------- (中略) Infected files: 0 Data scanned: 0.02 MB Data read: 0.01 MB (ratio 2.00:1) Time: 7.878 sec (0 m 7 s) $ clamdscan ./messages ./lpd-errs /var/log/./messages: OK /var/log/./lpd-errs: OK ----------- SCAN SUMMARY ----------- Infected files: 0 Time: 0.033 sec (0 m 0 s)
使い方:clamdscan
仕組みは以下の通りと理解している。
スキャンするときには、ファイルの場所をclamdscanに伝える。
clamdscanはdaemonとして常駐しているので、いちいちウイルスデータベースを読み込まなくてよい。
だから速い。
しかしNFSマウントしたファイルのスキャンなど、ファイルへのアクセス権限が特殊な場合に問題となるケースがあった。
clamdscan起動の準備をする。/etc/rc.confに以下を追加。
ついでにfreshclamもdaemonモードで起動するように。
#clamd clamav_clamd_enable="YES" clamav_freshclam_enable="YES"
portsから入れたなら、clamd.conf、freshclam.confは特にデフォルトでよい。
起動させる。
# /usr/local/etc/rc.d/clamav-clamd start # /usr/local/etc/rc.d/clamav-freshclam start
以上。
以下は参考。
/usr/local/etc/freshclam.conf
影響しそうなところのみピックアップ
・ウイルスデータベース格納場所
# Path to the database directory. # WARNING: It must match clamd.conf's directive! # Default: hardcoded (depends on installation options) DatabaseDirectory /var/db/clamav
・freshclamのログファイル場所
# Path to the log file (make sure it has proper permissions) # Default: disabled UpdateLogFile /var/log/clamav/freshclam.log
・定義ファイル更新を試みる頻度
# 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
・データベース更新時にclamdに再読み込みさせる。
# Send the RELOAD command to clamd. # Default: no NotifyClamd /usr/local/etc/clamd.conf
・データベース更新が失敗したときに実行するコマンド
興味あるが今は保留
# 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
/usr/local/etc/clamd.conf
基本デフォルト。MaxScanSize、MaxFileSizeくらいか。
# 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 # 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 2M # Specify the type of syslog messages - please refer to 'man syslog' # for facility names. # Default: LOG_LOCAL6 #LogFacility LOG_MAIL # Path to the database directory. # Default: hardcoded (depends on installation options) DatabaseDirectory /var/db/clamav # Don't scan files and directories matching regex # This directive can be used multiple times # Default: scan all #ExcludePath ^/proc/ #ExcludePath ^/sys/ # Maximum depth directories are scanned at. # Default: 15 #MaxDirectoryRecursion 20 # Follow directory symlinks. # Default: no #FollowDirectorySymlinks yes # Perform a database check. # Default: 600 (10 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 # 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. If you turn off this option, the original files will still be # scanned, but without additional processing. # 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. # If you turn off this option, the original files will still be scanned, but # without additional processing. # Default: yes #ScanELF yes ## Documents ## # This option enables scanning of OLE2 files, such as Microsoft Office # documents and .msi files. # If you turn off this option, the original files will still be scanned, but # without additional processing. # Default: yes #ScanOLE2 yes # With this option enabled OLE2 files with VBA macros, which were not # detected by signatures will be marked as "Heuristics.OLE2.ContainsMacros". # Default: no #OLE2BlockMacros no # This option enables scanning within PDF files. # If you turn off this option, the original files will still be scanned, but # without decoding and additional processing. # Default: yes #ScanPDF yes ## ## Archives ## # ClamAV can scan within archives and compressed files. # If you turn off this option, the original files will still be scanned, but # without unpacking and additional processing. # Default: yes #ScanArchive yes # Mark encrypted archives as viruses (Encrypted.Zip, Encrypted.RAR). # Default: no #ArchiveBlockEncrypted no # This option sets the maximum amount of data to be scanned for each input file. # Archives and other containers are recursively extracted and scanned up to this # value. # Value of 0 disables the limit # Note: disabling this limit or setting it too high may result in severe damage # to the system. # Default: 100M #MaxScanSize 150M # Files larger than this limit won't be scanned. Affects the input file itself # as well as files contained inside it (when the input file is an archive, a # document or some other kind of container). # Value of 0 disables the limit. # Note: disabling this limit or setting it too high may result in severe damage # to the system. # Default: 25M #MaxFileSize 30M # 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. # Note: setting this limit too high may result in severe damage to the system. # Default: 16 #MaxRecursion 10 # Number of files to be scanned within an archive, a document, or any other # container file. # Value of 0 disables the limit. # Note: disabling this limit or setting it too high may result in severe damage # to the system. # Default: 10000 #MaxFiles 15000