-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Implement dns_lookup_events table on Windows #8553
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
eb44f50
partial progress on DNS lookup ETW implementation
zwass 39c83c0
refactor hard volume conversions
zwass eab717c
finishing up and tests
zwass 38bce79
revert eventfactory
zwass 9a70eb5
slight update to test (still failing)
zwass b110551
reset dbus
zwass 4ac8d67
reset other submodules
zwass b4b089e
working integration test
zwass c1e22f9
fix format
zwass 383663f
enable flag and cleanup
zwass fff26fe
remove part of integration test failing on CI
zwass c31a437
further fix tests for ci
zwass 98efc48
Merge branch 'master' into dns-lookup-events
zwass bebfce8
fix test
zwass 2ac2d2b
fix format
zwass 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ namespace osquery { | |
|
|
||
| EtwPublisherBase::EtwPublisherBase(const std::string& name) { | ||
| name_ = name; | ||
| initializeHardVolumeConversions(); | ||
| } | ||
|
|
||
| EtwController& EtwPublisherBase::EtwEngine() { | ||
|
|
@@ -34,4 +35,80 @@ EtwPublisherBase::getPostProcessorCallback() { | |
| }; | ||
| } | ||
|
|
||
| void EtwPublisherBase::updateUserInfo(const std::string& userSid, | ||
| std::string& username) { | ||
| // Updating user information using gathered user SIDs as input | ||
| auto usernameIt = usernamesBySIDs_.find(userSid); | ||
| if (usernameIt != usernamesBySIDs_.end()) { | ||
| auto cachedUsername = usernameIt->second; | ||
| username.assign(cachedUsername); | ||
| } else { | ||
| PSID pSid = nullptr; | ||
|
|
||
| if (!ConvertStringSidToSidA(userSid.c_str(), &pSid) || pSid == nullptr) { | ||
| // Inserting empty username to avoid the lookup logic to be called again | ||
| usernamesBySIDs_.insert({userSid, ""}); | ||
| return; | ||
| } | ||
|
|
||
| std::vector<char> domainNameStr(MAX_PATH - 1, 0x0); | ||
| std::vector<char> userNameStr(MAX_PATH - 1, 0x0); | ||
| DWORD domainNameSize = MAX_PATH; | ||
| DWORD userNameSize = MAX_PATH; | ||
| SID_NAME_USE sidType = SID_NAME_USE::SidTypeInvalid; | ||
|
|
||
| if (!LookupAccountSidA(NULL, | ||
|
Member
Author
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. Use unicode version |
||
| pSid, | ||
| userNameStr.data(), | ||
| &userNameSize, | ||
| domainNameStr.data(), | ||
| &domainNameSize, | ||
| &sidType) || | ||
| strlen(domainNameStr.data()) == 0 || | ||
| strlen(domainNameStr.data()) >= MAX_PATH || | ||
| strlen(userNameStr.data()) == 0 || | ||
| strlen(userNameStr.data()) >= MAX_PATH || | ||
| sidType == SID_NAME_USE::SidTypeInvalid) { | ||
| // Inserting empty username to avoid the lookup logic to be called again | ||
| usernamesBySIDs_.insert({userSid, ""}); | ||
| LocalFree(pSid); | ||
| return; | ||
| } | ||
|
|
||
| LocalFree(pSid); | ||
|
|
||
| username.append(domainNameStr.data()); | ||
| username.append("\\"); | ||
| username.append(userNameStr.data()); | ||
|
|
||
| usernamesBySIDs_.insert({userSid, username}); | ||
| } | ||
| } | ||
|
|
||
| void EtwPublisherBase::initializeHardVolumeConversions() { | ||
| const auto& validDriveLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ||
|
|
||
| for (const auto& driveLetter : validDriveLetters) { | ||
| std::string queryPath; | ||
| queryPath.push_back(driveLetter); | ||
| queryPath.push_back(':'); | ||
|
|
||
| char hardVolume[MAX_PATH + 1] = {0}; | ||
| if (QueryDosDeviceA(queryPath.c_str(), hardVolume, MAX_PATH)) { | ||
| hardVolumeDrives_.insert({hardVolume, queryPath}); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void EtwPublisherBase::updateHardVolumeWithLogicalDrive(std::string& path) { | ||
| // Updating the hardvolume entries with logical volume data | ||
| for (const auto& [hardVolume, logicalDrive] : hardVolumeDrives_) { | ||
| size_t pos = 0; | ||
| if ((pos = path.find(hardVolume, pos)) != std::string::npos) { | ||
| path.replace(pos, hardVolume.length(), logicalDrive); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } // namespace osquery | ||
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
Oops, something went wrong.
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.
Use unicode version
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.
Addressing this in a separate PR as it will affect both the existing process events table and this one.