-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanifestReceiverParser.py
236 lines (215 loc) · 7.75 KB
/
manifestReceiverParser.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import xml.etree.ElementTree as ET
from xml.dom import minidom
#from lxml import etree
import glob
import ntpath
cntPer = 0
cntNonPer = 0
hasPermission = False
cnt = 0
numOfPerm = 0
typeA = 0
typeB = 0
typeAB = 0
typeBNo = 0
typeANo = 0
typeABNo = 0
intNoWriteCnt = 0
intNWSNoWriteCnt = 0
permFreq = []
permDict = {}
appPerm = []
writeper = "android.permission.WRITE_EXTERNAL_STORAGE"
interperm = "android.permission.INTERNET"
nwsperm = "android.permission.ACCESS_NETWORK_STATE"
hasReciever = 0
noReceiver = 0
def isKeyboardApp(approot):
iskb = False
for child in approot.getchildren():
if child.tag == "application":
for subchild in child.getchildren():
if subchild.tag == "service":
attrs = subchild.attrib
keys = attrs.keys()
for key in keys:
if ( attrs[key] == "android.permission.BIND_INPUT_METHOD"):
iskb = True
#print ntpath.basename(files), " is a keyboard app"
break
return iskb
def hasReceiverComp(approot):
hasReceiver = False
for child in approot.getchildren():
if child.tag == "application":
for subchild in child.getchildren():
if subchild.tag == "receiver":
hasReceiver = True
break
## attrs = subchild.attrib
## keys = attrs.keys()
## for key in keys:
## if ( attrs[key] == "android.permission.BIND_INPUT_METHOD"):
## iskb = True
## #print ntpath.basename(files), " is a keyboard app"
## break
return hasReceiver
###########################################
def printIntentFilters(approot):
hasReceiver = False
for child in approot.getchildren():
if child.tag == "application":
for subchild in child.getchildren():
if subchild.tag == "receiver":
hasReceiver = True
for subsubchild in subchild.getchildren():
if subsubchild.tag == "intent-filter":
print "found intent filter"
for subsubsubchild in subsubchild.getchildren():
print subsubsubchild
attrs = subsubsubchild.attrib
keys = attrs.keys()
for key in keys:
print key
#########################################################
## typeB = False
## if writeper in permlist and interperm in permlist and nwsperm in permlist:
## typeB = True
## print typeB
## return typeB
def attackBNoType(permlist):
typeB = False
if writeper in permlist and interperm in permlist:
typeB = True
print typeB
return typeB
def attackAType(permlist):
typeA = False
if interperm in permlist and nwsperm in permlist:
typeA = True
print typeB
return typeA
def attackANoType(permlist):
typeA = False
if interperm in permlist:
typeA = True
print typeB
return typeA
def intNoWrite(permlist):
intNoW = False
if interperm in permlist and not(writeper in permlist):
intNoW = True
return intNoW
def intNWSNoWrite(permlist):
intNWSNoW = False
if interperm in permlist and nwsperm in permlist and not(writeper in permlist):
intNWSNoW = True
return intNWSNoW
def findReceiverAction(f):
for manifest_tag in f.findall('application'):
for app_item in manifest_tag.findall('receiver'):
for activity_item in app_item.findall('intent-filter'):
for intent_filter in activity_item.findall('action'):
print intent_filter.get('android:name')
#dropbox
#for files in glob.glob("C:\\Users\\Fadi\\Desktop\\DropboxAppsZIP\\DropboxManifests\\*.xml"):
#Keyboards
for files in glob.glob("C:\\Users\\Fadi\\Desktop\\Top\\Games\\Adventure\\Manifests\\*.xml"):
## perm = ET.parse(files).findall('uses-permissions')
## print perm
print "****************************"
#print "*",ntpath.basename(files),"*"
#print "****************************"
#print files
path = files.split('\\')
print path[len(path)-1]
#parser = ET.XMLParser(encoding="utf-8")
#tree = ET.fromstring(files, parser=parser)
tree = ET.parse(files)
root = tree.getroot()
if hasReceiverComp(root):
findReceiverAction(root)
hasReciever = hasReciever + 1
#printIntentFilters(root)
print "has receiver component"
else:
noReceiver = noReceiver + 1
print "doesn't have a receiver component"
##for perm in root.findall('uses-permission'):
#### print perm.items()
#### print perm.getchildren()
## print perm.tag
## print perm.tail
## print perm.text
##for child in root:
## if child.tag == "uses-permission":
## numOfPerm = numOfPerm + 1
## hasPermission = True
## attrs = child.attrib
## keys = attrs.keys()
## print "keys: ", keys
## print "keys[0]: ", keys[0]
## print "length: ", len(attrs)
## print "attrs: ", attrs
## if isKeyboardApp(root):
## print ntpath.basename(files), " is a keyboard app"
## appPerm.append(attrs[keys[0]])
## if attrs[keys[0]] in permDict:
## permDict[attrs[keys[0]]] +=1
## else:
## permDict[attrs[keys[0]]] = 1
##
## print attrs[keys[0]]
##
## if(hasPermission):
## cntPer = cntPer + 1
## else:
## cntNonPer = cntNonPer + 1
## hasPermission = False
## cnt = cnt + 1
## print "Number of Permissions: " , numOfPerm
## if(isKeyboardApp(root)):
## permFreq.append(numOfPerm)
## if (attackBType(appPerm)):
## typeB = typeB + 1
## if(attackAType(appPerm)):
## typeA = typeA + 1
## if(attackAType(appPerm) or attackBType(appPerm)):
## typeAB = typeAB + 1
## if(attackANoType(appPerm)):
## typeANo = typeANo + 1
## if(attackBNoType(appPerm)):
## typeBNo = typeBNo + 1
## if(attackANoType(appPerm) or attackBNoType(appPerm)):
## typeABNo = typeABNo + 1
## if(intNoWrite(appPerm)):
## print "internet no write"
## intNoWriteCnt = intNoWriteCnt + 1
## if(intNWSNoWrite(appPerm)):
## print "internet and nws no write"
## intNWSNoWriteCnt = intNWSNoWriteCnt + 1
##
##
## numOfPerm = 0
## appPerm = []
##
##print "number of apps processed: ", cnt
##print "number of apps with zero permission: ", cntNonPer
##print "number of apps with one or more permission: ", cntPer
##print "number of apps with typeA attacks : " , typeA
##print "number of apps with typeB attacks : " , typeB
##print "number of apps with typeAB attacks : " , typeAB
##print "number of apps with typeA- attacks : " , typeANo
##print "number of apps with typeB- attacks : " , typeBNo
##print "number of apps with typeAB- attacks : " , typeABNo
##print "number of apps with internet but no write : " , intNoWriteCnt
##print "number of apps with internet, nw state but no write : " , intNWSNoWriteCnt
## print cnt
## cnt = cnt + 1
## print files
## tree = ET.parse(files)
## tree.parse(
## root = tree.getroot()
## for perm in root.findall('uses-permissions'):
## print perm.get('android:name')
##