Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Review severity levels of CRS to make sure all rules have severity levels #610

Closed
csanders-git opened this issue Oct 11, 2016 · 32 comments
Closed
Assignees

Comments

@csanders-git
Copy link
Contributor

No description provided.

@csanders-git csanders-git added this to the CRS v3.1.0 RC1 milestone Oct 11, 2016
@lifeforms
Copy link
Contributor

lifeforms commented Oct 11, 2016

Hopefully we could lint the rules automatically.

I currently use the following primitive script to detect missing tags and severities:

# check missing attack tags
./cont.py rules/*.conf|grep ^SecRule|grep -v TX:PARANOIA_LEVEL|grep -v id:980|grep -v id:901|grep -v id:900|grep -v 959100|grep -v skipAfter|grep -v attack-|grep -o id:\\d\\+
# check missing severity tags
./cont.py rules/*.conf|grep ^SecRule|grep -v TX:PARANOIA_LEVEL|grep -v id:980|grep -v id:901|grep -v id:900|grep -v 959100|grep -v skipAfter|grep -v severity|grep anomaly|grep -o id:\\d\\+
# check wrong severities
./cont.py rules/*.conf|grep ^SecRule|grep -v TX:PARANOIA_LEVEL|grep -v id:980|grep -v id:901|grep -v id:900|grep -v 959100|grep -v skipAfter|grep critical_anomaly|grep -v CRITICAL|grep -o id:\\d\\+
./cont.py rules/*.conf|grep ^SecRule|grep -v TX:PARANOIA_LEVEL|grep -v id:980|grep -v id:901|grep -v id:900|grep -v 959100|grep -v skipAfter|grep warning_anomaly|grep -v WARNING|grep -o id:\\d\\+

cont.py just glues lines with \ together so any rule is one line:

#!/usr/bin/env python

import fileinput, sys

for line in fileinput.input():
    line = line.strip()
    if line == '':
        sys.stdout.write("\n")
        continue

    if line[-1] == '\\':
        sys.stdout.write(line[0:-1])
    else:
        sys.stdout.write(line)
        sys.stdout.write("\n")

@csanders-git
Copy link
Contributor Author

Yeah i'm pretty much all but ready to have a serious linter as part of the travis CI integration that i plan to roll out soon :)

@emphazer
Copy link
Contributor

emphazer commented Oct 12, 2016

@lifeforms that python script is a nice and dirty way to fix the newline problems with the apache < 2.4 bug https://bz.apache.org/bugzilla/show_bug.cgi?id=55910
for rhel7/centos7
:-)
thx

@dune73
Copy link
Contributor

dune73 commented Oct 12, 2016

This is aimed for 3.1.0 and I - sorry for repeating myself - think it needs to be part of a bigger initiative doing the following:

  • reformat all rules 100% consistently
  • check severities
  • re-order actions by a strict policy which we will have to discuss and define beforehand
  • have a clear transformation concept and apply it consistently
  • comb all rule messages and update as appropriate
  • check all logdata actions and do housekeeping

Otherwise, I welcome this completely.

@csanders-git
Copy link
Contributor Author

csanders-git commented Oct 12, 2016

:-D i'm glad this ticket has lots of traction - I think it would behoove us to use a proper parser for this and not just make it dirty, that way we can say 100% this will work in ModSecurity (at least 3, i can't speak for apache :-P )

@lifeforms
Copy link
Contributor

lifeforms commented Oct 12, 2016

Yeah using the modsec parser would be very cool to do rule validation. At the other hand, the parser might not retain source information such as spacing and lines conventions, so we'll probably want both stupid and smart scripts :)

@csanders-git
Copy link
Contributor Author

Absolutely @lifeforms -- I literally cannot wait to have TavisCI running on our code and making sure we don't have little issues, like missing regression tests, bad formatting, etc.... we're gonna #devops so hard with 3.1 :)

@dune73
Copy link
Contributor

dune73 commented Oct 12, 2016

How about the python module to pull this off?

@csanders-git
Copy link
Contributor Author

Thats what i was thinking @dune73 - it'd be great if it was in python since the rest of the project pretty much is. I really wanted to straight up convert the parser from c++ to python but the python regex engine is different :( so a little work there

@dune73
Copy link
Contributor

dune73 commented Oct 12, 2016

Way to go then.

@csanders-git
Copy link
Contributor Author

Haven't started yet but for CRS 3.1 this is a must in my opinion, i'm sure once we push 3.0.0 we'll have a nice long break and a conversation about what should make the cut :)

@dune73
Copy link
Contributor

dune73 commented Oct 12, 2016

Yes, I suggest we rent a boat in the Carribean somewhere and talk it out - for a week or two. ;)

On a more serious note, I think we have to force ourselves to clean out the pile of old issues before we touch anything 3.1.

@csanders-git
Copy link
Contributor Author

good idea about cleaning out the log .... if the flight wouldn't be so expensive for you two i'd do the boat trip, I could use one :-P Maybe i'll go to the next AppSec EU instead :)

@dune73
Copy link
Contributor

dune73 commented Oct 12, 2016

I'm seeing myself at the AppSecEU as well next year. It's been a while.

@dune73
Copy link
Contributor

dune73 commented Oct 12, 2016

I see it's Belfast. Hmm. Never been to Ireland. But it's like half way to the Caribbean. Makes me think...

@fzipi
Copy link
Contributor

fzipi commented Oct 2, 2019

@dune73 What is remaining to do here? Maybe we can have a pass of airween 's magical tool here also, identifying what changes remain?

@fzipi fzipi self-assigned this Oct 2, 2019
@airween
Copy link
Contributor

airween commented Oct 3, 2019

What do you think about this? (List of severity levels at every rule.)

If you have any idea, just let me know.

@fzipi
Copy link
Contributor

fzipi commented Oct 3, 2019

What I see is that there are lots of rules without severity 😮

@fgsch
Copy link
Contributor

fgsch commented Oct 3, 2019

I think a lot of the rules missing severity are the paranoia level checks.
Could we exclude those from the list?

@dune73
Copy link
Contributor

dune73 commented Oct 3, 2019

Yes, the rule IDs below xxx100 probably don't need the severity.

I made some comment above what else needs to be done. I stand by that comment, but I think it should not keep this issue back. Let's get this over and do the rest afterwards.

@airween
Copy link
Contributor

airween commented Oct 3, 2019

Yes, the rule IDs below xxx100 probably don't need the severity.

Right, it's important info. Any other criteria? I mean, severity needs only if rule contains any disruptive action?

@dune73
Copy link
Contributor

dune73 commented Oct 3, 2019

I'd skip the rule files below 910 and also 949, 959 and 980.

@fgsch
Copy link
Contributor

fgsch commented Oct 3, 2019

Perhaps rather than skipping ranges we could exclude some of these files altogether?

@dune73
Copy link
Contributor

dune73 commented Oct 3, 2019

That's what I tried to express, yes.

@fgsch
Copy link
Contributor

fgsch commented Oct 3, 2019

Sorry, I can't read. Reading it again, your comment was clear.

@airween
Copy link
Contributor

airween commented Oct 3, 2019

Table updated.

The used filter was:

    if ruleid%1000 >= 100 and
        round(current_ruleid/1000) not in [949, 959, 980] and
        round(current_ruleid/1000) > 910 and
        current_ruleid < 1000000

Tha last condition filters out the rules with id 900NNNN...

@annawinkler
Copy link
Contributor

I would be happy to help out with this issue. I was talking with @airween about it and I can take an initial go at updating the rules in the range listed. Are there any other suggested heuristics for setting the severity?

@airween
Copy link
Contributor

airween commented Oct 31, 2019

After dissussing with @fgsch I updated the table.

This table also filtered the rules with this condition:

if current_ruleid%1000 >= 100 and
        round(current_ruleid/1000) not in [949, 959, 980] and
        round(current_ruleid/1000) > 910 and
        current_ruleid < 1000000

The concept what I checked: the code follows the used PL (which controlled with a special rule what checks the TX:EXECUTING_PARANOIA_LEVEL variable) (this is the column F). It collects the used severity action's value (column G). Column E shows the disruptive actions (if exists) or pass, for help. Column H contains the used variable name at setvar action, eg tx.anomaly_score_pl1, and column I shows the given value (also in that setvar action), eg: +%{tx.notice_anomaly_score}'.

If the used PL not equals with variable name (column F and H) then it marked in column J.

If the given severity level not equals with variable value (column G and I) then it marked in column K.

I think I still can't decide when needs a rule any severity action, that's why I put this info into column E.

Hope it will helpfully :).

@fgsch
Copy link
Contributor

fgsch commented Nov 4, 2019

Meeting outcome: @airween with make sure this issue is solved together with Anna.

@airween
Copy link
Contributor

airween commented Feb 3, 2020

Updated the table, please review this issue the next monthly chat.

@dune73
Copy link
Contributor

dune73 commented Mar 4, 2020

Decision during the CRS project chat on March 2, 2020: @lifeforms will sort this out.

#1683 (comment)

@lifeforms
Copy link
Contributor

Addressed in #1732. Thanks for the help, everyone!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants