You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by "marcin@mejor.pl" <ma...@mejor.pl> on 2017/03/13 13:38:02 UTC

mk_meta_rule_scores - does it work correctly?:)

Hi!
Thanks to AXB seek-in-phrases-in-log works OK. Now I'm on the next step with automated creating rules.
I suspect that mk_meta_rule_scores doesn't assign scores correctly. I set in mk_meta_rule_scores:
my %scoremap = (
  '70' => '1.5',
  '4' => '2.0',
  '0.01' => '3.0',
);

$ cat tmp/clean.cf
# passed hit-rate threshold: 70
body __RULE_AUTORULE_3NILJ5  /Je\u017celi zainteresowa\u0142a Ci\u0119 ta oferta, to odwied\u017a nasz\u0105 stron\u0119/
body __RULE_AUTORULE_TQJGPO  /N�zzen k�r�l OTTHON-TAKAR�T�S aj�nlataink k�z�tt\!/
# passed hit-rate threshold: 4
body __RULE_AUTORULE_UG4HMS  /100 W-os LED REFLEKTOR, MOZG�S�RZ�KEL\u0150S F�NYVET\u0150/
body __RULE_AUTORULE_GYUXEK  /MR\. WINDOW ABLAKTISZT�T� K�SZLET/

$ ./mk_meta_rule_scores rule tmp/clean.cf
# Creation: 2017-03-13 14:37:19

# Note: rule names are based on a hash of the content pattern.

# passed hit-rate threshold: 70
#current th: 70 outscore=1.5
meta rule1   (0)
score rule1  0
describe rule1  Body contains frequently-spammed text patterns

body __RULE_AUTORULE_3NILJ5  /Je\x{c5}\x{bc}eli zainteresowa\x{c5}\x{82}a Ci\x{c4}\x{99} ta oferta, to odwied\x{c5}\x{ba} nasz\x{c4}\x{85} stron\x{c4}\x{99}/
body __RULE_AUTORULE_TQJGPO  /N\x{c3}\x{a9}zzen k\x{c3}\x{b6}r\x{c3}\x{bc}l OTTHON-TAKAR\x{c3}\x{8d}T\x{c3}\x{81}S aj\x{c3}\x{a1}nlataink k\x{c3}\x{b6}z\x{c3}\x{b6}tt\!/
# passed hit-rate threshold: 4
#current th: 4 outscore=2.0
meta rule2   (__RULE_AUTORULE_3NILJ5 || __RULE_AUTORULE_TQJGPO)
score rule2  2.0
describe rule2  Body contains frequently-spammed text patterns

body __RULE_AUTORULE_UG4HMS  /100 W-os LED REFLEKTOR, MOZG\x{c3}\x{81}S\x{c3}\x{89}RZ\x{c3}\x{89}KEL\x{c5}\x{90}S F\x{c3}\x{89}NYVET\x{c5}\x{90}/
body __RULE_AUTORULE_GYUXEK  /MR\. WINDOW ABLAKTISZT\x{c3}\x{8d}T\x{c3}\x{93} K\x{c3}\x{89}SZLET/

#current th:  outscore=2.8
meta rule3   (__RULE_AUTORULE_UG4HMS || __RULE_AUTORULE_GYUXEK)
score rule3  2.8
describe rule3  Body contains frequently-spammed text patterns


Why "score rule1" is set to zero?
Marcin

Re: mk_meta_rule_scores - does it work correctly?:)

Posted by Kris Deugau <kd...@vianet.ca>.
Marcin Mirosaw wrote:
> W dniu 2017-03-14 16:23, Kris Deugau napisa(a):
>> If I read the information flow correctly, this is actually decided by
>> seek-phrases-in-log, which spits out subrules that reached a certain
>> hit rate in blocks, followed by the "# passed hit-rate threshold nnn"
>> line. mk_meta_rule_scores just takes that in, collects the rule names
>> in each block, and spits out the meta.
>
>
> I made some tests and watch how output looks to understand how some
> paremeters works. Meseems that "--reqhitrate" works in this way:
> a) if --reqhitrate contains only one value then output od
> seek-phrases-in-log contains only rules that hits more than value passed
> to --reqhitrate. So this cuts off rules that are hitted rarely
>
> b) if --reqhitrate contains more than one value then:
> <high cut off level equal to higher value passed to --reqhitrate> rules
> <second value> other rules <low cut off>
> example:
> --reqhitrate "70 10 1" gives:
> <100%> - no rules here - <70%> - rules that matches less than 70% of
> spam - <10%> rules that matches less than 10% of spam and more than 1% -
> <1%> - cut off, no rules here

You got me curious about exactly what this means, and we're both right, 
just describing it differently.

For this usage, seek-phrases-in-log does roughly the following (for 
multiple values to --reqhitrate):

for each pattern
   determine the percentage of spam it hits
   discard the pattern if it's less than the lowest threshold
sort patterns by hit percentage, highest first
for each pattern
   if the hit rate has passed the next threshold
     print flag line "# passed hit-rate threshold <threshold>"
     advance to next threshold
   print a line "# 1.0 <percentage> 0"
   print the subrule

So if you call it with --reqhitrate "50 0.1 5 20 1" on the right set of 
spam, you might get an intermediate file containing:

body __FOO1 /foo1/
# passed hit-rate threshold: 50
body __FOO2 /foo2/
body __FOO3 /foo3/
# passed hit-rate threshold: 20
body __FOO4 /foo4/
body __FOO5 /foo5/
body __FOO6 /foo6/
# passed hit-rate threshold: 5
body __FOO7 /foo7/
# passed hit-rate threshold: 1
body __FOO8 /foo8/

(Plus the additional "# 1.0 <percentage> 0" comment lines that are just 
noise at this point.)

mk_meta_rule just takes those groups of rules, separated by the "# 
passed hit-rate..." lines, and builds FOO_1, FOO_2, F00_3 etc meta rules 
- 5 of them in this case.  mk_meta_rules itself is a pretty simpleminded 
script;  most of the heavy lifting is done in seek-phrases-in-log.

However, if the message data you feed in doesn't separate out to produce 
at least one rule in each range, between seek-phrases-in-log and 
mk_meta_rule it will happily create an empty meta rule:

# passed hit-rate threshold: 50
body __FOO1 /foo1/
body __FOO2 /foo2/
body __FOO3 /foo3/
# passed hit-rate threshold: 20
body __FOO4 /foo4/
body __FOO5 /foo5/
body __FOO6 /foo6/
# passed hit-rate threshold: 5
# passed hit-rate threshold: 1
body __FOO7 /foo7/
body __FOO8 /foo8/

With the above output from seek-phrases-in-log, mk_meta_rule will create 
"meta FOO_1 ()" and "meta FOO_4 ()", since there are no patterns in the 
first or fourth groups (100% to 50% and 5% to 1%, by your description). 
It also scores these empty metas at 0 for tidiness - after all, they'll 
never fire.

In your case, to look at your original question, none of the derived 
patterns matched more than 70% of the the spam set you fed in, so the _1 
rule was empty.

> Have you tried to use mk_meta_rule_scores and did I get more values of
> scores than two? The default and the value in medium range. I suspect
> that mk_meta_rule_scores doesn't play well with ranges. It is something
> that I can live with it but if somewhere is bug I would try report it.
> If it will not be fixed it can save some time of other users trying to
> use this scipt.

Try a set of numbers closer together (eg, "10 7 4 1"), and I'd suggest 
not using high percentages as it's very unlikely you'll see results in 
the highest group even with a narrowly targeted set of spam, or if you 
only have a very small number of nearly identical spams.

-kgd

Re: mk_meta_rule_scores - does it work correctly?:)

Posted by Marcin Mirosław <ma...@mejor.pl>.
W dniu 2017-03-14 16:23, Kris Deugau napisa(a):
> marcin@mejor.pl wrote:
>> Hi!
>> Thanks to AXB seek-in-phrases-in-log works OK. Now I'm on the next
>> step with automated creating rules.
>> I suspect that mk_meta_rule_scores doesn't assign scores correctly. I
>> set in mk_meta_rule_scores:
>> my %scoremap = (
>>   '70' => '1.5',
>>   '4' => '2.0',
>>   '0.01' => '3.0',
>> );
>
> If I understand correctly (quite possible I don't;  I haven't dug in
> to the internals of this stage), the %scoremap hash above indicates
> the percentage of the messages that need to hit on a subrule for that
> subrule to be included in one of the meta rules.
>
> So, 70% of the mail in the set would need to hit on a subrule for it
> to be included in the first group, 4% in the second, and 0.01% in the
> third.
>
> If I read the information flow correctly, this is actually decided by
> seek-phrases-in-log, which spits out subrules that reached a certain
> hit rate in blocks, followed by the "# passed hit-rate threshold nnn"
> line. mk_meta_rule_scores just takes that in, collects the rule names
> in each block, and spits out the meta.


I made some tests and watch how output looks to understand how some 
paremeters works. Meseems that "--reqhitrate" works in this way:
a) if --reqhitrate contains only one value then output od 
seek-phrases-in-log contains only rules that hits more than value passed 
to --reqhitrate. So this cuts off rules that are hitted rarely

b) if --reqhitrate contains more than one value then:
<high cut off level equal to higher value passed to --reqhitrate> rules 
<second value> other rules <low cut off>
example:
--reqhitrate "70 10 1" gives:
<100%> - no rules here - <70%> - rules that matches less than 70% of 
spam - <10%> rules that matches less than 10% of spam and more than 1% - 
<1%> - cut off, no rules here

> (In fact the stock setup refers to mk_meta_rule, although it's nearly
> identical to mk_meta_rule_scores.)
>
> By raising the hit percentage to 70%, you're requiring that 70% of the
> spam you're using must hit on one of the subrules.  TBH, by that
> point, you may as well hand-extract a couple of the subrules and make
> them static, standalone rules.

Have you tried to use mk_meta_rule_scores and did I get more values of 
scores than two? The default and the value in medium range. I suspect 
that mk_meta_rule_scores doesn't play well with ranges. It is something 
that I can live with it but if somewhere is bug I would try report it. 
If it will not be fixed it can save some time of other users trying to 
use this scipt.


> My experience has been that you need lots of mail to generate multiple
> metas in any case;  I've taken a different tack and separated out
> different groups of mail for different generated rule sets instead.


Thanks,
Marcin

Re: mk_meta_rule_scores - does it work correctly?:)

Posted by Kris Deugau <kd...@vianet.ca>.
marcin@mejor.pl wrote:
> Hi!
> Thanks to AXB seek-in-phrases-in-log works OK. Now I'm on the next step with automated creating rules.
> I suspect that mk_meta_rule_scores doesn't assign scores correctly. I set in mk_meta_rule_scores:
> my %scoremap = (
>   '70' => '1.5',
>   '4' => '2.0',
>   '0.01' => '3.0',
> );

If I understand correctly (quite possible I don't;  I haven't dug in to 
the internals of this stage), the %scoremap hash above indicates the 
percentage of the messages that need to hit on a subrule for that 
subrule to be included in one of the meta rules.

So, 70% of the mail in the set would need to hit on a subrule for it to 
be included in the first group, 4% in the second, and 0.01% in the third.

If I read the information flow correctly, this is actually decided by 
seek-phrases-in-log, which spits out subrules that reached a certain hit 
rate in blocks, followed by the "# passed hit-rate threshold nnn" line. 
mk_meta_rule_scores just takes that in, collects the rule names in each 
block, and spits out the meta.

(In fact the stock setup refers to mk_meta_rule, although it's nearly 
identical to mk_meta_rule_scores.)

By raising the hit percentage to 70%, you're requiring that 70% of the 
spam you're using must hit on one of the subrules.  TBH, by that point, 
you may as well hand-extract a couple of the subrules and make them 
static, standalone rules.

My experience has been that you need lots of mail to generate multiple 
metas in any case;  I've taken a different tack and separated out 
different groups of mail for different generated rule sets instead.

-kgd