2011/2/27 John P. Rouillard <[email protected]>:
>
> In message <[email protected]>,
> Risto Vaarandi writes:
>>I'd like to return to a topic recently discussed in the mailing list.
>>I am in the process of implementing a pattern match caching for SEC, and
>>it is really hard to decide which way is the best one. Currently, I have
>>already implemented a separate Parse rule for this purpose. For example,
>>
>>type=Parse
>>ptype=RegExp
>>pattern=sshd\[(?'pid'\d+)\]: Failed (?'auth'\w+) for (?'user'[\w.-]+) from
>>(?'ip'[\d.]+)
>>continue=TakeNext
>>dpat=sshd-login-failure
>>
>>would create a new dynamic pattern sshd-login-failure,
>
> Does parse also include the action and context keywords? Also if the
> context is false is dpat created and are $+auth, $+user
> and $+ip defined? I assume not.
No, for Parse there is only the 'context' keyword an no action - in
many ways, it is similar to Jump.
In fact, after having written implementations for both cases and
tested them both in action, I have started to like the 'varmap'
approach quite a bit.
Parse does look cleared, but one can always configure parsing with
using the Jump rule which is very similar to Parse anyway. For
example:
type=Jump
ptype=RegExp
pattern=sshd\[(?'pid'\d+)\]: Failed (?'auth'\w+) for (?'user'[\w.-]+)
from (?'ip'[\d.]+)
varmap=sshd-login-failure; username=3
continue=TakeNext
cfset=sshd-messages
I'd like to point out one thing that I didn't explain well enough in
the previous mail - 'varmap' also supports Perl native named match
variables, and the named match variables $+{username} defined in the
above example is created as a complement to already existing $+{pid},
$+{auth}, $+{user} and $+{ip} (both $+{user} and $+{username} hold
equal values). In fact, if one wants to create a dynamic pattern only,
then the above varmap declaration could be simply written as
'varmap=sshd-login-failure'. In other words, each name without a
number value creates an entry in the match cache, while a name with a
number sets up additional named match variable.
One thing which is handy about varmap-based approach is the abiliy to
reuse pattern match results in small rulesets (like 2 rules only)
without having the need to set up a separate rule. Also, one could
cache the match result from the 'pattern2' field of Pair rule and
reuse it for the following Single rule. One the other hand, a separate
Single or Jump rule can always be set up if the parsing process needs
to be highlighted for larger rulesets.
>
> Also is it possible to trigger on multiple pattern matches?
>
> # route to ssh parsing rules if prior pattern matched
> type = jump
> desc = matches sshd login failure
> ptype = dynamic
> pattern = sshd-login-failure ssh-login-success
> cfset = ssh_access_log
The above example looks like a logical OR to me (either
sshd-login-failure or ssh-login-success must match). For this case,
two separate Jump rules must be written.
The thing is that internally, a dynamic (or cached) pattern match is
implemented as a lookup in match cache, and if the entry with a given
name is present, all match variables and their values are retrieved
from cache and propagated throughout the rule. If two names are given
for lookup, they might refer to entirely different variable-value
sets, so its unclear which set to use in the rule.
>>Also, 'varmap' would create a cache entity even if the rule context
>>expression evaluates false
>
> Hmm, why would that be the case? Won't the mapping be done only if the
> rule would be executed (i.e. if an action would be executed)?
...
>>-- which is sometimes beneficial, but sometimes might be confusing.
>
> Could you elaborate on when it would be beneficial? I can't think of a
> use for that off the top of my head.
Not quite -- the thing is that named match variables created from
varmap are identical to numbered and native named match variables.
They are instantiated during the match process and must exist before
context is evaluated, since the context definition might contain these
variables.
However, after reasoning a while, I found this behavior of varmap
beneficial -- for example, consider the following ruleset:
type=Single
ptype=RegExp
pattern=sshd\[(?'pid'\d+)\]: Failed (?'auth'\w+) for (?'user'[\w.-]+)
from (?'ip'[\d.]+)
varmap=sshd_login_failure
context=WEEKEND
desc=User $+{user} failed to login from $+{ip}
action=write - %s
type=SingleWithThreshold
ptype=Cached
pattern=sshd_login_failure
desc=User $+{user} failed to login from $+{ip} three times
action=write - %s
thresh=3
window=60
Note that when the context WEEKEND is present, the first rule will
create an alert immediately. However, when the context does not exist,
the first rule does not match as a whole, but the regular expression
match is still cached and reused by the second rule.
While some people might dislike this style (depending on the task, I
might also pick up another way of implementation :), this opportunity
does not enforce itself as the only way. If needed, a separate rule
could be set up for parsing task alone, and the above rules could then
both use a cached match from this rule.
Finally, my apologies for the somewhat confusing last mail - I didn't
explain some of the concepts well enough there.
kind regards,
risto
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________
Simple-evcorr-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/simple-evcorr-users