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

Add UserAssist table #5539

Merged
merged 55 commits into from Mar 29, 2020
Merged

Add UserAssist table #5539

merged 55 commits into from Mar 29, 2020

Conversation

puffyCid
Copy link
Contributor

This PR adds a UsserAssist table for Windows systems.
The UserAssist Registry key tracks of what applications were executed on the system.
https://www.magnetforensics.com/blog/artifact-profile-userassist/
https://www.hecfblog.com/2013/08/daily-blog-45-understanding-artifacts.html

Let me know if additional edits need to be made

osquery> select * from userassist;
+------------------------------------------------------------------------------------------------------------------+--------------------------+-------+--------------------------------------------+
| path                                                                                                             | last_execution_time      | count | sid                                        |
+------------------------------------------------------------------------------------------------------------------+--------------------------+-------+--------------------------------------------+
| UEME_CTLCUACount:ctor                                                                                            |                          |       | S-1-5-21-7825111-416168317-3060585499-1001 |
| Microsoft.Getstarted_8wekyb3d8bbwe!App                                                                           | Thu Feb 21 01:46:04 2019 | 14    | S-1-5-21-7825111-416168317-3060585499-1001 |
| UEME_CTLSESSION                                                                                                  |                          |       | S-1-5-21-7825111-416168317-3060585499-1001 |
| Microsoft.Office.Sway_8wekyb3d8bbwe!Microsoft.Sway                                                               | Thu Feb 21 01:46:04 2019 | 13    | S-1-5-21-7825111-416168317-3060585499-1001 |
| Microsoft.WindowsMaps_8wekyb3d8bbwe!App                                                                          | Thu Feb 21 01:46:04 2019 | 12    | S-1-5-21-7825111-416168317-3060585499-1001 |
| Microsoft.People_8wekyb3d8bbwe!x4c7a3b7dy2188y46d4ya362y19ac5a5805e5x                                            | Thu Feb 21 01:46:04 2019 | 11    | S-1-5-21-7825111-416168317-3060585499-1001 |
| Microsoft.WindowsCalculator_8wekyb3d8bbwe!App                                                                    | Thu Feb 21 01:46:04 2019 | 10    | S-1-5-21-7825111-416168317-3060585499-1001 |
| Microsoft.WindowsAlarms_8wekyb3d8bbwe!App                                                                        | Thu Feb 21 01:46:04 2019 | 9     | S-1-5-21-7825111-416168317-3060585499-1001 |
| {1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\SnippingTool.exe                                                          | Thu Feb 21 01:46:04 2019 | 8     | S-1-5-21-7825111-416168317-3060585499-1001 |
| {1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\mspaint.exe                                                               | Thu Feb 21 01:46:04 2019 | 7     | S-1-5-21-7825111-416168317-3060585499-1001 |
| {1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\notepad.exe                                                               | Mon Mar 25 04:25:31 2019 | 8     | S-1-5-21-7825111-416168317-3060585499-1001 |
| Microsoft.Windows.StickyNotes                                                                                    | Thu Feb 21 01:46:04 2019 | 5     | S-1-5-21-7825111-416168317-3060585499-1001 |
| Microsoft.Windows.Explorer                                                                                       | Tue Mar 26 03:07:30 2019 | 12    | S-1-5-21-7825111-416168317-3060585499-1001 |
| {F38BF404-1D43-42F2-9305-67DE0B28FC23}\SystemApps\ShellExperienceHost_cw5n1h2txyewy\ShellExperienceHost.exe      | Wed Apr 22 19:24:48 2009 | 0     | S-1-5-21-7825111-416168317-3060585499-1001 |
| {F38BF404-1D43-42F2-9305-67DE0B28FC23}\SystemApps\Microsoft.Windows.Cortana_cw5n1h2txyewy\SearchUI.exe           | Wed Apr 22 19:24:48 2009 | 0     | S-1-5-21-7825111-416168317-3060585499-1001 |
| Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge                                                              | Thu Feb 21 01:49:25 2019 | 1     | S-1-5-21-7825111-416168317-3060585499-1001 |
| C:\Users\bob\Desktop\W10Privacy.exe                                                                              | Mon Mar 25 04:19:51 2019 | 4     | S-1-5-21-7825111-416168317-3060585499-1001 |
+------------------------------------------------------------------------------------------------------------------+--------------------------+-------+--------------------------------------------+

@facebook-github-bot facebook-github-bot added the cla signed Automated label: Pull Request author has signed the osquery CLA label Mar 27, 2019
@puffyCid
Copy link
Contributor Author

puffyCid commented Apr 7, 2019

Is there anything I need to add or change for this to get reviewed/merged?
Any feedback/comments would be great!

Copy link
Member

@directionless directionless left a comment

Choose a reason for hiding this comment

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

I can't speak to the implementation, but I think this should have tests. Possible a sample file for them.

osquery/tables/system/BUCK Outdated Show resolved Hide resolved
specs/darwin/diagnostics.table Outdated Show resolved Hide resolved
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 27, 2019

@theopolis
Copy link
Member

Also, let's rebase against master and change the target branch.

@puffyCid puffyCid changed the base branch from experimental to master July 31, 2019 02:05
@puffyCid
Copy link
Contributor Author

Also, let's rebase against master and change the target branch.

Rebased and target branch changed

@Smjert
Copy link
Member

Smjert commented Jul 31, 2019

Could it be possible to add a more comprehensive test about the table functionality?
Like testing against known values or edge cases?

Unfortunately the "integration" test that's already present it really only serve the purpose of exposing major issues with the table spec and/or "communication" between the different modules, but it doesn't tell if the table is really working as expected and showing correct values.

osquery/tables/system/windows/userassist.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/userassist.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/userassist.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/userassist.cpp Outdated Show resolved Hide resolved
osquery/tables/system/windows/userassist.cpp Show resolved Hide resolved
osquery/tables/system/windows/userassist.cpp Outdated Show resolved Hide resolved
tests/integration/tables/userassist.cpp Show resolved Hide resolved
Copy link
Contributor

@muffins muffins 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 writing this table, this is gunna be super nifty to have! I had a couple of notes, but overall it's looking good. Just a few small changes and I think we'll be good to land.

Comment on lines 71 to 77
unsigned long long last_run =
tryTo<unsigned long long>(last_run_string, 16).takeOr(0ull);
if (last_run == 0ull) {
LOG(WARNING) << "Failed to convert FILETIME to UNIX time.";
return std::string();
}
last_run = (last_run / 10000000) - 11644473600;
Copy link
Contributor

Choose a reason for hiding this comment

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

We've already got a helper function for converting a FILETIME to a unix timestamp here, mind using that? You'll also need to import <osquery/filesystem/fileops.h>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

switched to helper function

osquery/tables/system/windows/userassist.cpp Outdated Show resolved Hide resolved

// split reg path by \Count\ to get Key values
std::size_t count_key = subkey.find("Count\\");
std::string value_key = subkey.substr(count_key);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you declare std::string and std::size_t and others quite a bit, could these be auto?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

switched to auto

Comment on lines 173 to 177
if (time_str == "") {
r["count"] = "";
} else {
r["count"] = INTEGER(count);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me like you could bring the function call on line 168 to get the count value inside of your else condition. If the time_str == "", then we should avoid making the call to execution_num.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved function

specs/windows/userassist.table Outdated Show resolved Hide resolved
@puffyCid
Copy link
Contributor Author

Thanks for writing this table, this is gunna be super nifty to have! I had a couple of notes, but overall it's looking good. Just a few small changes and I think we'll be good to land.

thanks for the review, changes should be applied
let me know if there are any issues

@puffyCid
Copy link
Contributor Author

puffyCid commented Jan 8, 2020

@muffins I believe all issues should be resolved. Once this gets accepted I can quickly fix and address #5831
If there are any other issues, just let me know I can try to fix them

muffins
muffins previously approved these changes Jan 9, 2020
Copy link
Contributor

@muffins muffins left a comment

Choose a reason for hiding this comment

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

This lgtm, I think we're good to merge. I'll leave this for a bit so others have a chance to look it over, but I think we're alright. Thanks for your work on this!

auto value_key = subkey.substr(count_key);
auto value_key_reg = value_key.substr(6, std::string::npos);

std::string decoded_value_key = rotDecode(value_key_reg);
Copy link
Contributor

@woodruffw woodruffw Feb 18, 2020

Choose a reason for hiding this comment

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

N.B.: UserAssist aren't guaranteed to be ROT-13 encoded. If NoEncrypt is a DWORD of value 1 under the UserAssist registry key, the values are saved in plain text.

I'm not sure how common that is, though, so it might just be worth adding as a NOTE or TODO for the future in case someone runs into it.

Copy link
Contributor Author

@puffyCid puffyCid Feb 22, 2020

Choose a reason for hiding this comment

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

Thats true if NoEncrypt is added to the Userassist key ROT13 would be turned off (though i tried adding that DWORD to my Windows 10 VM and it was still ROT13 encoding the values, but i may have doing something wrong). I think even if ROT13 is turned off, the existing values would still be encoded. So it would be easy to check to see if the NoEncrypt is set to 1. But I think it would be difficult to determine which data is ROT13 encoded and which is not?

Regardless ive never seen that added to any of the Windows systems ive looked at.

I can add NOTE/comment though mentioning the NoEncrypt setting

@theopolis theopolis merged commit d974bb3 into osquery:master Mar 29, 2020
@puffyCid puffyCid deleted the userassist_table branch February 11, 2021 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla signed Automated label: Pull Request author has signed the osquery CLA virtual tables Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants