LoginSignup
2
2

More than 3 years have passed since last update.

Linux Malware Detectを試してみた[CentOS7.6]

Last updated at Posted at 2019-08-11

はじめに

セキュリティの意識が低いと耳の痛い言葉を見かけることが多くなったので、自分の出来る範囲でセキュリティ対策を頑張ろうと思いました。

Linux Malware Detectとは?

マルウェア検知ツールらしいです。マルウェアっていうのは、ウィルスはPCを破壊するもの、マルウェアは破壊をするわけではないけど、アカウント情報を抜き取ったりしてPCの利用者にダメージを与えるもの。と理解してす。
マルウェアじゃなくてスパイウェアの事でした。マルウェアはこうしたスパイウェア、トロイの木馬等の総称のようです。

インストール

https://qiita.com/curryperformer-kato/items/ed352bccf4aa70ff871f
上記サイトを参考にやりました。
つまずいたところとうは全く無く非常にスムーズにできました。

スキャン及び結果確認

ルート配下からのフルスキャン!!!
…をやってみたのですが、途中でフリーズしてしまいました。
ので、とりあえず/var配下で再実行しました。

# maldet --scan-all /var
Linux Malware Detect v1.6
            (C) 2002-2017, R-fx Networks <proj@rfxn.com>
            (C) 2017, Ryan MacDonald <ryan@rfxn.com>
This program may be freely redistributed under the terms of the GNU GPL v2

maldet(2743): {scan} signatures loaded: 15550 (12738 MD5 | 2035 HEX | 777 YARA | 0 USER)
maldet(2743): {scan} building file list for /var, this might take awhile...
maldet(2743): {scan} setting nice scheduler priorities for all operations: cpunice 19 , ionice 6
maldet(2743): {scan} file list completed in 0s, found 20080 files...
maldet(2743): {scan} scan of /var (20080 files) in progress...
maldet(2743): {scan} 20080/20080 files scanned: 4 hits 0 cleaned

maldet(2743): {scan} scan completed on /var: files 20080, malware hits 4, cleaned hits 0, time 860s
maldet(2743): {scan} scan report saved, to view run: maldet --report 190811-2127.2743
maldet(2743): {scan} quarantine is disabled! set quarantine_hits=1 in conf.maldet or to quarantine results run: maldet -q 190811-2127.2743

4つ検知あり…怖いですね。
このコマンドでレポートが見れるよ。
と書いてあるので早速見ましょう。

maldet --report 190811-2127.2743

HOST:      hoge
SCAN ID:   190811-2127.2743
STARTED:    8月 11 2019 21:27:58 +0900
COMPLETED:  8月 11 2019 21:42:18 +0900
ELAPSED:   860s [find: 0s]

PATH:          /var
TOTAL FILES:   20080
TOTAL HITS:    4
TOTAL CLEANED: 0

WARNING: Automatic quarantine is currently disabled, detected threats are still accessible to users!
To enable, set quarantine_hits=1 and/or to quarantine hits from this scan run:
/usr/sbin/maldet -q 190811-2127.2743

FILE HIT LIST:
{HEX}php.nested.base64.641 : /var/www/wordpress_old/wp-content/themes/tower-bridge/footer.php
{HEX}php.gzbase64.inject.452 : /var/www/wordpress_old/wp-content/themes/tower-bridge/index.php
{HEX}php.nested.base64.641 : /var/www/wordpress/wp-content/themes/tower-bridge/footer.php
{HEX}php.gzbase64.inject.452 : /var/www/wordpress/wp-content/themes/tower-bridge/index.php
===============================================
Linux Malware Detect v1.6 < proj@rfxn.com >

wordpressのtower-bridgeというテーマになんらかの問題があるような書かれ方がされてます。ふわっとした理解ですけど、今利用中のテーマでもないので、ここはバッサリ該当のテーマを削除して対策しました。

自動スキャンを有効にしてみる。

思い出したようにたまに実行するだけではあまり意味がないですよね。
そういうわけで自動スキャンを有効にしたいと思います。
やり方は知らないので調べてみる。

maldet -h
.
.
    -m, --monitor USERS|PATHS|FILE|RELOAD
       Run maldet with inotify kernel level file create/modify monitoring
       If USERS is specified, monitor user homedirs for UID's > 500
       If FILE is specified, paths will be extracted from file, line spaced
       If PATHS are specified, must be comma spaced list, NO WILDCARDS!
       e.g: maldet --monitor users
       e.g: maldet --monitor /root/monitor_paths
       e.g: maldet --monitor /home/mike,/home/ashton
.
.

多分これかな?
どう設定すべきが最適なのかわからないですけど、素人考えでは一番攻撃の可能性が高いのはWeb経由だと思うので、Apacheユーザに対してモニターするようにしよう…と思いましたが、ユーザー指定でのコマンド実行方法がわかりませんでした。
なので素直に/var/www配下とPHPの一時ファイルが作られる/tmp配下を指定します。

maldet -m /var/www,/tmp
Linux Malware Detect v1.6
            (C) 2002-2017, R-fx Networks <proj@rfxn.com>
            (C) 2017, Ryan MacDonald <ryan@rfxn.com>
This program may be freely redistributed under the terms of the GNU GPL v2

maldet(6034): {mon} added /var/www to inotify monitoring array
maldet(6034): {mon} added /tmp to inotify monitoring array
maldet(6034): {mon} starting inotify process on 2 paths, this might take awhile...
maldet(6034): {mon} inotify startup successful (pid: 6136)
maldet(6034): {mon} inotify monitoring log: /var/lib/maldetect/logs/inotify_log

動いてるのか確認する

実際に動いているのかわからないので、下記URLを参考にテストファイルを用意します。
https://support.kaspersky.co.jp/459
いざ、アップロード…と思ったらWindowsDefenderが削除済だった…。やるやん…。

今回はテストなので復元して、wordpressにアップデート。
するも、普通に成功してしまいます。
teratermでSCPでアップデート…しても成功。

/var/www/wordpress/wp-content/cache/object/e8f/c00/e8fc002e890affcad13b9173274b7953.php MODIFY 11 Aug 23:16:57
/var/www/wordpress/wp-content/cache/object/225/950/225950acee9ab02755d78c16696fbe8a.php MODIFY 11 Aug 23:16:57
/var/www/wordpress/wp-content/cache/object/cd5/a47/cd5a47cbf5051bc5963ab96d4a5c468d.php MODIFY 11 Aug 23:16:57
/var/www/wordpress/wp-content/cache/object/840/e32/840e3285cbb308af683cce68a97cb1f8.php CREATE 11 Aug 23:16:57
/var/www/wordpress/wp-content/cache/object/840/e32/840e3285cbb308af683cce68a97cb1f8.php MODIFY 11 Aug 23:16:57
/var/www/wordpress/wp-content/cache/object/f1a/9b3/f1a9b3dd6890f449c4e6cb755513ad58.php CREATE 11 Aug 23:16:57
/var/www/wordpress/wp-content/cache/object/f1a/9b3/f1a9b3dd6890f449c4e6cb755513ad58.php MODIFY 11 Aug 23:16:57
/tmp/V帰eLXg hLg.txt CREATE 11 Aug 23:18:49
/tmp/V帰eLXg hLg.txt MODIFY 11 Aug 23:18:49
/tmp/V帰eLXg hLg.txt MODIFY 11 Aug 23:18:49

ログ上では一応確認はしてるみたいですけど…。
あ、これはマルウェアじゃなくてウィルスだから、ちょっとまた違うものかな?
https://live.paloaltonetworks.com/t5/%E3%83%8A%E3%83%AC%E3%83%83%E3%82%B8%E3%83%89%E3%82%AD%E3%83%A5%E3%83%A1%E3%83%B3%E3%83%88/%E5%81%BD%E3%83%9E%E3%83%AB%E3%82%A6%E3%82%A7%E3%82%A2-%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%9FWildFire%E3%81%AE%E3%83%86%E3%82%B9%E3%83%88%E6%96%B9%E6%B3%95/ta-p/75363
こちらでマルウェアを入手できるようなので、試してみますが、WindowsでもLinuxでも検知しません。

わっかんねぇ…。動いていることは確認できましたが、本当に言葉通り動いている事しか確認できませんでした。
わかんないので今日はもうこの程度にしといてやります。
ちなみにモニターを止める時は

maldet -k

ちなみに手動でスキャンしても引っかからないので、やっぱりシグネチャが対応してないのか、私がちゃんとマルウェアを用意できてないのかのどっちかなんでしょう。
※1.sophos anti-virus for linuxを試した際にWindows側で作成してアップロードしたのが原因だった事例があったので、サーバ側でテストファイル作成からやって確認もしましたが、結果は変わりませんでした。
※2.上記のURLはおそらくウィルス用テストファイルなのと、特定の機器専用?っぽいのでMcAfeeのマルウェア用テストファイル作成方法のURLも追記しておきます。
https://kc.mcafee.com/corporate/index?page=content&id=KB59742&actp=null&viewlocale=ja_JP&locale=ja_JP

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

maldet(12251): {scan} signatures loaded: 15550 (12738 MD5 | 2035 HEX | 777 YARA | 0 USER)
maldet(12251): {scan} building file list for /tmp, this might take awhile...
maldet(12251): {scan} setting nice scheduler priorities for all operations: cpunice 19 , ionice 6
maldet(12251): {scan} file list completed in 0s, found 97 files...
maldet(12251): {scan} scan of /tmp (97 files) in progress...
maldet(12251): {scan} 97/97 files scanned: 0 hits 0 cleaned

maldet(12251): {scan} scan completed on /tmp: files 97, malware hits 0, cleaned hits 0, time 22s
maldet(12251): {scan} scan report saved, to view run: maldet --report 190811-2348.12251
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