如何使用 LMD 检测 Linux 上的恶意软件
如果您正在运行任务关键型 Web 服务器,或管理 Linux 上的共享托管环境,您很可能会不断警惕来自 Linux 恶意软件(例如病毒、特洛伊木马、rootkit 和蠕虫)的潜在威胁。虽然保持最新的服务器强化指南对于防止未来的任何攻击至关重要,但您可能希望将恶意软件检测工具添加到您的武器库中以提高安全性。
Linux Malware Detect (LMD) 是一款适用于 Linux 的免费开源恶意软件扫描工具。在本指南中,我将向您展示如何安装和配置 LMD 以扫描 Linux 系统上的恶意软件。
在 Linux 上安装 LMD
要在 Linux 上安装 LMD,请运行以下命令。
$ wget http://www.rfxn.com/downloads/maldetect-current.tar.gz
$ tar xvfvz maldetect-current.tar.gz
$ cd maldetect-1.4.2
$ sudo ./install.sh
Linux Malware Detect v1.4.1
(C) 2002-2011, R-fx Networks
(C) 2011, Ryan MacDonald
inotifywait (C) 2007, Rohan McGovern
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
maldet(6073): {sigup} performing signature update check...
maldet(6073): {sigup} local signature set is version 201205035915
maldet(6073): {sigup} new signature set (2013031328301) available
maldet(6073): {sigup} downloaded http://www.rfxn.com/downloads/md5.dat
maldet(6073): {sigup} downloaded http://www.rfxn.com/downloads/hex.dat
maldet(6073): {sigup} downloaded http://www.rfxn.com/downloads/rfxn.ndb
maldet(6073): {sigup} downloaded http://www.rfxn.com/downloads/rfxn.hdb
maldet(6073): {sigup} downloaded http://www.rfxn.com/downloads/maldet-clean.tgz
maldet(6073): {sigup} signature set update completed
maldet(6073): {sigup} 10849 signatures (8981 MD5 / 1868 HEX)
安装后,/etc/cron.daily/maldet
中会添加每日 cron 作业,该作业检查最新版本的 LMD 和恶意软件定义/签名文件,并自动更新。如果启用基于 inotify 的实时监控,每日 cron 作业还会扫描最近更新/创建的文件是否存在恶意软件。
使用 LMD 扫描 Linux 系统中的恶意软件
要手动启动恶意软件扫描,请使用要扫描的目标文件夹运行 maldet
。
$ sudo maldet --scan-all /home
maldet(27752): {scan} signatures loaded: 10849 (8981 MD5 / 1868 HEX)
maldet(27752): {scan} building file list for /home, this might take awhile...
maldet(27752): {scan} file list completed, found 20586 files...
maldet(27752): {scan} 20586/20586 files scanned: 1 hits 0 cleaned
maldet(27752): {scan} scan completed on /home: files 20586, malware hits 1, cleaned hits 0
maldet(27752): {scan} scan report saved, to view run: maldet --report 032813-1606.27752
maldet(27752): {scan} quarantine is disabled! set quar_hits=1 in conf.maldet or to quarantine results run: maldet -q 032813-1606.27752
扫描后,您可以通过使用扫描报告 ID 运行以下命令来检查恶意软件扫描报告。
$ sudo maldet --report 032813-1606.27752
malware detect scan report for my_host:
SCAN ID: 032813-1606.27752
TIME: Mar 28 16:33:36 -0700
PATH: /home
TOTAL FILES: 20586
TOTAL HITS: 1
TOTAL CLEANED: 0
NOTE: quarantine is disabled! set quar_hits=1 in conf.maldet or to quarantine results run: maldet -q 032813-1606.27752
FILE HIT LIST:
{MD5}gzbase64.inject.unclassed.1110 : /home/linux教程/maldetect-1.4.2/files/clean/gzbase64.inject.unclassed
===============================================
Linux Malware Detect v1.4.2 < [email >
通过恶意软件扫描保护 Linux 系统
要隔离受感染的文件,请使用扫描报告 ID 运行以下命令。然后,受感染的文件将被隔离以进行清理。
$ sudo maldet -q 032813-1606.27752
maldet(14738): {quar} malware quarantined from '/home/linux教程/maldetect-1.4.2/files/clean/gzbase64.inject.unclassed' to '/usr/local/maldetect/quarantine/gzbase64.inject.unclassed.10045'
maldet(14738): {clean} restoring /usr/local/maldetect/quarantine/gzbase64.inject.unclassed.10045 for cleaning attempt
maldet(14738): {clean} trying to clean /home/linux教程/maldetect-1.4.2/files/clean/gzbase64.inject.unclassed with gzbase64.inject.unclassed rule
maldet(14738): {clean} rescanning /home/linux教程/maldetect-1.4.2/files/clean/gzbase64.inject.unclassed for malware hits
maldet(14738): {clean} clean successful on /home/linux教程/maldetect-1.4.2/files/clean/gzbase64.inject.unclassed
如果您想要主动监控特定目录是否有恶意软件感染,您可以将 maldet
作为守护程序运行,如下所示。
$ sudo maldet -m /var,/home/linux教程
maldet(5330): {mon} set inotify max_user_instances to 128
maldet(5330): {mon} set inotify max_user_watches to 61440
maldet(5330): {mon} added /var to inotify monitoring array
maldet(5330): {mon} added /home/linux教程 to inotify monitoring array
maldet(5330): {mon} starting inotify process on 1 paths, this might take awhile...
maldet(5330): {mon} inotify startup successful (pid: 5409)
maldet(5330): {mon} inotify monitoring log: /usr/local/maldetect/inotify/inotify_log
如果您希望 maldet
通过电子邮件提醒您检测到的恶意软件,您可以按如下方式修改 maldet
配置。对于电子邮件通知,您需要在系统上使用 Postfix 或 sendmail 设置邮件服务器。
$ sudo vi /usr/local/maldetect/conf.maldet
email_alert=1
email_subj="Malware detected by maldet"
email_addr="[email "