-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
windows/certificates: Fix enumeration bugs, add columns #5631
windows/certificates: Fix enumeration bugs, add columns #5631
Conversation
@@ -34,6 +34,10 @@ function(osqueryTablesSystemTestsMain) | |||
generateOsqueryTablesSystemTestsStartupitemstestsTest() | |||
generateOsqueryTablesSystemTestsSignaturetestsTest() | |||
endif() | |||
|
|||
if(DEFINED PLATFORM_WINDOWS) | |||
generateOsqueryTablesSystemTestsCertificatestestsTest() |
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.
This name collides with an already existing function in the macOS case.
You might want to rename both and add the platform, like generateOsqueryTablesSystemTestsWindowsCertificatestestsTest
and generateOsqueryTablesSystemTestsmacOSCertificatestestsTest
Formatting the code is required (as shown by the Linux CI job), if you add the clang-format root folder in the PATH, something like |
return Status(-1, "Invalid SID"); | ||
} | ||
|
||
Status getCurrentUserInfo(PTOKEN_USER& info) { |
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.
The getCurrentUserInfo() and isUserCurrentUser() are only used by tables. I wish there were separate libraries for table support routines like this, as it makes the core harder and harder to separate and whittle down. It appears that both of these routines are not used outside the certificates table, so perhaps it can be contained in there for now?
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 somewhat disagree.
I think there's value in having some core table helper functions about. These sound like great candidates to me. (Certainly we have equivalents in our go tables)
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.
@packetzero I see what you're saying- In this particular case, I feel like although the certificates table is the only caller, these functions are general enough that it makes sense to keep them in a general library of routines available to windows tables, including future ones, so I tend to agree with @directionless here.
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.
yeah, not a huge deal. I'm all for common routines, we need to start thinking about the monolith that is osquery and how to separate core from tables at some point. When builds have stabilized, we can think about moving table-specific helpers into libs separate from core.
Fixes a bug where certificates for services that correspond to Local Service or Network Service may not have their sids appear correctly. This is because the services table is inconsistent with its user_account column.
5bd26a6
to
fca2e16
Compare
Previously, the service name cache existed for the lifetime of the osquery process, which made it susceptible to stale reads if a service restarted under a different user during osquery's lifetime. Now the cache is created for each query. Also refactor it to directly map to the sid, rather than the account name, which removes the need to translate from account name to sid every row.
Previously, getCurrentUserInfo took a reference to data from a local vector, whose data is free'd after the function. This refactors the code to use a unique_ptr (similar to how getSidFromUsername) does it.
Thanks for the review @packetzero! 😄 |
This PR addresses a few bugs in the certificates table on Windows (which was somewhat broken), and also implements some additional functionality (new columns). This is the first of two PRs, the second of which improves the table's completeness with respect to the
Personal
certificate store.Bugs Fixed
Current User
store location. TheCertOpenStore
API is now used, which is the correct functionality for opening arbitrary stores in arbitrary locations.Improvements Made
const void* systemStore
parameter thatcertEnumSystemStoreCallback
receives. Specifically, thatsystemStore
parameter could also contain information about the service or user store location that the store was in (previously, the code expected something likeMy
, and now that parameter could contain something likeS-1-5-18\My
). Handling this required adding more parsing logic (parseSystemStoreString
) and refactoring to use the additional provided information.path
column. That functionality has been preserved, but that information (username, SID, store location, store) has been broken out into individual columns so it can be queried for.Testing Notes
select common_name, path, sid, username, store_location from certificates;
is a good starting queryQuestions