Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jasonish/py-idstools
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.4.2
Choose a base ref
...
head repository: jasonish/py-idstools
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0.4.3
Choose a head ref
  • 4 commits
  • 4 files changed
  • 1 contributor

Commits on Dec 12, 2014

  1. Copy the full SHA
    da339c6 View commit details
  2. 0.4.3

    jasonish committed Dec 12, 2014
    Copy the full SHA
    9ff9e26 View commit details
  3. Copy the full SHA
    d8f69a4 View commit details
  4. 0.4.3 changelog.

    jasonish committed Dec 12, 2014
    Copy the full SHA
    32b9f0b View commit details
Showing with 24 additions and 9 deletions.
  1. +10 −0 README.rst
  2. +1 −1 idstools/__init__.py
  3. +12 −8 idstools/rule.py
  4. +1 −0 tests/test_rule.py
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -54,6 +54,16 @@ Further documentation is located at http://idstools.readthedocs.org.
Changelog
---------

0.4.3
~~~~~

- Make the rule direction an accessible field of the rule object.

0.4.2
~~~~~

- Fix issue loading signature map files (GitHub issue #2).

0.4.1
~~~~~

2 changes: 1 addition & 1 deletion idstools/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "0.4.2"
version = "0.4.3"
20 changes: 12 additions & 8 deletions idstools/rule.py
Original file line number Diff line number Diff line change
@@ -49,15 +49,15 @@
# Compiled regular expression to detect a rule and break out some of
# its parts.
rule_pattern = re.compile(
r"^(?P<enabled>#)*\s*" # Enabled/disabled
r"^(?P<enabled>#)*\s*" # Enabled/disabled
r"(?P<raw>"
r"(?P<action>%s)\s*" # Action
r"[^\s]*\s*" # Protocol
r"[^\s]*\s*" # Source address(es)
r"[^\s]*\s*" # Source port
r"[-><]+\s*" # Direction
r"[^\s]*\s*" # Destination address(es)
r"[^\s]*\s*" # Destination port
r"(?P<action>%s)\s*" # Action
r"[^\s]*\s*" # Protocol
r"[^\s]*\s*" # Source address(es)
r"[^\s]*\s*" # Source port
r"(?P<direction>[-><]+)\s*" # Direction
r"[^\s]*\s*" # Destination address(es)
r"[^\s]*\s*" # Destination port
r"\((?P<options>.*)\)\s*" # Options
r")"
% "|".join(actions))
@@ -99,6 +99,8 @@ class Rule(dict):
- **action**: The action of the rule (alert, pass, etc) as a
string
- **direction**: The direction string of the rule.
- **gid**: The gid of the rule as an integer
- **sid**: The sid of the rule as an integer
@@ -127,6 +129,7 @@ def __init__(self, enabled=None, action=None):
dict.__init__(self)
self["enabled"] = enabled
self["action"] = action
self["direction"] = None
self["gid"] = 1
self["sid"] = None
self["rev"] = None
@@ -183,6 +186,7 @@ def parse(buf):
rule = Rule(enabled=True if m.group("enabled") is None else False,
action=m.group("action"))

rule["direction"] = m.group("direction")
options = m.group("options")
for p in option_patterns:
for opt, val in p.findall(options):
1 change: 1 addition & 0 deletions tests/test_rule.py
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ def test_parse1(self):
rule = idstools.rule.parse("""alert tcp $HOME_NET any -> $EXTERNAL_NET $HTTP_PORTS (msg:"ET CURRENT_EVENTS Request to .in FakeAV Campaign June 19 2012 exe or zip"; flow:established,to_server; content:"setup."; fast_pattern:only; http_uri; content:".in|0d 0a|"; flowbits:isset,somebit; flowbits:unset,otherbit; http_header; pcre:"/\/[a-f0-9]{16}\/([a-z0-9]{1,3}\/)?setup\.(exe|zip)$/U"; pcre:"/^Host\x3a\s.+\.in\r?$/Hmi"; metadata:stage,hostile_download; reference:url,isc.sans.edu/diary/+Vulnerabilityqueerprocessbrittleness/13501; classtype:trojan-activity; sid:2014929; rev:1;)""")
self.assertEqual(rule.enabled, True)
self.assertEqual(rule.action, "alert")
self.assertEqual(rule.direction, "->")
self.assertEqual(rule.sid, 2014929)
self.assertEqual(rule.rev, 1)
self.assertEqual(rule.msg, "ET CURRENT_EVENTS Request to .in FakeAV Campaign June 19 2012 exe or zip")