OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/enumerate_modules_model_win.h" | 5 #include "chrome/browser/enumerate_modules_model_win.h" |
6 | 6 |
7 #include <Tlhelp32.h> | 7 #include <Tlhelp32.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <wintrust.h> | 10 #include <wintrust.h> |
11 | 11 |
12 #include <algorithm> | 12 #include <algorithm> |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 #include "base/bind.h" | 15 #include "base/bind.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/environment.h" | 17 #include "base/environment.h" |
18 #include "base/file_version_info_win.h" | 18 #include "base/file_version_info_win.h" |
19 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
20 #include "base/i18n/case_conversion.h" | 20 #include "base/i18n/case_conversion.h" |
21 #include "base/lazy_instance.h" | |
21 #include "base/macros.h" | 22 #include "base/macros.h" |
22 #include "base/metrics/histogram.h" | 23 #include "base/metrics/histogram.h" |
23 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
24 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
25 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
26 #include "base/time/time.h" | 27 #include "base/time/time.h" |
27 #include "base/values.h" | 28 #include "base/values.h" |
28 #include "base/version.h" | 29 #include "base/version.h" |
29 #include "base/win/registry.h" | 30 #include "base/win/registry.h" |
30 #include "base/win/scoped_handle.h" | 31 #include "base/win/scoped_handle.h" |
31 #include "base/win/windows_version.h" | 32 #include "base/win/windows_version.h" |
32 #include "chrome/browser/chrome_notification_types.h" | |
33 #include "chrome/browser/net/service_providers_win.h" | 33 #include "chrome/browser/net/service_providers_win.h" |
34 #include "chrome/common/chrome_constants.h" | 34 #include "chrome/common/chrome_constants.h" |
35 #include "chrome/grit/generated_resources.h" | 35 #include "chrome/grit/generated_resources.h" |
36 #include "content/public/browser/notification_service.h" | |
37 #include "crypto/sha2.h" | 36 #include "crypto/sha2.h" |
38 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
39 | 38 |
40 using content::BrowserThread; | 39 using content::BrowserThread; |
41 | 40 |
42 // The period of time (in milliseconds) to wait until checking to see if any | 41 // The period of time (in milliseconds) to wait until checking to see if any |
43 // incompatible modules exist. | 42 // incompatible modules exist. |
44 static const int kModuleCheckDelayMs = 45 * 1000; | 43 static const int kModuleCheckDelayMs = 45 * 1000; |
45 | 44 |
46 // The path to the Shell Extension key in the Windows registry. | 45 // The path to the Shell Extension key in the Windows registry. |
47 static const wchar_t kRegPath[] = | 46 static const wchar_t kRegPath[] = |
48 L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"; | 47 L"Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"; |
49 | 48 |
50 // Short-hand for things on the blacklist you should simply get rid of. | |
51 static const ModuleEnumerator::RecommendedAction kUninstallLink = | |
52 static_cast<ModuleEnumerator::RecommendedAction>( | |
53 ModuleEnumerator::UNINSTALL | ModuleEnumerator::SEE_LINK); | |
54 | |
55 // Short-hand for things on the blacklist we are investigating and have info. | |
56 static const ModuleEnumerator::RecommendedAction kInvestigatingLink = | |
57 static_cast<ModuleEnumerator::RecommendedAction>( | |
58 ModuleEnumerator::INVESTIGATING | ModuleEnumerator::SEE_LINK); | |
59 | |
60 // A sort method that sorts by bad modules first, then by full name (including | 49 // A sort method that sorts by bad modules first, then by full name (including |
61 // path). | 50 // path). |
62 static bool ModuleSort(const ModuleEnumerator::Module& a, | 51 static bool ModuleSort(const ModuleEnumerator::Module& a, |
63 const ModuleEnumerator::Module& b) { | 52 const ModuleEnumerator::Module& b) { |
64 if (a.status != b.status) | 53 if (a.status != b.status) |
65 return a.status > b.status; | 54 return a.status > b.status; |
66 | 55 |
67 if (a.location == b.location) | 56 if (a.location == b.location) |
68 return a.name < b.name; | 57 return a.name < b.name; |
69 | 58 |
70 return a.location < b.location; | 59 return a.location < b.location; |
71 } | 60 } |
72 | 61 |
73 namespace { | 62 namespace { |
74 | 63 |
75 // Used to protect the LoadedModuleVector which is accessed | |
76 // from both the UI thread and the FILE thread. | |
77 base::Lock* lock = NULL; | |
78 | |
79 // A struct to help de-duping modules before adding them to the enumerated | 64 // A struct to help de-duping modules before adding them to the enumerated |
80 // modules vector. | 65 // modules vector. |
81 struct FindModule { | 66 struct FindModule { |
82 public: | 67 public: |
83 explicit FindModule(const ModuleEnumerator::Module& x) | 68 explicit FindModule(const ModuleEnumerator::Module& x) |
84 : module(x) {} | 69 : module(x) {} |
85 bool operator()(const ModuleEnumerator::Module& module_in) const { | 70 bool operator()(const ModuleEnumerator::Module& module_in) const { |
86 return (module.location == module_in.location) && | 71 return (module.location == module_in.location) && |
87 (module.name == module_in.name); | 72 (module.name == module_in.name); |
88 } | 73 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 version(version), | 116 version(version), |
132 digital_signer(digital_signer), | 117 digital_signer(digital_signer), |
133 recommended_action(recommended_action), | 118 recommended_action(recommended_action), |
134 duplicate_count(0), | 119 duplicate_count(0), |
135 normalized(false) { | 120 normalized(false) { |
136 } | 121 } |
137 | 122 |
138 ModuleEnumerator::Module::~Module() { | 123 ModuleEnumerator::Module::~Module() { |
139 } | 124 } |
140 | 125 |
141 // The browser process module blacklist. This lists modules that are known | |
142 // to cause compatibility issues within the browser process. When adding to this | |
143 // list, make sure that all paths are lower-case, in long pathname form, end | |
144 // with a slash and use environments variables (or just look at one of the | |
145 // comments below and keep it consistent with that). When adding an entry with | |
146 // an environment variable not currently used in the list below, make sure to | |
147 // update the list in PreparePathMappings. Filename, Description/Signer, and | |
148 // Location must be entered as hashes (see GenerateHash). Filename is mandatory. | |
149 // Entries without any Description, Signer info, or Location will never be | |
150 // marked as confirmed bad (only as suspicious). | |
151 const ModuleEnumerator::BlacklistEntry ModuleEnumerator::kModuleBlacklist[] = { | |
152 // NOTE: Please keep this list sorted by dll name, then location. | |
153 | |
154 // Version 3.2.1.6 seems to be implicated in most cases (and 3.2.2.2 in some). | |
155 // There is a more recent version available for download. | |
156 // accelerator.dll, "%programfiles%\\speedbit video accelerator\\". | |
157 { "7ba9402f", "c9132d48", "", "", "", ALL, kInvestigatingLink }, | |
158 | |
159 // apiqq0.dll, "%temp%\\". | |
160 { "26134911", "59145acf", "", "", "", ALL, kUninstallLink }, | |
161 | |
162 // arking0.dll, "%systemroot%\\system32\\". | |
163 { "f5d8f549", "23d01d5b", "", "", "", ALL, kUninstallLink }, | |
164 | |
165 // arking1.dll, "%systemroot%\\system32\\". | |
166 { "c60ca062", "23d01d5b", "", "", "", ALL, kUninstallLink }, | |
167 | |
168 // aswjsflt.dll, "%ProgramFiles%\\avast software\\avast\\", "AVAST Software". | |
169 // NOTE: The digital signature of the DLL is double null terminated. | |
170 // Avast Antivirus prior to version 8.0 would kill the Chrome child process | |
171 // when blocked from running. | |
172 { "2ea5422a", "6b3a1b00", "a7db0e0c", "", "8.0", XP, | |
173 static_cast<RecommendedAction>(UPDATE | SEE_LINK | NOTIFY_USER) }, | |
174 | |
175 // aswjsflt.dll, "%ProgramFiles%\\alwil software\\avast5\\", "AVAST Software". | |
176 // NOTE: The digital signature of the DLL is double null terminated. | |
177 // Avast Antivirus prior to version 8.0 would kill the Chrome child process | |
178 // when blocked from running. | |
179 { "2ea5422a", "d8686924", "a7db0e0c", "", "8.0", XP, | |
180 static_cast<RecommendedAction>(UPDATE | SEE_LINK | NOTIFY_USER) }, | |
181 | |
182 // Said to belong to Killer NIC from BigFoot Networks (not verified). Versions | |
183 // 6.0.0.7 and 6.0.0.10 implicated. | |
184 // bfllr.dll, "%systemroot%\\system32\\". | |
185 { "6bb57633", "23d01d5b", "", "", "", ALL, kInvestigatingLink }, | |
186 | |
187 // clickpotatolitesahook.dll, "". Different version each report. | |
188 { "0396e037.dll", "", "", "", "", ALL, kUninstallLink }, | |
189 | |
190 // cvasds0.dll, "%temp%\\". | |
191 { "5ce0037c", "59145acf", "", "", "", ALL, kUninstallLink }, | |
192 | |
193 // cwalsp.dll, "%systemroot%\\system32\\". | |
194 { "e579a039", "23d01d5b", "", "", "", ALL, kUninstallLink }, | |
195 | |
196 // datamngr.dll (1), "%programfiles%\\searchqu toolbar\\datamngr\\". | |
197 { "7add320b", "470a3da3", "", "", "", ALL, kUninstallLink }, | |
198 | |
199 // datamngr.dll (2), "%programfiles%\\windows searchqu toolbar\\". | |
200 { "7add320b", "7a3c8be3", "", "", "", ALL, kUninstallLink }, | |
201 | |
202 // dsoqq0.dll, "%temp%\\". | |
203 { "1c4df325", "59145acf", "", "", "", ALL, kUninstallLink }, | |
204 | |
205 // flt.dll, "%programfiles%\\tueagles\\". | |
206 { "6d01f4a1", "7935e9c2", "", "", "", ALL, kUninstallLink }, | |
207 | |
208 // This looks like a malware edition of a Brazilian Bank plugin, sometimes | |
209 // referred to as Malware.Banc.A. | |
210 // gbieh.dll, "%programfiles%\\gbplugin\\". | |
211 { "4cb4f2e3", "88e4a3b1", "", "", "", ALL, kUninstallLink }, | |
212 | |
213 // hblitesahook.dll. Each report has different version number in location. | |
214 { "5d10b363", "", "", "", "", ALL, kUninstallLink }, | |
215 | |
216 // icf.dll, "%systemroot%\\system32\\". | |
217 { "303825ed", "23d01d5b", "", "", "", ALL, INVESTIGATING }, | |
218 | |
219 // idmmbc.dll (IDM), "%systemroot%\\system32\\". See: http://crbug.com/26892/. | |
220 { "b8dce5c3", "23d01d5b", "", "", "6.03", ALL, | |
221 static_cast<RecommendedAction>(UPDATE | DISABLE) }, | |
222 | |
223 // imon.dll (NOD32), "%systemroot%\\system32\\". See: http://crbug.com/21715. | |
224 { "8f42f22e", "23d01d5b", "", "", "4.0", ALL, | |
225 static_cast<RecommendedAction>(UPDATE | DISABLE) }, | |
226 | |
227 // is3lsp.dll, "%commonprogramfiles%\\is3\\anti-spyware\\". | |
228 { "7ffbdce9", "bc5673f2", "", "", "", ALL, | |
229 static_cast<RecommendedAction>(UPDATE | DISABLE | SEE_LINK) }, | |
230 | |
231 // jsi.dll, "%programfiles%\\profilecraze\\". | |
232 { "f9555eea", "e3548061", "", "", "", ALL, kUninstallLink }, | |
233 | |
234 // kernel.dll, "%programfiles%\\contentwatch\\internet protection\\modules\\". | |
235 { "ead2768e", "4e61ce60", "", "", "", ALL, INVESTIGATING }, | |
236 | |
237 // mgking0.dll, "%systemroot%\\system32\\". | |
238 { "d0893e38", "23d01d5b", "", "", "", ALL, kUninstallLink }, | |
239 | |
240 // mgking0.dll, "%temp%\\". | |
241 { "d0893e38", "59145acf", "", "", "", ALL, kUninstallLink }, | |
242 | |
243 // mgking1.dll, "%systemroot%\\system32\\". | |
244 { "3e837222", "23d01d5b", "", "", "", ALL, kUninstallLink }, | |
245 | |
246 // mgking1.dll, "%temp%\\". | |
247 { "3e837222", "59145acf", "", "", "", ALL, kUninstallLink }, | |
248 | |
249 // mstcipha.ime, "%systemroot%\\system32\\". | |
250 { "5523579e", "23d01d5b", "", "", "", ALL, INVESTIGATING }, | |
251 | |
252 // mwtsp.dll, "%systemroot%\\system32\\". | |
253 { "9830bff6", "23d01d5b", "", "", "", ALL, kUninstallLink }, | |
254 | |
255 // nodqq0.dll, "%temp%\\". | |
256 { "b86ce04d", "59145acf", "", "", "", ALL, kUninstallLink }, | |
257 | |
258 // nProtect GameGuard Anti-cheat system. Every report has a different | |
259 // location, since it is installed into and run from a game folder. Various | |
260 // versions implicated. | |
261 // npggnt.des, no fixed location. | |
262 { "f2c8790d", "", "", "", "", ALL, kInvestigatingLink }, | |
263 | |
264 // nvlsp.dll, | |
265 // "%programfiles%\\nvidia corporation\\networkaccessmanager\\bin32\\". | |
266 { "37f907e2", "3ad0ff23", "", "", "", ALL, INVESTIGATING }, | |
267 | |
268 // post0.dll, "%systemroot%\\system32\\". | |
269 { "7405c0c8", "23d01d5b", "", "", "", ALL, kUninstallLink }, | |
270 | |
271 // questbrwsearch.dll, "%programfiles%\\questbrwsearch\\". | |
272 { "0953ed09", "f0d5eeda", "", "", "", ALL, kUninstallLink }, | |
273 | |
274 // questscan.dll, "%programfiles%\\questscan\\". | |
275 { "f4f3391e", "119d20f7", "", "", "", ALL, kUninstallLink }, | |
276 | |
277 // radhslib.dll (Naomi web filter), "%programfiles%\\rnamfler\\". | |
278 // See http://crbug.com/12517. | |
279 { "7edcd250", "0733dc3e", "", "", "", ALL, INVESTIGATING }, | |
280 | |
281 // rlls.dll, "%programfiles%\\relevantknowledge\\". | |
282 { "a1ed94a7", "ea9d6b36", "", "", "", ALL, kUninstallLink }, | |
283 | |
284 // rooksdol.dll, "%programfiles%\\trusteer\\rapport\\bin\\". | |
285 { "802aefef", "06120e13", "", "", "3.5.1008.40", ALL, UPDATE }, | |
286 | |
287 // scanquery.dll, "%programfiles%\\scanquery\\". | |
288 { "0b52d2ae", "a4cc88b1", "", "", "", ALL, kUninstallLink }, | |
289 | |
290 // sdata.dll, "%programdata%\\srtserv\\". | |
291 { "1936d5cc", "223c44be", "", "", "", ALL, kUninstallLink }, | |
292 | |
293 // searchtree.dll, | |
294 // "%programfiles%\\contentwatch\\internet protection\\modules\\". | |
295 { "f6915a31", "4e61ce60", "", "", "", ALL, INVESTIGATING }, | |
296 | |
297 // sgprxy.dll, "%commonprogramfiles%\\is3\\anti-spyware\\". | |
298 { "005965ea", "bc5673f2", "", "", "", ALL, INVESTIGATING }, | |
299 | |
300 // snxhk.dll, "%ProgramFiles%\\avast software\\avast\\", "AVAST Software". | |
301 // NOTE: The digital signature of the DLL is double null terminated. | |
302 // Avast Antivirus prior to version 8.0 would kill the Chrome child process | |
303 // when blocked from running. | |
304 { "46c16aa8", "6b3a1b00", "a7db0e0c", "", "8.0", XP, | |
305 static_cast<RecommendedAction>(UPDATE | SEE_LINK | NOTIFY_USER) }, | |
306 | |
307 // snxhk.dll, "%ProgramFiles%\\alwil software\\avast5\\", "AVAST Software". | |
308 // NOTE: The digital signature of the DLL is double null terminated. | |
309 // Avast Antivirus prior to version 8.0 would kill the Chrome child process | |
310 // when blocked from running. | |
311 { "46c16aa8", "d8686924", "a7db0e0c", "", "8.0", XP, | |
312 static_cast<RecommendedAction>(UPDATE | SEE_LINK | NOTIFY_USER) }, | |
313 | |
314 // sprotector.dll, "". Different location each report. | |
315 { "24555d74", "", "", "", "", ALL, kUninstallLink }, | |
316 | |
317 // swi_filter_0001.dll (Sophos Web Intelligence), | |
318 // "%programfiles%\\sophos\\sophos anti-virus\\web intelligence\\". | |
319 // A small random sample all showed version 1.0.5.0. | |
320 { "61112d7b", "25fb120f", "", "", "", ALL, kInvestigatingLink }, | |
321 | |
322 // twking0.dll, "%systemroot%\\system32\\". | |
323 { "0355549b", "23d01d5b", "", "", "", ALL, kUninstallLink }, | |
324 | |
325 // twking1.dll, "%systemroot%\\system32\\". | |
326 { "02e44508", "23d01d5b", "", "", "", ALL, kUninstallLink }, | |
327 | |
328 // vksaver.dll, "%systemroot%\\system32\\". | |
329 { "c4a784d5", "23d01d5b", "", "", "", ALL, kUninstallLink }, | |
330 | |
331 // vlsp.dll (Venturi Firewall?), "%systemroot%\\system32\\". | |
332 { "2e4eb93d", "23d01d5b", "", "", "", ALL, INVESTIGATING }, | |
333 | |
334 // vmn3_1dn.dll, "%appdata%\\roaming\\vmndtxtb\\". | |
335 { "bba2037d", "9ab68585", "", "", "", ALL, kUninstallLink }, | |
336 | |
337 // webanalyzer.dll, | |
338 // "%programfiles%\\contentwatch\\internet protection\\modules\\". | |
339 { "c70b697d", "4e61ce60", "", "", "", ALL, INVESTIGATING }, | |
340 | |
341 // wowst0.dll, "%systemroot%\\system32\\". | |
342 { "38ad9963", "23d01d5b", "", "", "", ALL, kUninstallLink }, | |
343 | |
344 // wxbase28u_vc_cw.dll, "%systemroot%\\system32\\". | |
345 { "e967210d", "23d01d5b", "", "", "", ALL, kUninstallLink }, | |
346 }; | |
347 | |
348 // Generates an 8 digit hash from the input given. | |
349 static void GenerateHash(const std::string& input, std::string* output) { | |
350 if (input.empty()) { | |
351 *output = ""; | |
352 return; | |
353 } | |
354 | |
355 uint8_t hash[4]; | |
356 crypto::SHA256HashString(input, hash, sizeof(hash)); | |
357 *output = base::ToLowerASCII(base::HexEncode(hash, sizeof(hash))); | |
358 } | |
359 | |
360 // ----------------------------------------------------------------------------- | 126 // ----------------------------------------------------------------------------- |
361 | 127 |
362 // static | 128 // static |
363 void ModuleEnumerator::NormalizeModule(Module* module) { | 129 void ModuleEnumerator::NormalizeModule(Module* module) { |
364 base::string16 path = module->location; | 130 base::string16 path = module->location; |
365 if (!ConvertToLongPath(path, &module->location)) | 131 if (!ConvertToLongPath(path, &module->location)) |
366 module->location = path; | 132 module->location = path; |
367 | 133 |
368 module->location = base::i18n::ToLower(module->location); | 134 module->location = base::i18n::ToLower(module->location); |
369 | 135 |
(...skipping 10 matching lines...) Expand all Loading... | |
380 | 146 |
381 // Some version strings have things like (win7_rtm.090713-1255) appended | 147 // Some version strings have things like (win7_rtm.090713-1255) appended |
382 // to them. Remove that. | 148 // to them. Remove that. |
383 size_t first_space = module->version.find_first_of(L" "); | 149 size_t first_space = module->version.find_first_of(L" "); |
384 if (first_space != base::string16::npos) | 150 if (first_space != base::string16::npos) |
385 module->version = module->version.substr(0, first_space); | 151 module->version = module->version.substr(0, first_space); |
386 | 152 |
387 module->normalized = true; | 153 module->normalized = true; |
388 } | 154 } |
389 | 155 |
390 // static | |
391 ModuleEnumerator::ModuleStatus ModuleEnumerator::Match( | |
392 const ModuleEnumerator::Module& module, | |
393 const ModuleEnumerator::BlacklistEntry& blacklisted) { | |
394 // All modules must be normalized before matching against blacklist. | |
395 DCHECK(module.normalized); | |
396 // Filename is mandatory and version should not contain spaces. | |
397 DCHECK(strlen(blacklisted.filename) > 0); | |
398 DCHECK(!strstr(blacklisted.version_from, " ")); | |
399 DCHECK(!strstr(blacklisted.version_to, " ")); | |
400 | |
401 base::win::Version version = base::win::GetVersion(); | |
402 switch (version) { | |
403 case base::win::VERSION_XP: | |
404 if (!(blacklisted.os & XP)) return NOT_MATCHED; | |
405 break; | |
406 default: | |
407 break; | |
408 } | |
409 | |
410 std::string filename_hash, location_hash; | |
411 GenerateHash(base::WideToUTF8(module.name), &filename_hash); | |
412 GenerateHash(base::WideToUTF8(module.location), &location_hash); | |
413 | |
414 // Filenames are mandatory. Location is mandatory if given. | |
415 if (filename_hash == blacklisted.filename && | |
416 (std::string(blacklisted.location).empty() || | |
417 location_hash == blacklisted.location)) { | |
418 // We have a name match against the blacklist (and possibly location match | |
419 // also), so check version. | |
420 Version module_version(base::UTF16ToASCII(module.version)); | |
421 Version version_min(blacklisted.version_from); | |
422 Version version_max(blacklisted.version_to); | |
423 bool version_ok = !version_min.IsValid() && !version_max.IsValid(); | |
424 if (!version_ok) { | |
425 bool too_low = version_min.IsValid() && | |
426 (!module_version.IsValid() || | |
427 module_version.CompareTo(version_min) < 0); | |
428 bool too_high = version_max.IsValid() && | |
429 (!module_version.IsValid() || | |
430 module_version.CompareTo(version_max) >= 0); | |
431 version_ok = !too_low && !too_high; | |
432 } | |
433 | |
434 if (version_ok) { | |
435 // At this point, the names match and there is no version specified | |
436 // or the versions also match. | |
437 | |
438 std::string desc_or_signer(blacklisted.desc_or_signer); | |
439 std::string signer_hash, description_hash; | |
440 GenerateHash(base::WideToUTF8(module.digital_signer), &signer_hash); | |
441 GenerateHash(base::WideToUTF8(module.description), &description_hash); | |
442 | |
443 // If signatures match (or both are empty), then we have a winner. | |
444 if (signer_hash == desc_or_signer) | |
445 return CONFIRMED_BAD; | |
446 | |
447 // If descriptions match (or both are empty) and the locations match, then | |
448 // we also have a confirmed match. | |
449 if (description_hash == desc_or_signer && | |
450 !location_hash.empty() && location_hash == blacklisted.location) | |
451 return CONFIRMED_BAD; | |
452 | |
453 // We are not sure, but it is likely bad. | |
454 return SUSPECTED_BAD; | |
455 } | |
456 } | |
457 | |
458 return NOT_MATCHED; | |
459 } | |
460 | |
461 ModuleEnumerator::ModuleEnumerator(EnumerateModulesModel* observer) | 156 ModuleEnumerator::ModuleEnumerator(EnumerateModulesModel* observer) |
462 : enumerated_modules_(NULL), | 157 : enumerated_modules_(NULL), |
463 observer_(observer), | 158 observer_(observer), |
464 limited_mode_(false), | 159 limited_mode_(false), |
465 callback_thread_id_(BrowserThread::ID_COUNT) { | 160 callback_thread_id_(BrowserThread::ID_COUNT) { |
466 } | 161 } |
467 | 162 |
468 void ModuleEnumerator::ScanNow(ModulesVector* list, bool limited_mode) { | 163 void ModuleEnumerator::ScanNow(ModulesVector* list, bool limited_mode) { |
469 enumerated_modules_ = list; | 164 enumerated_modules_ = list; |
470 | 165 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
504 checkpoint2 = base::TimeTicks::Now(); | 199 checkpoint2 = base::TimeTicks::Now(); |
505 UMA_HISTOGRAM_TIMES("Conflicts.EnumerateShellExtensions", | 200 UMA_HISTOGRAM_TIMES("Conflicts.EnumerateShellExtensions", |
506 checkpoint2 - checkpoint); | 201 checkpoint2 - checkpoint); |
507 | 202 |
508 checkpoint = checkpoint2; | 203 checkpoint = checkpoint2; |
509 EnumerateWinsockModules(); | 204 EnumerateWinsockModules(); |
510 checkpoint2 = base::TimeTicks::Now(); | 205 checkpoint2 = base::TimeTicks::Now(); |
511 UMA_HISTOGRAM_TIMES("Conflicts.EnumerateWinsockModules", | 206 UMA_HISTOGRAM_TIMES("Conflicts.EnumerateWinsockModules", |
512 checkpoint2 - checkpoint); | 207 checkpoint2 - checkpoint); |
513 | 208 |
514 MatchAgainstBlacklist(); | 209 // TODO(chrisha): Annotate any modules that are suspicious/bad. |
210 | |
211 ReportThirdPartyMetrics(); | |
515 | 212 |
516 std::sort(enumerated_modules_->begin(), | 213 std::sort(enumerated_modules_->begin(), |
517 enumerated_modules_->end(), ModuleSort); | 214 enumerated_modules_->end(), ModuleSort); |
518 | 215 |
519 if (!limited_mode_) { | 216 if (!limited_mode_) { |
520 // Send a reply back on the UI thread. | 217 // Send a reply back on the UI thread. |
521 BrowserThread::PostTask(callback_thread_id_, FROM_HERE, | 218 BrowserThread::PostTask(callback_thread_id_, FROM_HERE, |
522 base::Bind(&ModuleEnumerator::ReportBack, this)); | 219 base::Bind(&ModuleEnumerator::ReportBack, this)); |
523 } else { | 220 } else { |
524 // We are on the main thread already. | 221 // We are on the main thread already. |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 location.substr(prefix.length() - 1); | 399 location.substr(prefix.length() - 1); |
703 size_t length = new_location.length() - mapping->second.length(); | 400 size_t length = new_location.length() - mapping->second.length(); |
704 if (length < min_length) { | 401 if (length < min_length) { |
705 entry->location = new_location; | 402 entry->location = new_location; |
706 min_length = length; | 403 min_length = length; |
707 } | 404 } |
708 } | 405 } |
709 } | 406 } |
710 } | 407 } |
711 | 408 |
712 void ModuleEnumerator::MatchAgainstBlacklist() { | |
713 for (size_t m = 0; m < enumerated_modules_->size(); ++m) { | |
714 // Match this module against the blacklist. | |
715 Module* module = &(*enumerated_modules_)[m]; | |
716 module->status = GOOD; // We change this below potentially. | |
717 for (size_t i = 0; i < arraysize(kModuleBlacklist); ++i) { | |
718 #if !defined(NDEBUG) | |
719 // This saves time when constructing the blacklist. | |
720 std::string hashes(kModuleBlacklist[i].filename); | |
721 std::string hash1, hash2, hash3; | |
722 GenerateHash(kModuleBlacklist[i].filename, &hash1); | |
723 hashes += " - " + hash1; | |
724 GenerateHash(kModuleBlacklist[i].location, &hash2); | |
725 hashes += " - " + hash2; | |
726 GenerateHash(kModuleBlacklist[i].desc_or_signer, &hash3); | |
727 hashes += " - " + hash3; | |
728 #endif | |
729 | |
730 ModuleStatus status = Match(*module, kModuleBlacklist[i]); | |
731 if (status != NOT_MATCHED) { | |
732 // We have a match against the blacklist. Mark it as such. | |
733 module->status = status; | |
734 module->recommended_action = kModuleBlacklist[i].help_tip; | |
735 break; | |
736 } | |
737 } | |
738 | |
739 // Modules loaded from these locations are frequently malicious | |
740 // and notorious for changing frequently so they are not good candidates | |
741 // for blacklisting individually. Mark them as suspicious if we haven't | |
742 // classified them as bad yet. | |
743 if (module->status == NOT_MATCHED || module->status == GOOD) { | |
744 if (base::StartsWith(module->location, L"%temp%", | |
745 base::CompareCase::INSENSITIVE_ASCII) || | |
746 base::StartsWith(module->location, L"%tmp%", | |
747 base::CompareCase::INSENSITIVE_ASCII)) { | |
748 module->status = SUSPECTED_BAD; | |
749 } | |
750 } | |
751 } | |
752 } | |
753 | |
754 void ModuleEnumerator::ReportBack() { | 409 void ModuleEnumerator::ReportBack() { |
755 if (!limited_mode_) | 410 if (!limited_mode_) |
756 DCHECK_CURRENTLY_ON(callback_thread_id_); | 411 DCHECK_CURRENTLY_ON(callback_thread_id_); |
757 observer_->DoneScanning(); | 412 observer_->DoneScanning(); |
758 } | 413 } |
759 | 414 |
760 base::string16 ModuleEnumerator::GetSubjectNameFromDigitalSignature( | 415 base::string16 ModuleEnumerator::GetSubjectNameFromDigitalSignature( |
761 const base::FilePath& filename) { | 416 const base::FilePath& filename) { |
762 HCERTSTORE store = NULL; | 417 HCERTSTORE store = NULL; |
763 HCRYPTMSG message = NULL; | 418 HCRYPTMSG message = NULL; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
832 0, | 487 0, |
833 NULL, | 488 NULL, |
834 const_cast<LPWSTR>(subject_name.c_str()), | 489 const_cast<LPWSTR>(subject_name.c_str()), |
835 subject_name_size))) { | 490 subject_name_size))) { |
836 return base::string16(); | 491 return base::string16(); |
837 } | 492 } |
838 | 493 |
839 return subject_name; | 494 return subject_name; |
840 } | 495 } |
841 | 496 |
497 void ModuleEnumerator::ReportThirdPartyMetrics() { | |
498 size_t signed_modules = 0; | |
499 size_t microsoft_modules = 0; | |
500 for (const auto& module : *enumerated_modules_) { | |
501 if (!module.digital_signer.empty()) { | |
502 ++signed_modules; | |
503 if (module.digital_signer.find(L"Microsoft") != base::string16::npos) | |
504 ++microsoft_modules; | |
505 } | |
506 } | |
507 | |
508 // Report back some metrics regarding third party modules. | |
509 UMA_HISTOGRAM_CUSTOM_COUNTS("ThirdPartyModules.Modules.Signed", | |
510 signed_modules, 1, 500, 50); | |
511 UMA_HISTOGRAM_CUSTOM_COUNTS("ThirdPartyModules.Modules.Signed.Microsoft", | |
512 microsoft_modules, 1, 500, 50); | |
513 UMA_HISTOGRAM_CUSTOM_COUNTS("ThirdPartyModules.Modules.Total", | |
514 enumerated_modules_->size(), 1, 500, 50); | |
515 } | |
516 | |
842 // ---------------------------------------------------------------------------- | 517 // ---------------------------------------------------------------------------- |
843 | 518 |
844 // static | 519 // static |
845 EnumerateModulesModel* EnumerateModulesModel::GetInstance() { | 520 EnumerateModulesModel* EnumerateModulesModel::GetInstance() { |
846 return base::Singleton<EnumerateModulesModel>::get(); | 521 static base::LazyInstance<EnumerateModulesModel>::Leaky model; |
grt (UTC plus 2)
2016/06/20 20:36:28
model = LAZY_INSTANCE_INITIALIZER;
chrisha
2016/07/22 20:30:12
Done.
| |
522 return &model.Get(); | |
grt (UTC plus 2)
2016/06/20 20:36:28
model.Pointer();
chrisha
2016/07/22 20:30:12
Done.
| |
847 } | 523 } |
848 | 524 |
849 bool EnumerateModulesModel::ShouldShowConflictWarning() const { | 525 bool EnumerateModulesModel::ShouldShowConflictWarning() const { |
850 // If the user has acknowledged the conflict notification, then we don't need | 526 // If the user has acknowledged the conflict notification, then we don't need |
851 // to show it again (because the scanning only happens once per the lifetime | 527 // to show it again (because the scanning only happens once per the lifetime |
852 // of the process). If we were to run the scanning more than once, then we'd | 528 // of the process). If we were to run the scanning more than once, then we'd |
853 // need to clear the flag somewhere when we are ready to show it again. | 529 // need to clear the flag somewhere when we are ready to show it again. |
854 if (conflict_notification_acknowledged_) | 530 if (conflict_notification_acknowledged_) |
855 return false; | 531 return false; |
856 | 532 |
857 return confirmed_bad_modules_detected_ > 0; | 533 return confirmed_bad_modules_detected_ > 0; |
858 } | 534 } |
859 | 535 |
860 void EnumerateModulesModel::AcknowledgeConflictNotification() { | 536 void EnumerateModulesModel::AcknowledgeConflictNotification() { |
861 if (!conflict_notification_acknowledged_) { | 537 if (!conflict_notification_acknowledged_) { |
862 conflict_notification_acknowledged_ = true; | 538 conflict_notification_acknowledged_ = true; |
863 content::NotificationService::current()->Notify( | 539 FOR_EACH_OBSERVER(Observer, observers_, OnConflictsAcknowledged()); |
864 chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_ICON_CHANGE, | |
865 content::Source<EnumerateModulesModel>(this), | |
866 content::NotificationService::NoDetails()); | |
867 } | 540 } |
868 } | 541 } |
869 | 542 |
870 void EnumerateModulesModel::ScanNow() { | 543 void EnumerateModulesModel::ScanNow() { |
871 if (scanning_) | 544 lock_.Acquire(); // Balanced in DoneScanning(); |
872 return; // A scan is already in progress. | |
873 | 545 |
874 lock->Acquire(); // Balanced in DoneScanning(); | 546 if (scanning_) { |
547 lock_.Release(); | |
548 return; | |
549 } | |
875 | 550 |
876 scanning_ = true; | 551 scanning_ = true; |
877 | 552 |
878 // Instruct the ModuleEnumerator class to load this on the File thread. | 553 // Instruct the ModuleEnumerator class to load this on the File thread. |
879 // ScanNow does not block. | 554 // ScanNow does not block. |
880 if (!module_enumerator_.get()) | 555 if (!module_enumerator_.get()) |
881 module_enumerator_ = new ModuleEnumerator(this); | 556 module_enumerator_ = new ModuleEnumerator(this); |
882 module_enumerator_->ScanNow(&enumerated_modules_, limited_mode_); | 557 module_enumerator_->ScanNow(&enumerated_modules_, limited_mode_); |
883 } | 558 } |
884 | 559 |
885 base::ListValue* EnumerateModulesModel::GetModuleList() const { | 560 base::ListValue* EnumerateModulesModel::GetModuleList() { |
886 if (scanning_) | 561 lock_.Acquire(); |
887 return NULL; | |
888 | 562 |
889 lock->Acquire(); | 563 if (scanning_) { |
564 lock_.Release(); | |
565 return nullptr; | |
566 } | |
890 | 567 |
891 if (enumerated_modules_.empty()) { | 568 if (enumerated_modules_.empty()) { |
892 lock->Release(); | 569 lock_.Release(); |
893 return NULL; | 570 return nullptr; |
894 } | 571 } |
895 | 572 |
896 base::ListValue* list = new base::ListValue(); | 573 base::ListValue* list = new base::ListValue(); |
897 | 574 |
898 for (ModuleEnumerator::ModulesVector::const_iterator module = | 575 for (ModuleEnumerator::ModulesVector::const_iterator module = |
899 enumerated_modules_.begin(); | 576 enumerated_modules_.begin(); |
900 module != enumerated_modules_.end(); ++module) { | 577 module != enumerated_modules_.end(); ++module) { |
901 base::DictionaryValue* data = new base::DictionaryValue(); | 578 base::DictionaryValue* data = new base::DictionaryValue(); |
902 data->SetInteger("type", module->type); | 579 data->SetInteger("type", module->type); |
903 base::string16 type_string; | 580 base::string16 type_string; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
957 IDS_CONFLICTS_CHECK_POSSIBLE_ACTION_DISABLE); | 634 IDS_CONFLICTS_CHECK_POSSIBLE_ACTION_DISABLE); |
958 } | 635 } |
959 } | 636 } |
960 base::string16 possible_resolution; | 637 base::string16 possible_resolution; |
961 if (!actions.empty()) { | 638 if (!actions.empty()) { |
962 possible_resolution = | 639 possible_resolution = |
963 l10n_util::GetStringUTF16(IDS_CONFLICTS_CHECK_POSSIBLE_ACTIONS) + | 640 l10n_util::GetStringUTF16(IDS_CONFLICTS_CHECK_POSSIBLE_ACTIONS) + |
964 L" " + actions; | 641 L" " + actions; |
965 } | 642 } |
966 data->SetString("possibleResolution", possible_resolution); | 643 data->SetString("possibleResolution", possible_resolution); |
967 data->SetString("help_url", | 644 // TODO(chrisha): Set help_url when we have a meaningful place for users |
968 ConstructHelpCenterUrl(*module).spec().c_str()); | 645 // to land. |
969 } | 646 } |
970 | 647 |
971 list->Append(data); | 648 list->Append(data); |
972 } | 649 } |
973 | 650 |
974 lock->Release(); | 651 lock_.Release(); |
975 return list; | 652 return list; |
976 } | 653 } |
977 | 654 |
978 GURL EnumerateModulesModel::GetFirstNotableConflict() { | 655 GURL EnumerateModulesModel::GetConflictUrl() { |
979 lock->Acquire(); | 656 // For now, simply bring up the chrome://conflicts page, which has detailed |
980 GURL url; | 657 // information about each module. |
981 | 658 if (ShouldShowConflictWarning()) |
982 if (enumerated_modules_.empty()) { | 659 return GURL(L"chrome://conflicts"); |
983 lock->Release(); | 660 return GURL(); |
984 return GURL(); | |
985 } | |
986 | |
987 for (ModuleEnumerator::ModulesVector::const_iterator module = | |
988 enumerated_modules_.begin(); | |
989 module != enumerated_modules_.end(); ++module) { | |
990 if (!(module->recommended_action & ModuleEnumerator::NOTIFY_USER)) | |
991 continue; | |
992 | |
993 url = ConstructHelpCenterUrl(*module); | |
994 DCHECK(url.is_valid()); | |
995 break; | |
996 } | |
997 | |
998 lock->Release(); | |
999 return url; | |
1000 } | 661 } |
1001 | 662 |
1002 EnumerateModulesModel::EnumerateModulesModel() | 663 EnumerateModulesModel::EnumerateModulesModel() |
1003 : limited_mode_(false), | 664 : limited_mode_(false), |
1004 scanning_(false), | 665 scanning_(false), |
1005 conflict_notification_acknowledged_(false), | 666 conflict_notification_acknowledged_(false), |
1006 confirmed_bad_modules_detected_(0), | 667 confirmed_bad_modules_detected_(0), |
1007 modules_to_notify_about_(0), | 668 modules_to_notify_about_(0), |
1008 suspected_bad_modules_detected_(0) { | 669 suspected_bad_modules_detected_(0) { |
1009 lock = new base::Lock(); | |
1010 } | |
1011 | |
1012 EnumerateModulesModel::~EnumerateModulesModel() { | |
1013 delete lock; | |
1014 } | 670 } |
1015 | 671 |
1016 void EnumerateModulesModel::MaybePostScanningTask() { | 672 void EnumerateModulesModel::MaybePostScanningTask() { |
1017 static bool done = false; | 673 static bool done = false; |
1018 if (!done) { | 674 if (!done) { |
1019 done = true; | 675 done = true; |
1020 if (base::win::GetVersion() == base::win::VERSION_XP) { | 676 check_modules_timer_.Start(FROM_HERE, |
1021 check_modules_timer_.Start(FROM_HERE, | 677 base::TimeDelta::FromMilliseconds(kModuleCheckDelayMs), |
1022 base::TimeDelta::FromMilliseconds(kModuleCheckDelayMs), | 678 this, &EnumerateModulesModel::ScanNow); |
1023 this, &EnumerateModulesModel::ScanNow); | |
1024 } | |
1025 } | 679 } |
1026 } | 680 } |
1027 | 681 |
1028 void EnumerateModulesModel::DoneScanning() { | 682 void EnumerateModulesModel::DoneScanning() { |
1029 confirmed_bad_modules_detected_ = 0; | 683 confirmed_bad_modules_detected_ = 0; |
1030 suspected_bad_modules_detected_ = 0; | 684 suspected_bad_modules_detected_ = 0; |
1031 modules_to_notify_about_ = 0; | 685 modules_to_notify_about_ = 0; |
1032 for (ModuleEnumerator::ModulesVector::const_iterator module = | 686 for (ModuleEnumerator::ModulesVector::const_iterator module = |
1033 enumerated_modules_.begin(); | 687 enumerated_modules_.begin(); |
1034 module != enumerated_modules_.end(); ++module) { | 688 module != enumerated_modules_.end(); ++module) { |
1035 if (module->status == ModuleEnumerator::CONFIRMED_BAD) { | 689 if (module->status == ModuleEnumerator::CONFIRMED_BAD) { |
1036 ++confirmed_bad_modules_detected_; | 690 ++confirmed_bad_modules_detected_; |
1037 if (module->recommended_action & ModuleEnumerator::NOTIFY_USER) | 691 if (module->recommended_action & ModuleEnumerator::NOTIFY_USER) |
1038 ++modules_to_notify_about_; | 692 ++modules_to_notify_about_; |
1039 } else if (module->status == ModuleEnumerator::SUSPECTED_BAD) { | 693 } else if (module->status == ModuleEnumerator::SUSPECTED_BAD) { |
1040 ++suspected_bad_modules_detected_; | 694 ++suspected_bad_modules_detected_; |
1041 if (module->recommended_action & ModuleEnumerator::NOTIFY_USER) | 695 if (module->recommended_action & ModuleEnumerator::NOTIFY_USER) |
1042 ++modules_to_notify_about_; | 696 ++modules_to_notify_about_; |
1043 } | 697 } |
1044 } | 698 } |
1045 | 699 |
1046 scanning_ = false; | 700 scanning_ = false; |
1047 lock->Release(); | 701 lock_.Release(); |
1048 | 702 |
1049 UMA_HISTOGRAM_COUNTS_100("Conflicts.SuspectedBadModules", | 703 UMA_HISTOGRAM_COUNTS_100("Conflicts.SuspectedBadModules", |
1050 suspected_bad_modules_detected_); | 704 suspected_bad_modules_detected_); |
1051 UMA_HISTOGRAM_COUNTS_100("Conflicts.ConfirmedBadModules", | 705 UMA_HISTOGRAM_COUNTS_100("Conflicts.ConfirmedBadModules", |
1052 confirmed_bad_modules_detected_); | 706 confirmed_bad_modules_detected_); |
1053 | 707 |
1054 // Notifications are not available in limited mode. | 708 // Forward the callback to any registered observers. |
1055 if (limited_mode_) | 709 FOR_EACH_OBSERVER(Observer, observers_, OnScanCompleted(limited_mode_)); |
1056 return; | |
1057 | |
1058 content::NotificationService::current()->Notify( | |
1059 chrome::NOTIFICATION_MODULE_LIST_ENUMERATED, | |
1060 content::Source<EnumerateModulesModel>(this), | |
1061 content::NotificationService::NoDetails()); | |
1062 } | 710 } |
1063 | |
1064 GURL EnumerateModulesModel::ConstructHelpCenterUrl( | |
1065 const ModuleEnumerator::Module& module) const { | |
1066 if (!(module.recommended_action & ModuleEnumerator::SEE_LINK) && | |
1067 !(module.recommended_action & ModuleEnumerator::NOTIFY_USER)) | |
1068 return GURL(); | |
1069 | |
1070 // Construct the needed hashes. | |
1071 std::string filename, location, description, signer; | |
1072 GenerateHash(base::WideToUTF8(module.name), &filename); | |
1073 GenerateHash(base::WideToUTF8(module.location), &location); | |
1074 GenerateHash(base::WideToUTF8(module.description), &description); | |
1075 GenerateHash(base::WideToUTF8(module.digital_signer), &signer); | |
1076 | |
1077 base::string16 url = | |
1078 l10n_util::GetStringFUTF16(IDS_HELP_CENTER_VIEW_CONFLICTS, | |
1079 base::ASCIIToUTF16(filename), base::ASCIIToUTF16(location), | |
1080 base::ASCIIToUTF16(description), base::ASCIIToUTF16(signer)); | |
1081 return GURL(base::UTF16ToUTF8(url)); | |
1082 } | |
OLD | NEW |