Linux Malware Detect (LMD) è un rilevatore di malware per sistemi operativi Linux, distribuito con licenza GNU GPLv2. LMD è pensato soprattutto per gli ambienti di shared hosting, dove occorre individuare o rimuovere le minacce presenti nei file degli utenti.
In questo articolo installeremo Linux Malware Detect insieme a ClamAV su CentOS 7.
Installare LMD su CentOS 7 / RHEL 7
LMD non è disponibile come pacchetto precompilato nei repository ufficiali di CentOS, ma viene distribuito come archivio tarball dal sito del progetto. Scarichiamo l'ultima versione.
cd /tmp/ curl -O https://www.rfxn.com/downloads/maldetect-current.tar.gz
Estrarre l'archivio e spostarsi nella directory creata.
tar -zxvf maldetect-current.tar.gz cd maldetect*
Avviare lo script di installazione install.sh.
bash install.sh
Output:
Created symlink from /etc/systemd/system/multi-user.target.wants/maldet.service to /usr/lib/systemd/system/maldet.service.
Linux Malware Detect v1.6
(C) 2002-2017, R-fx Networks <proj@r-fx.org>
(C) 2017, 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
maldet(1344): {sigup} performing signature update check...
maldet(1344): {sigup} local signature set is version 2017070716978
maldet(1344): {sigup} new signature set (2017080720059) available
maldet(1344): {sigup} downloading https://cdn.rfxn.com/downloads/maldet-sigpack.tgz
maldet(1344): {sigup} downloading https://cdn.rfxn.com/downloads/maldet-cleanv2.tgz
maldet(1344): {sigup} verified md5sum of maldet-sigpack.tgz
maldet(1344): {sigup} unpacked and installed maldet-sigpack.tgz
maldet(1344): {sigup} verified md5sum of maldet-clean.tgz
maldet(1344): {sigup} unpacked and installed maldet-clean.tgz
maldet(1344): {sigup} signature set update completed
maldet(1344): {sigup} 15215 signatures (12485 MD5 | 1951 HEX | 779 YARA | 0 USER)
Configurare Linux Malware Detect
Il file di configurazione principale di LMD è /usr/local/maldetect/conf.maldet e può essere modificato in base alle proprie necessità.
vi /usr/local/maldetect/conf.maldet
Di seguito alcune impostazioni importanti per una corretta individuazione e rimozione delle minacce.
# Abilita le notifiche email email_alert="1" # Indirizzo email su cui ricevere i report delle scansioni email_addr="itzgeek.web@gmail.com" # Utilizza ClamAV scan_clamscan="1" # Abilita la scansione dei file di proprietà di root. Impostare 1 per disabilitare. scan_ignore_root="0" # Sposta le minacce in quarantena quarantine_hits="1" # Rimuove le iniezioni di malware basate su stringhe quarantine_clean="1" # Sospende l'utente se viene rilevato malware quarantine_suspend_user="1" # Valore minimo dello userid da sospendere quarantine_suspend_user_minuid="500"
Se non si intende usare LMD insieme a ClamAV, si può saltare direttamente alla sezione sulle scansioni.
Linux Malware Detect con ClamAV
LMD offre prestazioni migliori nella scansione di grandi insiemi di file quando viene affiancato a ClamAV. ClamAV (Clam Antivirus) è una soluzione antivirus open source in grado di rilevare virus, malware, trojan e altri programmi malevoli.
ClamAV è disponibile nel repository EPEL: configuriamolo sulla macchina CentOS / RHEL.
rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Installare ClamAV con YUM.
yum -y install clamav clamav-devel clamav-update inotify-tools
Aggiornare il database delle firme di ClamAV.
freshclam
Non è richiesta alcuna configurazione aggiuntiva: l'integrazione tra ClamAV e LMD è attiva per impostazione predefinita.
Testare Linux Malware Detect
Verifichiamo il funzionamento di LMD utilizzando un virus di prova. Scaricare le firme di test dal sito EICAR.
cd /tmp wget https://www.eicar.org/download/eicar_com.zip wget https://www.eicar.org/download/eicarcom2.zip
Avviare la scansione della directory.
maldet -a /tmp
Output:
Linux Malware Detect v1.6.2
(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(2004): {scan} signatures loaded: 15215 (12485 MD5 | 1951 HEX | 779 YARA | 0 USER)
maldet(2004): {scan} building file list for /tmp, this might take awhile...
maldet(2004): {scan} setting nice scheduler priorities for all operations: cpunice 19 , ionice 6
maldet(2004): {scan} file list completed in 0s, found 74 files...
maldet(2004): {scan} found clamav binary at /bin/clamscan, using clamav scanner engine...
maldet(2004): {scan} scan of /tmp (74 files) in progress...
maldet(2004): {scan} processing scan results for hits: 2 hits 0 cleaned
maldet(2004): {scan} scan completed on /tmp: files 74, malware hits 2, cleaned hits 0, time 11s
maldet(2004): {scan} scan report saved, to view run: maldet --report 170814-1058.2004
maldet(2004): {alert} sent scan report to itzgeek.web@gmail.com
Dall'output si nota che LMD utilizza il motore di scansione di ClamAV e ha individuato due minacce.
Consultare il report di scansione
LMD salva i report in /usr/local/maldetect/sess/. Per visualizzare il dettaglio di una scansione si usa il comando maldet con lo Scan ID.
maldet --report 170808-1035.18497
Output:
SUBJECT: maldet alert from server.itzgeek.local
HOST: lmddd
SCAN ID: 170814-1058.2004
STARTED: Aug 14 2017 10:58:20 +0000
COMPLETED: Aug 14 2017 10:58:31 +0000
ELAPSED: 11s [find: 0s]
PATH: /tmp
TOTAL FILES: 74
TOTAL HITS: 2
TOTAL CLEANED: 0
FILE HIT LIST:
{HEX}EICAR.TEST.10 : /tmp/eicar_com.zip => /usr/local/maldetect/quarantine/eicar_com.zip.491714154
{HEX}EICAR.TEST.10 : /tmp/eicarcom2.zip => /usr/local/maldetect/quarantine/eicarcom2.zip.506330946
===============================================
Linux Malware Detect v1.6.2 < proj@rfxn.com >
Come si può notare, entrambi i file sono stati spostati in quarantena.
Aggiornare Linux Malware Detect
Per aggiornare LMD:
maldet -d
Per aggiornare le firme di LMD:
maldet -u
Fatto.