1
2
3
4
5
6
7 import logging
8 import os
9 from zipfile import BadZipfile
10
11 from lib.cuckoo.common.objects import File
12 from lib.cuckoo.common.abstracts import Processing
13 from lib.cuckoo.common.exceptions import CuckooProcessingError
14
15 try:
16 from androguard.core.bytecodes.apk import APK
17 HAVE_ANDROGUARD = True
18 except ImportError:
19 HAVE_ANDROGUARD = False
20
21 try:
22 from lib.api.googleplay.googleplay import GooglePlayAPI
23 HAVE_GOOGLEPLAY = True
24 except ImportError:
25 HAVE_GOOGLEPLAY = False
26
27 log = logging.getLogger(__name__)
28
30 """Google Play information about the analysis session"""
31
33 """Run Google play unofficial python api the get the google play information
34 @return: list of google play features
35 """
36 self.key = "googleplay"
37 googleplay = {}
38
39 if not HAVE_GOOGLEPLAY:
40 log.error("Unable to import the GooglePlay library, has it been "
41 "installed properly?")
42 return
43
44 if not HAVE_ANDROGUARD:
45 log.error("Could not find the Androguard library, please install "
46 "it. (`pip install androguard`)")
47
48 if ("file" not in self.task["category"]):
49 return
50
51 f = File(self.task["target"])
52 if f.get_name().endswith((".zip", ".apk")) or "zip" in f.get_type():
53 if not os.path.exists(self.file_path):
54 raise CuckooProcessingError("Sample file doesn't exist: \"%s\"" % self.file_path)
55
56 android_id = self.options.get("android_id")
57 google_login = self.options.get("google_login")
58 google_password = self.options.get("google_password")
59
60
61 if not android_id and not google_login and not google_password:
62 raise CuckooProcessingError("Google Play Credentials not configured, skip")
63
64 try:
65 a = APK(self.file_path)
66 if a.is_valid_APK():
67 package = a.get_package()
68
69 api = GooglePlayAPI(android_id)
70 api.login(google_login, google_password, None)
71
72
73 app_data = api.details(package)
74 app_detail = app_data.docV2.details.appDetails
75
76 if not app_detail.installationSize:
77 return googleplay
78
79 googleplay["title"] = app_detail.title
80 googleplay["app_category"] = app_detail.appCategory._values
81 googleplay["version_code"] = app_detail.versionCode
82 googleplay["app_type"] = app_detail.appType
83 googleplay["content_rating"] = app_detail.contentRating
84 googleplay["developer_email"] = app_detail.developerEmail
85 googleplay["developer_name"] = app_detail.developerName
86 googleplay["developer_website"] = app_detail.developerWebsite
87 googleplay["installation_size"] = app_detail.installationSize
88 googleplay["num_downloads"] = app_detail.numDownloads
89 googleplay["upload_date"] = app_detail.uploadDate
90 googleplay["permissions"] = app_detail.permission._values
91 except (IOError, OSError, BadZipfile) as e:
92 raise CuckooProcessingError("Error opening file %s" % e)
93
94 return googleplay
95