Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chrome/common/safe_browsing/download_protection_util.cc

Issue 1262753002: [SafeBrowsing] Send pings for Zip files that contain other archives. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address asvitkine comments Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/common/safe_browsing/download_protection_util.h" 5 #include "chrome/common/safe_browsing/download_protection_util.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 9
10 namespace safe_browsing { 10 namespace safe_browsing {
11 namespace download_protection_util { 11 namespace download_protection_util {
12 12
13 bool IsArchiveFile(const base::FilePath& file) { 13 bool IsArchiveFile(const base::FilePath& file) {
14 // TODO(mattm): should .dmg be checked here instead of IsBinaryFile? 14 // List of interesting archive file formats. These are by no means exhaustive,
15 return file.MatchesExtension(FILE_PATH_LITERAL(".zip")); 15 // but are currently file types that Safe Browsing would like to see pings for
16 // due to the possibility of them being used as wrapper formats for malicious
17 // payloads.
18 const base::FilePath::CharType* kArchiveFileTypes[] = {
19 FILE_PATH_LITERAL(".zip"),
20 FILE_PATH_LITERAL(".rar"),
21 FILE_PATH_LITERAL(".7z"),
22 FILE_PATH_LITERAL(".cab"),
23 FILE_PATH_LITERAL(".xz"),
24 FILE_PATH_LITERAL(".gz"),
25 FILE_PATH_LITERAL(".tgz"),
26 FILE_PATH_LITERAL(".bz2"),
27 FILE_PATH_LITERAL(".tar"),
28 FILE_PATH_LITERAL(".arj"),
29 FILE_PATH_LITERAL(".lzh"),
30 FILE_PATH_LITERAL(".lha"),
31 FILE_PATH_LITERAL(".wim"),
32 FILE_PATH_LITERAL(".z"),
33 FILE_PATH_LITERAL(".lzma"),
34 FILE_PATH_LITERAL(".cpio"),
35 };
36 for (const auto& extension : kArchiveFileTypes) {
37 if (file.MatchesExtension(extension))
38 return true;
39 }
40 // TODO(mattm): should .dmg be checked here instead of IsSupportedBinaryFile?
palmer 2015/07/31 22:48:18 Yes, I think so. rsesek@ wrote a handler for it; y
asanka 2015/08/02 03:43:32 Cool. Thanks. Noted and I'll send a note to the SB
41 return false;
16 } 42 }
17 43
18 bool IsBinaryFile(const base::FilePath& file) { 44 bool IsSupportedBinaryFile(const base::FilePath& file) {
19 const base::FilePath::CharType* kSupportedBinaryFileTypes[] = { 45 const base::FilePath::CharType* kSupportedBinaryFileTypes[] = {
20 // Executable extensions for MS Windows. 46 // Executable extensions for MS Windows.
21 FILE_PATH_LITERAL(".cab"),
22 FILE_PATH_LITERAL(".cmd"), 47 FILE_PATH_LITERAL(".cmd"),
23 FILE_PATH_LITERAL(".com"), 48 FILE_PATH_LITERAL(".com"),
24 FILE_PATH_LITERAL(".dll"), 49 FILE_PATH_LITERAL(".dll"),
25 FILE_PATH_LITERAL(".exe"), 50 FILE_PATH_LITERAL(".exe"),
26 FILE_PATH_LITERAL(".msc"), 51 FILE_PATH_LITERAL(".msc"),
27 FILE_PATH_LITERAL(".msi"), 52 FILE_PATH_LITERAL(".msi"),
28 FILE_PATH_LITERAL(".msp"), 53 FILE_PATH_LITERAL(".msp"),
29 FILE_PATH_LITERAL(".mst"), 54 FILE_PATH_LITERAL(".mst"),
30 FILE_PATH_LITERAL(".pif"), 55 FILE_PATH_LITERAL(".pif"),
31 FILE_PATH_LITERAL(".scr"), 56 FILE_PATH_LITERAL(".scr"),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // Mac extensions. 90 // Mac extensions.
66 FILE_PATH_LITERAL(".app"), 91 FILE_PATH_LITERAL(".app"),
67 FILE_PATH_LITERAL(".dmg"), 92 FILE_PATH_LITERAL(".dmg"),
68 FILE_PATH_LITERAL(".osx"), 93 FILE_PATH_LITERAL(".osx"),
69 FILE_PATH_LITERAL(".pkg"), 94 FILE_PATH_LITERAL(".pkg"),
70 }; 95 };
71 for (const auto& extension : kSupportedBinaryFileTypes) 96 for (const auto& extension : kSupportedBinaryFileTypes)
72 if (file.MatchesExtension(extension)) 97 if (file.MatchesExtension(extension))
73 return true; 98 return true;
74 99
75 // Archives _may_ contain binaries, we'll check in ExtractFileFeatures. 100 // .zip files are examined for any executables or other archives they may
76 return IsArchiveFile(file); 101 // contain. Currently no other archive formats are supported.
102 return file.MatchesExtension(FILE_PATH_LITERAL(".zip"));
77 } 103 }
78 104
79 ClientDownloadRequest::DownloadType GetDownloadType( 105 ClientDownloadRequest::DownloadType GetDownloadType(
80 const base::FilePath& file) { 106 const base::FilePath& file) {
81 DCHECK(IsBinaryFile(file)); 107 DCHECK(IsSupportedBinaryFile(file));
82 if (file.MatchesExtension(FILE_PATH_LITERAL(".apk"))) 108 if (file.MatchesExtension(FILE_PATH_LITERAL(".apk")))
83 return ClientDownloadRequest::ANDROID_APK; 109 return ClientDownloadRequest::ANDROID_APK;
84 else if (file.MatchesExtension(FILE_PATH_LITERAL(".crx"))) 110 else if (file.MatchesExtension(FILE_PATH_LITERAL(".crx")))
85 return ClientDownloadRequest::CHROME_EXTENSION; 111 return ClientDownloadRequest::CHROME_EXTENSION;
86 // For zip files, we use the ZIPPED_EXECUTABLE type since we will only send
87 // the pingback if we find an executable inside the zip archive.
88 else if (file.MatchesExtension(FILE_PATH_LITERAL(".zip"))) 112 else if (file.MatchesExtension(FILE_PATH_LITERAL(".zip")))
113 // DownloadProtectionService doesn't send a ClientDownloadRequest for ZIP
114 // files unless they contain either executables or archives. The resulting
115 // DownloadType is either ZIPPED_EXECUTABLE or ZIPPED_ARCHIVE respectively.
116 // This function will return ZIPPED_EXECUTABLE for ZIP files as a
117 // placeholder. The correct DownloadType will be determined based on the
118 // result of analyzing the ZIP file.
89 return ClientDownloadRequest::ZIPPED_EXECUTABLE; 119 return ClientDownloadRequest::ZIPPED_EXECUTABLE;
90 else if (file.MatchesExtension(FILE_PATH_LITERAL(".dmg")) || 120 else if (file.MatchesExtension(FILE_PATH_LITERAL(".dmg")) ||
91 file.MatchesExtension(FILE_PATH_LITERAL(".pkg")) || 121 file.MatchesExtension(FILE_PATH_LITERAL(".pkg")) ||
92 file.MatchesExtension(FILE_PATH_LITERAL(".osx")) || 122 file.MatchesExtension(FILE_PATH_LITERAL(".osx")) ||
93 file.MatchesExtension(FILE_PATH_LITERAL(".app"))) 123 file.MatchesExtension(FILE_PATH_LITERAL(".app")))
94 return ClientDownloadRequest::MAC_EXECUTABLE; 124 return ClientDownloadRequest::MAC_EXECUTABLE;
95 return ClientDownloadRequest::WIN_EXECUTABLE; 125 return ClientDownloadRequest::WIN_EXECUTABLE;
96 } 126 }
97 127
98 } // namespace download_protection_util 128 } // namespace download_protection_util
99 } // namespace safe_browsing 129 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698