-
Notifications
You must be signed in to change notification settings - Fork 1.7k
mlogc can't parse entry #2682
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
Hello @bozhinov , I haven't investigated your report in any detail, but ... There are some line-length limits in the overall functionality, and some CRS rules can result in very long lines due to their use of tags. One thing you could try is to experimentally remove several of the 'tag:' lines from the relevant rules so that the resultant log line is much shorter. I'm not predicting that that is your problem, but it's something pretty easy to try and either confirm or rule out. Something else curious is the mlogc.c that you linked to at the outset. I'm curious as to how you got there. It appears to be a much older version of mlog.c that is in v2/master (or v2.9.5), ... and with a different path ( https://github.com/SpiderLabs/ModSecurity/blob/1dd1c6defd635625537ff8865b1ee47a4d89c733/mlogc/mlogc.c#L96 ) |
I was looking for the source code for mlogc to check what that regex pattern was that failed By the way I have a fairly standard setup - so I m guessing not much use of mlogc on Windows Thank you for the tip. Will test is as soon as I can and provide feedback |
OK. so no change after removing all tags from the rule I hit with the test url |
I have the same error. I updated Apache and mod_security2. Before update everything was ok. After update with error: |
Posting one or more (minimal, and without any secure information) log entries that cause this failure might help. Any nonprintable characters should be included clearly. A likely avenue of investigation here is around line endings. This could be related to the normal difference between Windows and Linux, PCRE options related to line endings, or both. |
@martinhsv It's not a particular entry. mlogc failed on every entry. I updated one of three apache server without configuration change. Before update the same entrys were transfered correctly. |
@martinhsv |
After some tests I think it is the log entries timestamps that triggers the regex error: |
The logline_pattern in mlogc.c should be modified:
or the timestamp format should be modified to the 2.9.3 format. |
The new timesstamp format was added in mod_security 2.9.4 with issue #2095 . |
Thanks for digging into that @ABrauer-CPT . I think you've found the explanation. I'll put that into a pull request. |
Hello @martinhsv, I don't really know if it's enough to change
I could not determine how the timestamp regex-group would be processed in the rest of the code. |
Thanks again. Let me know if you encounter any difficulties. |
To test go to: download removed |
Thanks @martinhsv and @SteffenAL . I tested this patch. [12/May/2022:10:27:55.-123245 +0200] We should add something like "-?" |
Or is this a bug and the timestamp should never include a negative value? |
I cannot see any reason why the microsecond portion of the timestamp could ever make sense as a negative number. It smells like a bug independent of the regex adjusted as part of this issue. |
I had a look at the code and did not see any obvious bugs. Also I tried to reproduce the reported effect but, even with thousands of requests, I was not able to do so; the '-' never appeared. |
I could reproduce this problem on Windows with this code snippet:
|
I suspect the cast '(long)now'. The value returned by apr_time_now() is explicitly 64 bits, but I expect in your case (on Windows) the type 'long' is only 32 bits. This would explain why my test on Linux+Apache+ModSecurity v2 did not have the problem. |
I think you found the "bug". Perhaps someone with more programming experience could confirm this. |
Hi @ABrauer-CPT I have created a pull request ( #2753 ) for that issue if you want to test it out in Windows. (I have run some tests on it but not in a Windows setup.) |
Thanks @martinhsv Perhaps @SteffenAL from Apachelounge could compile the modsecurity module with this patch to test the complete processing. |
For test, see https://www.apachelounge.com/viewtopic.php?p=41253#41253 |
I tested this patch in our environment and it works without errors. I have an eye on it in the next days but I think we found all bugs. Many thanks to @martinhsv and @SteffenAL . Great work! |
Thanks for the assistance with verification. #2753 has been merged. |
Hello,
I have Apache 2.4.52 x64 from apachelounge.com with mod_security 2.9.5 (CRS 3.3.2), both of them compiled with PCRE 8.45
I get "Invalid entry (failed to match regex)" when trying to use mlogc
I m not even gonna pretend I can eval this regex:
https://github.com/SpiderLabs/ModSecurity/blob/a06d8f8ce74d423885a1f09a74c060bb21dd7485/apache2/mlogc-src/mlogc.c#L97
Here is my httpd.conf:
SecRuleEngine On
SecDataDir /tmp
Include conf/owasp-modsecurity-crs/crs-setup.conf
Include conf/owasp-modsecurity-crs/rules/*.conf
SecAuditEngine RelevantOnly
SecAuditLogRelevantStatus ^2-5
SecAuditLogParts ABCDEFGHZ
SecAuditLogType Serial
SecAuditLog "|bin/mlogc.exe conf/mlogc.conf"
and my mlogc.conf:
CollectorRoot "C:/APACHE/logs"
ConsoleURI "https://127.0.0.1:9000/rpc/auditLogReceiver"
SensorUsername "test"
SensorPassword "testtest"
LogStorageDir "data"
TransactionLog "mlogc-transaction.log"
QueuePath "mlogc-queue.log"
ErrorLog "mlogc-error.log"
LockFile "mlogc.lck"
KeepEntries 0
ErrorLogLevel 2
MaxConnections 10
MaxWorkerRequests 1000
TransactionDelay 50
StartupDelay 5000
CheckpointInterval 15
ServerErrorTimeout 60
I tried with different values for SecAuditLogParts but it did not seem to help
Log here:
https://bojinov.info/mlogc-error.log
Steps to reproduce the behavior:
A curl command line that mimics the original request and reproduces the problem
https://x.x.x.x/aphpfilethatdonotexist.php?something=../../etc
What am I doing wrong ?
Momchil
The text was updated successfully, but these errors were encountered: