| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
""" |
| 4 |
cloud_enum by initstring (github.com/initstring) |
| 5 |
|
| 6 |
Multi-cloud OSINT tool designed to enumerate storage and services in AWS, |
| 7 |
Azure, and GCP. |
| 8 |
|
| 9 |
Enjoy! |
| 10 |
""" |
| 11 |
|
| 12 |
import os |
| 13 |
import sys |
| 14 |
import argparse |
| 15 |
import re |
| 16 |
from enum_tools import aws_checks |
| 17 |
from enum_tools import azure_checks |
| 18 |
from enum_tools import gcp_checks |
| 19 |
from enum_tools import utils |
| 20 |
|
| 21 |
BANNER = ''' |
| 22 |
########################## |
| 23 |
cloud_enum |
| 24 |
github.com/initstring |
| 25 |
########################## |
| 26 |
|
| 27 |
''' |
| 28 |
|
| 29 |
|
| 30 |
def parse_arguments(): |
| 31 |
""" |
| 32 |
Handles user-passed parameters |
| 33 |
""" |
| 34 |
desc = "Multi-cloud enumeration utility. All hail OSINT!" |
| 35 |
parser = argparse.ArgumentParser(description=desc) |
| 36 |
|
| 37 |
# Grab the current dir of the script, for setting some defaults below |
| 38 |
script_path = os.path.split(os.path.abspath(sys.argv[0]))[0] |
| 39 |
|
| 40 |
kw_group = parser.add_mutually_exclusive_group(required=True) |
| 41 |
|
| 42 |
# Keyword can given multiple times |
| 43 |
kw_group.add_argument('-k', '--keyword', type=str, action='append', |
| 44 |
help='Keyword. Can use argument multiple times.') |
| 45 |
|
| 46 |
# OR, a keyword file can be used |
| 47 |
kw_group.add_argument('-kf', '--keyfile', type=str, action='store', |
| 48 |
help='Input file with a single keyword per line.') |
| 49 |
|
| 50 |
# Use included mutations file by default, or let the user provide one |
| 51 |
parser.add_argument('-m', '--mutations', type=str, action='store', |
| 52 |
default='/usr/lib/cloud-enum/enum_tools/fuzz.txt', |
| 53 |
help='Mutations. Default: /usr/lib/cloud-enum/enum_tools/fuzz.txt') |
| 54 |
|
| 55 |
# Use include container brute-force or let the user provide one |
| 56 |
parser.add_argument('-b', '--brute', type=str, action='store', |
| 57 |
default='/usr/lib/cloud-enum/enum_tools/fuzz.txt', |
| 58 |
help='List to brute-force Azure container names.' |
| 59 |
' Default: /usr/lib/cloud-enum/enum_tools/fuzz.txt') |
| 60 |
|
| 61 |
parser.add_argument('-t', '--threads', type=int, action='store', |
| 62 |
default=5, help='Threads for HTTP brute-force.' |
| 63 |
' Default = 5') |
| 64 |
|
| 65 |
parser.add_argument('-ns', '--nameserver', type=str, action='store', |
| 66 |
default='1.1.1.1', |
| 67 |
help='DNS server to use in brute-force.') |
| 68 |
parser.add_argument('-nsf', '--nameserverfile', type=str, |
| 69 |
help='Path to the file containing nameserver IPs') |
| 70 |
parser.add_argument('-l', '--logfile', type=str, action='store', |
| 71 |
help='Appends found items to specified file.') |
| 72 |
parser.add_argument('-f', '--format', type=str, action='store', |
| 73 |
default='text', |
| 74 |
help='Format for log file (text,json,csv)' |
| 75 |
' - default: text') |
| 76 |
|
| 77 |
parser.add_argument('--disable-aws', action='store_true', |
| 78 |
help='Disable Amazon checks.') |
| 79 |
|
| 80 |
parser.add_argument('--disable-azure', action='store_true', |
| 81 |
help='Disable Azure checks.') |
| 82 |
|
| 83 |
parser.add_argument('--disable-gcp', action='store_true', |
| 84 |
help='Disable Google checks.') |
| 85 |
|
| 86 |
parser.add_argument('-qs', '--quickscan', action='store_true', |
| 87 |
help='Disable all mutations and second-level scans') |
| 88 |
|
| 89 |
args = parser.parse_args() |
| 90 |
|
| 91 |
# Ensure mutations file is readable |
| 92 |
if not os.access(args.mutations, os.R_OK): |
| 93 |
print(f"[!] Cannot access mutations file: {args.mutations}") |
| 94 |
sys.exit() |
| 95 |
|
| 96 |
# Ensure brute file is readable |
| 97 |
if not os.access(args.brute, os.R_OK): |
| 98 |
print("[!] Cannot access brute-force file, exiting") |
| 99 |
sys.exit() |
| 100 |
|
| 101 |
# Ensure keywords file is readable |
| 102 |
if args.keyfile: |
| 103 |
if not os.access(args.keyfile, os.R_OK): |
| 104 |
print("[!] Cannot access keyword file, exiting") |
| 105 |
sys.exit() |
| 106 |
|
| 107 |
# Parse keywords from input file |
| 108 |
with open(args.keyfile, encoding='utf-8') as infile: |
| 109 |
args.keyword = [keyword.strip() for keyword in infile] |
| 110 |
|
| 111 |
# Ensure log file is writeable |
| 112 |
if args.logfile: |
| 113 |
if os.path.isdir(args.logfile): |
| 114 |
print("[!] Can't specify a directory as the logfile, exiting.") |
| 115 |
sys.exit() |
| 116 |
if os.path.isfile(args.logfile): |
| 117 |
target = args.logfile |
| 118 |
else: |
| 119 |
target = os.path.dirname(args.logfile) |
| 120 |
if target == '': |
| 121 |
target = '.' |
| 122 |
|
| 123 |
if not os.access(target, os.W_OK): |
| 124 |
print("[!] Cannot write to log file, exiting") |
| 125 |
sys.exit() |
| 126 |
|
| 127 |
# Set up logging format |
| 128 |
if args.format not in ('text', 'json', 'csv'): |
| 129 |
print("[!] Sorry! Allowed log formats: 'text', 'json', or 'csv'") |
| 130 |
sys.exit() |
| 131 |
# Set the global in the utils file, where logging needs to happen |
| 132 |
utils.init_logfile(args.logfile, args.format) |
| 133 |
|
| 134 |
return args |
| 135 |
|
| 136 |
|
| 137 |
def print_status(args): |
| 138 |
""" |
| 139 |
Print a short pre-run status message |
| 140 |
""" |
| 141 |
print(f"Keywords: {', '.join(args.keyword)}") |
| 142 |
if args.quickscan: |
| 143 |
print("Mutations: NONE! (Using quickscan)") |
| 144 |
else: |
| 145 |
print(f"Mutations: {args.mutations}") |
| 146 |
print(f"Brute-list: {args.brute}") |
| 147 |
print("") |
| 148 |
|
| 149 |
|
| 150 |
def check_windows(): |
| 151 |
""" |
| 152 |
Fixes pretty color printing for Windows users. Keeping out of |
| 153 |
requirements.txt to avoid the library requirement for most users. |
| 154 |
""" |
| 155 |
if os.name == 'nt': |
| 156 |
try: |
| 157 |
import colorama |
| 158 |
colorama.init() |
| 159 |
except ModuleNotFoundError: |
| 160 |
print("[!] Yo, Windows user - if you want pretty colors, you can" |
| 161 |
" install the colorama python package.") |
| 162 |
|
| 163 |
|
| 164 |
def read_mutations(mutations_file): |
| 165 |
""" |
| 166 |
Read mutations file into memory for processing. |
| 167 |
""" |
| 168 |
with open(mutations_file, encoding="utf8", errors="ignore") as infile: |
| 169 |
mutations = infile.read().splitlines() |
| 170 |
|
| 171 |
print(f"[+] Mutations list imported: {len(mutations)} items") |
| 172 |
return mutations |
| 173 |
|
| 174 |
|
| 175 |
def clean_text(text): |
| 176 |
""" |
| 177 |
Clean text to be RFC compliant for hostnames / DNS |
| 178 |
""" |
| 179 |
banned_chars = re.compile('[^a-z0-9.-]') |
| 180 |
text_lower = text.lower() |
| 181 |
text_clean = banned_chars.sub('', text_lower) |
| 182 |
|
| 183 |
return text_clean |
| 184 |
|
| 185 |
|
| 186 |
def append_name(name, names_list): |
| 187 |
""" |
| 188 |
Ensure strings stick to DNS label limit of 63 characters |
| 189 |
""" |
| 190 |
if len(name) <= 63: |
| 191 |
names_list.append(name) |
| 192 |
|
| 193 |
|
| 194 |
def build_names(base_list, mutations): |
| 195 |
""" |
| 196 |
Combine base and mutations for processing by individual modules. |
| 197 |
""" |
| 198 |
names = [] |
| 199 |
|
| 200 |
for base in base_list: |
| 201 |
# Clean base |
| 202 |
base = clean_text(base) |
| 203 |
|
| 204 |
# First, include with no mutations |
| 205 |
append_name(base, names) |
| 206 |
|
| 207 |
for mutation in mutations: |
| 208 |
# Clean mutation |
| 209 |
mutation = clean_text(mutation) |
| 210 |
|
| 211 |
# Then, do appends |
| 212 |
append_name(f"{base}{mutation}", names) |
| 213 |
append_name(f"{base}.{mutation}", names) |
| 214 |
append_name(f"{base}-{mutation}", names) |
| 215 |
|
| 216 |
# Then, do prepends |
| 217 |
append_name(f"{mutation}{base}", names) |
| 218 |
append_name(f"{mutation}.{base}", names) |
| 219 |
append_name(f"{mutation}-{base}", names) |
| 220 |
|
| 221 |
print(f"[+] Mutated results: {len(names)} items") |
| 222 |
|
| 223 |
return names |
| 224 |
|
| 225 |
def read_nameservers(file_path): |
| 226 |
try: |
| 227 |
with open(file_path, 'r') as file: |
| 228 |
nameservers = [line.strip() for line in file if line.strip()] |
| 229 |
if not nameservers: |
| 230 |
raise ValueError("Nameserver file is empty") |
| 231 |
return nameservers |
| 232 |
except FileNotFoundError: |
| 233 |
print(f"Error: File '{file_path}' not found.") |
| 234 |
exit(1) |
| 235 |
except ValueError as e: |
| 236 |
print(e) |
| 237 |
exit(1) |
| 238 |
|
| 239 |
def main(): |
| 240 |
""" |
| 241 |
Main program function. |
| 242 |
""" |
| 243 |
args = parse_arguments() |
| 244 |
print(BANNER) |
| 245 |
|
| 246 |
# Generate a basic status on targets and parameters |
| 247 |
print_status(args) |
| 248 |
|
| 249 |
# Give our Windows friends a chance at pretty colors |
| 250 |
check_windows() |
| 251 |
|
| 252 |
# First, build a sorted base list of target names |
| 253 |
if args.quickscan: |
| 254 |
mutations = [] |
| 255 |
else: |
| 256 |
mutations = read_mutations(args.mutations) |
| 257 |
names = build_names(args.keyword, mutations) |
| 258 |
|
| 259 |
# All the work is done in the individual modules |
| 260 |
try: |
| 261 |
if not args.disable_aws: |
| 262 |
aws_checks.run_all(names, args) |
| 263 |
if not args.disable_azure: |
| 264 |
azure_checks.run_all(names, args) |
| 265 |
if not args.disable_gcp: |
| 266 |
gcp_checks.run_all(names, args) |
| 267 |
except KeyboardInterrupt: |
| 268 |
print("Thanks for playing!") |
| 269 |
sys.exit() |
| 270 |
|
| 271 |
# Best of luck to you! |
| 272 |
print("\n[+] All done, happy hacking!\n") |
| 273 |
sys.exit() |
| 274 |
|
| 275 |
|
| 276 |
if __name__ == '__main__': |
| 277 |
main() |