-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanalizeAPK.py
170 lines (143 loc) · 5.93 KB
/
analizeAPK.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/python
#-*- coding:utf-8 -*-
'''
Copyright (C) 2016 QuantiKa14 Servicios Integrales S.L
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
from apk_parse.apk import APK
from pymongo import MongoClient
import os, re, time
from os import listdir
#import modules.idiomas_detector as ID
class colores:
header = '\033[95m'
blue = '\033[94m'
green = '\033[92m'
alert = '\033[93m'
fail = '\033[91m'
normal = '\033[0m'
bold = '\033[1m'
underline = '\033[4m'
client = MongoClient()
db = client.Tacita
start = 100000
end = 110000
def banner():
print "---------||| |||--------"
print "---------||| |||--------"
print "---------||| ||||||||---"
print "---------||| |||---||---"
print "---------||| |||---||---"
print "---------||| ||||||||---"
print "---------|||||||||||--------"
print "****************************"
print "little-cup.py | QuantiKa14"
print "Author: Jorge Websec"
print "Name app: Tacita-APKanalyze.py"
print "****************************"
print "- The last version 12/12/2019"
def insert_mongodb(id_file, package, md5, file_size, andro_version, main_activity, activities, services, permissions, urls, emails, ftps, IPs, strings):
global client, db
try:
cursor = db.Tacita.find({"id_file":id_file})
if cursor:
date_Insert = time.strftime("%c")
date_Update = "none"
cursor = db.Tacita.update({"id_file":id_file},{"id_file": id_file, "package": package, "file_md5": md5, "file_size": file_size, "AndroidVersion": andro_version,"main_activity": main_activity, "activities": activities, "services": services, "permissions": permissions, "links": urls, "emails": emails, "ftps": ftps, "ips": IPs, "strings": strings, "date_Insert": date_Insert, "date_Update": date_Update, "bot":"DownloadAPK"})
print colores.blue + "[INFO][>] UPDATE IN DB" + colores.normal
else:
date_Insert = time.strftime("%c")
date_Update = "none"
cursor = db.Tacita.insert({"id_file": id_file, "package": package, "file_md5": md5, "file_size": file_size, "AndroidVersion": andro_version,"main_activity": main_activity, "activities": activities, "services": services, "permissions": permissions, "links": urls, "emails": emails, "ftps": ftps, "ips": IPs, "strings": strings, "date_Insert": date_Insert, "date_Update": date_Update, "bot":"DownloadAPK"})
print colores.blue + "[INFO][>] INSERT IN DB" + colores.normal
except Exception as e:
print e
pass
def ls(ruta = 'bot'):
return listdir(ruta)
def main():
banner()
for target in ls():
target = "bot/" + str(target)
apkf = APK(target)
md5 = apkf.file_md5
package = apkf.get_package()
file_size = apkf.file_size
andro_version = apkf.get_androidversion_name()
libraries = apkf.get_libraries()
main_activity = apkf.get_main_activity()
activities = apkf.get_activities()
services = apkf.get_services()
files = apkf.get_files()
permissions = apkf.get_permissions()
counter_emails = 0
counter_urls = 0
counter_ftps = 0
all_emails = []
all_urls = []
all_ftps = []
all_ips = []
all_words = []
print "----------------------------------------------"
print colores.underline + "[+][TARGET][>]" + str(package) + " ["+ str(target) +"]" + colores.normal
print colores.header + "[-][md5][>] " + md5
print colores.header + "[-][Android version][>] " + andro_version
print colores.green + "|----[>] " + "Searching emails, links, FTP and IPs in strings ..." + colores.normal
#Strings
strings = os.popen("strings " + target)
for word in strings:
#Save word in array
all_words.append(word)
#To found emails in strings
if "@" in word:
try:
if word.find(".com")>0 or word.find(".es")>0 or word.find(".eu")>0 or word.find(".net")>0 or word.find(".gob")>0 or word.find(".info")>0 or word.find(".org")>0:
words = word.split(" ")
for w in words:
if word.find(".com")>0 or word.find(".es")>0 or word.find(".eu")>0 or word.find(".net")>0 or word.find(".gob")>0 or word.find(".info")>0 or word.find(".org")>0:
counter_emails += 1
email = re.findall(r'[\w\.-]+@[\w\.-]+', word)
if not email in all_emails:
print(colores.green + "|----[EMAIL][>] " + str(email) + colores.normal)
all_emails.append(email)
except Exception as e:
print e
#To found urls in strings
if "http" in word or "wwww." in word:
try:
url = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', word)
if not url in all_urls or url == "":
all_urls.append(url)
print colores.green + "|----[URL][>] " + str(url) + colores.normal
except Exception as e:
print e
#To found FTP in strings
if "ftp" in word:
try:
ftp = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', word)
if not ftp in all_ftps or ftp == "":
all_ftps.append(ftp)
print colores.green + "|----[FTP][>] " + str(ftp) + colores.normal
except Exception as e:
print e
#Find IP in strings
ip = re.findall( r'[0-9]+(?:\.[0-9]+){3}', word)
if ip:
try:
all_ips.append(ip)
print colores.green + "|----[IP][>] " + str(ip) + colores.normal
except Exception as e:
print e
#Save in DB
insert_mongodb(target, package, md5, file_size, andro_version, main_activity, activities, services, permissions, all_urls, all_emails, all_ftps, all_ips, all_words)
if __name__ == "__main__":
main()