Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you calculate the number of rules in CRS? #3

Closed
yashhere opened this issue May 27, 2019 · 4 comments
Closed

How do you calculate the number of rules in CRS? #3

yashhere opened this issue May 27, 2019 · 4 comments

Comments

@yashhere
Copy link

Hi, I am trying to reproduce the results given on the wiki page. But I am not able to get the number of rules in CRS that you have posted on the very bottom of the wiki page. It says that CRS v3.1.0 has 1634 rules. How did you calculate this? I tried calculating, but I am getting 847 as a result. I used the following command -

# running it in the rules directory of CRS
grep -c "Sec" *.conf | cut -d':' -f2 | awk '{total = total + $1}END{print total}'

I think I am missing something here. Can you share your method/command of counting the number of rules? It would be of great help.

Thank you :)

@defanator
Copy link
Owner

@yashhere a number comes from total amount of loaded rules, and the default nginx.conf in this environment contains two locations with modsecurity_rules_file: https://github.com/defanator/modsecurity-performance/blob/master/states/files/etc/nginx/nginx.conf#L86 and https://github.com/defanator/modsecurity-performance/blob/master/states/files/etc/nginx/nginx.conf#L92.

You may check the following code to see how it's being calculated:
https://github.com/SpiderLabs/ModSecurity-nginx/blob/master/src/ngx_http_modsecurity_module.c#L316-L317
https://github.com/SpiderLabs/ModSecurity-nginx/blob/master/src/ngx_http_modsecurity_module.c#L350-L351
https://github.com/SpiderLabs/ModSecurity-nginx/blob/master/src/ngx_http_modsecurity_module.c#L389-L390

That is, you see the exact number of loaded rules as they are being represented architecturally within the library.

(Tagging @zimmerle for visibility.)

@yashhere
Copy link
Author

I was thinking that the number of rules is the total number of rules in CRS, not the rules that are actually loaded in ModSecurity. That's why I was trying to grep the occurrences of the word "Sec" to get the approximate count of all the rules. Still, from my testing, the word "Sec" occurs for ~847 times in CRS, so at any time, the number of loaded rules in ModSecurity cannot be more than 847, provided that a rule can't be loaded twice (which is actually the case, if I am not wrong). Then how are you getting almost twice of my result? Is it because of the fact, that the main.conf is used two times for two different URL paths (/modsec-full and /modsec-full/upload) and you take both these configurations into account while calculating the numbers?

@defanator
Copy link
Owner

@yashhere rules are tied to an object of nginx configuration (which can be separated by levels, e.g. http, server, location, etc), so when you're loading even the identical modsecurity configuration from the same file into two different contexts (locations, servers), you'll get a sum of rules.

You can check nginx development guide for the configuration parts here:
http://nginx.org/en/docs/dev/development_guide.html#http_conf

@defanator
Copy link
Owner

re: "a rule can't be loaded twice" - in fact, it can (cc'ing @zimmerle again to confirm)

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

No branches or pull requests

2 participants