LoginSignup
0
6

More than 3 years have passed since last update.

Debian / Ubuntu / LinuxMintにLinux Malware Detectをインストールする

Last updated at Posted at 2019-11-11

はじめに

既出の記事は幾つかあるのですが、Debian系にMalware Detectをインストールするという記事が無かったので、取り敢えずやってみました。やった事は海外のブログ記事をそのまま実行して、上手く動作したので、開発した「WEBファイルをPCへ落とさずにブラウザで読むには」という機能に実装して、マルウェアの検出も同時に出来るようにする予定です。

LMD (Linux Malware Detect) をダウンロード

まずUbuntuのコンソールでLMDをダウンロードします。英文記事の説明に従ってtmpフォルダで作業を行ってみました。これで最新版が落ちてきます。

cd /tmp/
curl -O http://www.rfxn.com/downloads/maldetect-current.tar.gz

tar コマンドで解凍します。

tar -zxvf maldetect-current.tar.gz

ディレクトリを調べると maldetect-1.6.4 が解凍されています。これが現在(2019.11.11)は最新版のようです。フォルダに移動してインストールします。

cd maldetect-1.6.4/
bash install.sh

インストールされた状態で実行しているので、多少違いますがインストールの出力は以下のようになります。

update-rc.d: error: unable to read /etc/init.d/maldet
Linux Malware Detect v1.6.4
            (C) 2002-2019, R-fx Networks <proj@r-fx.org>
            (C) 2019, Ryan MacDonald <ryan@r-fx.org>
This program may be freely redistributed under the terms of the GNU GPL

installation completed to /usr/local/maldetect
config file: /usr/local/maldetect/conf.maldet
exec file: /usr/local/maldetect/maldet
exec link: /usr/local/sbin/maldet
exec link: /usr/local/sbin/lmd
cron.daily: /etc/cron.daily/maldet
imported config options from /usr/local/maldetect.last/conf.maldet
maldet(23574): {sigup} performing signature update check...
maldet(23574): {sigup} local signature set is version 201907043616
maldet(23574): {sigup} signature files missing or corrupted, forcing update...
maldet(23574): {sigup} new signature set 2019111027906 available
maldet(23574): {sigup} downloading https://cdn.rfxn.com/downloads/maldet-sigpack.tgz
maldet(23574): {sigup} downloading https://cdn.rfxn.com/downloads/maldet-cleanv2.tgz
maldet(23574): {sigup} verified md5sum of maldet-sigpack.tgz
maldet(23574): {sigup} unpacked and installed maldet-sigpack.tgz
maldet(23574): {sigup} verified md5sum of maldet-clean.tgz
maldet(23574): {sigup} unpacked and installed maldet-clean.tgz
maldet(23574): {sigup} signature set update completed
maldet(23574): {sigup} 15569 signatures (12749 MD5 | 2035 HEX | 785 YARA | 0 USER)

LMDの設定ファイルを編集します。

vi /usr/local/maldetect/conf.maldet

設定項目についてはファイルの中のメモを読むと大体理解できますが、細かくは読んでいません。

# Enable Email Alerting
email_alert="1"

# Email Address in which you want to receive scan reports
email_addr="you@domain.com"

# Use with ClamAV
scan_clamscan="1"

# Enable scanning for root-owned files. Set 1 to disable.
scan_ignore_root="0"

# Move threats to quarantine
quarantine_hits="1"

# Clean string based malware injections
quarantine_clean="1"

# Suspend user if malware found. 
quarantine_suspend_user="1"

# Minimum userid value that be suspended
quarantine_suspend_user_minuid="500"

ClamAV のインストール

LMD は ClamAV との利用が推奨されているので、LMDの設定ファイルで有効にしています。

apt-get -y install clamav clamav-daemon clamdscan

以上で LMD が ClamAV と共に動作するようになったはずですので、次にサンプルのマルウェアを tmp フォルダにダウンロードしてテストを行います。「EICAR のサイト」にテスト用のサンプルが用意されています。

cd /tmp
wget http://www.eicar.org/download/eicar_com.zip
wget http://www.eicar.org/download/eicarcom2.zip

検出のテスト(実際にスキャンしてみます)

maldet -a /tmp

以下のような結果が出力されます。正常に動いているようです。(下から2、3、4、行目)

Linux Malware Detect v1.6.4
            (C) 2002-2019, R-fx Networks <proj@rfxn.com>
            (C) 2019, Ryan MacDonald <ryan@rfxn.com>
This program may be freely redistributed under the terms of the GNU GPL v2

maldet(26768): {scan} signatures loaded: 15569 (12749 MD5 | 2035 HEX | 785 YARA | 0 USER)
maldet(26768): {scan} building file list for /tmp, this might take awhile...
maldet(26768): {scan} setting nice scheduler priorities for all operations: cpunice 19 , ionice 6
maldet(26768): {scan} file list completed in 0s, found 153 files...
maldet(26768): {scan} found clamav binary at /usr/bin/clamscan, using clamav scanner engine...
maldet(26768): {scan} scan of /tmp (153 files) in progress...
maldet(26768): {clean} could not find clean rule for hit EICAR.TEST or file /usr/local/maldetect/quarantine/eicarcom2.zip.3007128723 no longer exists.
maldet(26768): {scan} processing scan results for hits: 1 hits 0 cleanedmaldet(26768): {clean} could not find clean rule for hit E
ICAR.TEST or file /usr/local/maldetect/quarantine/eicar_com.zip.1422715434 no longer exists.
maldet(26768): {scan} processing scan results for hits: 2 hits 0 cleaned
maldet(26768): {scan} scan completed on /tmp: files 153, malware hits 2, cleaned hits 0, time 81s
maldet(26768): {scan} scan report saved, to view run: maldet --report 191111-1645.26768

再度、スキャンするとマルウェアは綺麗に消えています。

Linux Malware Detect v1.6.4
            (C) 2002-2019, R-fx Networks <proj@rfxn.com>
            (C) 2019, Ryan MacDonald <ryan@rfxn.com>
This program may be freely redistributed under the terms of the GNU GPL v2

maldet(30554): {scan} signatures loaded: 15569 (12749 MD5 | 2035 HEX | 785 YARA | 0 USER)
maldet(30554): {scan} building file list for /tmp, this might take awhile...
maldet(30554): {scan} setting nice scheduler priorities for all operations: cpunice 19 , ionice 6
maldet(30554): {scan} file list completed in 0s, found 149 files...
maldet(30554): {scan} found clamav binary at /usr/bin/clamscan, using clamav scanner engine...
maldet(30554): {scan} scan of /tmp (149 files) in progress...
maldet(30554): {scan} scan completed on /tmp: files 149, malware hits 0, cleaned hits 0, time 80s
maldet(30554): {scan} scan report saved, to view run: maldet --report 191111-1741.30554

レポートの表示(マルウェアが検出されたレポートを表示してみましょう。)

maldet --report 191111-1645.26768

2つの検出結果がレポートされています。

HOST:      118-27-2-234
SCAN ID:   191111-1645.26768
STARTED:   11月 11 2019 16:45:21 +0900
COMPLETED: 11月 11 2019 16:46:42 +0900
ELAPSED:   81s [find: 0s]

PATH:          /tmp
TOTAL FILES:   153
TOTAL HITS:    2
TOTAL CLEANED: 0

FILE HIT LIST:
{HEX}EICAR.TEST.3 : /tmp/eicarcom2.zip => /usr/local/maldetect/quarantine/eicarcom2.zip.3007128723
{HEX}EICAR.TEST.3 : /tmp/eicar_com.zip => /usr/local/maldetect/quarantine/eicar_com.zip.1422715434
===============================================
Linux Malware Detect v1.6.4 < proj@rfxn.com >

検査したログの一覧を表示します。

maldet -e list

何と初回のスキャニングで10件のマルウェアを発見していました。

Linux Malware Detect v1.6.4
            (C) 2002-2019, R-fx Networks <proj@rfxn.com>
            (C) 2019, Ryan MacDonald <ryan@rfxn.com>
This program may be freely redistributed under the terms of the GNU GPL v2

11月  12  2019  16:28:51  |  SCANID:  191112-1628.25736  |  RUNTIME:  357s  |  FILES:  40989  |  HITS:  0   |  CLEANED:  0
11月  12  2019  10:40:06  |  SCANID:  191112-1040.3390   |  RUNTIME:  123s  |  FILES:  37     |  HITS:  0   |  CLEANED:  0
11月  12  2019  01:25:10  |  SCANID:  191112-0125.31326  |  RUNTIME:  85s   |  FILES:  198    |  HITS:  0   |  CLEANED:  0
11月  11  2019  22:49:45  |  SCANID:  191111-2249.19186  |  RUNTIME:  75s   |  FILES:  151    |  HITS:  1   |  CLEANED:  0
11月  11  2019  20:49:17  |  SCANID:  191111-2049.11084  |  RUNTIME:  339s  |  FILES:  40987  |  HITS:  0   |  CLEANED:  0
11月  11  2019  20:47:36  |  SCANID:  191111-2047.10699  |  RUNTIME:  82s   |  FILES:  77     |  HITS:  0   |  CLEANED:  0
11月  11  2019  20:45:07  |  SCANID:  191111-2045.10231  |  RUNTIME:  76s   |  FILES:  79     |  HITS:  2   |  CLEANED:  0
11月  11  2019  20:37:10  |  SCANID:  191111-2037.9454   |  RUNTIME:  347s  |  FILES:  40987  |  HITS:  0   |  CLEANED:  0
11月  11  2019  17:41:18  |  SCANID:  191111-1741.30554  |  RUNTIME:  80s   |  FILES:  149    |  HITS:  0   |  CLEANED:  0
11月  11  2019  16:45:21  |  SCANID:  191111-1645.26768  |  RUNTIME:  81s   |  FILES:  153    |  HITS:  2   |  CLEANED:  0
11月  11  2019  14:45:10  |  SCANID:  191111-1445.15896  |  RUNTIME:  81s   |  FILES:  149    |  HITS:  0   |  CLEANED:  0
11月  11  2019  14:40:58  |  SCANID:  191111-1440.15436  |  RUNTIME:  87s   |  FILES:  315    |  HITS:  0   |  CLEANED:  0
11月  11  2019  14:38:41  |  SCANID:  191111-1438.14937  |  RUNTIME:  90s   |  FILES:  315    |  HITS:  0   |  CLEANED:  0
11月  11  2019  14:32:02  |  SCANID:  191111-1432.13026  |  RUNTIME:  86s   |  FILES:  169    |  HITS:  10  |  CLEANED:  0

スキャンの範囲を変更するオプション(日数)

このオプションで指定した最後の数字は日数です。過去5日間の更新ファイルをスキャンします。

maldet -r /var/www/html/ 5

続きはアプリケーションへの実装と検出時の処理の予定です。

0
6
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
0
6