Skip to main content

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,;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!


[...] This post was mentioned on Twitter by JoelEsler and - the Blog!, Scott Hazel. Scott Hazel said: RT @JoelEsler: Fun with profile_rules [...]

Popular posts from this blog

Offset, Depth, Distance, and Within

Without going off the deep-end here and discussing every single Snort rule keyword, I just wanted to touch on a few modifiers that people sometimes misunderstand.  They aren't difficult, and hopefully after this explanation and a few examples, I can clear some of the air around these five modifiers.

The five modifiers that I am talking about are
OffsetDepthDistanceWithinnocaseThese five modifiers are not keywords of themselves, but rather they apply as modifiers to another keyword.  That keyword is "content". The content keyword is one of the easiest pieces of the Snort rules language as all it does is look for a particular string.  So for instance if I wanted to look for the word "joel" within a packet.  A simple:
content:"joel";Would allow me to do that.  The interesting part comes into play when you want to specify where inside of a particular packet you want the string "joel" to be looked for.  If you are running just a plain content ma…

Writing Snort Rules Correctly

Let me start off by saying I'm not bashing the writer of this article, and I'm trying not to be super critical.  I don't want to discourage this person from writing articles about Snort rules.  It's great when people in the Snort community step up and explain some simple things out there.  There are mistakes, it comes with the territory.  If you choose to be one of the people that tries to write Snort rules, you also choose to be someone who wants to learn how to do it better.  That's why I write this blog post, not to bash the writer, but to teach.

I noticed this post today over at the "Tao of Signature Writing" blog, and to be honest I glanced over most of it figuring it was a rehash of things I've already read or things that have already been written from countless people about "Here's how you write Snort rules!".  I scrolled down quickly skimming, not reading at all really, and noticed this part:
Now, let us look at the second questio…

Safari 5.1.4 now available

Safari 5.1.4 now available, fixes issues and improves performance | TUAW - The Unofficial Apple Weblog:

Improve JavaScript performanceImprove responsiveness when typing into the search field after changing network configurations or with an intermittent network connectionAddress an issue that could cause webpages to flash white when switching between Safari windowsAddress issues that prevented printing U.S. Postal Service shipping labels and embedded PDFsPreserve links in PDFs saved from webpagesFix an issue that could make Flash content appear incomplete after using gesture zoomingFix an issue that could cause the screen to dim while watching HTML5 videoImprove stability, compatibility and startup time when using extensionsAllow cookies set during regular browsing to be available after using Private BrowsingFix an issue that could cause some data to be left behind after pressing the "Remove All Website Data" button