You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by Chris Mulcahy <ch...@gmail.com> on 2019/12/04 20:40:27 UTC

Custom rule help

Hi.

I’m relatively new to complex custom rules.  I have plenty of simple and
some multi-condition rules but need something custom.

My approach to using my domain name is bad but I started it in the 90s so…
 I have some sites where I gave them my email address as “
sitename.com@mydomain.com” so I would know who sold my address. Obviously,
now there are a bunch of leaked lists so I get spam to those addresses even
though it wasn’t really sold.

I want a rule that scores if “sitename” is not in the From: line.  If they
send from info@sitename.com, I’ll assume it’s legit. If sitename does not
exist, I’ll tick up the score a bit. I have done this for some specific
domains but they are all individual rules hardcoding the domain name. I
want it to search "To =~ /(.*)\.com\@mydomain\.com/i" and find the match in
the From: line.

Any advice?
Thanks

Re: Custom rule help

Posted by Chris Mulcahy <ch...@gmail.com>.
On Wed, 4 Dec 2019 12:40:27 -0800
Chris Mulcahy wrote:

> Hi.
>
> I’m relatively new to complex custom rules. I have plenty of simple
> and some multi-condition rules but need something custom.
>
> My approach to using my domain name is bad but I started it in the
> 90s so… I have some sites where I gave them my email address as “
> sitename.com@mydomain.com” so I would know who sold my address.
> Obviously, now there are a bunch of leaked lists so I get spam to
> those addresses even though it wasn’t really sold.
>
> I want a rule that scores if “sitename” is not in the From: line.

I think this should work:

header ABUSED_CONTACT_ADDRESS ALL =~
/\A(?=.*^To:\s(?:[^\n]*[<.\s])?([a-z0-9-]+)\.(?:com|net|org)\@yourdomain\.com).*^From:\s(?![^\n]+\1)/ism


Adapt the list of TLDs as necessary, and substitute your own domain for
yourdomain\.com.


That is absolutely perfect.  After extensive testing, I can confirm that it
does exactly what I wanted.

Thank you very much!

Re: Custom rule help

Posted by RW <rw...@googlemail.com>.
On Wed, 4 Dec 2019 12:40:27 -0800
Chris Mulcahy wrote:

> Hi.
> 
> I’m relatively new to complex custom rules.  I have plenty of simple
> and some multi-condition rules but need something custom.
> 
> My approach to using my domain name is bad but I started it in the
> 90s so… I have some sites where I gave them my email address as “
> sitename.com@mydomain.com” so I would know who sold my address.
> Obviously, now there are a bunch of leaked lists so I get spam to
> those addresses even though it wasn’t really sold.
> 
> I want a rule that scores if “sitename” is not in the From: line.  

I think this should work:

header  ABUSED_CONTACT_ADDRESS ALL =~  /\A(?=.*^To:\s(?:[^\n]*[<.\s])?([a-z0-9-]+)\.(?:com|net|org)\@yourdomain\.com).*^From:\s(?![^\n]+\1)/ism

Adapt the list of TLDs as necessary, and substitute your own domain for
yourdomain\.com.




Re: Custom rule help

Posted by Martin Gregorie <ma...@gregorie.org>.
On Wed, 2019-12-04 at 14:22 -0800, Chris Mulcahy wrote:
> Actually, I want it to score if there ISN’T a match. If I get an email
> addressed to slashdot.org@example.com from an address that isn’t from
> slashdot, it’s likely spam.
> 
> Currently, I am doing like you mentioned with a bunch of individual
> rules
> that look like this:
> header   __CRM_FAMAZON   From =~ /amazon/i
> header   __CRM_TAMAZON   To =~ /amazon/i
> meta     CRM_AMAZON      (!__CRM_FAMAZON && __CRM_TAMAZON)
> describe CRM_AMAZON      amazon in to address but not from
> score    CRM_AMAZON      1.5
> 
> But I have to edit the rules every time I find a new one that comes
> in. I failed to keep the list because at the time I never anticipated
> spam would be as prevalent as it is.
> 
> I did grab your solution and will look through it. It may make this a
> less painful process.
> 
Merely using an list of alternative regexes in the rule should make life
easier than writing a whole set of subrules - and will almost certainly
run faster. Just reversing the comparison should do it If there isn't a
negated version of =~ (and I can't remember if there is one), use a
subrule:

header __ALT_TEST From:addr ~= /(alt1|alt2|....)/
meta   SPAMBLOCK  ( !__ALT_TEST )
score  SPAMBLOCK  -0.5

This should give the non-matches a small nudge towards hamminess.

Martin
 



> Thanks,
> Chris


Re: Custom rule help

Posted by Chris Mulcahy <ch...@gmail.com>.
From: Martin Gregorie <ma...@gregorie.org> <ma...@gregorie.org>
Reply: martin@gregorie.org <ma...@gregorie.org> <ma...@gregorie.org>
Date: December 4, 2019 at 4:12:22 PM
To: users@spamassassin.apache.org <us...@spamassassin.apache.org>
<us...@spamassassin.apache.org>
Subject:  Re: Custom rule help

On Wed, 2019-12-04 at 12:40 -0800, Chris Mulcahy wrote:
> I want a rule that scores if “sitename” is not in the From: line. If
> they send from info@sitename.com, I’ll assume it’s legit. If sitename
> does not exist, I’ll tick up the score a bit. I have done this for
> some specific domains but they are all individual rules hardcoding the
> domain name.
>
Presumably, you mean that if it matches, add a positive value to push it
toward spam. If no match, ignore.

One way would be to build a giant list of alternates along the lines of

header MYRULE M:addr =~ /(site1\.com\@mydomain\.com|
site2.com@mydomain.com|....)/
...
I did something similar some years back, but I first designed a
definition file that was easy to edit: it has fixed details such as the
descriptive comments, the rule name and score on a set of lines at the
front of the file. This is followed by the list of alternates, each on a
separate line. It helps maintenance and the addition of new terms if you
keep the alternates in alphabetic sequence too.

Then I wrote a script that reads the definition and spits out a .cf file
containing a correctly formatted SA rule. This is a bash script that
runs a gawk script to do the heavy lifting. I used gawk because i know
and like it, but any scriptable language should do: Perl, Python or even
Javascript or BASIC are all possibilities.

You can download my solution from here:
libelle-systems.com/free/portmanteau/portmanteau.tgz

...

Martin


Thanks for the quick reply!

Actually, I want it to score if there ISN’T a match. If I get an email
addressed to slashdot.org@example.com from an address that isn’t from
slashdot, it’s likely spam.

Currently, I am doing like you mentioned with a bunch of individual rules
that look like this:
header   __CRM_FAMAZON   From =~ /amazon/i
header   __CRM_TAMAZON   To =~ /amazon/i
meta     CRM_AMAZON      (!__CRM_FAMAZON && __CRM_TAMAZON)
describe CRM_AMAZON      amazon in to address but not from
score    CRM_AMAZON      1.5

But I have to edit the rules every time I find a new one that comes in. I
failed to keep the list because at the time I never anticipated spam would
be as prevalent as it is.

I did grab your solution and will look through it. It may make this a less
painful process.

Thanks,
Chris

Re: Custom rule help

Posted by Martin Gregorie <ma...@gregorie.org>.
On Wed, 2019-12-04 at 12:40 -0800, Chris Mulcahy wrote:
> I want a rule that scores if “sitename” is not in the From: line.  If
> they send from info@sitename.com, I’ll assume it’s legit. If sitename
> does not exist, I’ll tick up the score a bit. I have done this for
> some specific domains but they are all individual rules hardcoding the
> domain name. 
>
Presumably, you mean that if it matches, add a positive value to push it
toward spam. If no match, ignore.

One way would be to build a giant list of alternates along the lines of 

header MYRULE M:addr =~ /(site1\.com\@mydomain\.com|
site2.com@mydomain.com|....)/

but note that this needs to be all on a single line.

You can build that with a test editor, adding alternates as you find
them - unless you kept a list, jut its a real pain editing an alternates
list thats more than 100 characters or so.

I did something similar some years back, but I first designed a
definition file that was easy to edit: it has fixed details such as the
descriptive comments, the rule name and score on a set of lines at the
front of the file. This is followed by the list of alternates, each on a
separate line. It helps maintenance and the addition of new terms if you
keep the alternates in alphabetic sequence too.

Then I wrote a script that reads the definition and spits out a .cf file
containing a correctly formatted SA rule. This is a bash script that
runs a gawk script to do the heavy lifting. I used gawk because i know
and like it, but any scriptable language should do: Perl, Python or even
Javascript or BASIC are all possibilities.

You can download my solution from here:
 libelle-systems.com/free/portmanteau/portmanteau.tgz

and modify to suit your own purposes ...but be patient - the site is
rather slow at present. If you can't get through, yell and I'll send you
the archive.

Alternatively, if you know Perl and SQL, you may want to write yourself
an SA plugin to access a database containing your personal blacklist.

Or, there are blacklist handlers around that would serve the same
purpose as thje database + plugin. I haven't used any of them, so can't
give names or recommendations.

Martin