-
Notifications
You must be signed in to change notification settings - Fork 1.6k
ModSecurity 3 and NginX-Connector only logging with SecRuleEngine On #1568
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
Comments
Update: In the DEBUG logs, I see the rules, this is for example my debug log with log level 9. Even the test rule is being matched, and the message shows that something should be written to the logs, but my /var/log/modsec_audit.log and /var/log/nginx/error.log stays empty.
|
Hi @aadlung, The audit logs should be saved while SecAuditEngine is On or RelevantOnly, however, SecAuditLogRelevantStatus is taking into consideration in both cases. The logs are saved by the end of the transaction, during logging phase. Check in your debug logs for something similar to this:
That should give you a hint why your logs are not being saved. |
I will check again - with Detection Only - no Logging Phase is executed in the debug logs, I do not find one. If I take the same configuration, just change the SecAuditEngine to On, everything works as expected. But I think I will have to play around maybe the RelevantStatus is used all the time as @zimmerle mentioned compared to the documentation.
Same config with "DetectionOnly":
|
Hi @aadlung, That is odd. The logging phase (as well the other phases), should be called regardless of the engine status. I will double check it. |
@aadlung can you share your nginx debug logs? it may help to identify what is going on with the request life cycle. |
@zimmerle you mean logs of nginx, so switching nginx to debug logging mode, or the logs of mod security in another logging mode? |
Hi @aadlung, It is about the nginx debug logs. It will be even better if you can also enable the ModSecurity-nginx connector debug logs. That could be done by changing it here: https://github.com./SpiderLabs/ModSecurity-nginx/blob/master/src/ddebug.h#L15-L18 Notice that the connector debug log will be saved all together with the nginx debug logs. |
@zimmerle I confirm the same problem - libmodsecurity is compiled with son support and the log is empty (in if it's detection only and turned on). Here is attached debug log on level 9. Please review it and instruct me what I can do. Thank you in advance. |
I am also getting nowhere with the audit.log, I have a FP in my implementation when "SecRuleEngine On" but I can't find it in any log when setting "SecRuleEngine DetectionOnly" so I can run live. nginx version: nginx/1.12.1 Also my modsecurity.conf is using OWASP rules and I have been alternating things like this below to try and trigger a clean log of the rule. #SecDefaultAction "phase:1,log,auditlog,deny,status:403" SecDefaultAction "phase:1,log,auditlog,pass" I can't get concurrent logging or serial to do anything for an actual rule violation event |
I discovered Modsecurity V3 can't logging when I custom the nginx 403 page. Maybe when we use custom error page,the nginx status code looks like 200? |
Hi all,
|
That is exactly what was causing no log to be written. However, I also can't run in 'SecRuleEngine DetectionOnly' mode, not getting any logging there no matter what. |
@zimmerle thank you about your reply. I provide you my configuration of nginx with custom page: server blocks Here is the custom 403 page:
Do you need additional information? I think this is enough. |
@zimmerle I stripped down the config to a minimalist one, lots of legacy if statements in it for old school wordpress security. When I reloaded with DetectionOnly on all is good. I'm not sure exactly what the culprit was/is but here is what was in the old included conf, which had a lot of useless stuff in it. |
@intelbg That's right ! When I used nginx custom 403 page with |
is there any progress on this case or eta? |
@zimmerle is it planned this problem to be fixed? If not can you please tell / orient me in which source file the problem may be to hire a programmer that can write a patch, because I had a deadline for this project and it's overdued? |
@zimmerle can you share your minimal configuration which works with mod_security and nginx, which can easily be tested by testparams or curl?
|
Regarding your information with the 2017/11/03 14:17:30 [info] 13034#13034: *443 [client 188.x.x.x] ModSecurity: Warning. Matched "Operator |
@zimmerle I think I can explain the issue now fairly simple: I had the modsecurity configuration in the But for sure, to catch PHP scripts and so on, I need to have it configured/included in the corresponding PHP-Location-Blocks as well, and all other blocks where I want to activate it. Not sure why I saw debug logging which shows the request in The only weird thing is that I see now ALL PHP requests in Audit Log, even if there is no debug log, the audit log stores the request, without any rule matched. Just to confirm, that's as expected? I should not have only 1 configuration for ModSecurity but it should be configured combined with the nginx `location´ blocks? |
please have a look on those two configuration files: [1] and [2]. As you can see those two configurations differ by the place where the error_page was added. Notice that in [1] ModSecurity rules will be valid for the error_page, which is not case of the example [2]. What seems to be happening is that your request was redirected to a nested location that was configured without any ModSecurity rule. Therefore, no logging was generated. If you place the error_page inside the same location block that you have ModSecurity, the audit_log will work as expected. |
@zimmerle I tried to move the error_page inside location / { block, but it does not work to me again. Is there any other dependent thing? |
@intelbg please share your new configuration. In our tests we are not able to reproduce it. |
In my new tests with the following configuration the logging works, but it's because the custom error page is ignored (can't figure out why) and the nginx default error page is used instead: location / {
|
Hi @intelbg, I am not sure why the custom error page is not being displayed. The scenario changes if you enable/disable ModSecurity? |
Hi ~ @zimmerle @intelbg ,
The custom error page can't be displayed.
It works well . I think it may be a bug . So I've been using second options . |
@zimmerle I tested now again and copy new vhost file with mod security enabled. Everything is ok and the custom error_page is displayed. After that I moved error_page in /location, restarted nginx and custom error_page was no more displayed. I then moved back error_page outside location / and custom display appeared again. The problem I think is not in the mod security about this, but this confirms that moving the error_page is not a solution. |
I found the right configuration. Please test you too to confirm it :)
location / {
modsecurity_rules_file /usr/local/nginx/conf/owasp-modsecurity-crs/modsec_includes.conf; With this the custom error_page works and modsec_audit logs works too. I am waiting for your confirmation. |
The mistake is mine :( The custom error page works, but not and the logging :( |
The original issue titled "ModSecurity 3 and NginX-Connector only logging with SecRuleEngine On" has proved to be a non-issue (#1568 (comment)). The discussion has moved to be related with custom 403 error page not working as expected specifically with the Nginx connector. This is a known issue and already being handled at owasp-modsecurity/ModSecurity-nginx#76. As such I'm assuming the initial issue has been resolved and the connector specific should be handled at owasp-modsecurity/ModSecurity-nginx#76. Please follow up on that issue. Thanks! |
Dear ModSecurity-Team,
I've setup ModSecurity 3 including the nginx connector. If I turn it on for testing with
SecRuleEngine On
- I get the audit log, and debug log, and blocking requests if rules match.If I just use
SecRuleEngine DetectionOnly
I do not get any audit or error log.Is this "as designed", or anything that needs to be turned on in addition? Even test rules do not trigger any logs, even with
SecAuditEngine On
.Regards,
Andy
The text was updated successfully, but these errors were encountered: