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

wattie

Verified User
Joined
May 31, 2008
Messages
1,004
Location
Bulgaria
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 <proj@rfxn.com>
(C) 2016, Ryan MacDonald <ryan@rfxn.com>
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 <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(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:

th£ lord

Verified User
Joined
Jan 6, 2007
Messages
16
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 <proj@r-fx.org>
            (C) 2011, Ryan MacDonald <ryan@r-fx.org>
inotifywait (C) 2007, Rohan McGovern <rohan@mcgovern.id.au>
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"

##
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
13,902
Location
GMT +7.00
If you changed your settings after started scan then it's expected. You need to update settings before starting a new scan.
 

th£ lord

Verified User
Joined
Jan 6, 2007
Messages
16
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
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
13,902
Location
GMT +7.00
You should update config under /usr/local/maldetect/, i.e. /usr/local/maldetect/conf.maldet, not under /usr/local/src/
 

th£ lord

Verified User
Joined
Jan 6, 2007
Messages
16
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"
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
13,902
Location
GMT +7.00
Update:

Code:
[COLOR=#333333]quarantine_suspend_user="1"
should be 0, as it does not work with Directadmin.
[/COLOR]

and try again.
 

th£ lord

Verified User
Joined
Jan 6, 2007
Messages
16
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:

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
13,902
Location
GMT +7.00
Run this:

Code:
maldet --config-option quarantine_hits=1 -b -a [COLOR=#333333]/home/xxuser
[/COLOR]
 

th£ lord

Verified User
Joined
Jan 6, 2007
Messages
16

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
13,902
Location
GMT +7.00
I've updated the initial post of the thread with actualized setup steps + Malware.Experts virus definitions connected
 
Top