[How-To] Linux Malware Detect on Directadmin Powered server

maldet 1.4.2 worked fine on FreeBSD 9.3

Then I moved to FreeBSD 11. Version 1.5 of maldet have some strange issue:

root@srv2:/ # maldet -a /home
sed: 1: "/usr/local/maldetect/ig ...": extra characters at the end of l command
Linux Malware Detect v1.5
(C) 2002-2016, R-fx Networks <[email protected]>
(C) 2016, Ryan MacDonald <[email protected]>
This program may be freely redistributed under the terms of the GNU GPL v2

maldet(35281): {scan} signatures loaded: 11294 (9343 MD5 / 1951 HEX / 0 USER)
maldet(35281): {scan} building file list for "/home", this might take awhile...
maldet(35281): {scan} setting nice scheduler priorities for all operations: cpunice 19 , ionice 6
maldet(35281): {scan} scan returned empty file list; check that path exists and contains files in scope of configuration.

The 1.6 version from github has one error less, but still no-go:

root@srv2:/ # maldet -a /home
Linux Malware Detect v1.6
(C) 2002-2017, R-fx Networks <[email protected]>
(C) 2017, Ryan MacDonald <[email protected]>
This program may be freely redistributed under the terms of the GNU GPL v2

maldet(36829): {scan} signatures loaded: 12077 (9343 MD5 | 1951 HEX | 783 YARA | 0 USER)
maldet(36829): {scan} building file list for /home, this might take awhile...
maldet(36829): {scan} setting nice scheduler priorities for all operations: cpunice 19 , ionice 6
maldet(36829): {scan} scan returned empty file list; check that path exists and contains files in scope of configuration.

My pending ticket: https://github.com/rfxn/linux-malware-detect/issues/202
 
Last edited:
Description

Linux Malware Detect (LMD) is a malware scanner for Linux released under the GNU GPLv2 license, that is designed around the threats faced in shared hosted environments. It uses threat data from network edge intrusion detection systems to extract malware that is actively being used in attacks and generates signatures for detection. In addition, threat data is also derived from user submissions with the LMD checkout feature and from malware community resources. The signatures that LMD uses are MD5 file hashes and HEX pattern matches, they are also easily exported to any number of detection tools such as ClamAV.

Installation
Code:
# cd /usr/local/src
# wget http://www.rfxn.com/downloads/maldetect-current.tar.gz
# tar -zxvf maldetect-current.tar.gz
# cd maldetect-1.4.1
# ./install.sh

As soon as installation finishes you'll see something similar to:
Code:
Linux Malware Detect v1.4.1
            (C) 2002-2011, R-fx Networks <[email protected]>
            (C) 2011, Ryan MacDonald <[email protected]>
inotifywait (C) 2007, Rohan McGovern <[email protected]>
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(19402): {sigup} performing signature update check...
maldet(19402): {sigup} local signature set is version 2012011929852
maldet(19402): {sigup} latest signature set already installed

Running as cron job

Note, /etc/cron.daily/maldet should be changed for compatibility with Directadmin's structure of homedirs:

Code:
#!/bin/bash

# clear quarantine/session/tmp data every 14 days
/usr/sbin/tmpwatch 336 /usr/local/maldetect/tmp >> /dev/null 2>&1
/usr/sbin/tmpwatch 336 /usr/local/maldetect/sess >> /dev/null 2>&1
/usr/sbin/tmpwatch 336 /usr/local/maldetect/quarantine >> /dev/null 2>&1
/usr/sbin/tmpwatch 336 /usr/local/maldetect/pub/*/ >> /dev/null 2>&1

# check for new release version
/usr/local/maldetect/maldet -d >> /dev/null 2>&1

# check for new definition set
/usr/local/maldetect/maldet -u >> /dev/null 2>&1

# if were running inotify monitoring, send daily hit summary
if [ "$(ps -A --user root -o "comm" | grep inotifywait)" ]; then
        /usr/local/maldetect/maldet --alert-daily >> /dev/null 2>&1
else
        # scan the last 2 days of file changes
        if [ -d "/home/virtual" ] && [ -d "/usr/lib/opcenter" ]; then
                # ensim
                /usr/local/maldetect/maldet -b -r /home/virtual/?/fst/var/www/html 2 >> /dev/null 2>&1
                /usr/local/maldetect/maldet -b -r /home/virtual/?/fst/home/?/public_html 2 >> /dev/null 2>&1
        elif [ -d "/etc/psa" ] && [ -d "/var/lib/psa" ]; then
                # psa
                /usr/local/maldetect/maldet -b -r /var/www/vhosts/?/httpdocs 2 >> /dev/null 2>&1
                /usr/local/maldetect/maldet -b -r /var/www/vhosts/?/subdomains/?/httpdocs 2 >> /dev/null 2>&1
        elif [ -d "/usr/local/directadmin" ]; then
                # directadmin
                /usr/local/maldetect/maldet -b -r /home?/?/domains/?/public_html 2 >> /dev/null 2>&1
        else
                # cpanel, interworx and other standard home/user/public_html setups
                /usr/local/maldetect/maldet -b -r /home?/?/public_html 2 >> /dev/null 2>&1
        fi

        # scan default apache docroot paths
        if [ -d "/var/www/html" ]; then
                /usr/local/maldetect/maldet -b -r /var/www/html 2 >> /dev/null 2>&1
        fi
        if [ -d "/usr/local/apache/htdocs" ]; then
                /usr/local/maldetect/maldet -b -r /usr/local/apache/htdocs 2 >> /dev/null 2>&1
        fi
fi

Note, in the file we should find the section:

Code:
# scan default apache docroot paths
        if [ -d "/var/www/html" ]; then
                /usr/local/maldetect/maldet -b -r /var/www/html 2
        fi
        if [ -d "/usr/local/apache/htdocs" ]; then
                /usr/local/maldetect/maldet -b -r /usr/local/apache/htdocs 2
        fi

and change it to (so we add >> /dev/null 2>&1 at the end of two lines)

Code:
# scan default apache docroot paths
        if [ -d "/var/www/html" ]; then
                /usr/local/maldetect/maldet -b -r /var/www/html 2 >> /dev/null 2>&1
        fi
        if [ -d "/usr/local/apache/htdocs" ]; then
                /usr/local/maldetect/maldet -b -r /usr/local/apache/htdocs 2 >> /dev/null 2>&1
         fi

Manual scanning

To scan all files in /home/ you should run it as following
Code:
# maldet -a /home?/?/domains/?/public_html

or

Code:
# maldet -b -a /home?/?/domains/?/public_html

in a background.

Please, consider that some PHP shells might still stay invisible for maldet.

The maldet website

http://www.rfxn.com/projects/linux-malware-detect/

Firstly, thank you. I have installed the latest version of Linux Malware Detect v1.6.2.
I did the Cron settings as you specified. I did a scan for a user.

Example maldet -a / home / xxuserxx

The result was two malicious files. Mail address I received mail information.

But I did not get into the quarantine even though the option was active so I wanted to get it in the conf file.

SCAN ID: 171205-2331.31423
STARTED: Dec 5 2017 23:31:53 +0300
COMPLETED: Dec 5 2017 23:32:45 +0300
ELAPSED: 52s [find: 1s]
PATH: /home/elit
TOTAL FILES: 10609
TOTAL HITS: 3
TOTAL CLEANED: 0
FILE HIT LIST:

{HEX}perl.generic.fakeproc.52 : /home/elit/domains/simpledomain.com/public_html/images/error/error.log
{HEX}php.cmdshell.SimShell.362 : /home/elit/domains/simpledomain.com/public_html/images/command.php
{HEX}perl.connback.DataCha0s.42 : /home/elit/domains/simpledomain.com/public_html/images/cgishell/dc.pl


MALDET CONF FILES :
=============================================== Linux Malware Detect v1.6.2 <

##
# [ QUARANTINE OPTIONS ]
##
# The default quarantine action for malware hits
# [0 = alert only, 1 = move to quarantine & alert]
quarantine_hits="1"

# Try to clean string based malware injections
# [NOTE: quarantine_hits=1 required]
# [0 = disabled, 1 = clean]
quarantine_clean="1"

# The default suspend action for users wih hits
# Cpanel suspend or set shell /bin/false on non-Cpanel
# [NOTE: quarantine_hits=1 required]
# [0 = disabled, 1 = suspend account]
quarantine_suspend_user="1"

# The minimum userid value that can be suspended
# [ default = 500 ]
quarantine_suspend_user_minuid="500"

##
 
If you changed your settings after started scan then it's expected. You need to update settings before starting a new scan.
 
If you changed your settings after started scan then it's expected. You need to update settings before starting a new scan.

Thnks zEitEr
Sequence operation. Start setup, setup and scan.
But he gave the same result again. How do I stop and restart all of them, including fully hidden scans on the backplane?

Regards
 
You should update config under /usr/local/maldetect/, i.e. /usr/local/maldetect/conf.maldet, not under /usr/local/src/
 
You should update config under /usr/local/maldetect/, i.e. /usr/local/maldetect/conf.maldet, not under /usr/local/src/


After the installation, I first updated the file in the following path.

[root@serverlord ~]# nano /usr/local/maldetect/conf.maldet


##
# [ QUARANTINE OPTIONS ]
##
# The default quarantine action for malware hits
# [0 = alert only, 1 = move to quarantine & alert]
quarantine_hits="1"

# Try to clean string based malware injections
# [NOTE: quarantine_hits=1 required]
# [0 = disabled, 1 = clean]
quarantine_clean="1"

# The default suspend action for users wih hits
# Cpanel suspend or set shell /bin/false on non-Cpanel
# [NOTE: quarantine_hits=1 required]
# [0 = disabled, 1 = suspend account]
quarantine_suspend_user="1"

# The minimum userid value that can be suspended
# [ default = 500 ]
quarantine_suspend_user_minuid="500"
 
Update:

Code:
[COLOR=#333333]quarantine_suspend_user="1"

should be 0, as it does not work with Directadmin.
[/COLOR]

and try again.
 
Update:

Code:
[COLOR=#333333]quarantine_suspend_user="1"

should be 0, as it does not work with Directadmin.
[/COLOR]

and try again.



same again zEitEr :(

PATH: /home/elit
TOTAL FILES: 13332
TOTAL HITS: 3
TOTAL CLEANED: 0

we can do this at the command line. Can we restart Yada maldet?

The example command I am using is: [root@serverlord ~]# maldet -a /home/xxuser
 
Last edited:
Run this:

Code:
maldet --config-option quarantine_hits=1 -b -a [COLOR=#333333]/home/xxuser
[/COLOR]
 
I've updated the initial post of the thread with actualized setup steps + Malware.Experts virus definitions connected
 
Description

Linux Malware Detect (LMD) is a malware scanner for Linux released under the GNU GPLv2 license, that is designed around the threats faced in shared hosted environments. It uses threat data from network edge intrusion detection systems to extract malware that is actively being used in attacks and generates signatures for detection. In addition, threat data is also derived from user submissions with the LMD checkout feature and from malware community resources. The signatures that LMD uses are MD5 file hashes and HEX pattern matches, they are also easily exported to any number of detection tools such as ClamAV.

Installation (run as root)

Code:
cd /usr/local/src
wget http://www.rfxn.com/downloads/maldetect-current.tar.gz
tar -zxvf maldetect-current.tar.gz
cd $(ls -1d maldetect-*/ | tail -1)
./install.sh

As soon as installation finishes you'll see something similar to:
Code:
Linux Malware Detect v1.4.1
            (C) 2002-2011, R-fx Networks <[email protected]>
            (C) 2011, Ryan MacDonald <[email protected]>
inotifywait (C) 2007, Rohan McGovern <[email protected]>
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(19402): {sigup} performing signature update check...
maldet(19402): {sigup} local signature set is version 2012011929852
maldet(19402): {sigup} latest signature set already installed

Running as cron job

The file /etc/cron.daily/maldet does not need any modification for DirectAdmin compatibles any longer. The support DirectAdmin from a box already.

Manual scanning

To scan all files in /home/ you should run it as following
Code:
# maldet -a /home?/?/domains/?/public_html

or

Code:
# maldet -b -a /home?/?/domains/?/public_html

in a background.

Please, consider that some PHP shells might still stay invisible for maldet.

The maldet website

http://www.rfxn.com/projects/linux-malware-detect/

Update (2019-06-26):

- Connect Virus Definitions from Malware.Experts (if you don't have ClamAV installed):

Code:
perl -pi -e 's#^import_custsigs_md5_url=.*#import_custsigs_md5_url="http://cdn.malware.expert/malware.expert.hdb"#' /usr/local/maldetect/conf.maldet
perl -pi -e 's#^import_custsigs_hex_url=.*#import_custsigs_hex_url="http://cdn.malware.expert/malware.expert.ndb"#' /usr/local/maldetect/conf.maldet


maldet -u

ls -la /usr/local/maldetect/sigs/custom.*.dat


- Connect Virus Definitions from Malware.Experts (with ClamAV installed):

Code:
echo "DatabaseCustomURL http://cdn.malware.expert/malware.expert.ndb" >> /etc/freshclam.conf
echo "DatabaseCustomURL http://cdn.malware.expert/malware.expert.hdb" >> /etc/freshclam.conf
echo "DatabaseCustomURL http://cdn.malware.expert/malware.expert.ldb" >> /etc/freshclam.conf
echo "DatabaseCustomURL http://cdn.malware.expert/malware.expert.fp" >> /etc/freshclam.conf


service freshclam restart


ls -la /usr/local/share/clamav/malware.expert.* /var/lib/clamav/malware.expert.*


[root@server maldetect-1.6.4]# ls -la /usr/local/share/clamav/malware.expert.* /var/lib/clamav/malware.expert.*
ls: cannot access /var/lib/clamav/malware.expert.*: No such file or directory
-rw-r--r-- 1 clamav clamav 2963 Dec 18 23:38 /usr/local/share/clamav/malware.expert.fp
-rw-r--r-- 1 clamav clamav 29852 Dec 18 23:38 /usr/local/share/clamav/malware.expert.hdb
-rw-r--r-- 1 clamav clamav 20550 Dec 18 23:38 /usr/local/share/clamav/malware.expert.ldb
-rw-r--r-- 1 clamav clamav 137254 Dec 18 23:38 /usr/local/share/clamav/malware.expert.ndb
 
So what is te problem? If you installed clamav via Custombuild it's present in /usr/local/share/clamav and there are also the files you mentioned:
-rw-r--r-- 1 clamav clamav 2963 Dec 18 23:38 /usr/local/share/clamav/malware.expert.fp
-rw-r--r-- 1 clamav clamav 29852 Dec 18 23:38 /usr/local/share/clamav/malware.expert.hdb
-rw-r--r-- 1 clamav clamav 20550 Dec 18 23:38 /usr/local/share/clamav/malware.expert.ldb
-rw-r--r-- 1 clamav clamav 137254 Dec 18 23:38 /usr/local/share/clamav/malware.expert.ndb

I don't have a /var/lib/clamav directory either on Centos 7.

So what is your problem/question?
 
I'm not sure if maldetect scanner is faster than clamav. Maybe because one features that the scanner has is scan_ignore_root="1". Meaning that all files that owned by root are skipped during the scan. If you have a virus file that has permission as root, then maldet won't detect it unless scan_ignore_root="0".
 
Maldetect and Clamav are different things but they can work together. If Clamav is installed then Maldetect will also use Clamav routines.
Best is to use both, so Maldetect with clamav workign combined imho.
 
Trying to get this running in monitor mode (inotifywait), however, it states the paths are invalid
/usr/local/maldetect/monitor_paths has
/home/?/domains/?/public_html/,/var/www/html/?
but.......
{mon} ignored invalid path /home/?/domains/?/public_html/
{mon} ignored invalid path /var/www/html/?

I know there's a user option, but that would just monitor the default (symlinked) domain eg. /home/{user}/public_html

So, you can't monitor ALL public_html's by providing a wildcard? But you can use wildcards when in scanning mode?

I've just put /home in but you would need to add /home/mysql in the /usr/local/maldetect/ignore_paths - you dont want it to scan DB files!
 
Back
Top