clamfsを使う

 clamfsはClam AntiVirusを利用したウイルススキャン機能付きのファイルシステムだ。これをファイルサーバーに導入した。
現在Debianにおいてclamfsのパッケージはlenny/sidでしか提供されていないのでまずはlennyにアップグレードしておく。
apt-get install clamfsしたあと、設定ファイルを作成する必要がある。

設定ファイル/etc/clamfs/monooki.xmlの例。

<!--
 Only three options are mandatory:
      <clamd socket="" />
      <filesystem root="" />
      <filesystem mountpoint="" />

     All other can be removed, but this will disable related subsystem.
     For example removing <cache ... /> will disable caching completly. 
-->
<clamfs>
<!-- Clamd socket -->
<clamd socket="/var/run/clamav/clamd.ctl"/>
<!--
 File system settings
             root       - real directory to attach as our root
             mountpoint - where to attach our root
             public     - limit access to process owner only or make
                          file system publicly available for all users
             nonempty   - allow mount to directory which contains
                          files or sub-directories 
-->
<filesystem root="/monooki" mountpoint="/clamfs/monooki" public="yes" nonempty="yes"/>
<!--
 Maximal file size (in bytes).
             This option can speed up access to large files, as they will be
             never scanned. On the other hand attacker can append long portion
             of junk at the end of file to make it big enough to be omitted. 
-->
<file maximal-size="21474836480"/>
<!-- 20GB -->
<!--
 Whitelisted files are never scanned.
             This can speed up access to some files, but be careful with this,
             some data files like JPEG, RIFF or WMF can be prepared to cause
             problems (like buffers overflows) in applications and thus execute
             malicious code even not being executable itself. Finally even text
             files can have "modeline" causing problems in some buggy editors. 
-->
<whitelist>
</whitelist>
<!--
 Blacklisted files are scanned regardless of their sizes 
-->
<blacklist>
<include extension="exe"/>
<!-- executable file -->
<include extension="com"/>
<!-- executable file -->
<include extension="dll"/>
<!-- library -->
<include extension="sys"/>
<!-- system file / driver -->
<include extension="vbs"/>
<!-- Visual Basic Script -->
<include extension="bat"/>
<!-- DOS Batch file -->
<include extension="cmd"/>
<!-- Windows Command file -->
</blacklist>
<!--
 How many entries to keep in cache and for how long (in ms) 
-->
<cache entries="16384" expire="108000000"/>
<!-- 30h -->
<!-- Logging method (stdout, syslog or file) -->
<!-- <log method="stdout" verbose="yes" /> -->
<log method="syslog"/>
<!--
 <log method="file" filename="/var/log/clamfs.log" verbose="no" /> 
-->
<!-- Send mail when virus is found -->
<!--
 <mail server="localhost" to="root@localhost" from="clamfs@localhost"
             subject="ClamFS: Virus detected" /> 
-->
<!--
 subject="ClamFS: Virus detected on @@HOSTNAME@@" /> 
-->
<!-- Debug settings -->
<!-- <debug threads="no" fork="no" /> -->
</clamfs>

最低限設定しないといけないのは

<filesystem root="/monooki" mountpoint="/clamfs/monooki" public="yes" nonempty="yes"/>

の部分で、どの実ディレクトリをどこにマウントするかを書いておかなければならない。
この例では/monookiというディレクトリを/clamfs/monookiにマウントするように設定した。なお、clamfs/monookiというディレクトリをマウントポイントとして作成しておく必要がある。

設定ができたらいよいよ起動だ。

# clamfs /etc/clamfs/monooki.xml

これで/monookiが/clamfs/monookiにマウントされる。

さてうまく動作しているか確かめてみよう。eicar.comというアンチウィルスソフトがうまく動作しているか確かめるためのファイルがあるのでこれを利用する。
eicar.comの作り方はテキストエディタでeicar.comという名前のファイルを作成し、内容を

X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*

とするだけ。
まずは素の/monookiディレクトリに入っているファイルを開いてみる。

# cat /monooki/eicar.com 
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*

ファイルの内容が読める。
ところが、/clamfs/monooki内の同じファイルを開こうとすると

# cat /clamfs/monooki/eicar.com 
cat: /clamfs/monooki/eicar.com: Operation not permitted

このようにエラーが出る。
ちなみに記録はsyslogに

Dec 23 10:16:15 ***** clamfs: (cat:3448) (*****:1000) /eicar.com: forced anti-virus scan because extension blacklisted 
Dec 23 10:16:15 ***** clamfs: (cat:3448) (*****:1000) /monooki/eicar.com: Eicar-Test-Signature FOUND

のように残る。
リンク:http://clamfs.sourceforge.net/