RSPAMD - Rspamd custom regexp module

NethServer Version: NethServer 7.9.2009
Module: rspamd

I want to build a customized (own) spam rule. Basically we’re receiving spam form different domains, IP’s and senders, but all emails have the same unsubscribe from a mailing list. Please have a look at a sample:

— snip
Return-Path: hostmaster@flowweb.co.uk
Received: from myserver.de
by myserver.de with LMTP id eBleOPMACWOXJAAA2Ygdtg
; Fri, 26 Aug 2022 19:20:52 +0200
Received: from flowweb.co.uk (flowweb.co.uk [109.235.62.245])
by myserver.de (Postfix) with ESMTPS id 9EEA82956
for info@myserver.de; Fri, 26 Aug 2022 19:20:50 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;
d=flowweb.co.uk; s=email; h=Content-Type:MIME-Version:List-Unsubscribe:
Message-ID:Subject:Reply-to:From:To:Date:Sender:Cc:Content-Transfer-Encoding:
Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender:
Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id:
List-Help:List-Subscribe:List-Post:List-Owner:List-Archive;
bh=ZLi/JvyyO5cZCsSbkLiFh2t6W5AR84Q2+OCyf1BF15E=; b=ZkjjDAopTFOJJDy3p325Qqv2zS
VJJlUbtldTRG2Cm374cJZYG/HNyKXygJXG97mY5CQunXXTzE8IB9arVxgDUQzpQsSC8s06QwgRyRS
qB/ohtpZEz3qcMnVWfBJvFbm4b39+lYVnC5aBAwTNVAz86cHwTm3LXrIT3A/SeJqUmvo=;
Date: Fri, 26 Aug 2022 18:41:11 +0200
To: info@myserver.de
From: XXX YYY XXXYYY@flowweb.co.uk
Reply-to: XXX YYY XXXYYY@flowweb.co.uk
Subject: Maschinenbau - XXX YYY
Message-ID: 6dac1aacdb6fa260568d3b2e820833d6@flowweb.co.uk
X-Priority: 3
X-Mailer: PHPMailer
X-SNDR_determinant: PjA0LDI6LDAyMDBdMzo4NjM4MzM8PmRwbW84IlRrcWpjbml3b2NwRmd0Y2t7Y0Jkbm11dWdgLGFtLHdpPD52bTgia2xkbUJuZ2t2eC9xYWprbmZncCxmZzw=
List-Unsubscribe-Post: List-Unsubscribe=One-Click
List-Unsubscribe: <https://dev1.jobiniton.de/unsubscribe.php?hash=PjA0LDI6LDAyMDBdMzo4NjM4MzM8PmRwbW84IlRrcWpjbml3b2NwRmd0Y2t7Y0Jkbm11dWdgLGFtLHdpPD52bTgia2xkbUJuZ2t2eC9xYWprbmZncCxmZzw%3D
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary=“b1_6dac1aacdb6fa260568d3b2e820833d6”
X-Rspamd-Server: myserver.de
X-Spamd-Result: default: False [4.44 / 9.00];
BAYES_SPAM(4.95)[99.62%];
DMARC_POLICY_ALLOW(-0.50)[flowweb.co.uk,none];
FORGED_SENDER(0.30)[XXXYYY@flowweb.co.uk,hostmaster@flowweb.co.uk];
MIME_HTML_ONLY(0.20)[];
R_SPF_ALLOW(-0.20)[+ip4:109.235.62.245];
R_DKIM_ALLOW(-0.20)[flowweb.co.uk:s=email];
MIME_GOOD(-0.10)[multipart/mixed];
MX_GOOD(-0.01)[];
XM_UA_NO_VERSION(0.01)[];
HAS_LIST_UNSUB(-0.01)[];
IP_REPUTATION_HAM(-0.00)[asn: 25504(0.00), country: DE(-0.00), ip: 109.235.62.245(0.00)];
RCPT_COUNT_ONE(0.00)[1];
FROM_HAS_DN(0.00)[];
REPLYTO_EQ_FROM(0.00)[];
HAS_PHPMAILER_SIG(0.00)[];
TO_MATCH_ENVRCPT_ALL(0.00)[];
HAS_REPLYTO(0.00)[XXXYYY@flowweb.co.uk];
MIME_TRACE(0.00)[0:+,1:~,2:~];
FROM_NEQ_ENVFROM(0.00)[XXXYYY@flowweb.co.uk,hostmaster@flowweb.co.uk];
TO_DN_NONE(0.00)[];
HAS_ATTACHMENT(0.00)[];
MID_RHS_MATCH_FROM(0.00)[];
DKIM_TRACE(0.00)[flowweb.co.uk:+];
RCVD_COUNT_ZERO(0.00)[0];
HAS_X_PRIO_THREE(0.00)[3];
ASN(0.00)[asn:25504, ipnet:109.235.56.0/21, country:DE];
GREYLIST(0.00)[pass,body]
X-Rspamd-Queue-Id: 9EEA82956

–b1_6dac1aacdb6fa260568d3b2e820833d6
Content-Type: text/html; charset = “utf-8”
Content-Transfer-Encoding: 8bit

Sehr geehrte Damen und Herren,

engagiert, organisiert und zielorientiert - so gestalte ich meinen Arbeitsalltag. Mein Fokus liegt auf der kontinuierlichen Weiterentwicklung meiner Fähigkeiten und Kenntnisse, um das Unternehmen in eine erfolgreiche Zukunft zu führen. In Ihrem Unternehmen möchte ich mich neuen Herausforderungen  stellen, die meine Fähigkeiten und mein Wissen weiterentwickeln werden.

Flexibilität, Belastbarkeit und die Fähigkeit, selbstständig und unter Druck zu arbeiten, sind Eigenschaften, die ich während meines Studiums und meiner Tätigkeit als studentische Hilfskraft an der Universität Rostock erworben habe. Während meiner Zeit in Deutschland konnte ich meine kommunikativen, zwischenmenschlichen und teamorientierten Fähigkeiten auf ein professionelles Niveau heben. Darüber hinaus war ich als Service-Ingenieur damit beschäftigt, schwierige und komplexe technische Problemlösungsaufgaben zu betreuen und verschiedene Projektmitarbeiter zu führen und zu delegieren.

Ich bin davon überzeugt, dass ich für Ihr Unternehmen eine geeignete Person bin, die in der Lage sein wird, schwierige Hindernisse zu überwinden, kreative Lösungen vorzuschlagen und Vereinfachungen der menschlichen Arbeit zu ermöglichen.

Gern möchte ich Ihnen meine Motivation und meine Fähigkeiten persönlich präsentieren und freue mich auf Ihre Einladung zu einem Gespräch.

Mit freundlichen Grüßen

XXX YYY

 

PS: Falls Sie meine Bewerbung gestört hat, das können Sie mir über „Antwort“ mitteilen.

Ich stimme den Datenschutzbestimmungen und der Verarbeitung meiner Daten für den Bewerbungsprozess in Ihrem Unternehmen.

–b1_6dac1aacdb6fa260568d3b2e820833d6
Content-Type: application/octet-stream; name=“Maschinenbau - XXX YYY.pdf”
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=“Maschinenbau - XXX YYY.pdf”
— snip

The idea is to scan the header and catch the expression “jobinition”. If there’s a match I’d like to reject the mail, or score it with e.g. 20 points.

I read the the rspamd documentation and tried different config-files, but this is beyond my abilities. Any help with this is greatly appreciated.

regards,
stefan

Found a solution:

1.) Add to /etc/rspamd/local.d/multimap.conf i.e. something what matches the filter best:

CONTENT_BLACKLISTED {
type = “content”;
filter = “headers”; # can be full, body, oneline, text, rawtext
map = “${LOCAL_CONFDIR}/content.map”;
prefilter = “true”;
action = “reject”;
regexp = true;
}

2.) Create a map file in /etc/rspamd i.e. content.map with the regexp you want to match. In my case

'# content.map
'# Sole key
/jobinition/i

Restart rspamd, it should just work. Emails matching the regexp will be rejected.

Basically it’s explained here: Multimap module

Maybe it helps someone.

regards,
stefan

EDIT: this is not persistent. It should go in a custom template.

3 Likes

Thanks Stefan for posting the solution :smiley: have a nice day