Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up[master task] event driven file integrity monitoring #722
Comments
|
@jedi22, when you get a chance, can you comment on here with your initial run at a plan of action? |
|
There are several parts of getting this done:
So far, every table in osquery is defined by its own .cpp file. With these tables that may no longer be the case. The tables and their names will be dynamically generated at program start based on the contents of the configuration file. An example of such configuration data is shown above, and the plan is for the schema to remain consistent with existing event based tables:
The above example would translate to following schemas:
Presently, the extra |
|
A just made the first commit to a pull request that will eventually implement this feature, #770. In both OS X and Linux, you can now add a top level dictionary to your config JSON in this form, "additional_monitoring" : {
"file_paths": {
"system_binaries": [
"/bin/bash",
"/bin/zsh"
]
}
}Wildcard are also supported and every file that the wildcard resolves to will have a file listener attached to it. This will generate table entries if the file is ever changed. Example output of this table is:
As you can see, the top level inside additional monitoring is the value of category, so you can easily distinguish your lists this way. This has several advantages to the previously proposed approach:
Outstanding Issues
This issue was resolved after we started returning a static reference in config. We would like the ability to only optionally define a callback with Also it seems the that the time stamps on events are temperamental. This should be investigated before a final merge. |
It is important to note:Monitoring /bin/% will not alert you of new files added to /bin/ It will alert on change or removal of already existing files. |
|
@jedi22 we definitely need to fix that |
|
This is fixed on OS X because fsevents is really robust and generally awesome. The inotify API is going to take more work to get to a stage where we are happy with the functionality of it. |
|
|
|
Progress on inotify is coming along, there are probably a few bugs and edge cases to be worked out, but so far we should now have recursive directory monitoring with updates. Meaning that if a folder is added, this is detected and also added to the listening group. Currently our overflow case handling is not tested but it does exist. The thread should exit if an overflow is encounter less than 10 seconds after the previous one. Example Served Configuration {
"scheduledQueries": [
{
"name": "time",
"query": "select * from time;",
"interval": 1
}
],
"additional_monitoring" : {
"file_paths": {
"system_files": [
"/etc"
],
"core_binaries": [
"/bin/"
],
"other_binaries":[
"/sbin/",
"/usr/sbin"
]
}
}
}Output:
Also, much thanks to @theopolis for his help and his existing inotify code :D |
|
The inotify and fsevents interfaces should now be the same (save some bugs I haven't found yet). You should be able to use the entire supported wildcard spec implemented in osquery to monitor file, folders or both. The osquery wildcard specosquery has a simplified wildcarding system for matching operating system directories and files. % - Match all Examples/bin/% - Resolves a vector of every file in /bin Note%XX% and XX%XX is undefined and will not resolve wildcards in the expected way. This may be implemented in future but there are no plans. Filesystem API ChangesIn this update I have tried to keep resolveFilePattern API compatible, it should still be but I would still encourage any testing of extensions that use this functionality that they still work as intended. This will also help surface any bugs in the new implementation. As far as features go, you can now specify a bitmask for returning: You may notice there is another flag called Other notesEvents, at least with fsevents, do not fire on links. This may be fixed in the future but it is a known issue now. Prior to this, fsevents was not returning results for touches. This has been fixed by adding the new event type Listening will only apply starting at the last wildcard, or component. For example, if you add monitoring to /Users/%/Downloads/%% You will get updates for when any user add, removes, or updates a file in their downloads folder. You will NOT however get updates if a new user is added. ConclusionThis table is nearing it's v1 release and should have all the features listed above. If you find any bugs, please open a task and link it here and I will try to resolve it. The merge goal for this code in Friday March 6th, 2015 |
|
Epic! Can we summarize this in a wiki format next week? Sent from my Android
|
|
For sure |
|
I decided to implement an idea of mine in osquery and it turns out I need many of these features, so thank you for writing them! I hope you don't mind me hijacking this issue but I think it is related. I am not sure things are working right or if I'm just misunderstanding everything. I decided to take a look at how This is the config I'm using:
If I start with an empty I suspect this has to do with the fsevents code missing the event for "file created in this directory" but I'm not able to track it down right now before I have to get some sleep. |
|
Absolutely, I will attempt to fix this today |

Let's add a top-level config as such:
For context, see the example config.
On process startup, we should expand all of those paths. Let's say the expanded paths looked something like:
We should hash all of those paths and store the results in RocksDB. If hash results already exist for those pasts, these values should be updated to reflect the new, correct hash value.
With regards to RocksDB, this will probably cause us to create one or two new column families.
The first column family (
threats_map) would look something like:The second column family (
threats_hashes) would look something like:{"sha256": "72b7650b237c3e124aa6b6e625a4f665ca137b411c0b257d696080cdf9254a01", "sha1": "1b29766d8882c8279b2c20e32f933578dfdf41b4", "md5": "f81cce1751382506604e244039bf4724"}{"sha256": "72b7650b237c3e124aa6b6e625a4f665ca137b411c0b257d696080cdf9254a01", "sha1": "1b29766d8882c8279b2c20e32f933578dfdf41b4", "md5": "f81cce1751382506604e244039bf4724"}{"sha256": "72b7650b237c3e124aa6b6e625a4f665ca137b411c0b257d696080cdf9254a01", "sha1": "1b29766d8882c8279b2c20e32f933578dfdf41b4", "md5": "f81cce1751382506604e244039bf4724"}{"sha256": "72b7650b237c3e124aa6b6e625a4f665ca137b411c0b257d696080cdf9254a01", "sha1": "1b29766d8882c8279b2c20e32f933578dfdf41b4", "md5": "f81cce1751382506604e244039bf4724"}So, again, on process startup, we'll have to expand all paths and make the appropriate entry in
threats_map. There should be a background thread that constantly (but performantly) keepsthreats_mapup to date.Once
threats_mapis expanded and up to date, the process should make an initial run throughthreats_hashesto make sure all of the data is correct. We'll obviously incur a performance penalty here.Once
threats_hashesis up to date, event subscribers should be attached to all of the expanded paths (or their parent directories). If the files change, the file should be re-hashed andthreats_hashesshould be updated.