end0tknr's kipple - web写経開発

太宰府天満宮の狛犬って、妙にカワイイ

install clamav v.0.99.4 to centos 7 と、独自virus 定義の作成

超大量のサーバがあり && EOLなミドルウエア管理ができていない場合、 「独自virus定義を作成し、virus scanに検知だけさせれば」と思ったのがきっかけ

参考url

install

groupadd

$ su - 
# groupadd clamav
# useradd -g clamav -s /bin/false -c "Clam Antivirus" clamav

download , configure , make ...

$ wget https://www.clamav.net/downloads/production/clamav-0.99.4.tar.gz
$ tar -xvf clamav-0.99.4.tar.gz
$ cd clamav-0.99.4
$ ./configure
  :
configure: Summary of detected features follows
              OS          : linux-gnu
              pthreads    : yes (-lpthread)
configure: Summary of miscellaneous features
              check       : no (auto)
              fanotify    : yes
              fdpassing   : 1
              IPv6        : yes
configure: Summary of optional tools
              clamdtop    : -lncurses (auto)
              milter      : yes (disabled)
              clamsubmit  : yes
configure: Summary of engine performance features
              release mode: yes
              llvm        : yes, from built-in (auto)
              mempool     : yes
configure: Summary of engine detection features
              bzip2       : ok
              zlib        : /usr
              unrar       : yes
              pcre        : /usr
              libxml2     : yes, from /usr
              yara        : yes
$
$ su
# make install

setting clamav( freshclam.conf )

install後、virus定義file(DB)を更新しようと、freshclam を実行したところ、 errorとなった為、freshclam.conf を作成。

freshclam.conf のファイルすらなかったので、サンプルよりcopy

# /usr/local/bin/freshclam
ERROR: Can't open/parse the config file /usr/local/etc/freshclam.conf

# cp ~/clamav-0.99.4/etc/freshclam.conf.sample /usr/local/etc/freshclam.conf

が、freshclam.conf 内に「Example」という記述があったので、コメント化

# /usr/local/bin/freshclam
ERROR: Please edit the example config file /usr/local/etc/freshclam.conf
ERROR: Can't open/parse the config file /usr/local/etc/freshclam.conf

# vi /usr/local/etc/freshclam.conf

が、virus定義file 用のdirがない為、mkdir

# /usr/local/bin/freshclam
ERROR: Can't change dir to /usr/local/share/clamav

# mkdir /usr/local/share/clamav

が、ユーザ(clamav)への書込み権限が必要らしく、chown

# /usr/local/bin/freshclam
ERROR: Can't create temporary directory /usr/local/share/clamav/clamav-3187640ea28ef290eedab5f5bfa9fc8c.tmp
Hint: The database directory must be writable for UID 1003 or GID 1003

# ls -l /usr/local/share
# chown clamav /usr/local/share/clamav

で、やっと成功。

# /usr/local/bin/freshclam 
ClamAV update process started at Sun Apr  8 10:47:58 2018
Downloading main.cvd [100%]
main.cvd updated (version: 58, sigs: 4566249, f-level: 60, builder: sigmgr)
Downloading daily.cvd [100%]
daily.cvd updated (version: 24459, sigs: 1902655, f-level: 63, builder: neo)
Downloading bytecode.cvd [100%]
bytecode.cvd updated (version: 319, sigs: 75, f-level: 63, builder: neo)
Database updated (6468979 signatures) from database.clamav.net (IP: 27.96.54.66)
#

独自virus 定義の作成 (.db , .hdb , *.mdb)

clamavには、3種類の定義fileの書式があるようです。 以下に記載していますが、いずれも clamav付属の sigtool を利用できます。

その1 - hexdump による *.db

hexdumpし、適当な範囲(40~400文字程度?)でcutし、これを*.dbに保存

$ cat /usr/local/openssl_1_0_1/bin/openssl | \
    /usr/local/bin/sigtool --hex-dump | \
    cut -c 1-100 >> /home/endo/tmp/CLAM_DATA/test.db 

その2 - md5チェックサムによる *.hdb

$ /usr/local/bin/sigtool --md5 /usr/local/openssl_1_0_1/bin/openssl \
   > /home/endo/tmp/CLAM_DATA/test.hdb

その3 - 実行ファイルのPEセクションを使用する *.mdb

$ /usr/local/bin/sigtool --mdb /usr/local/openssl_1_0_1/bin/openssl \
  > /home/endo/tmp/CLAM_DATA/test.mdb

独自virus 定義によるscan実行

以下の通りです。infected オプションにより検知のみ(削除等を行わない)にしています

$ /usr/local/bin/clamscan --verbose --infected \
    --database=/home/endo/tmp/CLAM_DATA \
    -r /home/endo/tmp/CLAM_TEST