forked from carnal0wnage/weirdAAL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweirdAAL.py
executable file
·179 lines (145 loc) · 6.14 KB
/
weirdAAL.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
# This file will help to serve as a starting point for using the rest of the tools
# Things we want to figure out
# 1) Is your key active?
# 2) If active, can you read monitoring configs, can you write?
# 3) Okay, you can read monitoring configs. We recommend things to avoid. Want to go further? Use write access to disable (if applicable)
# 4) Don't want to do anything with monitoring? That's fine, let's guide you through figuring out what your access looks like
# 5) Help with a printout of options from this point forward
import boto3
import argparse
import os
from botocore.exceptions import ClientError
from botocore.exceptions import ConfigParseError
from modules import *
import sys
import builtins
import re
from tabulate import tabulate
import textwrap
# Let a user set .aws/credentials or another file as the credentials source
# If user-defined, must be an absolute path
if 'AWS_SHARED_CREDENTIALS_FILE' not in os.environ:
try:
# print("loading .env into our ENV")
os.environ['AWS_SHARED_CREDENTIALS_FILE'] = '.env'
except Exception as e:
print("Error: {}".format(e))
sys.exit("fix your credentials file -exiting...")
# If you want to use a transparent + supports SSL proxy you can put it here
# os.environ['HTTPS_PROXY'] = 'https://127.0.0.1:3128'
sys.path.append("modules")
for module in all_modules:
# Assuming module is a string like 'modules.aws.aws_lambda'
module_path = module.replace("\\", ".") # Replace backslashes with dots
imported_module = importlib.import_module(module_path)
# Import all attributes from the module into the current namespace
for attr in dir(imported_module):
if not attr.startswith('_'):
globals()[attr] = getattr(imported_module, attr)
parser = argparse.ArgumentParser()
parser.add_argument("-m", "--module", help="list the module you would like to run", action="store", type=str, required=False)
parser.add_argument("-t", "--target", help="Give your target a name so we can track results", action="store", type=str, required=False)
parser.add_argument("-a", "--arguments", help="Provide a list of arguments, comma separated. Ex: arg1,arg2,arg3", action="store", type=str, required=False)
parser.add_argument("-l", "--list", help="list modules", required=False, action="store_true")
parser.add_argument("-v", "--verbosity", help="increase output verbosity", action="store_true")
args = parser.parse_args()
# Provides us with a global var "db_name" we can access anywhere
builtins.db_name = "weirdAAL.db"
def perform_credential_check():
'''
Check that the AWS keys work before we go any further. It picks the keys up from the local .env file
We are letting boto3 do all the work that way we can handle session tokens natively
'''
try:
client = boto3.client("sts")
account_id = client.get_caller_identity()["Account"]
except (botocore.exceptions.NoCredentialsError) as e:
print("Error: Unable to locate credentials")
sys.exit("fix your credentials file -exiting...")
except ClientError as e:
print("[X] The AWS Access Keys are not valid/active [X]")
sys.exit(1)
def method_create():
try:
arg = globals()["module_" + args.module]
return arg
except KeyError:
print("That module does not exist")
exit(1)
builtins.aws_module_methods_info = {}
builtins.gcp_module_methods_info = {}
def get_methods_for_classname(classname):
methods = []
all_methods = dir(sys.modules[classname])
for meth in all_methods:
if meth.startswith("module_"):
narg = "{}.__doc__".format(meth)
narg = eval(narg)
nhash = {}
nhash[meth] = narg
methods.append(nhash)
return methods
def make_list_of_methods(cloud_service, mod):
meths = get_methods_for_classname(mod)
if cloud_service == 'aws':
new_mod_name = re.sub("modules.aws.", "", mod)
aws_module_methods_info[new_mod_name.upper()] = meths
elif cloud_service == 'gcp':
new_mod_name = re.sub("modules.gcp.", "", mod)
gcp_module_methods_info[new_mod_name.upper()] = meths
def make_the_list():
for m in sys.modules.keys():
if (m.startswith("modules.aws")
and not (m == "modules.aws")):
make_list_of_methods("aws", m)
elif ((m.startswith("modules.gcp"))
and not (m == "modules.gcp")):
make_list_of_methods("gcp", m)
def normalize_comments(string):
string = textwrap.fill(string.strip(), 40)
return string
def make_tabulate_rows(hash, cloud_provider):
entire_contents = []
for (key) in hash:
for item in hash[key]:
for (k,v) in item.items():
normalized_comment = normalize_comments(v)
k = re.sub("module_", "", k)
entire_contents.append([cloud_provider, key, k, normalized_comment])
return entire_contents
def print_the_list():
aws_rows = make_tabulate_rows(aws_module_methods_info, 'AWS')
gcp_rows = make_tabulate_rows(gcp_module_methods_info, 'GCP')
print(tabulate(aws_rows, headers=['Cloud Provider', 'Service', 'Mod', 'Desc']))
print(tabulate(gcp_rows, headers=['Cloud Provider', 'Service', 'Mod', 'Desc']))
if (args.list):
make_the_list()
print_the_list()
sys.exit(1)
# Need to figure out if we have keys in the ENV or not
try:
perform_credential_check()
except:
print("[-] Check the above error message and fix to use weirdAAL [-]")
sys.exit(1)
# arg_list has to be defined otherwise will cause an exception
arg_list = None
if (args.arguments):
arg_list = args.arguments.split(',')
# We need the user to tell us the module they want to proceed on
if (args.module):
if not (args.target):
print("Use -t to give your target a name so we can track results!!!")
sys.exit(1)
else:
# Provides us with a global var "target" we can access anywhere
builtins.target = args.target
arg = method_create()
if callable(arg):
if arg_list:
arg(arg_list)
else:
arg()
# Allow the user to specify verbosity for debugging
if (args.verbosity):
print("Verbosity is enabled")