2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【2024年08月版】Ubuntu でウイルス対策【clamav】

Posted at

はじめに

ノーガードのubuntu卒業したい。。。

cronで定期実行したい。。。

そうだ、clamav しよう

設定

インストール

sudo apt install clamav clamav-daemon

サービス設定

すでに自動アップデートのサービスはインストールされている(clamav-freshclam.service

スキャンにはスタンドアロンスキャナーを使用する方法と、デーモンを使用する方法がある。

デーモンを使用する場合は、clamavデーモンを登録しておく。

sudo systemctl enable --now clamav-daemon.service 

動作確認

スタンドアロンスキャナーによるスキャン

clamscan
/home/tarou/test.txt: OK

----------- SCAN SUMMARY -----------
Known viruses: 8697172
Engine version: 0.103.11
Scanned directories: 1
Scanned files: 1
Infected files: 0
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 0.00:1)
Time: 14.108 sec (0 m 14 s)
Start Date: 2024:08:16 16:08:55
End Date:   2024:08:16 16:09:09

テストのウイルスファイルをスキャン

~$ echo 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' > clamav-testfile 
~$ clamscan
/home/tarou/clamav-testfile: Eicar-Signature FOUND

----------- SCAN SUMMARY -----------
Known viruses: 8697172
Engine version: 0.103.11
Scanned directories: 1
Scanned files: 1
Infected files: 1
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 0.00:1)
Time: 14.289 sec (0 m 14 s)
Start Date: 2024:08:16 16:06:48
End Date:   2024:08:16 16:07:02

cron 設定

シェルの作成

スキャン用のスクリプト(~/.clamav/scan.sh)、ログディレクトリ(~/.clamav/log)を作成しておく。

オプション
-i Only print infected files
-r Scan subdirectories recursively
-l Save scan report to FILE
--exclude=REGEX Don't scan file names matching REGEX
--exclude-dir=REGEX Don't scan directories matching REGEX

ホームディレクトリは以下をスキャンする例。ログディレクトリに結果は保存される。

/home/.clamav/scan.sh
#!/bin/bash
/usr/bin/clamscan -i -r $HOME -l "$HOME/.clamav/log/$(date +%Y%m%d%H%M%S).log" 2>/dev/null

cron 登録

tarou ユーザでスクリプトを作っている場合

crontab -e
crontab -l
0 4 * * * bash /home/tarou/scan.sh

さいごに

かんたんでしたね

関連リンク

ClamAV Documentation | 2.3. Unix from source (v0.104+) | Ubuntu / Debian

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?