-
Notifications
You must be signed in to change notification settings - Fork 1.1k
WIP: Allow file change before syscheck raise an alert #790
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
Open
calve
wants to merge
13
commits into
ossec:master
Choose a base branch
from
calve:allowchange-publishable
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3ebc3b4
Stubs
calve e171885
Non working allow change command
calve ced08ce
Fix segfault
calve 6674edf
AllowChange events communication !
calve 07e858b
Produce and consume allow changes events
calve db43bb2
Set SYSCHECK_ALLOWED decoder
calve 991836f
Create the ALLOWCHANGE file if not exists
calve f6d8e9b
Raise rule 556 level to write an alert in alerts.log
calve df8a38a
Parse time as long
calve 3810cd9
Fix compilation
calve 4b63d91
Less sleep(), more debug()
calve 11880da
Read allowed change paths from stdin
calve bfa8770
Add missing syscheck-allowchange.h
calve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* Copyright (C) 2009 Trend Micro Inc. | ||
| * All right reserved. | ||
| * | ||
| * This program is a free software; you can redistribute it | ||
| * and/or modify it under the terms of the GNU General Public | ||
| * License (version 2) as published by the FSF - Free Software | ||
| * Foundation | ||
| */ | ||
|
|
||
| /* Syscheck decoder */ | ||
|
|
||
| #include "eventinfo.h" | ||
| #include "os_regex/os_regex.h" | ||
| #include "config.h" | ||
| #include "decoder.h" | ||
|
|
||
| /* We write allowed filenames in a database located at /queue/syscheck-allowchange/<agent> | ||
| * Each line represents an entry which is structured as | ||
| * <is_valid> <validity_timestamp> <path> | ||
| * where <is_valid> is either the char '0' or '1', | ||
| * and indicate whereas this entry have already been consummed. | ||
| */ | ||
|
|
||
|
|
||
| /* Determine if this filename have at least one allowed change, and | ||
| consumme it */ | ||
| int consumeAllowchange(const char *filename, Eventinfo *lf){ | ||
| FILE *db_file; | ||
| char db_filename[OS_FLSIZE]; | ||
| char line[OS_FLSIZE*2]; | ||
| int allowed = 0; | ||
| time_t current; | ||
| snprintf(db_filename, OS_FLSIZE , "%s/%s", ALLOWCHANGE_DIR, lf->hostname); | ||
| db_file = fopen(db_filename, "r+"); | ||
| if (!db_file) { | ||
| db_file = fopen(db_filename, "w+"); | ||
| if (!db_file) { | ||
| verbose("failed to open %s", db_filename); | ||
| return 0; | ||
| } | ||
| } | ||
| rewind(db_file); | ||
| current = time(0); | ||
|
|
||
| while (fgets(line, OS_FLSIZE*2, db_file) != NULL) { | ||
| /* Attempt to parse the line */ | ||
| int validity; | ||
| time_t until; | ||
| char path[OS_FLSIZE]; | ||
| sscanf(line, "%d %ld %s", &validity, &until, path); | ||
| if (validity) { | ||
| if (until > current) { | ||
| if (strcmp(path, filename) == 0){ | ||
| int len = strlen(line); | ||
| /* Rewrite current entry */ | ||
| fseek(db_file, -len, SEEK_CUR); | ||
| fprintf(db_file, "0"); | ||
| fclose(db_file); | ||
| return until; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fclose(db_file); | ||
| return allowed; | ||
| } | ||
|
|
||
| /* Save an Allowchange record in our "database" | ||
| */ | ||
| int produceAllowchange(time_t timestamp, const char *filename, Eventinfo *lf){ | ||
| FILE *db_file; | ||
| char db_filename[OS_FLSIZE]; | ||
| snprintf(db_filename, OS_FLSIZE , "%s/%s", ALLOWCHANGE_DIR, lf->hostname); | ||
| db_file = fopen(db_filename, "a"); | ||
| if (db_file) { | ||
| fprintf(db_file, "%d %ld %s\n", 1, timestamp, filename); | ||
| fclose(db_file); | ||
| return timestamp; | ||
| } | ||
| verbose("Failed to open %s", db_filename); | ||
| return 0; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| /* A special decoder to read an AllowChange event */ | ||
| int DecodeAllowchange(Eventinfo *lf) | ||
| { | ||
| time_t timestamp; | ||
| char *f_name; | ||
|
|
||
| /* Allowchange messages must be in the following format: | ||
| * timestamp filename | ||
| */ | ||
| f_name = strchr(lf->log, ' '); | ||
| if (f_name == NULL) { | ||
| merror(SK_INV_MSG, ARGV0); | ||
| return (0); | ||
| } | ||
|
|
||
| /* Zero to get the timestamp */ | ||
| *f_name = '\0'; | ||
| f_name++; | ||
|
|
||
| /* Get timestamp */ | ||
| timestamp = atoi(lf->log); | ||
| produceAllowchange(timestamp, f_name, lf); | ||
| return timestamp; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #ifndef __SYSCHECK_ALLOW_H | ||
| #define __SYSCHECK_ALLOW_H | ||
|
|
||
| #include "shared.h" | ||
|
|
||
| int consumeAllowchange(const char *filename, Eventinfo *lf); | ||
| int produceAllowchange(time_t timestamp, const char *filename, Eventinfo *lf); | ||
| int DecodeAllowchange(Eventinfo *lf); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is an entirely new file, you should probably take ownership.