forked from osquery/osquery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
windows/certificates: Fix enumeration bugs, add columns (osquery#5631)
* Initial implementation * Use case insensitive comparisons for all service names 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. * Make service name cache query-local 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. * Fix reference to destroyed object 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.
- Loading branch information
1 parent
31e35ae
commit a60b940
Showing
10 changed files
with
475 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -64,6 +64,7 @@ osquery_cxx_library( | |
WINDOWS, | ||
[ | ||
"windows/registry.h", | ||
"windows/certificates.h", | ||
], | ||
), | ||
], | ||
|
This file contains 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 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 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
110 changes: 110 additions & 0 deletions
110
osquery/tables/system/tests/windows/certificates_tests.cpp
This file contains 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 |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed in accordance with the terms specified in | ||
* the LICENSE file found in the root directory of this source tree. | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <osquery/database.h> | ||
#include <osquery/flags.h> | ||
#include <osquery/registry.h> | ||
#include <osquery/system.h> | ||
#include <osquery/tables.h> | ||
|
||
#include <osquery/tables/system/windows/certificates.h> | ||
|
||
namespace osquery { | ||
|
||
DECLARE_bool(disable_database); | ||
|
||
namespace tables { | ||
|
||
class CertificatesTablesTest : public testing::Test { | ||
protected: | ||
void SetUp() override { | ||
Initializer::platformSetup(); | ||
registryAndPluginInit(); | ||
|
||
FLAGS_disable_database = true; | ||
DatabasePlugin::setAllowOpen(true); | ||
DatabasePlugin::initPlugin(); | ||
} | ||
}; | ||
|
||
TEST_F(CertificatesTablesTest, test_only_store_non_special_case) { | ||
LPCWSTR input = L"My"; | ||
std::string storeLocation = "CurrentService"; | ||
std::string serviceNameOrUserId, sid, storeName; | ||
ServiceNameMap cache; | ||
|
||
parseSystemStoreString( | ||
input, storeLocation, cache, serviceNameOrUserId, sid, storeName); | ||
|
||
EXPECT_EQ(serviceNameOrUserId, ""); | ||
EXPECT_EQ(sid, ""); | ||
EXPECT_EQ(storeName, "Personal"); | ||
} | ||
|
||
TEST_F(CertificatesTablesTest, test_service) { | ||
LPCWSTR input = L"RpcSs\\My"; // This service should always exist | ||
std::string storeLocation = "Services"; | ||
std::string serviceNameOrUserId, sid, storeName; | ||
ServiceNameMap cache; | ||
|
||
parseSystemStoreString( | ||
input, storeLocation, cache, serviceNameOrUserId, sid, storeName); | ||
|
||
EXPECT_EQ(serviceNameOrUserId, "RpcSs"); | ||
EXPECT_EQ(sid, kNetworkService); | ||
EXPECT_EQ(storeName, "Personal"); | ||
} | ||
|
||
TEST_F(CertificatesTablesTest, test_user_default) { | ||
LPCWSTR input = L".DEFAULT\\My"; | ||
std::string storeLocation = "Users"; | ||
std::string serviceNameOrUserId, sid, storeName; | ||
ServiceNameMap cache; | ||
|
||
parseSystemStoreString( | ||
input, storeLocation, cache, serviceNameOrUserId, sid, storeName); | ||
|
||
EXPECT_EQ(serviceNameOrUserId, ".DEFAULT"); | ||
EXPECT_EQ(sid, kLocalSystem); | ||
EXPECT_EQ(storeName, "Personal"); | ||
} | ||
|
||
TEST_F(CertificatesTablesTest, test_user_sid) { | ||
LPCWSTR input = L"S-1-5-18\\Root"; | ||
std::string storeLocation = "Users"; | ||
std::string serviceNameOrUserId, sid, storeName; | ||
ServiceNameMap cache; | ||
|
||
parseSystemStoreString( | ||
input, storeLocation, cache, serviceNameOrUserId, sid, storeName); | ||
|
||
EXPECT_EQ(serviceNameOrUserId, "S-1-5-18"); | ||
EXPECT_EQ(sid, kLocalSystem); | ||
EXPECT_EQ(storeName, "Trusted Root Certification Authorities"); | ||
} | ||
|
||
TEST_F(CertificatesTablesTest, test_user_classes) { | ||
LPCWSTR input = | ||
L"S-1-5-21-2821152761-3909955410-1545212275-1001_Classes\\Root"; | ||
std::string storeLocation = "Users"; | ||
std::string serviceNameOrUserId, sid, storeName; | ||
ServiceNameMap cache; | ||
|
||
parseSystemStoreString( | ||
input, storeLocation, cache, serviceNameOrUserId, sid, storeName); | ||
|
||
EXPECT_EQ(serviceNameOrUserId, | ||
"S-1-5-21-2821152761-3909955410-1545212275-1001_Classes"); | ||
EXPECT_EQ(sid, "S-1-5-21-2821152761-3909955410-1545212275-1001"); | ||
EXPECT_EQ(storeName, "Trusted Root Certification Authorities"); | ||
} | ||
|
||
} // namespace tables | ||
} // namespace osquery |
Oops, something went wrong.