| 1 |
""" |
| 2 |
Google-specific checks. Part of the cloud_enum package available at |
| 3 |
github.com/initstring/cloud_enum |
| 4 |
""" |
| 5 |
|
| 6 |
from enum_tools import utils |
| 7 |
from enum_tools import gcp_regions |
| 8 |
|
| 9 |
BANNER = ''' |
| 10 |
++++++++++++++++++++++++++ |
| 11 |
google checks |
| 12 |
++++++++++++++++++++++++++ |
| 13 |
''' |
| 14 |
|
| 15 |
|
| 16 |
GCP_URL = 'storage.googleapis.com' |
| 17 |
FBRTDB_URL = 'firebaseio.com' |
| 18 |
APPSPOT_URL = 'appspot.com' |
| 19 |
FUNC_URL = 'cloudfunctions.net' |
| 20 |
FBAPP_URL = 'firebaseapp.com' |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
HAS_FUNCS = [] |
| 25 |
|
| 26 |
|
| 27 |
def print_bucket_response(reply): |
| 28 |
""" |
| 29 |
Parses the HTTP reply of a brute-force attempt |
| 30 |
|
| 31 |
This function is passed into the class object so we can view results |
| 32 |
in real-time. |
| 33 |
""" |
| 34 |
data = {'platform': 'gcp', 'msg': '', 'target': '', 'access': ''} |
| 35 |
|
| 36 |
if reply.status_code == 404: |
| 37 |
pass |
| 38 |
elif reply.status_code == 200: |
| 39 |
data['msg'] = 'OPEN GOOGLE BUCKET' |
| 40 |
data['target'] = reply.url |
| 41 |
data['access'] = 'public' |
| 42 |
utils.fmt_output(data) |
| 43 |
utils.list_bucket_contents(reply.url + '/') |
| 44 |
elif reply.status_code == 403: |
| 45 |
data['msg'] = 'Protected Google Bucket' |
| 46 |
data['target'] = reply.url |
| 47 |
data['access'] = 'protected' |
| 48 |
utils.fmt_output(data) |
| 49 |
else: |
| 50 |
print(f" Unknown status codes being received from {reply.url}:\n" |
| 51 |
" {reply.status_code}: {reply.reason}") |
| 52 |
|
| 53 |
|
| 54 |
def check_gcp_buckets(names, threads): |
| 55 |
""" |
| 56 |
Checks for open and restricted Google Cloud buckets |
| 57 |
""" |
| 58 |
print("[+] Checking for Google buckets") |
| 59 |
|
| 60 |
|
| 61 |
start_time = utils.start_timer() |
| 62 |
|
| 63 |
|
| 64 |
candidates = [] |
| 65 |
|
| 66 |
|
| 67 |
for name in names: |
| 68 |
candidates.append(f'{GCP_URL}/{name}') |
| 69 |
|
| 70 |
|
| 71 |
utils.get_url_batch(candidates, use_ssl=False, |
| 72 |
callback=print_bucket_response, |
| 73 |
threads=threads) |
| 74 |
|
| 75 |
|
| 76 |
utils.stop_timer(start_time) |
| 77 |
|
| 78 |
|
| 79 |
def print_fbrtdb_response(reply): |
| 80 |
""" |
| 81 |
Parses the HTTP reply of a brute-force attempt |
| 82 |
|
| 83 |
This function is passed into the class object so we can view results |
| 84 |
in real-time. |
| 85 |
""" |
| 86 |
data = {'platform': 'gcp', 'msg': '', 'target': '', 'access': ''} |
| 87 |
|
| 88 |
if reply.status_code == 404: |
| 89 |
pass |
| 90 |
elif reply.status_code == 200: |
| 91 |
data['msg'] = 'OPEN GOOGLE FIREBASE RTDB' |
| 92 |
data['target'] = reply.url |
| 93 |
data['access'] = 'public' |
| 94 |
utils.fmt_output(data) |
| 95 |
elif reply.status_code == 401: |
| 96 |
data['msg'] = 'Protected Google Firebase RTDB' |
| 97 |
data['target'] = reply.url |
| 98 |
data['access'] = 'protected' |
| 99 |
utils.fmt_output(data) |
| 100 |
elif reply.status_code == 402: |
| 101 |
data['msg'] = 'Payment required on Google Firebase RTDB' |
| 102 |
data['target'] = reply.url |
| 103 |
data['access'] = 'disabled' |
| 104 |
utils.fmt_output(data) |
| 105 |
elif reply.status_code == 423: |
| 106 |
data['msg'] = 'The Firebase database has been deactivated.' |
| 107 |
data['target'] = reply.url |
| 108 |
data['access'] = 'disabled' |
| 109 |
utils.fmt_output(data) |
| 110 |
else: |
| 111 |
print(f" Unknown status codes being received from {reply.url}:\n" |
| 112 |
" {reply.status_code}: {reply.reason}") |
| 113 |
|
| 114 |
|
| 115 |
def check_fbrtdb(names, threads): |
| 116 |
""" |
| 117 |
Checks for Google Firebase RTDB |
| 118 |
""" |
| 119 |
print("[+] Checking for Google Firebase Realtime Databases") |
| 120 |
|
| 121 |
|
| 122 |
start_time = utils.start_timer() |
| 123 |
|
| 124 |
|
| 125 |
candidates = [] |
| 126 |
|
| 127 |
|
| 128 |
for name in names: |
| 129 |
|
| 130 |
|
| 131 |
if '.' not in name: |
| 132 |
candidates.append(f'{name}.{FBRTDB_URL}/.json') |
| 133 |
|
| 134 |
|
| 135 |
utils.get_url_batch(candidates, use_ssl=True, |
| 136 |
callback=print_fbrtdb_response, |
| 137 |
threads=threads, |
| 138 |
redir=False) |
| 139 |
|
| 140 |
|
| 141 |
utils.stop_timer(start_time) |
| 142 |
|
| 143 |
|
| 144 |
def print_fbapp_response(reply): |
| 145 |
""" |
| 146 |
Parses the HTTP reply of a brute-force attempt |
| 147 |
|
| 148 |
This function is passed into the class object so we can view results |
| 149 |
in real-time. |
| 150 |
""" |
| 151 |
data = {'platform': 'gcp', 'msg': '', 'target': '', 'access': ''} |
| 152 |
|
| 153 |
if reply.status_code == 404: |
| 154 |
pass |
| 155 |
elif reply.status_code == 200: |
| 156 |
data['msg'] = 'OPEN GOOGLE FIREBASE APP' |
| 157 |
data['target'] = reply.url |
| 158 |
data['access'] = 'public' |
| 159 |
utils.fmt_output(data) |
| 160 |
else: |
| 161 |
print(f" Unknown status codes being received from {reply.url}:\n" |
| 162 |
" {reply.status_code}: {reply.reason}") |
| 163 |
|
| 164 |
def check_fbapp(names, threads): |
| 165 |
""" |
| 166 |
Checks for Google Firebase Applications |
| 167 |
""" |
| 168 |
print("[+] Checking for Google Firebase Applications") |
| 169 |
|
| 170 |
|
| 171 |
start_time = utils.start_timer() |
| 172 |
|
| 173 |
|
| 174 |
candidates = [] |
| 175 |
|
| 176 |
|
| 177 |
for name in names: |
| 178 |
|
| 179 |
|
| 180 |
if '.' not in name: |
| 181 |
candidates.append(f'{name}.{FBAPP_URL}') |
| 182 |
|
| 183 |
|
| 184 |
utils.get_url_batch(candidates, use_ssl=True, |
| 185 |
callback=print_fbapp_response, |
| 186 |
threads=threads, |
| 187 |
redir=False) |
| 188 |
|
| 189 |
|
| 190 |
utils.stop_timer(start_time) |
| 191 |
|
| 192 |
def print_appspot_response(reply): |
| 193 |
""" |
| 194 |
Parses the HTTP reply of a brute-force attempt |
| 195 |
|
| 196 |
This function is passed into the class object so we can view results |
| 197 |
in real-time. |
| 198 |
""" |
| 199 |
data = {'platform': 'gcp', 'msg': '', 'target': '', 'access': ''} |
| 200 |
|
| 201 |
if reply.status_code == 404: |
| 202 |
pass |
| 203 |
elif str(reply.status_code)[0] == 5: |
| 204 |
data['msg'] = 'Google App Engine app with a 50x error' |
| 205 |
data['target'] = reply.url |
| 206 |
data['access'] = 'public' |
| 207 |
utils.fmt_output(data) |
| 208 |
elif reply.status_code in (200, 302, 404): |
| 209 |
if 'accounts.google.com' in reply.url: |
| 210 |
data['msg'] = 'Protected Google App Engine app' |
| 211 |
data['target'] = reply.history[0].url |
| 212 |
data['access'] = 'protected' |
| 213 |
utils.fmt_output(data) |
| 214 |
else: |
| 215 |
data['msg'] = 'Open Google App Engine app' |
| 216 |
data['target'] = reply.url |
| 217 |
data['access'] = 'public' |
| 218 |
utils.fmt_output(data) |
| 219 |
else: |
| 220 |
print(f" Unknown status codes being received from {reply.url}:\n" |
| 221 |
" {reply.status_code}: {reply.reason}") |
| 222 |
|
| 223 |
|
| 224 |
def check_appspot(names, threads): |
| 225 |
""" |
| 226 |
Checks for Google App Engine sites running on appspot.com |
| 227 |
""" |
| 228 |
print("[+] Checking for Google App Engine apps") |
| 229 |
|
| 230 |
|
| 231 |
start_time = utils.start_timer() |
| 232 |
|
| 233 |
|
| 234 |
candidates = [] |
| 235 |
|
| 236 |
|
| 237 |
for name in names: |
| 238 |
|
| 239 |
|
| 240 |
if '.' not in name: |
| 241 |
candidates.append(f'{name}.{APPSPOT_URL}') |
| 242 |
|
| 243 |
|
| 244 |
utils.get_url_batch(candidates, use_ssl=False, |
| 245 |
callback=print_appspot_response, |
| 246 |
threads=threads) |
| 247 |
|
| 248 |
|
| 249 |
utils.stop_timer(start_time) |
| 250 |
|
| 251 |
|
| 252 |
def print_functions_response1(reply): |
| 253 |
""" |
| 254 |
Parses the HTTP reply the initial Cloud Functions check |
| 255 |
|
| 256 |
This function is passed into the class object so we can view results |
| 257 |
in real-time. |
| 258 |
""" |
| 259 |
data = {'platform': 'gcp', 'msg': '', 'target': '', 'access': ''} |
| 260 |
|
| 261 |
if reply.status_code == 404: |
| 262 |
pass |
| 263 |
elif reply.status_code == 302: |
| 264 |
data['msg'] = 'Contains at least 1 Cloud Function' |
| 265 |
data['target'] = reply.url |
| 266 |
data['access'] = 'public' |
| 267 |
utils.fmt_output(data) |
| 268 |
HAS_FUNCS.append(reply.url) |
| 269 |
else: |
| 270 |
print(f" Unknown status codes being received from {reply.url}:\n" |
| 271 |
" {reply.status_code}: {reply.reason}") |
| 272 |
|
| 273 |
|
| 274 |
def print_functions_response2(reply): |
| 275 |
""" |
| 276 |
Parses the HTTP reply from the secondary, brute-force Cloud Functions check |
| 277 |
|
| 278 |
This function is passed into the class object so we can view results |
| 279 |
in real-time. |
| 280 |
""" |
| 281 |
data = {'platform': 'gcp', 'msg': '', 'target': '', 'access': ''} |
| 282 |
|
| 283 |
if 'accounts.google.com/ServiceLogin' in reply.url: |
| 284 |
pass |
| 285 |
elif reply.status_code in (403, 401): |
| 286 |
data['msg'] = 'Auth required Cloud Function' |
| 287 |
data['target'] = reply.url |
| 288 |
data['access'] = 'protected' |
| 289 |
utils.fmt_output(data) |
| 290 |
elif reply.status_code == 405: |
| 291 |
data['msg'] = 'UNAUTHENTICATED Cloud Function (POST-Only)' |
| 292 |
data['target'] = reply.url |
| 293 |
data['access'] = 'public' |
| 294 |
utils.fmt_output(data) |
| 295 |
elif reply.status_code in (200, 404): |
| 296 |
data['msg'] = 'UNAUTHENTICATED Cloud Function (GET-OK)' |
| 297 |
data['target'] = reply.url |
| 298 |
data['access'] = 'public' |
| 299 |
utils.fmt_output(data) |
| 300 |
else: |
| 301 |
print(f" Unknown status codes being received from {reply.url}:\n" |
| 302 |
" {reply.status_code}: {reply.reason}") |
| 303 |
|
| 304 |
|
| 305 |
def check_functions(names, brute_list, quickscan, threads): |
| 306 |
""" |
| 307 |
Checks for Google Cloud Functions running on cloudfunctions.net |
| 308 |
|
| 309 |
This is a two-part process. First, we want to find region/project combos |
| 310 |
that have existing Cloud Functions. The URL for a function looks like this: |
| 311 |
https://[ZONE]-[PROJECT-ID].cloudfunctions.net/[FUNCTION-NAME] |
| 312 |
|
| 313 |
We look for a 302 in [ZONE]-[PROJECT-ID].cloudfunctions.net. That means |
| 314 |
there are some functions defined in that region. Then, we brute force a list |
| 315 |
of possible function names there. |
| 316 |
|
| 317 |
See gcp_regions.py to define which regions to check. The tool currently |
| 318 |
defaults to only 1 region, so you should really modify it for best results. |
| 319 |
""" |
| 320 |
print("[+] Checking for project/zones with Google Cloud Functions.") |
| 321 |
|
| 322 |
|
| 323 |
start_time = utils.start_timer() |
| 324 |
|
| 325 |
|
| 326 |
candidates = [] |
| 327 |
|
| 328 |
|
| 329 |
regions = gcp_regions.REGIONS |
| 330 |
|
| 331 |
print(f"[*] Testing across {len(regions)} regions defined in the config file") |
| 332 |
|
| 333 |
|
| 334 |
for region in regions: |
| 335 |
candidates += [region + '-' + name + '.' + FUNC_URL for name in names] |
| 336 |
|
| 337 |
|
| 338 |
utils.get_url_batch(candidates, use_ssl=False, |
| 339 |
callback=print_functions_response1, |
| 340 |
threads=threads, |
| 341 |
redir=False) |
| 342 |
|
| 343 |
|
| 344 |
if not HAS_FUNCS: |
| 345 |
utils.stop_timer(start_time) |
| 346 |
return |
| 347 |
|
| 348 |
|
| 349 |
if quickscan: |
| 350 |
return |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
print(f"[*] Brute-forcing function names in {len(HAS_FUNCS)} project/region combos") |
| 355 |
|
| 356 |
|
| 357 |
brute_strings = utils.get_brute(brute_list) |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
for func in HAS_FUNCS: |
| 362 |
print(f"[*] Brute-forcing {len(brute_strings)} function names in {func}") |
| 363 |
|
| 364 |
|
| 365 |
func = func.replace("http://", "") |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
candidates = [func + brute + '/' for brute in brute_strings] |
| 371 |
|
| 372 |
|
| 373 |
utils.get_url_batch(candidates, use_ssl=False, |
| 374 |
callback=print_functions_response2, |
| 375 |
threads=threads) |
| 376 |
|
| 377 |
|
| 378 |
utils.stop_timer(start_time) |
| 379 |
|
| 380 |
|
| 381 |
def run_all(names, args): |
| 382 |
""" |
| 383 |
Function is called by main program |
| 384 |
""" |
| 385 |
print(BANNER) |
| 386 |
|
| 387 |
check_gcp_buckets(names, args.threads) |
| 388 |
check_fbrtdb(names, args.threads) |
| 389 |
check_appspot(names, args.threads) |
| 390 |
check_functions(names, args.brute, args.quickscan, args.threads) |