Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/safe_browsing/incident_reporting/module_load_analyzer.h " | |
| 6 | |
| 7 #include "base/file_version_info.h" | |
| 8 #include "base/files/file_path.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/metrics/histogram_macros.h" | |
| 11 #include "base/strings/string_number_conversions.h" | |
| 12 #include "base/strings/string_util.h" | |
| 13 #include "base/strings/utf_string_conversions.h" | |
| 14 #include "chrome/browser/browser_process.h" | |
| 15 #include "chrome/browser/install_verification/win/module_verification_common.h" | |
| 16 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" | |
| 17 #include "chrome/browser/safe_browsing/incident_reporting/suspicious_module_inci dent.h" | |
| 18 #include "chrome/browser/safe_browsing/path_sanitizer.h" | |
| 19 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | |
| 20 #include "chrome/common/safe_browsing/binary_feature_extractor.h" | |
| 21 #include "chrome/common/safe_browsing/csd.pb.h" | |
| 22 | |
| 23 #if defined(SAFE_BROWSING_DB_LOCAL) | |
| 24 #include "chrome/browser/safe_browsing/local_database_manager.h" | |
| 25 #elif defined(SAFE_BROWSING_DB_REMOTE) | |
| 26 #include "chrome/browser/safe_browsing/remote_database_manager.h" | |
| 27 #endif | |
| 28 | |
| 29 namespace safe_browsing { | |
| 30 | |
| 31 // Enables analysis and reporting of suspicious modules loaded in the process. | |
| 32 const base::Feature kIncidentReportingModuleLoadAnalysis{ | |
| 33 "IncidentReportingModuleLoadAnalysis", base::FEATURE_DISABLED_BY_DEFAULT}; | |
| 34 | |
| 35 void RegisterModuleLoadAnalysis( | |
| 36 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager) { | |
| 37 DCHECK(database_manager); | |
| 38 if (base::FeatureList::IsEnabled(kIncidentReportingModuleLoadAnalysis)) { | |
|
grt (UTC plus 2)
2016/02/11 15:55:00
i think the impl for this will be the same for all
proberge
2016/02/11 20:25:21
Done.
| |
| 39 scoped_refptr<SafeBrowsingService> safe_browsing_service( | |
| 40 g_browser_process->safe_browsing_service()); | |
| 41 | |
| 42 if (safe_browsing_service) { | |
| 43 safe_browsing_service | |
| 44 ->RegisterExtendedReportingOnlyDelayedAnalysisCallback( | |
| 45 base::Bind(&VerifyModuleLoadState, database_manager)); | |
| 46 } | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 void GetLoadedSuspiciousModulesOnIOThread( | |
|
grt (UTC plus 2)
2016/02/11 15:55:00
rename to something like CheckModuleWhitelistOnIOT
grt (UTC plus 2)
2016/02/11 15:55:00
move into unnamed namespace on line 31
proberge
2016/02/11 20:25:21
Done.
proberge
2016/02/11 20:25:22
Done.
| |
| 51 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, | |
| 52 scoped_ptr<IncidentReceiver> incident_receiver, | |
| 53 scoped_ptr<std::set<ModuleInfo>> module_info_set) { | |
|
grt (UTC plus 2)
2016/02/11 15:55:00
#include <set>
proberge
2016/02/11 20:25:21
Done.
| |
| 54 SCOPED_UMA_HISTOGRAM_TIMER("SBIRS.SuspiciousModuleDetectionTime"); | |
| 55 scoped_ptr<std::set<base::string16>> suspicious_names( | |
|
grt (UTC plus 2)
2016/02/11 15:55:00
can you make this a set of FilePaths since that's
proberge
2016/02/11 20:25:21
Done.
| |
| 56 new std::set<base::string16>); | |
| 57 | |
| 58 std::set<ModuleInfo>::const_iterator module_iter(module_info_set->begin()); | |
|
grt (UTC plus 2)
2016/02/11 15:55:00
for (const ModuleInfo& module_info : *module_info_
proberge
2016/02/11 20:25:22
Done.
| |
| 59 for (; module_iter != module_info_set->end(); ++module_iter) { | |
| 60 base::string16 module_file_name(base::ToLowerASCII( | |
|
grt (UTC plus 2)
2016/02/11 15:55:00
there's no guarantee that filenames are ascii. con
proberge
2016/02/11 20:25:21
Done.
| |
| 61 base::FilePath(module_iter->name).BaseName().value())); | |
| 62 | |
| 63 // If not whitelisted. | |
| 64 if (!database_manager->MatchModuleWhitelistString( | |
| 65 base::UTF16ToUTF8(module_file_name))) | |
| 66 suspicious_names->insert(module_iter->name); | |
| 67 } | |
| 68 | |
| 69 UMA_HISTOGRAM_COUNTS("SBIRS.SuspiciousModuleReportCount", | |
| 70 suspicious_names->size()); | |
| 71 | |
| 72 if (!suspicious_names->empty()) { | |
| 73 content::BrowserThread::GetBlockingPool() | |
| 74 ->PostWorkerTaskWithShutdownBehavior( | |
| 75 FROM_HERE, base::Bind(&ReportIncidentsForSuspiciousModules, | |
| 76 base::Passed(std::move(suspicious_names)), | |
|
grt (UTC plus 2)
2016/02/11 15:55:00
#include <utility>
proberge
2016/02/11 20:25:21
Done.
| |
| 77 base::Passed(std::move(incident_receiver))), | |
| 78 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 void ReportIncidentsForSuspiciousModules( | |
|
grt (UTC plus 2)
2016/02/11 15:55:00
move into unnamed namespace
proberge
2016/02/11 20:25:21
Done.
| |
| 83 scoped_ptr<std::set<base::string16>> module_names, | |
| 84 scoped_ptr<IncidentReceiver> incident_receiver) { | |
| 85 PathSanitizer path_sanitizer; | |
| 86 SCOPED_UMA_HISTOGRAM_TIMER("SBIRS.SuspiciousModuleReportingTime"); | |
| 87 | |
| 88 for (const auto& module_name : *module_names) { | |
| 89 // TODO(proberge): Skip over modules that have already been reported. | |
| 90 | |
| 91 scoped_ptr<ClientIncidentReport_IncidentData_SuspiciousModuleIncident> | |
| 92 suspicious_module( | |
| 93 new ClientIncidentReport_IncidentData_SuspiciousModuleIncident()); | |
| 94 | |
| 95 const base::FilePath module_path(module_name); | |
| 96 | |
| 97 // Sanitized path. | |
| 98 base::FilePath sanitized_path(module_path); | |
| 99 path_sanitizer.StripHomeDirectory(&sanitized_path); | |
| 100 suspicious_module->set_path(base::WideToUTF8(sanitized_path.value())); | |
| 101 | |
| 102 // Digest. | |
| 103 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor( | |
|
grt (UTC plus 2)
2016/02/11 15:55:00
can you create one instance of this outside of the
proberge
2016/02/11 20:25:22
Done.
| |
| 104 new BinaryFeatureExtractor()); | |
| 105 | |
| 106 binary_feature_extractor->ExtractDigest( | |
| 107 module_path, suspicious_module->mutable_digest()); | |
| 108 | |
| 109 // Version. | |
| 110 scoped_ptr<FileVersionInfo> version_info( | |
| 111 FileVersionInfo::CreateFileVersionInfo(module_path)); | |
| 112 if (version_info) { | |
| 113 std::wstring file_version = version_info->file_version(); | |
|
grt (UTC plus 2)
2016/02/11 15:55:00
base::string16
proberge
2016/02/11 20:25:21
Done.
| |
| 114 if (!file_version.empty()) | |
| 115 suspicious_module->set_version(base::WideToUTF8(file_version)); | |
| 116 } | |
| 117 | |
| 118 // Signature. | |
| 119 binary_feature_extractor->CheckSignature( | |
| 120 module_path, suspicious_module->mutable_signature()); | |
| 121 | |
| 122 // Image headers. | |
| 123 if (!binary_feature_extractor->ExtractImageFeatures( | |
| 124 module_path, BinaryFeatureExtractor::kDefaultOptions, | |
| 125 suspicious_module->mutable_image_headers(), | |
| 126 nullptr /* signed_data */)) { | |
| 127 suspicious_module->clear_image_headers(); | |
| 128 } | |
| 129 | |
| 130 // Send the report. | |
|
grt (UTC plus 2)
2016/02/11 15:55:00
nit: this sends the incident to the reporting serv
proberge
2016/02/11 20:25:22
Done.
| |
| 131 incident_receiver->AddIncidentForProcess(make_scoped_ptr( | |
|
grt (UTC plus 2)
2016/02/11 15:55:00
while the construction of extended_reporting_only_
proberge
2016/02/11 20:25:21
Done.
| |
| 132 new SuspiciousModuleIncident(std::move(suspicious_module)))); | |
| 133 } | |
| 134 } | |
| 135 | |
| 136 void VerifyModuleLoadState( | |
| 137 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, | |
| 138 scoped_ptr<IncidentReceiver> incident_receiver) { | |
| 139 scoped_ptr<std::set<ModuleInfo>> module_info_set(new std::set<ModuleInfo>); | |
| 140 if (!GetLoadedModules(module_info_set.get())) | |
| 141 return; | |
| 142 | |
| 143 // PostTaskAndReply doesn't work here because we're in a sequenced blocking | |
| 144 // thread pool. | |
| 145 content::BrowserThread::PostTask( | |
| 146 content::BrowserThread::IO, FROM_HERE, | |
| 147 base::Bind(&GetLoadedSuspiciousModulesOnIOThread, database_manager, | |
| 148 base::Passed(std::move(incident_receiver)), | |
| 149 base::Passed(std::move(module_info_set)))); | |
| 150 } | |
| 151 | |
| 152 } // namespace safe_browsing | |
| OLD | NEW |