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 <set> | |
| 8 #include <utility> | |
| 9 | |
| 10 #include "base/file_version_info.h" | |
| 11 #include "base/files/file_path.h" | |
| 12 #include "base/i18n/case_conversion.h" | |
| 13 #include "base/logging.h" | |
| 14 #include "base/metrics/histogram_macros.h" | |
| 15 #include "base/strings/string16.h" | |
| 16 #include "base/strings/string_number_conversions.h" | |
|
grt (UTC plus 2)
2016/02/15 16:46:50
unused?
proberge
2016/02/16 16:56:23
Done.
| |
| 17 #include "base/strings/string_util.h" | |
|
grt (UTC plus 2)
2016/02/15 16:46:50
is this used?
proberge
2016/02/16 16:56:23
Done.
| |
| 18 #include "base/strings/utf_string_conversions.h" | |
| 19 #include "chrome/browser/browser_process.h" | |
|
grt (UTC plus 2)
2016/02/15 16:46:50
unused?
proberge
2016/02/16 16:56:23
Done.
| |
| 20 #include "chrome/browser/install_verification/win/module_info.h" | |
| 21 #include "chrome/browser/install_verification/win/module_verification_common.h" | |
| 22 #include "chrome/browser/safe_browsing/incident_reporting/incident_receiver.h" | |
| 23 #include "chrome/browser/safe_browsing/incident_reporting/suspicious_module_inci dent.h" | |
| 24 #include "chrome/browser/safe_browsing/path_sanitizer.h" | |
| 25 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | |
|
grt (UTC plus 2)
2016/02/15 16:46:50
unused?
proberge
2016/02/16 16:56:23
Done.
| |
| 26 #include "chrome/common/safe_browsing/binary_feature_extractor.h" | |
| 27 #include "chrome/common/safe_browsing/csd.pb.h" | |
| 28 | |
| 29 #if defined(SAFE_BROWSING_DB_LOCAL) | |
| 30 #include "chrome/browser/safe_browsing/local_database_manager.h" | |
| 31 #elif defined(SAFE_BROWSING_DB_REMOTE) | |
| 32 #include "chrome/browser/safe_browsing/remote_database_manager.h" | |
| 33 #endif | |
| 34 | |
| 35 namespace safe_browsing { | |
| 36 | |
| 37 namespace { | |
| 38 | |
| 39 void ReportIncidentsForSuspiciousModules( | |
| 40 scoped_ptr<std::set<base::FilePath>> module_names, | |
|
grt (UTC plus 2)
2016/02/15 16:46:50
module_names -> module_paths
proberge
2016/02/16 16:56:23
Done.
| |
| 41 scoped_ptr<IncidentReceiver> incident_receiver) { | |
| 42 PathSanitizer path_sanitizer; | |
| 43 scoped_refptr<BinaryFeatureExtractor> binary_feature_extractor( | |
| 44 new BinaryFeatureExtractor()); | |
| 45 SCOPED_UMA_HISTOGRAM_TIMER("SBIRS.SuspiciousModuleReportingTime"); | |
| 46 | |
| 47 for (const auto& module_name : *module_names) { | |
|
grt (UTC plus 2)
2016/02/15 16:46:50
module_name -> module_path and delete lines 54 and
proberge
2016/02/16 16:56:23
Done.
| |
| 48 // TODO(proberge): Skip over modules that have already been reported. | |
|
grt (UTC plus 2)
2016/02/15 16:46:50
how hard do you want to work at this? do you desir
proberge
2016/02/16 16:56:23
My main concern was that a Profile/ProfileContext
grt (UTC plus 2)
2016/02/17 18:04:59
Ack
| |
| 49 | |
| 50 scoped_ptr<ClientIncidentReport_IncidentData_SuspiciousModuleIncident> | |
| 51 suspicious_module( | |
| 52 new ClientIncidentReport_IncidentData_SuspiciousModuleIncident()); | |
| 53 | |
| 54 const base::FilePath module_path(module_name); | |
| 55 | |
| 56 // Sanitized path. | |
| 57 base::FilePath sanitized_path(module_path); | |
| 58 path_sanitizer.StripHomeDirectory(&sanitized_path); | |
| 59 suspicious_module->set_path(base::WideToUTF8(sanitized_path.value())); | |
|
grt (UTC plus 2)
2016/02/15 16:46:50
base::WideToUTF8(sanitized_path.value()) -> saniti
proberge
2016/02/16 16:56:23
Done.
| |
| 60 | |
| 61 // Digest. | |
| 62 binary_feature_extractor->ExtractDigest( | |
| 63 module_path, suspicious_module->mutable_digest()); | |
| 64 | |
| 65 // Version. | |
| 66 scoped_ptr<FileVersionInfo> version_info( | |
| 67 FileVersionInfo::CreateFileVersionInfo(module_path)); | |
| 68 if (version_info) { | |
| 69 base::string16 file_version = version_info->file_version(); | |
| 70 if (!file_version.empty()) | |
| 71 suspicious_module->set_version(base::WideToUTF8(file_version)); | |
|
grt (UTC plus 2)
2016/02/15 16:46:50
base::UTF16ToUTF8
proberge
2016/02/16 16:56:23
Done.
| |
| 72 } | |
| 73 | |
| 74 // Signature. | |
| 75 binary_feature_extractor->CheckSignature( | |
| 76 module_path, suspicious_module->mutable_signature()); | |
| 77 | |
| 78 // Image headers. | |
| 79 if (!binary_feature_extractor->ExtractImageFeatures( | |
| 80 module_path, BinaryFeatureExtractor::kDefaultOptions, | |
| 81 suspicious_module->mutable_image_headers(), | |
| 82 nullptr /* signed_data */)) { | |
| 83 suspicious_module->clear_image_headers(); | |
| 84 } | |
| 85 | |
| 86 // Send the incident to the reporting service. | |
| 87 incident_receiver->AddIncidentForProcess(make_scoped_ptr( | |
| 88 new SuspiciousModuleIncident(std::move(suspicious_module)))); | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 void CheckModuleWhitelistOnIOThread( | |
| 93 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, | |
| 94 scoped_ptr<IncidentReceiver> incident_receiver, | |
| 95 scoped_ptr<std::set<ModuleInfo>> module_info_set) { | |
| 96 SCOPED_UMA_HISTOGRAM_TIMER("SBIRS.SuspiciousModuleDetectionTime"); | |
| 97 scoped_ptr<std::set<base::FilePath>> suspicious_names( | |
|
grt (UTC plus 2)
2016/02/15 16:46:50
nit: this contains the full paths, not just the na
proberge
2016/02/16 16:56:23
Done.
| |
| 98 new std::set<base::FilePath>); | |
| 99 | |
| 100 for (const ModuleInfo& module_info : *module_info_set) { | |
| 101 base::string16 module_file_name(base::i18n::FoldCase( | |
| 102 base::FilePath(module_info.name).BaseName().value())); | |
|
grt (UTC plus 2)
2016/02/15 16:46:50
nit: stuff base::FilePath(module_info.name) in a l
grt (UTC plus 2)
2016/02/15 16:46:50
.value() -> .AsUTF16Unsafe()
proberge
2016/02/16 16:56:23
Done.
proberge
2016/02/16 16:56:23
Done.
| |
| 103 | |
| 104 // If not whitelisted. | |
| 105 if (!database_manager->MatchModuleWhitelistString( | |
| 106 base::UTF16ToUTF8(module_file_name))) | |
| 107 suspicious_names->insert(base::FilePath(module_info.name)); | |
| 108 } | |
| 109 | |
| 110 UMA_HISTOGRAM_COUNTS("SBIRS.SuspiciousModuleReportCount", | |
| 111 suspicious_names->size()); | |
| 112 | |
| 113 if (!suspicious_names->empty()) { | |
| 114 content::BrowserThread::GetBlockingPool() | |
|
grt (UTC plus 2)
2016/02/15 16:46:50
#include "content/public/browser/browser_thread.h"
proberge
2016/02/16 16:56:23
Done.
| |
| 115 ->PostWorkerTaskWithShutdownBehavior( | |
| 116 FROM_HERE, base::Bind(&ReportIncidentsForSuspiciousModules, | |
| 117 base::Passed(std::move(suspicious_names)), | |
| 118 base::Passed(std::move(incident_receiver))), | |
| 119 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 } // namespace | |
| 124 | |
| 125 void VerifyModuleLoadState( | |
| 126 const scoped_refptr<SafeBrowsingDatabaseManager>& database_manager, | |
| 127 scoped_ptr<IncidentReceiver> incident_receiver) { | |
| 128 scoped_ptr<std::set<ModuleInfo>> module_info_set(new std::set<ModuleInfo>); | |
| 129 if (!GetLoadedModules(module_info_set.get())) | |
| 130 return; | |
| 131 | |
| 132 // PostTaskAndReply doesn't work here because we're in a sequenced blocking | |
| 133 // thread pool. | |
| 134 content::BrowserThread::PostTask( | |
| 135 content::BrowserThread::IO, FROM_HERE, | |
| 136 base::Bind(&CheckModuleWhitelistOnIOThread, database_manager, | |
| 137 base::Passed(std::move(incident_receiver)), | |
| 138 base::Passed(std::move(module_info_set)))); | |
| 139 } | |
| 140 | |
| 141 } // namespace safe_browsing | |
| OLD | NEW |