forked from shivsahni/FireBaseScanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFirebaseMisconfig.py
198 lines (171 loc) · 8.05 KB
/
FirebaseMisconfig.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
#!/usr/bin/python
import os
import sys
import ntpath
import re
import urllib.error, urllib.request
import hashlib
from datetime import datetime
class bcolors:
TITLE = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
INFO = '\033[93m'
OKRED = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
BGRED = '\033[41m'
UNDERLINE = '\033[4m'
FGWHITE = '\033[37m'
FAIL = '\033[95m'
rootDir=os.path.expanduser("~")+"/.SourceCodeAnalyzer/" #ConfigFolder ~/.SourceCodeAnalyzer/
projectDir=""
apkFilePath=""
apkFileName=""
firbaseProjectList=[]
inScoprUrls=[]
apkHash=""
apktoolPath="./Dependencies/apktool_2.3.4.jar"
def myPrint(text, type):
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
if(type=="INFO"):
print(f"[{current_time}] {bcolors.INFO} {text}{bcolors.ENDC}\n")
return
if(type=="ERROR"):
print(f"[{current_time}] {bcolors.BGRED+bcolors.FGWHITE+bcolors.BOLD} {text}{bcolors.ENDC}")
return
if(type=="MESSAGE"):
print(f"[{current_time}] {bcolors.TITLE+bcolors.BOLD} {text}{bcolors.ENDC}\n")
return
if(type=="INSECURE_WS"):
print(f"[{current_time}] {bcolors.OKRED+bcolors.BOLD} {text}{bcolors.ENDC}")
return
if(type=="OUTPUT"):
print(f"[{current_time}] {bcolors.OKBLUE+bcolors.BOLD} {text}{bcolors.ENDC}\n")
return
if(type=="OUTPUT_WS"):
print(f"[{current_time}] {bcolors.OKBLUE+bcolors.BOLD} {text}{bcolors.ENDC}")
return
if(type=="SECURE"):
print(f"[{current_time}] {bcolors.OKGREEN+bcolors.BOLD} {text}{bcolors.ENDC}")
return
def isNewInstallation():
if (os.path.exists(rootDir)==False):
myPrint("Thank you for Installing Firebase Scanner!", "MESSAGE")
os.mkdir(rootDir)
return True
else:
return False
def isValidPath(apkFilePath):
global apkFileName
myPrint("Checking if the APK file path is valid.", "INFO")
if (os.path.exists(apkFilePath)==False):
myPrint("Incorrect APK file path found. Please try again with correct file name.", "ERROR")
print()
exit(1)
else:
myPrint("APK File Found.", "INFO")
apkFileName=ntpath.basename(apkFilePath)
def reverseEngineerApplication(apkFileName):
global projectDir
myPrint("Initiating APK Decompilation Process.", "INFO")
projectDir=rootDir+apkFileName+"_"+hashlib.md5().hexdigest()
if (os.path.exists(projectDir)==True):
myPrint("The same APK is already decompiled. Skipping decompilation and proceeding with scanning application.", "INFO")
return projectDir
os.mkdir(projectDir)
myPrint("Decompiling the APK file using APKtool.", "INFO")
result=os.system("java -jar "+apktoolPath+" d "+"--output "+'"'+projectDir+"/apktool/"+'"'+' "'+apkFilePath+'"'+' >/dev/null 2>&1')
if (result!=0):
myPrint("Apktool failed with exit status "+str(result)+". Please Try Again.", "ERROR")
print()
exit(1)
myPrint("Successfully decompiled the application. Proceeding with enumeraing firebase peoject names from the application code.", "INFO")
def findFirebaseProjectNames():
global firbaseProjectList
regex='https*://(.+?)\.firebaseio.com'
for dir_path, dirs, file_names in os.walk(rootDir+apkFileName+"_"+hashlib.md5().hexdigest()):
for file_name in file_names:
fullpath = os.path.join(dir_path, file_name)
with open(fullpath) as f:
for line in f:
temp=re.findall(regex,line)
if (len(temp)!=0):
firbaseProjectList=firbaseProjectList+temp
myPrint("Firebase Instance(s) Found", "INFO")
if (len(firbaseProjectList)==0):
myPrint("No Firebase Project Found. Taking an exit!\nHave an nice day.", "OUTPUT")
exit(0)
def printFirebaseProjectNames():
myPrint("Found "+str(len(firbaseProjectList))+"Project References in the application. Printing the list of Firebase Projects found.", "OUTPUT")
for projectName in firbaseProjectList:
myPrint(projectName, "OUTPUT_WS")
print()
def scanDarlingScan():
myPrint("Scanning Firebase Instance(s)", "INFO")
for str in firbaseProjectList:
url='https://'+str+'.firebaseio.com/.json'
try:
response = urllib.request.urlopen(url)
except urllib.error.HTTPError as err:
if(err.code==401):
myPrint("Secure Firbase Instance Found: "+str, "SECURE")
continue
if(err.code==404):
myPrint("Project doesnot exist: "+str, "OUTPUT_WS")
continue
else:
myPrint("Unable to identify misconfiguration for: ", "OUTPUT_WS")
continue
except urllib.error.URLError as err:
myPrint("Facing connectivity issues. Please Check the Network Connectivity and Try Again.", "ERROR")
print()
continue
myPrint("Misconfigured Firbase Instance Found: "+str, "INSECURE_WS")
print()
####################################################################################################
####################################################################################################
print(bcolors.INFO+"""
@@@@@@@@ @@@ @@@@@@@@ @@@@@@@@ @@@@@@@@ @@@@@@@@ @@@@@@@ @@@@@@@@
@@! @@! @@! @@@ @@! @@! @@@ @@! @@@ !@@ @@!
!@! !@! !@! @!@ !@! !@ @!@ !@! @!@ !@! !@!
@!!!:! !!@ @!@!!@! @!!!:! @!@!@!@ @!@!@!@! !!@@!! @!!!:!
!!!!!: !!! !!@!@! !!!!!: !!!@!!!! !!!@!!!! !!@!!! !!!!!:
!!: !!: !!: :!! !!: !!: !!! !!: !!! !:! !!:
:!: :!: :!: !:! :!: :!: !:! :!: !:! !:! :!:
:: :: :: ::: :: :::: :: :::: :: ::: :::: :: :: ::::
@@@@@@ @@@@@@@ @@@@@@ @@@ @@@ @@@ @@@ @@@@@@@@ @@@@@@@
@@@@@@@ @@@@@@@@ @@@@@@@@ @@@@ @@@ @@@@ @@@ @@@@@@@@ @@@@@@@@
!@@ !@@ @@! @@@ @@!@!@@@ @@!@!@@@ @@! @@! @@@
!@! !@! !@! @!@ !@!!@!@! !@!!@!@! !@! !@! @!@
!!@@!! !@! @!@!@!@! @!@ !!@! @!@ !!@! @!!!:! @!@!!@!
!!@!!! !!! !!!@!!!! !@! !!! !@! !!! !!!!!: !!@!@!
!:! :!! !!: !!! !!: !!! !!: !!! !!: !!: :!!
!:! :!: :!: !:! :!: !:! :!: !:! :!: :!: !:!
:::: :: ::: ::: :: ::: :: :: :: :: :: :::: :: :::"""+bcolors.OKRED+bcolors.BOLD+"""
# Originally developed By Shiv Sahni - @shiv__sahni
# New supporters: Jorge Machado - @MachadoOtto
# Diego Franggi - @diale13
# TheMonada / https://github.com/TheMonada
"""+bcolors.ENDC)
if (len(sys.argv)<3):
myPrint("Please provide the required arguments to initiate scanning.", "ERROR")
print("")
myPrint("Usage: python FirebaseMisconfig.py [options]","ERROR")
myPrint("\t-p/--path <apkPathName>","ERROR")
myPrint("\t-f/--firebase <commaSeperatedFirebaseProjectName>","ERROR")
myPrint("Please try again!!", "ERROR")
print("")
exit(1)
if (sys.argv[1]=="-p" or sys.argv[1]=="--path"):
apkFilePath=sys.argv[2]
isNewInstallation()
isValidPath(apkFilePath)
reverseEngineerApplication(apkFileName)
findFirebaseProjectNames()
scanDarlingScan()
if (sys.argv[1]=="-f" or sys.argv[1]=="--firebase"):
firbaseProjectList=sys.argv[2].split(",")
isNewInstallation()
scanDarlingScan()
myPrint("Thank You For Using FireBase Scanner","INFO")