Debian Codegraph @

enum_tools/aws_checks.py

raw symbols SCIP
1 """
2 AWS-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
8 BANNER = '''
9 ++++++++++++++++++++++++++
10 amazon checks
11 ++++++++++++++++++++++++++
12 '''
13
14 # Known S3 domain names
15 S3_URL = 's3.amazonaws.com'
16 APPS_URL = 'awsapps.com'
17
18 # Known AWS region names. This global will be used unless the user passes
19 # in a specific region name. (NOT YET IMPLEMENTED)
20 AWS_REGIONS = ['amazonaws.com',
21 'ap-east-1.amazonaws.com',
22 'us-east-2.amazonaws.com',
23 'us-west-1.amazonaws.com',
24 'us-west-2.amazonaws.com',
25 'ap-south-1.amazonaws.com',
26 'ap-northeast-1.amazonaws.com',
27 'ap-northeast-2.amazonaws.com',
28 'ap-northeast-3.amazonaws.com',
29 'ap-southeast-1.amazonaws.com',
30 'ap-southeast-2.amazonaws.com',
31 'ca-central-1.amazonaws.com',
32 'cn-north-1.amazonaws.com.cn',
33 'cn-northwest-1.amazonaws.com.cn',
34 'eu-central-1.amazonaws.com',
35 'eu-west-1.amazonaws.com',
36 'eu-west-2.amazonaws.com',
37 'eu-west-3.amazonaws.com',
38 'eu-north-1.amazonaws.com',
39 'sa-east-1.amazonaws.com']
40
41
42 def print_s3_response(reply):
43 """
44 Parses the HTTP reply of a brute-force attempt
45
46 This function is passed into the class object so we can view results
47 in real-time.
48 """
49 data = {'platform': 'aws', 'msg': '', 'target': '', 'access': ''}
50
51 if reply.status_code == 404:
52 pass
53 elif 'Bad Request' in reply.reason:
54 pass
55 elif reply.status_code == 200:
56 data['msg'] = 'OPEN S3 BUCKET'
57 data['target'] = reply.url
58 data['access'] = 'public'
59 utils.fmt_output(data)
60 utils.list_bucket_contents(reply.url)
61 elif reply.status_code == 403:
62 data['msg'] = 'Protected S3 Bucket'
63 data['target'] = reply.url
64 data['access'] = 'protected'
65 utils.fmt_output(data)
66 elif 'Slow Down' in reply.reason:
67 print("[!] You've been rate limited, skipping rest of check...")
68 return 'breakout'
69 else:
70 print(f" Unknown status codes being received from {reply.url}:\n"
71 " {reply.status_code}: {reply.reason}")
72
73 return None
74
75
76 def check_s3_buckets(names, threads):
77 """
78 Checks for open and restricted Amazon S3 buckets
79 """
80 print("[+] Checking for S3 buckets")
81
82 # Start a counter to report on elapsed time
83 start_time = utils.start_timer()
84
85 # Initialize the list of correctly formatted urls
86 candidates = []
87
88 # Take each mutated keyword craft a url with the correct format
89 for name in names:
90 candidates.append(f'{name}.{S3_URL}')
91
92 # Send the valid names to the batch HTTP processor
93 utils.get_url_batch(candidates, use_ssl=False,
94 callback=print_s3_response,
95 threads=threads)
96
97 # Stop the time
98 utils.stop_timer(start_time)
99
100
101 def check_awsapps(names, threads, nameserver, nameserverfile=False):
102 """
103 Checks for existence of AWS Apps
104 (ie. WorkDocs, WorkMail, Connect, etc.)
105 """
106 data = {'platform': 'aws', 'msg': 'AWS App Found:', 'target': '', 'access': ''}
107
108 print("[+] Checking for AWS Apps")
109
110 # Start a counter to report on elapsed time
111 start_time = utils.start_timer()
112
113 # Initialize the list of domain names to look up
114 candidates = []
115
116 # Initialize the list of valid hostnames
117 valid_names = []
118
119 # Take each mutated keyword craft a domain name to lookup.
120 for name in names:
121 candidates.append(f'{name}.{APPS_URL}')
122
123 # AWS Apps use DNS sub-domains. First, see which are valid.
124 valid_names = utils.fast_dns_lookup(candidates, nameserver,
125 nameserverfile, threads=threads)
126
127 for name in valid_names:
128 data['target'] = f'https://{name}'
129 data['access'] = 'protected'
130 utils.fmt_output(data)
131
132 # Stop the timer
133 utils.stop_timer(start_time)
134
135
136 def run_all(names, args):
137 """
138 Function is called by main program
139 """
140 print(BANNER)
141
142 # Use user-supplied AWS region if provided
143 # if not regions:
144 # regions = AWS_REGIONS
145 check_s3_buckets(names, args.threads)
146 check_awsapps(names, args.threads, args.nameserver, args.nameserverfile)