-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Add Libsodium sodium support for sha256 filehashes #1381
Open
ddpbsd
wants to merge
113
commits into
ossec:master
Choose a base branch
from
ddpbsd:libsodium
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
113 commits
Select commit
Hold shift + click to select a range
523acdb
Add USE_LIBSODIUM to the Makefile
ddpbsd e1468ea
Start to add options for allowing different FIM hashes to be used.
ddpbsd 201bc61
Don't allow sha256 in non-sodium builds.
ddpbsd 1fa3d1e
Silence a clang warning.
ddpbsd 26c27e1
Make sure msg is initialized.
ddpbsd a9e725b
Merge branch 'master' of https://github.com/ossec/ossec-hids into lib…
ddpbsd a5452f9
Try to use libsodium to allow us to check sha256 hashes.
ddpbsd 882058b
Fix a typo
ddpbsd 09b44ce
xml_check_sha256sum is not used
ddpbsd fbcd126
randombytes -> OS_randombytes. There is a randombytes() in libsodium …
ddpbsd 7e91526
Fix-up the sha256 stuff. It compiles. Testing will begin shortly.
ddpbsd a556191
Merged into md5_sha1_op.c.
ddpbsd bd9fa4d
randombytes() -> OS_randombytes(). libsodium has a randombytes() too
ddpbsd fb1ac49
Add some more libsodium bits.
ddpbsd ce552d3
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd 765b499
alg_output -> hash_output
ddpbsd 9b339f8
OS_algorithms_File -> OS_Hash_File
ddpbsd a978513
Make sure we don't set the output for a hash if we aren't checking
ddpbsd b728cf5
sprintf->snprintf
ddpbsd da38953
Don't run the check if the md5 is 'xxx'
ddpbsd 3dbaf31
Not sure what I was thinking, but correct a stupid typo.
ddpbsd c75e255
Go about this in a slightly different way.
ddpbsd 98b4e64
Closer to supporting sha256
ddpbsd 54cdbd4
The basic idea is to have hash1 and hash2. Then the hash strings
ddpbsd 1134eaa
Add some more libsodium bits to create_db.c.
ddpbsd 9b1b3eb
I think sha256 is working.
ddpbsd e7e4b1a
Remove some debugging printfs
ddpbsd a166003
Merge branch 'master' of https://github.com/ossec/ossec-hids into lib…
ddpbsd 2dfc8d6
Make this actually compile.
ddpbsd 4910ca6
sqlite
ddpbsd 80a960a
Add some explicit nul terminators
ddpbsd d0b0050
More sha256 work. Still lots of debug stuff.
ddpbsd 69945bd
Remove some debugging.
ddpbsd de70834
Get rid of some debug stuff.
ddpbsd 17470fd
More debugging
ddpbsd 2d488e1
Correctly deal with these variables.
ddpbsd 6fe831a
Oops, I prefer -ggdb to -g, so I often change it and switch back before
ddpbsd 40815a3
Linux didn't like writing a variable to itself with snprintf, so
8e5401c
Spacing
ddpbsd 241817e
Make sure sodium.h isn't added if we're not in LIBSODIUM_ENABLED
ddpbsd c323f46
Disable these for now. The idea isn't fully fleshed out yet.
ddpbsd fd65186
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd d1ca9f3
Try to do tests for libsodium and sqlite
ddpbsd 869d653
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd 54b5df1
CID 166736: Ignoring number of bytes read
ddpbsd 1df3fb7
CID 153424: Buffer not null terminated
ddpbsd 01a28e7
CID 28500: Resource leak
ddpbsd 53c586c
CID 28511: Resource leak
ddpbsd e053db8
Merge branch 'master' of https://github.com/ossec/ossec-hids into cov…
ddpbsd a451d8e
spaces -> tabs
ddpbsd efe31a5
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd 258fe5d
Merge branch 'coverity_20180411' of github.com:ddpbsd/ossec-hids into…
ddpbsd 9d74ff7
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd 4f044a3
Close fp before leaving GetRandomNoise()
ddpbsd e16624b
Clarify calculation precedence for '&' and '?'.
ddpbsd e98f71c
The rest of the "Clarify calculation precedence for '&' and '?'" commit.
ddpbsd 02ff1ba
No libsodium-dev or libsodium in Trusty? There's a ppa for that!
ddpbsd 274b56b
md5->sha256
ddpbsd 7990e9e
Get rid of hash1 and hash2. Bad idea.
ddpbsd 4df6e64
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd 7a9f8a8
From codacy
ddpbsd fc54a34
Get rid of hash1, hash2.
ddpbsd cd7831c
Adjust
ddpbsd 6dfc111
Force add the libsodium repository
ddpbsd 827a62a
I'll get this right eventually.
ddpbsd a157c31
Try this again.
ddpbsd db2c5b7
Makes testing easier
ddpbsd e8d7873
Don't mention blake2b in case libsodium changes their generic algorithm.
ddpbsd b2923f6
Add libsodium's generichash (blake2b right now)
ddpbsd bb3a7e7
Start to add blake2b
ddpbsd 51f61ee
Make opts available everywhere.
ddpbsd 1edbff1
Start to make sure this reports everything properly.
ddpbsd 028ac28
Caused a crash in reportd
ddpbsd 992f532
I need these right now
ddpbsd bd7cf0a
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd fdadbef
Looks like I was previously truncating the SHA256 and GENERIC hash
ddpbsd b3088db
Generichash wasn't named in the log output.
ddpbsd 50aa923
Make sure the generic hash is written to new_hashes.
ddpbsd 4347d84
Remove my debug stuff.
ddpbsd 3a230d7
Remove some debugging stuff.
ddpbsd a36f047
This doesn't have to be extern here
ddpbsd 1682c31
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd 80381a0
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd e63681a
The variable should be sha256 not generic.
ddpbsd ae89927
Increase the alert_msg size from 916 to 2048 in some places.
ddpbsd 6835e83
Try to push the correct sums to run_check.
ddpbsd a5244f9
Add some more debugging.
ddpbsd 16effe5
Instead of passing syscheck_opts around (which I didn't do correctly)
ddpbsd 72d0ffb
I forgot to copy new_hashes_tmp to new_hashes like a moron.
ddpbsd 6252474
Remove the poorly done syscheck_opts idea. I switched to passing
ddpbsd 6302c1c
Remove more debugging stuff.
ddpbsd 792dea6
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd 5d5e806
Add the hash names into the hash output so that we know what we're
ddpbsd b2af210
Merge branch 'master' of https://github.com/ossec/ossec-hids into lib…
ddpbsd a38f439
Get rid of some debugging.
ddpbsd c02f109
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd ab95af3
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd e6f2fd5
Merge branch 'master' of github.com:ossec/ossec-hids into libsodium
ddpbsd 00b6de1
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd 9b5ddc7
Missed a conflict.
ddpbsd f803934
Merge branch 'libsodium' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd 4e2b2bf
Merge branch 'master' of github.com:ossec/ossec-hids into libsodium
ddpbsd 5b6f673
Fix this reference.
ddpbsd fe1dd8f
Handle the different hash types better.
ddpbsd bd5cc78
Remove some debugging
ddpbsd 136e7f3
Update the hash sizes
ddpbsd 5092227
I'm not sure why I thought strncat worked like that.
ddpbsd 823a0e4
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd 86f23ff
Make sure we can handle md5 and sha1 in libsodium mode too.
ddpbsd 425391c
I'm not sure there is enough space for the blake2b hash, so default
ddpbsd 0cc90b4
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd 3082ed5
Missed a white->allow change.
ddpbsd 17e2a2b
Merge branch 'master' of github.com:ddpbsd/ossec-hids into libsodium
ddpbsd 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 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
.DS_Store | ||
*.dll | ||
*.exe | ||
*.core | ||
|
||
# Auto generated build files | ||
src/LOCATION | ||
|
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -160,6 +160,8 @@ static int read_attr(syscheck_config *syscheck, const char *dirs, char **g_attrs | |
const char *xml_check_sum = "check_sum"; | ||
const char *xml_check_sha1sum = "check_sha1sum"; | ||
const char *xml_check_md5sum = "check_md5sum"; | ||
const char *xml_check_sha256sum = "check_sha256sum"; | ||
const char *xml_check_genericsum = "check_genericsum"; | ||
const char *xml_check_size = "check_size"; | ||
const char *xml_check_owner = "check_owner"; | ||
const char *xml_check_group = "check_group"; | ||
|
@@ -220,19 +222,39 @@ static int read_attr(syscheck_config *syscheck, const char *dirs, char **g_attrs | |
attrs = g_attrs; | ||
values = g_values; | ||
|
||
#ifdef LIBSODIUM_ENABLED | ||
#ifdef DEBUG | ||
merror("DEBUG: libsodium enabled"); | ||
#endif //DEBUG | ||
#endif //LIBSODIUM_ENABLED | ||
|
||
while (*attrs && *values) { | ||
/* Check all */ | ||
if (strcmp(*attrs, xml_check_all) == 0) { | ||
if (strcmp(*values, "yes") == 0) { | ||
#ifdef LIBSODIUM_ENABLED | ||
opts |= CHECK_PERM; | ||
opts |= CHECK_SIZE; | ||
opts |= CHECK_OWNER; | ||
opts |= CHECK_GROUP; | ||
opts |= CHECK_SHA256SUM; | ||
opts |= CHECK_MD5SUM; | ||
#else //LIBSODIUM_ENABLED | ||
opts |= CHECK_SHA1SUM; | ||
opts |= CHECK_MD5SUM; | ||
opts |= CHECK_PERM; | ||
opts |= CHECK_SIZE; | ||
opts |= CHECK_OWNER; | ||
opts |= CHECK_GROUP; | ||
#endif //LIBSODIUM_ENABLED | ||
} else if (strcmp(*values, "no") == 0) { | ||
#ifdef LIBSODIUM_ENABLED | ||
opts &= ~ ( CHECK_MD5SUM | CHECK_SHA1SUM | CHECK_PERM | ||
| CHECK_SIZE | CHECK_OWNER | CHECK_GROUP | CHECK_SHA256SUM | CHECK_GENERIC ); | ||
#else //LIBSODIUM_ENABLED | ||
opts &= ~ ( CHECK_MD5SUM | CHECK_SHA1SUM | CHECK_PERM | ||
| CHECK_SIZE | CHECK_OWNER | CHECK_GROUP ); | ||
#endif //LIBSODIUM_ENABLED | ||
} else { | ||
merror(SK_INV_OPT, __local_name, *values, *attrs); | ||
ret = 0; | ||
|
@@ -242,10 +264,20 @@ static int read_attr(syscheck_config *syscheck, const char *dirs, char **g_attrs | |
/* Check sum */ | ||
else if (strcmp(*attrs, xml_check_sum) == 0) { | ||
if (strcmp(*values, "yes") == 0) { | ||
#ifdef LIBSODIUM_ENABLED | ||
opts |= CHECK_SHA256SUM; | ||
opts |= CHECK_GENERIC; | ||
#else //LIBSODIUM_ENABLED | ||
opts |= CHECK_MD5SUM; | ||
opts |= CHECK_SHA1SUM; | ||
#endif //LIBSODIUM_ENABLED | ||
|
||
} else if (strcmp(*values, "no") == 0) { | ||
#ifdef LIBSODIUM_ENABLED | ||
opts &= ~ ( CHECK_GENERIC | CHECK_SHA256SUM ); | ||
#else //LIBSODIUM_ENALBED | ||
opts &= ~ ( CHECK_MD5SUM | CHECK_SHA1SUM ); | ||
#endif | ||
} else { | ||
merror(SK_INV_OPT, __local_name, *values, *attrs); | ||
ret = 0; | ||
|
@@ -276,6 +308,30 @@ static int read_attr(syscheck_config *syscheck, const char *dirs, char **g_attrs | |
goto out_free; | ||
} | ||
} | ||
#ifdef LIBSODIUM_ENABLED | ||
else if(strncmp(*attrs, xml_check_sha256sum, 15) == 0) { | ||
if(strncmp(*values, "yes", 3) == 0) { | ||
opts |= CHECK_SHA256SUM; | ||
} else if(strncmp(*values, "no", 2) == 0) { | ||
opts &= ~ CHECK_SHA256SUM; | ||
} else { | ||
merror(SK_INV_OPT, __local_name, *values, *attrs); | ||
ret = 0; | ||
goto out_free; | ||
} | ||
} | ||
else if(strncmp(*attrs, xml_check_genericsum, 16) == 0) { | ||
if(strncmp(*values, "yes", 3) == 0) { | ||
opts |= CHECK_GENERIC; | ||
} else if(strncmp(*values, "no", 2) == 0) { | ||
opts &= ~ CHECK_GENERIC; | ||
} else { | ||
merror(SK_INV_OPT, __local_name, *values, *attrs); | ||
ret = 0; | ||
goto out_free; | ||
} | ||
} | ||
#endif //LIBSODIUM_ENABLED | ||
/* Check permission */ | ||
else if (strcmp(*attrs, xml_check_perm) == 0) { | ||
if (strcmp(*values, "yes") == 0) { | ||
|
@@ -495,6 +551,7 @@ int Read_Syscheck(XML_NODE node, void *configp, __attribute__((unused)) void *ma | |
ExpandEnvironmentStrings(node[i]->content, dirs, sizeof(dirs) - 1); | ||
#else | ||
strncpy(dirs, node[i]->content, sizeof(dirs) - 1); | ||
dirs[sizeof(dirs) - 1] = '\0'; | ||
#endif | ||
|
||
if (!read_attr(syscheck, | ||
|
@@ -793,19 +850,22 @@ int Read_Syscheck(XML_NODE node, void *configp, __attribute__((unused)) void *ma | |
ExpandEnvironmentStrings(node[i]->content, cmd, sizeof(cmd) - 1); | ||
#else | ||
strncpy(cmd, node[i]->content, sizeof(cmd) - 1); | ||
cmd[sizeof(cmd) - 1] = '\0'; | ||
#endif | ||
|
||
if (strlen(cmd) > 0) { | ||
char statcmd[OS_MAXSTR]; | ||
char *ix; | ||
strncpy(statcmd, cmd, sizeof(statcmd) - 1); | ||
statcmd[sizeof(statcmd) - 1] = '\0'; | ||
if (NULL != (ix = strchr(statcmd, ' '))) { | ||
*ix = '\0'; | ||
} | ||
if (stat(statcmd, &statbuf) == 0) { | ||
/* More checks needed (perms, owner, etc.) */ | ||
os_calloc(1, strlen(cmd) + 1, syscheck->prefilter_cmd); | ||
strncpy(syscheck->prefilter_cmd, cmd, strlen(cmd)); | ||
syscheck->prefilter_cmd[sizeof(syscheck->prefilter_cmd) - 1] = '\0'; | ||
} else { | ||
merror(XML_VALUEERR, __local_name, node[i]->element, node[i]->content); | ||
return (OS_INVALID); | ||
|
@@ -833,24 +893,32 @@ char *syscheck_opts2str(char *buf, int buflen, int opts) { | |
CHECK_SIZE, | ||
CHECK_OWNER, | ||
CHECK_GROUP, | ||
CHECK_MD5SUM, | ||
CHECK_MD5SUM, | ||
CHECK_SHA1SUM, | ||
CHECK_REALTIME, | ||
CHECK_SEECHANGES, | ||
#ifdef LIBSODIUM_ENABLED | ||
CHECK_SHA256SUM, | ||
CHECK_GENERIC, | ||
#endif //LIBSODIUM_ENABLED | ||
CHECK_NORECURSE, | ||
0 | ||
0 | ||
}; | ||
char *check_strings[] = { | ||
"perm", | ||
"size", | ||
"owner", | ||
"group", | ||
"md5sum", | ||
"md5sum", | ||
"sha1sum", | ||
"realtime", | ||
"report_changes", | ||
#ifdef LIBSODIUM_ENABLED | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as above |
||
"sha256sum", | ||
"genericsum", | ||
#endif //LIBSODIUM_ENABLED | ||
"no_recurse", | ||
NULL | ||
NULL | ||
}; | ||
|
||
buf[0] = '\0'; | ||
|
This file contains 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 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
Oops, something went wrong.
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.
Having MD5 and SHA1 together makes some sense as both can have collisions, but dual-mode collisions are much less likely. SHA256 on the other hand is already computationally expensive, and not determined to have predictable collisions far as i know. Would it make more sense to
so as to avoid the redundancy in processing and storage?
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.
I'm not against that, I was just continuing the tradition of using 2 hashes. I hope to replace md5 with blake2b (or whatever libsodium has as default at that point) in the future. md5 and sha256 give an analyst more opportunities to compare the hashes to "known bad" files out there. I've seen plenty of Indicators of Compromise reports still using md5.
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.
Good point, and some still use sha1, which sounds like "we might want them all." Maybe a semantic in which we store one hash and create other-algo-derived hashes on a change event for the alert would address that? Users could configure generation of event hashes in the fmt used by their malware engine, or just to pass the unk file to viper or whatever they're using for sample management to let another component deal with that rabbit hole.