Fix alert email sending when no_full_log option is set in a rule#3174
Fix alert email sending when no_full_log option is set in a rule#3174chemamartinez merged 20 commits into3.10from
Conversation
|
|
I added the inclusion of the full JSON alert when |
|
Hi team! I add a new commit to modify an email alert format. Both Some email examples are: And netstat listening ports rule: Regards, |
|
Hi! The Windows Eventchannel alerts will show as follows: And Sysmon rule with And this is how you see some alerts in the same message: Regards, |
|
Hello team! Following examples are Syscheck alert emails: And this is how you see two Syscheck alerts in the same message: And this is how you see two Windows Syscheck alerts: Regards, |
| { | ||
| int i = 0, sms_set = 0, donotgroup = 0; | ||
| size_t body_size = OS_MAXSTR - 3, log_size; | ||
| size_t *body_size = malloc(sizeof(size_t)), log_size; |
There was a problem hiding this comment.
Use os_malloc() instead of calling malloc directly. Same for the others occurrences.
| if (!(rule = cJSON_GetObjectItem(al_json, "rule"), rule && (mail_flag = cJSON_GetObjectItem(rule, "mail"), mail_flag && cJSON_IsTrue(mail_flag)))) | ||
| goto end; | ||
|
|
||
|
|
There was a problem hiding this comment.
Remove this whiteline
| // Add alert to logs | ||
| char *tab = malloc(14*sizeof(char)); | ||
| strcpy(tab, "\t"); | ||
| cJSON_PrintTable(al_json, logs, body_size, tab, 2); |
There was a problem hiding this comment.
Change the name of the function. cJSON_X() can lead to a think it belongs to the cJSON library.
| { | ||
| char *val1 = NULL, *val2 = NULL; | ||
| int log_size; | ||
| char *t = malloc(14*sizeof(char)); |
There was a problem hiding this comment.
It's the maximum number of times it can be tabulated.
| char *val1 = NULL, *val2 = NULL; | ||
| int log_size; | ||
| char *t = malloc(14*sizeof(char)); | ||
| strcpy(t, tab); |
| } | ||
| } | ||
|
|
||
| if(dep < 12){ |
There was a problem hiding this comment.
dep refers to the depth of the search in the incoming JSON? If so, it should not be limited.
There was a problem hiding this comment.
It's the number of times it's been tabulated. I have modified the variable name so that there is no confusion.
|
Hi! It needs a new review. I have added changes requested, and fixed invalid read and invalid free. I attach Valgrind log file: Regards, |
|
Hello team! I've added the following modifications:
If Syscheck alert hasn't This change is due that when Syscheck alert has As shown, Sha1sum, Sha256sum, and Md5sum are duplicated.
Test Valgrind: Regards, |
|
Hi! Also, I attach Eventchannel alerts: Regards, |
|
Defects found by building with
|
There was a problem hiding this comment.
Let's continue using Portion of the log(s), in many cases is the full_log field the printed data.
There was a problem hiding this comment.
Why counter should be less than 12? We have to allow more tabs by default.
There was a problem hiding this comment.
Add the explicit check of the json_field content. Some gcc versions complain about this:
os_maild/os_maild_client.c: In function ‘OS_RecvMailQ_JSON’:
os_maild/os_maild_client.c:389:8: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
if(json_field = cJSON_GetObjectItem(al_json,"full_log")){
^~~~~~~~~~
By adding:
if(json_field = cJSON_GetObjectItem(al_json,"full_log"), json_field){
we avoid the error
There was a problem hiding this comment.
Same as above:
else if (json_object = cJSON_GetObjectItem(al_json,"syscheck"), json_object){
There was a problem hiding this comment.
Same:
while(json_array = cJSON_GetArrayItem(item, i), json_array){
There was a problem hiding this comment.
Define log_size as size_t to avoid these errors:
os_maild/os_maild_client.c:808:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (body_size > log_size) {
Author: DaveVG1 <vgdavid91@gmail.com> Committer: DaveVG1 <vgdavid91@gmail.com>
2c2fbf6 to
cdde86f
Compare
|
Hi! I've subjected Maild generates about 12 emails per second. Regards, |
This fixes #3163 and #3762
Fix
no_full_logoption weren't working.Testing
Rule configuration
This rule has been included in
/var/ossec/etc/rules/local_rules.xml:To trigger the alert that matches this rule the following log has been concatenated to
/var/log/syslog(Ubuntu):Valgrind report
Result
An alert mail that's been triggered by a rule that has the
no_full_logoption, now look like this: