Code Monkey home page Code Monkey logo

snortparser's Introduction

snortparser

Snort rule parser written in python, a work in progress. The main goal for this code is to validate snort rules and have them parsed into a workable dictionary object.

The parser class accepts a snort rule as input and returnes a dictionary that containes the parsed output.

#> from snortparser import Parser

#> rule = ('alert tcp $HOME_NET any -> !$EXTERNAL_NET any (msg:"MALWARE-BACKDOOR - Dagger_1.4.0"; flow:to_client,established; content:"2|00 00 00 06 00 00 00|Drives|24 00|"; depth:16; metadata:ruleset community; classtype:misc-activity; sid:105; rev:14;)') #> parsed = Parser(rule)

"Header" #> print parsed.header

OrderedDict([('action', 'alert'), ('proto', 'tcp'), ('source', (True, '$HOME_NET')), ('src_port', (True, 'any')), ('arrow', '->'), ('destination', (False, '$EXTERNAL_NET')), ('dst_port', (True, 'any'))])

"Options" #> print parsed.options

OrderedDict([(0, {'msg': ['"MALWARE-BACKDOOR - Dagger_1.4.0"']}), (1, {'flow': ['to_client', 'established']}), (2, {'content': ['"2|00 00 00 06 00 00 00|Drives|24 00|"']}), (3, {'depth': ['16']}), (4, {'metadata': ['ruleset community']}), (5, {'classtype': ['misc-activity']}), (6, {'sid': ['105']}), (7, {'rev': ['14']})])

NOTE: if the parser is unable to parse the rule, it will return a ValueError with the invalid rule item. Additionally, it does not care about misplaced spaces in the headers ip and port definitions like: " alert tcp ![ 127.0.0.1, !8.8.8.8 ] any --> ". This i by design, since I am not sure if snort cares about header syntax that much.

Also, keep in mind, that I have never used snort myself, nor do I know what the best practices are, this tool is written for a project and entierly based on snort documentatin.

I hope this code is useful for someone.

Cheers!

snortparser's People

Contributors

g-rd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.