为什么 maldet 不通过邮件发送报告?

为什么 maldet 不通过邮件发送报告?

Postfix 正在运行。我正在尝试通过邮件发送 maldet 报告,但它给了我一个错误,我不知道为什么?

[root@do ~]#  maldet --report 170321-0115.21534 [email protected]
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

/usr/local/maldetect/internals/functions: line 608: -s: command not found
maldet(18718): {report} report ID 170321-0115.21534 sent to [email protected]

这是第 608 行

if [ -f "$sessdir/session.$rid" ] && [ ! -z "$(echo $2 | grep '\@')" ]; th$
            cat $sessdir/session.$rid | $mail -s "$email_subj" "$2"
            eout "{report} report ID $rid sent to $2" 1
            exit

答案1

变量 $mail 为空,因为命令 mail 尚未安装。

运行apt-get install mailx(debian 或 ubuntu)或yum install -y mailx(centos 或 redhat)

答案2

由于缺少mail命令,某些设置会遇到以下错误: /usr/local/maldetect/internals/functions: line 647: -s: command not found

如果您已经sendmail安装,您可以使用下面的 diff 来添加sendmail对电子邮件发送的支持:

diff --git a/files/internals/functions b/files/internals/functions
index f3e0a1a..acdb1b9 100644
--- a/files/internals/functions
+++ b/files/internals/functions
@@ -108,6 +108,10 @@ prerun() {
    if [ ! -f "$mail" ] || [ -z "$mail" ]; then
        email_alert=0
    fi
+
+   if [ "$email_alert" == "0" ] && [ -f "$sendmail" ]; then
+        email_alert=1
+    fi

    if [ ! -f "$sig_cust_hex_file" ]; then
        touch $sig_cust_hex_file
@@ -644,8 +648,19 @@ view_report() {
        fi
    fi
    if [ -f "$sessdir/session.$rid" ] && [ ! -z "$(echo $2 | grep '\@')" ]; then
-       cat $sessdir/session.$rid | $mail -s "$email_subj" "$2"
-       eout "{report} report ID $rid sent to $2" 1
+       if [ -f "$mail" ]; then
+           cat $sessdir/session.$rid | $mail -s "$email_subj" "$2"
+       elif [ -f "$sendmail" ]; then
+           if ! grep -q "SUBJECT: " "$sessdir/session.$rid"; then
+               echo -e "SUBJECT: $email_subj\n$(cat $sessdir/session.$rid)" > $sessdir/session.$rid
+           fi
+           cat $sessdir/session.$rid | $sendmail -t "$2"
+       else
+           eout "{scan} no \$mail or \$sendmail binaries found, e-mail alerts disabled."
+           exit
+       fi
+
+        eout "{report} report ID $rid sent to $2" 1
        exit
    fi
    if [ "$rid" == "" ] && [ -f "$sessdir/session.last" ]; then
@@ -1073,8 +1088,8 @@ scan() {
        eout "{scan.hook} scan of $spath in progress (id: $datestamp.$$)"
    fi
    cnt=0
-   if [ -z "$mail" ]; then
-       eout "{scan} no \$mail binary found, e-mail alerts disabled."
+   if [ -z "$mail" ] && [ -z "$sendmail" ]; then
+       eout "{scan} no \$mail or \$sendmail binaries found, e-mail alerts disabled."
    fi
    if [ -f "$clamscan" ] && [ "$scan_clamscan" == "1" ]; then
        if [ -z "$hscan" ]; then
@@ -1309,7 +1324,16 @@ genalert() {
    file="$2"
         if [ "$email_alert" == "1" ] || [ "$type" == "digest" ] || [ "$type" == "daily" ]; then
        if [ "$type" == "file" ] && [ -f "$file" ]; then
-           cat $file | $mail -s "$email_subj" $email_addr
+           if [ -f "$mail" ]; then
+                cat $file | $mail -s "$email_subj" $email_addr
+            elif [ -f "$sendmail" ]; then
+                if ! grep -q "SUBJECT: " "$file"; then
+                    echo -e "SUBJECT: $email_subj\n$(cat $file)" > $file
+                fi
+                cat $file | $sendmail -t $email_addr
+            else
+                eout "{scan} no \$mail or \$sendmail binaries found, e-mail alerts disabled."
+            fi
            if [ ! "$(whoami)" == "root" ] && [ -z "$(echo $2 | grep '\@')" ]; then
                if [ -z "$hscan" ]; then
                    eout "{alert} sent scan report to config default $email_addr" 1
@@ -1353,8 +1377,18 @@ genalert() {
                grep -E '^{.*}' $sessdir/session.$scanid > $sessdir/session.hits.$scanid
                echo "$scanid" > $sessdir/session.last
                email_subj="${email_subj}: monitor summary"
-               cat $tmpf | $mail -s "$email_subj" $email_addr
-               eout "{alert} sent $type alert to $email_addr"
+               if [ -f "$mail" ]; then
+                    cat $tmpf | $mail -s "$email_subj" $email_addr
+                    eout "{alert} sent $type alert to $email_addr"
+                elif [ -f "$sendmail" ]; then
+                    if ! grep -q "SUBJECT: " "$tmpf"; then
+                        echo -e "SUBJECT: $email_subj\n$(cat $tmpf)" > $tmpf
+                    fi
+                    cat $tmpf | $sendmail -t $email_addr
+                    eout "{alert} sent $type alert to $email_addr"
+                else
+                    eout "{scan} no \$mail or \$sendmail binaries found, e-mail alerts disabled."
+                fi
                rm -f $tmpf $tmpdir/.digest.alert.hits $tmpdir/.digest.clean.hits $tmpdir/.digest.monitor.alert $tmpdir/.digest.susp.hits
            fi
        else
diff --git a/files/internals/internals.conf b/files/internals/internals.conf
index c998fd3..1291960 100644
--- a/files/internals/internals.conf
+++ b/files/internals/internals.conf
@@ -44,6 +44,7 @@ cpulimit=`which cpulimit 2> /dev/null`
 ionice=`which ionice 2> /dev/null`
 wc=`which wc 2> /dev/null`
 mail=`which mail 2> /dev/null`
+sendmail=`which sendmail 2> /dev/null`
 pidof=`which pidof 2> /dev/null`
 sed=`which sed 2> /dev/null`
 stat=`which stat 2> /dev/null`
-- 
1.8.3.2

实际的提交可以在下面的链接中找到:

https://github.com/richardferaro/linux-malware-detect/commit/3837d00ee44a7b2fe048ee5688424ff47025da13

以上基于Linux Malware Detect v1.6.1。

相关内容