95
 SeaSnUG Snort Rule Clinic Keeping Sane This presentation is GPL, not because I'm that impressed with myself, but because I wanted to use real rule examples from widely available rulesets.  Some of those example rules are released under the GPL, so this must be as well. I think.  IANAL 

SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

  • Upload
    leque

  • View
    244

  • Download
    0

Embed Size (px)

Citation preview

Page 1: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic

Keeping Sane

This presentation is GPL, not because I'm that impressed with myself, but because I wanted to use real rule examples from widely available rulesets.  Some of those example rules are released under the GPL, so this must be as well.

I think.  IANAL  

Page 2: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic

● Organization of Material– Less methodical than official Snort docs– More like a newspaper story: 

● Most important to least important● Most useful to less so● more time on difficult topics; less or none on easy● topics chosen by statistical analysis and subjective impressions

– More likely to write simple rules– Still have to understand complex ones– Examples and demos to illustrate concepts

Page 3: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic

● So What is Important? Simple­Minded statistical analysis of features used in Sourcefire VRT rules shows:– 5547 rules enabled by default in current VRT ruleset (as of July 

4, 2006) – 32 options (ignored some deprecated and unused)– Looked at frequency plus made a subjective evaluation of an 

option's degree of difficulty – none of the rarely used options are that hard.

Page 4: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic

● Externalities – things outside snort rules that affect their behavior

● Rule structure – Rule Headers– Rule Options 

● High Performance rules ­ saving Snort work● Low analyst impact rules ­ saving the Analyst work● Strategy● References, resources, acknowledgements

Page 5: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Externalities – things outside snort rules that affect their 

behavior– Variables: set $HOME_NET, $HTTP_SERVERS, etc.

● $HOME_NET used 4043 times● $HTTP_SERVERS used 999 times● $HTTP_PORTS used 1589 times● Rest used rarely or never in VRT ruleset 

– Preprocessors● Generate events (see engine id)● some concatenate packets into giant pseudo­packet

– defeats some evasion attempts– can defeat some detection features (see rawbytes)

Page 6: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Snort Rule Structure: Header + Options

– Header● action: alert, pass, log, drop/reject, plus other rarely used● source/dest IP : 

– can be a list, but no spaces!– can be a negation

● direction of traffic● source/dest port : 

– can be a range, but not arbitrary list– can be a negation

● protocol

Page 7: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicHeader Examples

alert tcp 192.168.1.0/24 any ­> !192.168.1.4 80

log tcp 192.168.1.0/24 any ­> !192.168.1.4 8000:8080

alert tcp [192.168.1.0/24,192.168.2.0/24] any ­> !192.168.1.4 80

alert tcp $HOME_NET any ­> !192.168.1.4 $HTTP_PORTS

Page 8: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicRule Crafting Interlude 1

As we all know, the person to fear is the 31337 h4x0r.  

According to Treachery.net (and the Neohapsis database it uses for ports information), tcp/udp port 31337 is used for lots of backdoors and other evil traffic, including the notorious Backorifice.

http://www.treachery.net/tools/ports/lookup.cgi

Page 9: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic

Page 10: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicRule Crafting Interlude 1

For our first, naïve crack at writing a rule for this threat, let's use the header information we have.

alert tcp any any ­> any 31337 (msg: “31337 traffic!”;)

Page 11: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicRule Crafting Interlude

alert tcp any any ­> any 31337 (msg: “31337 traffic!”;)

Warning! This is terrible!  Why is this so bad?  ● Port­based rules suck apply a partial vacuum.  ● It lacks context.● Every single packet to tcp port 31337 will generate an 

alert.  Wouldn't you prefer one per connection?

Page 12: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicRule Crafting Interlude

alert tcp any any ­> any 31337 (msg: “31337 traffic!”;)● Port­based rules suck apply a partial vacuum.  

– Due to the nature of tcp/ip, many innocent connections will randomly pick 31337 as a source port.

– While unlikely for this port, with only 65535 available port #'s, there will be overlap between legit and evil apps.  

– In rare instances, can be good.  eg spambot catcher: 

alert $HOME_NET any ­> any 25 (msg: “SMTP traffic”;)

Page 13: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicRule Crafting Interlude

alert tcp any any ­> any 31337 (msg: “31337 traffic!”;)● It's without context: we're worried about connections to a 

backdoor ­ a server listening on 31337.  We don't care about return traffic to a client source port of 31337.

– Even then, active ftp will still trip this once in a while, because the ftp client sets up a listening port > 1024 for the ftp server to connect back to for the data channel.

Page 14: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicRule Crafting Interlude

alert tcp any any ­> any 31337 (msg: “31337 traffic!”;)

(contrived) example of innocent tcp traffic to targeted port 31337

06:33:40.056607 IP 192.168.102.100.31337 > 207.200.66.55.21: S 2257198927:2257198927(0) 

06:33:40.093637 IP 207.200.66.55.21 > 192.168.102.100.31337: S 480613166:480613166(0) ack 2257198928 

Page 15: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Snort Rule Structure: Header + Options

– Header

– Options● payload● non­payload● meta data● Post Detect

“Payload” means data encapsulated in the tcp/udp/icmp packet.  For a tcp packet, the payload follows the tcp header.  This is the reason you sent/received the packet, the stuff that goes to an application.

Page 16: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Snort Rule Options – payload

– 3 Flavors of Content Checks/pattern matching● content● uricontent● pcre

Page 17: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Snort Content Checks

– text data: ● example: content: “foo”;

– binary data: hex encoding inside | | chars● example: content: “| aa aa aa aa|”;● example – mixed binary and text: content: “|00 aa|foo”;

– can have multiple content checks in a rule● be aware of recursive content checks – more about this in 

performance

– often combined with the nocase option so you don't have to write rules for all capitalization permutations of a string

Page 18: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicContent Check Examples

● Text:

alert tcp any any ­> any any (msg:"COMMUNITY BOT IRC Traffic Detected By Nick Change"; flow: to_server,established; content:"NICK "; nocase; offset: 0; depth: 5; flowbits:set,community_is_proto_irc; flowbits: noalert; classtype:misc­activity; sid:100000240; rev:3;)

Note: nocase option means we match “nIcK” as well as “NICK”

Page 19: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicContent Check Examples

● Mixed Text and Binary, plus  Negation:

alert tcp $HOME_NET 6667:7000 ­> $EXTERNAL_NET any (msg:"COMMUNITY DOS EnergyMech parse_notice vulnerability ­ outbound"; flow:to_server,established; content:"NOTICE|20|"; content:!"|5c|"; within:11; reference:bugtraq,18664; sid:100000687; rev:1;)

Page 20: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Snort Uricontent Checks

– just like content checks except you examine fruits of http_inspect preprocessor

– defeats evasion attempts based on mixing the encoding styles used to represent characters by normalizing the content.  

– sometimes you WANT to use plain content check if evasion/obfuscation attempt is useful diagnostic

Page 21: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicUricontent Example

alert tcp $EXTERNAL_NET any ­> $HTTP_SERVERS 8008 (msg:"COMMUNITY MISC Novell eDirectory iMonitor access"; flow:to_server,established; uricontent:"/nds/"; nocase; reference:bugtraq,14548; reference:cve,2005­2551; reference:nessus,19248; reference:url,www.osvdb.org/displayvuln.php?osvdb_id=18703; classtype:web­application­attack; sid:100000199; rev:1;)

Page 22: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinicnon­Uricontent Example

alert tcp $HTTP_SERVERS $HTTP_PORTS ­> $EXTERNAL_NET any (msg:"COMMUNITY WEB­MISC apache directory list attempt"; flow:to_client,established; content:"HTTP/1.1 200 OK"; depth:15; content:"Index of /"; nocase; within:200; reference:bugtraq,3009; reference:cve,2001­0731; classtype:web­application­activity; sid:100000185; rev:1;)

Author of this rule wanted to look at exactly those strings, not worried about obfuscation.  

Page 23: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic

Rule Crafting Interlude 2

Suppose for our hypothetical back door application, it sends the following string after connecting: “lol 0wnz j00”

So to improve our rule, we add a content check as follows:

alert tcp any any ­> any 31337 (msg: “31337 traffic! lol backdoor”; content: ”lol 0wnz j00”; nocase;)

Page 24: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicRule Crafting Interlude 2

alert tcp any any ­> any 31337 (msg: “31337 traffic! lol backdoor”; content: ”lol 0wnz j00”; nocase;)

Still room for improvement: ● still no context.  This would fire if your web browsing 

session used source port 31337 and the web server sent a page describing the lol backdoor.  

● A little bit expensive: you make Snort search through the whole packet of all 31337 traffic for the string.

Page 25: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Snort Positional Options: limit region to search for 

content/uricontent matches– Dramatically improve rule performance – Dramatically improve rule accuracy– Make no sense by themselves – have to be used with a 

content/uricontent match– Options:

● Depth● Offset● within● distance

Page 26: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort Positional Options:● Depth: how far into the payload to search for the pattern.  

The end of the pattern must occur within the value specified.  Start counting at one.

Example (from last rule we looked at):

 content:"HTTP/1.1 200 OK"; depth:15; content:"Index of /"; nocase; within:200; 

Page 27: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort Positional Options: ● Offset: how deep into the payload to start looking.  Start 

counting at zero.  

bleeding­attack_response.rules:alert tcp $HOME_NET any ­> $EXTERNAL_NET !6661:6668 (msg: "BLEEDING­EDGE ATTACK RESPONSE IRC ­ Private message on non­std port"; flow: to_server,established; dsize: <128; content:"PRIVMSG "; nocase; offset: 0; depth: 8; tag: session,300,seconds;  sid: 2000347; rev:5; )

(Note that an offset: 0; is redundant: the search always starts at the beginning of the buffer unless offset: !=0)

Page 28: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort Positional Options● within: how close to previous match must next one be 

(similar to depth, but relative to last match rather than beginning of buffer) Start counting at one.

bleeding­virus.rules:alert tcp any any ­> $EXTERNAL_NET 21 (msg: "BLEEDING­EDGE VIRUS Hotword Trojan ­­ Possible FTP File Request .tea"; flow: to_server,established; content:"LIST "; content:".tea"; nocase; within: 50;  sid: 2001964; rev:5; );)

Page 29: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort Positional Options● distance: how far from LAST MATCH to start search

Like offset: option, but this is from last match, not beginning of buffer.  Start counting at zero.

alert tcp $HOME_NET any ­> $EXTERNAL_NET 25 (msg:"BLEEDING­EDGE EXPLOIT Outgoing Electronic Mail for UNIX Expires Header Buffer Overflow Exploit"; content:"Expires\:"; content:"|40 60 6e 63|"; distance:52; within:300; content:"|2d 70|";  distance:2; within:20; reference:url,www.frsirt.com/exploits/20050822.elmexploit.c.php; reference:url,www.instinct.org/elm/; classtype:misc­attack; sid:2002316; rev:3;)

Page 30: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort Positional Options ­ Summary

Page 31: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicRule Crafting Interlude 3

Suppose for our hypothetical back door application, it sends the following string in the first 20 bytes of the first packet after connecting: “lol 0wnz j00”

We alter our rule as follows: 

alert tcp any any ­> any 31337 (msg: “31337 traffic! lol backdoor”; content: ”lol 0wnz j00”; nocase; depth: 20;)

This makes the rule more accurate (no FP from websites describing the back door application) and more efficient because you no longer search entire payloads.

Page 32: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic

PCRE: (11:22:50) eric0: sfirefinch: sometimes when you 

stare too deeply into the regex, the regex also stares back into you (After Nietzsche)

Page 33: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort PCRE Checks● One of the amazingly cool things about Snort: using what 

many of us already know rather than unnecessary new language.  Some proprietary IDS use COBOL++ with XML goodness!

● Allows the use of patterns that vary within constraints – maddeningly flexible

● More expensive than content/uricontent checks– Use a content check (or other checks) so you can skip the pcre 

check as much as possible: everything that doesn't match the content check is filtered out.  

Page 34: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort PCRE Checks: pcre: “/ <regex>   /”;● Text● Character Classes● Alternates● Quantifiers● Anchors (positionals)● Modifiers● Metacharacters (shortcuts/macros)

Page 35: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort PCRE Checks● Text: Can match simple text● wildcard: .   <==== that's a period.  Call it a dot.  

pcre: “/match.this/”;

match “match” and basically any other character and “this”

matchZthis  match1this  match^this    etc.  

Page 36: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort PCRE Checks● Character Classes (no, this is not D&D|Everquest|WoW)

– says 'match one of these thingies in brackets': [0123456789]– can express ranges [0­9], [a­zA­Z]

pcre:”/[0­9][a­z][ABZ]/”;

matches one numeral, followed by a lower case letter, followed by capital A, or capital B, or a capital Z

Negation: use the ^ character

pcre:”/[^a­z]/”;  NOT lowercase a through lowercase z

Page 37: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort PCRE Checks● Alternates:  the ' | '  separates OR clauses● matches a whole string (char class matches single char)

pcre:”/foo|bar/”;

matches “foo” or it matches “bar”

Page 38: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort PCRE Checks● Quantifiers: how many of the previous match do we want?

– Zero or one (the “optional” quantifier): ?– Zero or more: *– One or more: +– Exactly M : {M}– At least M : {M,}– At least M and no more than N: {M,N}

Page 39: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort PCRE Checks● Anchors (positionals) 

– Usually apply to whole buffer, with the right modifier option can apply to newline

– Start of buffer/newline: ^– End of buffer/newline: $

Page 40: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort PCRE Checks● Modifiers – three types

– Perl compatible– PCRE compatible– Snort Specific

Page 41: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort PCRE Checks ­ Modifiers● Perl compatible:

– i ­ match is case insensitive– s ­  dot wildcard character includes newlines– m ­ anchors ^ and $ can match at start/end of newline, too– x ­ ignore whitespace in pattern unless explicitly declared

Page 42: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort PCRE Checks● PCRE compatible:

– A ­ whole pattern matches against start of buffer (like ^ anchor)

– E ­ $ must match end of string (removes one small exception for last newline)

– G ­ inverts 'greediness' of matches

Page 43: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort PCRE Checks

“Greediness” describes how much of a potential match is used.  If a greedy pattern matcher is looking for 'AA', it will consider 'AAAAAAAA' as a match.  This has implications for what comes after, i.e. positionals.  If you were expecting to start counting after the first two 'A' characters, you'd miss.  Unless you invert the greediness behavior for the regex with a /G or follow a quantity with '?'

Page 44: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort PCRE Checks● Snort Specific

– R ­ match relative to end of last pattern match (ties to last match Snort found, distance of 0)

– U ­ match against results of http_inspect  (like uricontent)– B ­ don't use any decodes (like rawbytes)

Page 45: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort PCRE Checks● Metacharacters ­ shortcuts to represent common cases

– \s  whitespace: tab, space, etc.     [\ \t\r\n\f]– \S NOT whitespace [^\ \t\r\n\f]– \d  numerics [0­9]– \D  NOT numerics [^0­9]– \w  alphanumeric and _ [0­9a­zA­Z_]– \W  NOT alphanumeric or _ [^0­9a­zA­Z]– \b  word boundary  [\w\W] or [\W\w]

Page 46: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort PCRE Example (from Community Rules)

alert tcp $EXTERNAL_NET any ­> $HTTP_SERVERS $HTTP_PORTS (msg:"COMMUNITY WEB­PHP PHPMyForum topic.php xss attempt"; flow:to_server,established; uricontent:"/topic.php"; nocase; uricontent:"highlight="; nocase; pcre:"/highlight(=|\x3f)\x3c[^\n]+\x3e/Ui"; reference:bugtraq,18542; classtype:web­application­attack; sid:100000528; rev:1;)

Page 47: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort PCRE Example

pcre:"/highlight(=|\x3f)\x3c[^\n]+\x3e/Ui"; 

do a case­insensitive check against uri decoded buffer and:

“match 'highlight' followed by 

(either '=' or 0x3f) followed by 

one or more characters that are not a newline followed by 

0x3e

Page 48: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicGnarly Snort PCRE Example (from Bleeding Snort)

alert tcp $EXTERNAL_NET $HTTP_PORTS ­> $HOME_NET any (msg: "BLEEDING­EDGE EXPLOIT Attempt to execute VBScript code"; flow: from_server,established; content:"vbscript"; nocase; pcre:"/(((URL|SRC|HREF|LOWSRC)[\s]*=)|(url[\s]*[\(]))[\s]*['"]*vbscript[\:]/i"; classtype: misc­attack; sid: 2001099; rev:5; )

Page 49: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic pcre:"/(((URL|SRC|HREF|LOWSRC)[\s]*=)|

(url[\s]*[\(]))[\s]*['"]*vbscript[\:]/i";

do a case­insensitive check for one of: 

either 'URL', 'SRC', 'HREF', or 'LOWSRC' followed by

zero or more whitespace characters and an '=' sign

or:

'url' followed by zero+ whitespace chars followed by either '\' or '('

followed by zero or more whitespace characters followed by

zero or more of either a single quote or a double quote 

followed by 'vbscript' followed by either a '\' or a ':'

Page 50: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic  Rule Crafting Interlude 4

Suppose for our hypothetical back door application, the author reacted to our signature by changing the application: now it pads the string with random amounts of whitespace between words, but the string starts on the 20th byte after the first packet after connecting: “lol 0wnz j00” or “lol       0wnz  j00”.  The case is always the same, however, so we drop the nocase options.

Page 51: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic  Rule Crafting Interlude 4

We alter our rule as follows: alert tcp any any ­> any 31337 (msg: “31337 traffic! lol 

backdoor”; content: ”lol”; offset: 21; content: “0wnz”;  content: “j00”; pcre: /lol[\s]*0wnz[\s]*j00[\s]*/”;)

The offset of 21 for the 'lol' content check makes this very specific.  This rule will be dropped early for all but very suspicious packets.  The subsequent content checks make it even more discriminating.  Only after all three content checks pass do we invoke the expensive pcre check.  

Page 52: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort Rule Options – misc payload options● byte_test: 

– used in 2581 netbios.rules, 30 rpc.rules, 135 others– test if byte is <,>,=,!= some value

● can use bit masking to test individual bits

● byte_jump: – used in 2,410 netbios.rules, 91 rcp.rules, 12 others– handles length­encoded protocols

Page 53: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Snort Rule Options – non­payload

– Flow– Flowbits– Everything Else

Page 54: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Snort Rule Options – non­payload

– Flow: Hugely important – used in 5342 rules● anti IDS­DoS measure 

– (stick, snot, etc try to generate stateless alerts to DoS the IDS setup)● accuracy 

– the more you can specify about the traffic the more accurate the rule● Place it ahead of other checks.  (thx to Nigel Houghten)

● format:

flow: [established|stateless] [,to_server|to_client|from_server|from_client]

Page 55: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Snort Rule Options – non­payload ­ Flow Example

bleeding­attack_response.rules:#alert tcp any any ­> $HOME_NET 31337 (msg: "BLEEDING­EDGE ATTACK RESPONSE Potential root shell connection detected!"; flow: established,to_server; tag: session, 20, packets; classtype: bad­unknown; sid: 2001545; rev:2; )

Page 56: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicRule Crafting Interlude 5

A lot of the inaccuracy of the initial drafts of this rule stemmed from lack of context, so we use flow to provide it as follows:

alert tcp any any ­> any 31337 (msg: “31337 traffic! lol backdoor”; flow: established,to_server; content: ”lol”; offset: 21; content: “0wnz”; nocase; content: “j00”; nocase; pcre: /lol\s*0wnz\s*j00\s*/”; )

Page 57: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Snort Rule Options – non­payload

– Flowbits: very common (1183 rules) ● allows multipacket/two stage detects

– set a flowbit with packet1– check for flowbit while looking at packet2

Basically just sets a flag and allows you to test for that flag for subsequent packets.  Somewhat costly in memory etc.

Page 58: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Snort Rule Options – non­payload ­ Flowbits Details

– Format: flowbits: [set|unset|toggle|isset,reset,noalert][,<STATE_NAME>]

– Options: ● Set● Unset● Toggle● isset● isnotset● noalert

Page 59: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Snort Rule Options – non­payload ­ Flowbits Example

bleeding­dos.rules:alert tcp $EXTERNAL_NET any ­> $HOME_NET $HTTP_PORTS (msg: "BLEEDING­EDGE DOS HTTP GET with newline appended"; flowbits:noalert; flow: to_server,established; content:"GET / HTTP/1.0|0a|"; offset: 0; depth: 15; flowbits:set,http.get;  sid: 2001635; rev:6; )

bleeding­dos.rules:alert tcp $EXTERNAL_NET any ­> $HOME_NET $HTTP_PORTS (msg: "BLEEDING­EDGE DOS squ1rt Apache DoS"; flow: to_server,established; flowbits:isset,http.get; dsize: 1448; content:"|20202020|"; depth: 4; content:"|20202020|"; offset: 1436; depth: 4;  sid: 2001636; rev:4; )

Page 60: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Snort Rule Options – non­payload ­ Flowbits Example

If a packet triggers the first rule, flowbit http.get is set.

 flowbits:set,http.get;  

The second rule will alert if and only if flowbit named http.get is set and the rest of the rule matches.

flowbits:isset,http.get; dsize: 1448; content:"|20202020|"; depth: 4; content:"|20202020|"; offset: 1436; depth: 4;  sid: 2001636; rev:4; )

Page 61: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Snort Rule Options – non­payload

– Everything Else:● ttl – common (2469 occurances), but only in netbios.rules● icode – common (1212 occurances) but only in netbios.rules● ack – 941 instances.  Only supports = operator, NOT <,>,!● rpc – 430 instances.  ● isdataat – 158 instances● Every other option – less than 40 instances each, all pretty simple

Page 62: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort Rule Options – meta data● msg: The text that shows in an alert● sid: signature ID

– use sids in the range of 1,000,000 – 1,999,999 for local rules– 100 – 999,999 for Sourcefire– 2,000,000 for Bleeding Snort– 10,000,000+ Community Rules (assigned by Sourcefire)

● rev: up to you, I increment the rev as I revise them.● reference: record source of information that led you to 

write the rule (for future reference and other analysts)

Page 63: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic

Snort Rule Options – meta data (continued)● classtype:  what type of activity is this?

– defined in etc/classification.config– (less interesting to me: my taxonomy is “must I remediate or 

not?”)

● priority: can override the default priority of a given classtype

Page 64: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicRule Crafting Interlude 6

This rule stands on its own pretty well, but it needs to fit into the overall IDS system to be useful to the human analysts.  Metadata options address this.  We need: 

● sid: so we can fit it into a ruleset● rev: so we know whether this is the latest and how many 

times we've worked on it.● reference: so we know where to get more information 

about the alert

Page 65: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicSnort rule crafting interval 6

alert tcp any any ­> any 31337 (msg: “31337 traffic! lol backdoor”; content: ”lol”; offset: 21; content: “0wnz”; nocase; content: “j00”; nocase; pcre: /lol\s*0wnz\s*j00\s*/”;flow: established,to_server;  reference:url,www.hypothetical.com/lol.html; sid: 1000001; rev: 6;)

While this rule is no more accurate than before, it is much more useful to the analyst.

Page 66: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic

Snort Rule Options – Post Detection● logto: for this rule, special output● tag: record x packets or all packets in y seconds after this 

rule matches● session: record ascii session transcript● react: close connections and send message

– NOT ENABLED BY DEFAULT.  Have to compile it in.

● resp: send packets to try to disrupt session.– NOT ENABLED BY DEFAULT.  Have to compile it in.

Page 67: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicPerformance: Limiting Impact on the Sensor● Put the most restrictive/cheapest check first (flow!) – you 

can quit looking at a rule more quickly● set variables! Don't let $HTTP_SERVERS = any● Put a content check (fast) ahead of a pcre check (slow)● be aware of recursive content checks

Page 68: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicPerformance: Limiting Impact on the Sensor● Put a content check (fast) ahead of a pcre check (slow)

– This gives Snort a chance to quit looking at a rule cheaply; if the cheap content check doesn't find a match, you don't need to do the expensive pcre check.  

Page 69: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicPerformance: Limiting Impact on the Sensor● be aware of recursive content checks

alert any any ­> any any (content: “foo”; content: “bar”; within 3;)

Snort must check for “bar” within 3 bytes of any occurance of “foo” in the packet.  If “foo” occurs, but “bar” does not follow closely enough to meet the within: constraint, Snort must look through the rest of the packet for another instance of “foo”.  Otherwise, an errant “foo” at the beginning of the packet masks “foo” and “bar” later on.

Page 70: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicPerformance: Limiting Impact on the Sensor● be aware of recursive content checks

So what do you do?  Try to limit with positionals, find other matches, etc.  Don't stress too hard if you can't find something, though.  

Page 71: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicPerformance: Limiting Impact on the Sensor● be aware of recursive content checks

alert any any ­> any any (content: “foo”; content: “bar” within: 1;)

Snort has to check for “bar” right after it finds “foo”.  If it doesn't find it, it must check again through the whole packet for any more “foo” instances that might be followed by “bar”.  Why? Well, what if there happened to be an extra “foo” at the front, with a “foo” and a “bar” at the back? You'd miss it without the recursive check. 

Try to mitigate this ­ a depth for the first content?

Page 72: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicPerformance: Limiting Impact on the Sensor and Analyst● Use bpf/tcpdump filters for mass exclusion of traffic

– Very common request on lists and forums: “How do I exclude all alerts from a specific host/net?”  Three options:

●  rewrite 5547 default VRT rules● make 5547 suppression directives● BPF/Tcpdump filter 

snort ­c /etc/snort.conf ­i eth0 'not host 192.168.96.5'– This helps Snort by excluding traffic before Snort ever sees it.– This helps the analyst by not forcing the rewrite of 5547 rules.

Page 73: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicPerformance: Limiting Impact on the Analyst● Port­based rules apply a partial vacuum (usually)

– Don't write naïve rules that generate lots of false positives.

● Make it specific– Don't write naïve rules that generate lots of false positives.

● Thresholding● Suppression

Page 74: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicPerformance: Limiting Impact on the Analyst● Thresholding ­ part of output, so doesn't save sensor 

detection work– Can do this as standalone snort config directive– Can do as global defaults– Probably belongs in the rule

● type: limit, threshold, both● track: by_src, or by_dst● count: # of events● seconds: time period

Page 75: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicPerformance: Limiting Impact on the Analyst● Thresholding Example: limit

– only give me 5 alerts in 5 minutes from a particular source

alert any any ­> any any (threshold: type limit, track by_src, count 5,  seconds 300;)

Page 76: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicPerformance: Limiting Impact on the Analyst● Thresholding Example: threshold

– only alert once after 5 events from a source in 5 minutes

alert any any ­> any any (threshold: type threshold, track by_src, count 5,  seconds 300;)

Page 77: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicPerformance: Limiting Impact on the Analyst● Thresholding Example: both

– Only 1 alert in 5 minutes from a given source, and only if we see 5 alerts in that time.

alert any any ­> any any (threshold: type both, track by_src, count 5,  seconds 300;)

Page 78: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicPerformance: Limiting Impact on the Analyst● Suppress ­ much better way to handle specific cases than 

the now deprecated pass rules.  – Put them in a separate file, as an include directive in snort.conf– elements 2 or 4 options:

● gen_id: the source of the alert, either the rule engine (1) or a preprocessor

● sig_id: the signature id● track: by_src or by_dst (optional)● ip: (required if track option used)

Page 79: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicPerformance: Limiting Impact on the Analyst● Suppress examples: Redhat update server generates 

some ICMP reject alerts I'm not worried about.  

suppress gen_id 1, sig_id 486 track by_dst, ip 208.209.50.18

Page 80: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicAdvanced Strategy:● Target the vulnerability, not the exploit.

– Exploits change easily, but if they all depend on a buffer overflow at payload offset 40, you'll catch them if that's what you look for.

– (approach described in Snort BoF at Usenix LISA 2005, Nigel Houghten)

Page 81: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicAdvanced Strategy (2):● Target­Based: Focus on targets, not attackers.

– Targets are your valued hosts– Attackers are infinite valueless drones

Do you care if a Nimda­infected host tries to spread to your webserver?  Probably not.  Internet background radiation.

Do you care if one of your hosts tries to spread Nimda? You betcha!

Page 82: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicReferences:

Snort Manual: esp. Section 3, “Writing Snort Rules: How to Write Snort Rules and Maintain Your Sanity” http://www.snort.org/docs/snort_htmanuals/htmanual_260/node15.htmlThis presentation is based 90%+ on this material, with the rest gleaned from email, irc, lists, and forums.  (See resources, below.)

Bleeding Snort: rules, forums discussing rules.  http://www.bleedingsnort.com

http://perldoc.perl.org/perlre.html ­ for regular expressions

Page 83: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicNOT References:

Snort 2.1, Jay Beale et. al.  Pretty poor treatment of rule writing.  I understand that the manuscript for that section was eaten by disk failure.  Book might have some value for other aspects of Snort.  Snort is up to version 2.6 now.

Intrusion Detection with Snort: Advanced IDS Techniques, Rafeeq Ur Rehman.  Too far out of date, missing some of the interesting rule options, including pcre.  Again, some value for other Snort topics.  

Page 84: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinicnot QUITE a Reference:

Mastering Regular Expressions, Jeffrey E F Friedl.

A great book, but if all you are after is writing Snort rules it's not the most applicable.  Does a great job of getting down into the details of different implementations, but overkill for just Snort. I think you'll find what you need on the http://perldoc.perl.org/perlre.html link  instead.

Page 85: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule ClinicResources:

Snort Forums (newbies, advanced, rules)

http://www.snort.org/reg­bin/forums.cgi

Snort Mailing lists: 

snort­users: https://lists.sourceforge.net/lists/listinfo/snort­users

snort­signatures:

https://lists.sourceforge.net/lists/listinfo/snort­sigs

Bleeding Snort forums:

http://www.bleedingsnort.com/forum/index.php

Page 86: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● # Bleeding Snort rules are:  Copyright (c) 2006, Bleedingsnort.com

● #  All rights reserved.  

● #  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 

● #  following conditions are met:

● #   * Redistributions of source code must retain the above copyright notice, this list of conditions and the following  disclaimer.

● #  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the  following disclaimer in the documentation and/or other materials provided with the distribution.

● #  * Neither the name of the nor the names of its contributors may be used to endorse or promote products derived  from this software without specific prior written permission.

● #  #  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, 

● #  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 

● #  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 

● #  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 

● #  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 

● #  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 

● #  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

Page 87: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● This presentation and the Snort Community Rules included are published under the General Public License

● Copyright (C)1998,1999,2000,2001,2002 Martin Roesch

● This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

● This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

● You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place ­ Suite 330, Boston, MA 02111­1307, USA.

● Some of this code has been taken from tcpdump, which was developed by the Network Research Group at Lawrence Berkeley National Lab, and is copyrighted by the University of California Regents.

● GNU GENERAL PUBLIC LICENSE

● Version 2, June 1991

● Copyright (C) 1989, 1991 Free Software Foundation, Inc.

● 59 Temple Place, Suite 330, Boston, MA 02111­1307 USA

● Everyone is permitted to copy and distribute verbatim copies

● of this license document, but changing it is not allowed.

Page 88: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Preamble

● The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software­­to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too.

● When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.

● To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.

● For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.

● We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.

● Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.

● Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.

Page 89: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● The precise terms and conditions for copying, distribution and modification follow.

● GNU GENERAL PUBLIC LICENSE

● TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

● 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".

● Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program).

● Whether that is true depends on what the Program does.

● 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.

● You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.

● 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:

● a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.

● b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.

Page 90: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most 

ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)

● These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.

● Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.

● In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.

● 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: 

● a) Accompany it with the complete corresponding machine­readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,

● b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine­readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,

● c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)

Page 91: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all 

the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.

● If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.

● 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.

● 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.

● 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.

Page 92: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are 

imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty­free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.

● If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.

● It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.

● This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.

● 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.

● 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.

● Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.

Page 93: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for 

permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.

● NO WARRANTY

● 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

● 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

● END OF TERMS AND CONDITIONS

● How to Apply These Terms to Your New Programs

● If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.

● To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.

Page 94: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● <one line to give the program's name and a brief idea of what it does.>

● Copyright (C) 19yy <name of author>

● This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

● This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

● You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111­1307 USA

● Also add information on how to contact you by electronic and paper mail.

● If the program is interactive, make it output a short notice like this when it starts in an interactive mode:

● Gnomovision version 69, Copyright (C) 19yy name of author

● Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.

● This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.

● The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse­clicks or menu items­­whatever suits your program.

● You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names:

● Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker.

Page 95: SeaSnUG Snort Rule Clinic - holisticinfosec.io · SeaSnUG Snort Rule Clinic Rule Crafting Interlude 1 As we all know, the person to fear is the 31337 h4x0r. According to Treachery.net

   

SeaSnUG Snort Rule Clinic● Ty Coon, President of Vice, 1 April 1989

● This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License.