8000 Shimcache Table by puffyCid · Pull Request #6463 · osquery/osquery · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
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

Shimcache Table #6463

Merged
merged 2 commits into from
Jul 13, 2020
Merged

Shimcache Table #6463

merged 2 commits into from
Jul 13, 2020

Conversation

puffyCid
Copy link
Contributor
@puffyCid puffyCid commented May 25, 2020

This PR adds a shimcache table to osquery for Windows systems.
Shimcache (Application Compatibility Cache, also sometimes called "AppcompatCache") contains entries of executed applications on Windows systems (it may also contain a list of executable's enumerated by Explorer when browsing the file system). Shimcache entries contain:

  • Path of file executed
  • Last modified time of the file
  • An execution flag on the file (this flag does not exist on Windows 10 systems)

Additional info can be found here: https://medium.com/@bromiley/windows-wednesday-shim-cache-1997ba8b13e7

This PR enumerates all the ControlSets on a Windows system and parses the Shimcache entries.
Its been tested on Windows 8.1 and Windows 10 (Creators update)
It should also work on Windows 10 (Pre-Creators) but I do not have VM to test on.
The PR also makes a few small changes to Userassist in regards timestamp conversion
Let me know if there are any issues

+-------+------------------------------------------------------------------------------------------------------------------------------+--------------------------------------+----------------+
| entry | path                                                                                                                         | DATETIME(modified_time, 'unixepoch') | execution_flag |
+-------+------------------------------------------------------------------------------------------------------------------------------+--------------------------------------+----------------+
| 1     | C:\Users\bob\AppData\Local\Temp\B7893AFE-DD60-43ED-AB8A-E0C7CEBF3BF1\dismhost.exe                                            | 2019-03-19 04:46:23                  |                |
| 2     | C:\WINDOWS\SoftwareDistribution\Download\Install\AM_Delta_Patch_1.315.1346.0.exe                                             | 2020-05-24 18:53:51                  |                |
| 3     | SIGN.MEDIA=103148F8 osqueryd.exe                                                                                             | 2020-05-24 18:37:35                  |                |
| 4     | SIGN.MEDIA=1031C8F8 osqueryd.exe                                                                                             | 2020-05-24 18:06:12                  |                |
| 5     | SIGN.MEDIA=1031C8F8 AppCompatCacheParser.exe                                                                                 | 2019-12-11 04:03:48                  |                |
| 6     | SIGN.MEDIA=E4A0A1F0 osqueryd.exe                                                                                             | 2020-05-24 01:01:14                  |                |
| 7     | SIGN.MEDIA=E8F4DD42 Microsoft ATA Center Setup.exe                                                                           | 2017-06-29 07:50:49                  |                |
| 8     | C:\Users\bob\Desktop\osqueryd.exe                                                                                            | 2020-05-24 18:37:35                  |                |
| 9     | C:\WINDOWS\SoftwareDistribution\Download\Install\AM_Delta_Patch_1.315.1290.0.exe                                             | 2020-05-24 17:49:46                  |                |
| 10    | C:\Users\bob\Projects\osquery\build\plugins\remote\enroll\tests\RelWithDebInfo\plugins_remote_enroll_tlsenrolltests-test.exe | 2020-05-24 22:24:16                  |                |
+-------+------------------------------------------------------------------------------------------------------------------------------+--------------------------------------+----------------+```

osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
@puffyCid
Copy link
Contributor Author

@theopolis Thanks for the comments and review
All comments should be addressed, let me know if there are any other issues

Copy link
Member
@theopolis theopolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for iterating on this!

osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/userassist.h Outdated Show resolved Hide resolved
specs/windows/shimcache.table Outdated Show resolved Hide resolved
osquery/tables/system/windows/shimcache.cpp Outdated Show resolved Hide resolved
@puffyCid
Copy link
Contributor Author
puffyCid commented Jul 3, 2020

@theopolis All comments should be addressed, let me know if there are any other issues

Copy link
Member
@theopolis theopolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

One last consideration for consistency. In a lot of other tables we represent "tri-states" in columns as either {-1, 0, 1} or {NULL, 0, 1}. My recommendation is to follow that pattern for execution_flag in the schema.

So concretely:

  • Change

specs/windows/shimcache.table Outdated Show resolved Hide resolved
@theopolis
Copy link
Member

Looks good!

@theopolis theopolis force-pushed the appcompat branch 2 times, most recently from 5584a9b to 040d472 Compare July 12, 2020 03:00
@theopolis
Copy link
Member

Hi @puffyCid, I did some work to refactor+minify the code. I'd like to look at recent PRs, specifically around Windows filetime parsing, and see if we should move some of the utility functions here, elsewhere.

@theopolis
Copy link
Member

Actually, we can do code shuffle in another PR.

Last question about this table: can we drop the entry column? Having it will make table comparisons difficult?

@puffyCid
Copy link
Contributor Author

Actually, we can do code shuffle in another PR.

Last question about this table: can we drop the entry column? Having it will make table comparisons difficult?

I would prefer if the entry column stayed.
The entry column can help show/clarify the order of how files were executed for example

+-------+------------------------------------------------------------------------------------------------------+---------------+----------------+
| entry | path                                                                                                 | modified_time | execution_flag |
+-------+------------------------------------------------------------------------------------------------------+---------------+----------------+
| 1     | C:\WINDOWS\system32\sc.exe                                                                           | 1552970734    | -1             |
| 2     | C:\WINDOWS\system32\Windows.WARP.JITService.exe                                                      | 1552970651    | -1             |
| 3     | C:\WINDOWS\system32\browser_broker.exe                                                               | 1571637135    | -1             |
| 4     | C:\WINDOWS\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\Application                              | 1592019201    | -1             |
| 5     | C:\WINDOWS\system32\ApplicationFrameHost.exe                                                         | 1552970663    | -1             |
| 6     | C:\WINDOWS\system32\net1.exe                                                                         | 1552970734    | -1             |
| 7     | C:\WINDOWS\system32\net.exe                                                                          | 1552970734    | -1             |
| 8     | C:\WINDOWS\system32\PING.EXE                                                                         | 1552970734    | -1             |
| 9     | C:\WINDOWS\system32\ipconfig.exe                                                                     | 1552970734    | -1             |
| 10    | C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.0.1811.0_x64__8wekyb3d8bbwe\OpenConsole.exe | 1593651272    | -1             |
...

The above shimcache entries show that the user launched Windows Terminal, executed ipconfig.exe, ping.exe, net.exe in that order (execution order is read bottom to top, newest shimcache entries are at the top)

but if it will cause issues i can remove it if necessary.
@theopolis what do you mean by making table comparisons difficult?

@theopolis theopolis merged commit 336e6b0 into osquery:master Jul 13, 2020
@theopolis
Copy link
Member

Ok, we can leave it. The problem I referenced is related to "differential" queries where osquery tries to calculate set differences between scheduled queries. If someone removes a row, for example the first sc.exe that will have a ripple effect on all other rows in shimcache because their entries will offset. If this happens osquery's differential will detect that all rows have changed, vs, detecting that the first entry is now missing.

@puffyCid puffyCid deleted the appcompat branch July 13, 2020 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0