Pages

Friday, April 30

Fun with profile_rules

I received a rule in my inbox today from StillSecure, and to be honest there wasn't anything wrong with it, but here was the rule:

alert tcp $EXTERNAL_NET $HTTP_PORTS -> $HOME_NET any (msg:"WEB-ATTACKS HP Digital Imaging ActiveX Control CLSID Access Attempt"; flow:established,to_client; content:"clsid"; nocase; content:"697F5209-0494-11D6-A2B0-0060B0FBD872"; nocase; distance:0; content:"Save"; nocase; pcre:"/<OBJECT\s+[^>]*classid\s*=\s*[\x22\x27]?\s*clsid\s*\x3a\s*\x7B?\s*697F5209-0494-11D6-A2B0-0060B0FBD872/si";classtype:attempted-user; reference:url,exploit-db.com/exploits/12367;sid:2012881; rev:1;)

So I started thinking about that pcre.  That's a pretty intensive pcre, and what does it do for us?  Checks order and formatting?  Okay.  I can see that, but as an experiment, I wanted to see how much faster that rule would run if you ran it natively in pure content matches.

I wrote the following:
alert tcp $EXTERNAL_NET $HTTP_PORTS -> $HOME_NET any (msg:"WEB-ATTACKS HP Digital Imaging ActiveX Control CLSID Access Attempt"; flow:established,to_client; content:"OBJECT"; nocase; content:"classid"; distance:0; nocase; content:"clsid"; distance:0; nocase; content:"697F5209-0494-11D6-A2B0-0060B0FBD872"; distance:0; content:"Save"; nocase; distance:0; sid:1000000; rev:1;)

All content matches, just using distance to stack the matches.

I threw this in my snort.conf:
config profile_rules

(Excerpt from Snort manual about rule profiling:)
Snort can provide statistics on rule and preprocessor performance. Each require only a simple config option to snort.conf and Snort will print statistics on the worst (or all) performers on exit.

My Snort is already compiled with the correct performance monitoring tags, by the way.

This is what I got:
Rule Profile Statistics (all rules)

==========================================================

Num      SID GID Rev     Checks   Matches    Alerts           Microsecs  Avg/Check  Avg/Match Avg/Nonmatch   Disabled

===      === === ===     ======   =======    ======           =========  =========  ========= ============   ========

1          2012881   1   1          2         0         0                 148 74.2        0.0         73.3          0

2          1000000   1   1          3         1         1                  29 9.7        8.6         10.3         0

Look at the bolded numbers above.  The first is the rule with the pcre, the second is the rule without the pcre.  The one without ran in 29 microseconds (against a pcap).  The first rule, with the pcre ran for 148 microseconds!  Less Avg/Checks too.

So I wanted to see what would happen if you took out the distances (because the formatting of webpages can be wonky and the words can move around)
Rule Profile Statistics (all rules)

==========================================================

Num      SID GID Rev     Checks   Matches    Alerts           Microsecs  Avg/Check  Avg/Match Avg/Nonmatch   Disabled

===      === === ===     ======   =======    ======           =========  =========  ========= ============   ========

1  2012881   1   1          2         0         0                 148 74.2        0.0         73.3          0

2  1000000   1   1          3         1         1                  29 9.7        8.6         10.3          0

3  1000001   1   1          3         1         1                  25 8.4       16.1          4.6          0

Again, the rule was faster, but it had double the amount of Avg/Matches.

Just an interesting experiment, and I'm definitely not recommending you start running out and removing your pcre, I just thought I'd try that out.

However, my point in this post is, use profile_rules.  It's there for you and it provides you some great feedback!

1 comment:

Tweets that mention Fun with profile_rules | Finshake -- Topsy.com said...

[...] This post was mentioned on Twitter by JoelEsler and Roer.com - the Blog!, Scott Hazel. Scott Hazel said: RT @JoelEsler: Fun with profile_rules http://goo.gl/fb/YcNOk [...]