diff --git a/libs/utils/common.py b/libs/utils/common.py index e7136e6..ecfc882 100644 --- a/libs/utils/common.py +++ b/libs/utils/common.py @@ -5,8 +5,13 @@ def list_all_files(directory): array = [] - for file in list_of_files: - filename_and_ext = os.path.splitext(file) - if (filename_and_ext[1] == ".py") and not (filename_and_ext[0].startswith("__")): - array.append(filename_and_ext[0]) + path ="modules" + for (dirpath, dirnames, filenames) in os.walk(path): + if ( not (dirpath == os.path.basename(directory)) and + (os.path.isdir(dirpath)) + and not (os.path.basename(dirpath).startswith('__')) ): + for file in filenames: + list_path_name = dirpath.split('/') + if not (file.startswith('.')): + array.append(".".join(list_path_name) + "." + os.path.splitext(file)[0]) return array diff --git a/modules/aws_lambda.py b/modules/aws/aws_lambda.py similarity index 100% rename from modules/aws_lambda.py rename to modules/aws/aws_lambda.py diff --git a/modules/ce.py b/modules/aws/ce.py similarity index 100% rename from modules/ce.py rename to modules/aws/ce.py diff --git a/modules/cloudfront.py b/modules/aws/cloudfront.py similarity index 100% rename from modules/cloudfront.py rename to modules/aws/cloudfront.py diff --git a/modules/cloudtrail.py b/modules/aws/cloudtrail.py similarity index 100% rename from modules/cloudtrail.py rename to modules/aws/cloudtrail.py diff --git a/modules/cloudwatch.py b/modules/aws/cloudwatch.py similarity index 100% rename from modules/cloudwatch.py rename to modules/aws/cloudwatch.py diff --git a/modules/config.py b/modules/aws/config.py similarity index 100% rename from modules/config.py rename to modules/aws/config.py diff --git a/modules/datapipeline.py b/modules/aws/datapipeline.py similarity index 100% rename from modules/datapipeline.py rename to modules/aws/datapipeline.py diff --git a/modules/db.py b/modules/aws/db.py similarity index 100% rename from modules/db.py rename to modules/aws/db.py diff --git a/modules/dynamodb.py b/modules/aws/dynamodb.py similarity index 100% rename from modules/dynamodb.py rename to modules/aws/dynamodb.py diff --git a/modules/dynamodbstreams.py b/modules/aws/dynamodbstreams.py similarity index 100% rename from modules/dynamodbstreams.py rename to modules/aws/dynamodbstreams.py diff --git a/modules/ec2.py b/modules/aws/ec2.py similarity index 100% rename from modules/ec2.py rename to modules/aws/ec2.py diff --git a/modules/ecr.py b/modules/aws/ecr.py similarity index 100% rename from modules/ecr.py rename to modules/aws/ecr.py diff --git a/modules/elasticbeanstalk.py b/modules/aws/elasticbeanstalk.py similarity index 100% rename from modules/elasticbeanstalk.py rename to modules/aws/elasticbeanstalk.py diff --git a/modules/emr.py b/modules/aws/emr.py similarity index 100% rename from modules/emr.py rename to modules/aws/emr.py diff --git a/modules/firehose.py b/modules/aws/firehose.py similarity index 100% rename from modules/firehose.py rename to modules/aws/firehose.py diff --git a/modules/iam.py b/modules/aws/iam.py similarity index 100% rename from modules/iam.py rename to modules/aws/iam.py diff --git a/modules/iam_pwn.py b/modules/aws/iam_pwn.py similarity index 100% rename from modules/iam_pwn.py rename to modules/aws/iam_pwn.py diff --git a/modules/lightsail.py b/modules/aws/lightsail.py similarity index 100% rename from modules/lightsail.py rename to modules/aws/lightsail.py diff --git a/modules/opsworks.py b/modules/aws/opsworks.py similarity index 100% rename from modules/opsworks.py rename to modules/aws/opsworks.py diff --git a/modules/pricing.py b/modules/aws/pricing.py similarity index 100% rename from modules/pricing.py rename to modules/aws/pricing.py diff --git a/modules/rds.py b/modules/aws/rds.py similarity index 100% rename from modules/rds.py rename to modules/aws/rds.py diff --git a/modules/recon.py b/modules/aws/recon.py similarity index 100% rename from modules/recon.py rename to modules/aws/recon.py diff --git a/modules/route53.py b/modules/aws/route53.py similarity index 100% rename from modules/route53.py rename to modules/aws/route53.py diff --git a/modules/s3.py b/modules/aws/s3.py similarity index 100% rename from modules/s3.py rename to modules/aws/s3.py diff --git a/modules/ses.py b/modules/aws/ses.py similarity index 100% rename from modules/ses.py rename to modules/aws/ses.py diff --git a/modules/sns.py b/modules/aws/sns.py similarity index 100% rename from modules/sns.py rename to modules/aws/sns.py diff --git a/modules/sqs.py b/modules/aws/sqs.py similarity index 100% rename from modules/sqs.py rename to modules/aws/sqs.py diff --git a/modules/sts.py b/modules/aws/sts.py similarity index 100% rename from modules/sts.py rename to modules/aws/sts.py diff --git a/modules/translate.py b/modules/aws/translate.py similarity index 100% rename from modules/translate.py rename to modules/aws/translate.py diff --git a/modules/gcp/.keep b/modules/gcp/.keep new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt index 3ae7987..dd47ee7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ python-dateutil==2.6.1 s3transfer==0.1.11 six==1.11.0 virtualenv==15.1.0 +tabulate=0.8.2 diff --git a/weirdAAL.py b/weirdAAL.py index 9771525..c79be88 100755 --- a/weirdAAL.py +++ b/weirdAAL.py @@ -13,6 +13,9 @@ from botocore.exceptions import ClientError from modules import * import sys import builtins +import re +from tabulate import tabulate +import textwrap os.environ['AWS_SHARED_CREDENTIALS_FILE'] = '.env' @@ -24,19 +27,18 @@ for module in all_modules: exec("from %s import *" % module) + parser = argparse.ArgumentParser() -parser.add_argument("-m", "--module", help="list the module you would like to run", action="store", type=str, required=True) -parser.add_argument("-t", "--target", help="Give your target a name so we can track results", action="store", type=str, required=True) +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", action="store_true") +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" -# Provides us with a global var "target" we can access anywhere -builtins.target = args.target def perform_credential_check(): ''' @@ -62,6 +64,63 @@ def method_create(): 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) + 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'])) # Need to figure out if we have keys in the ENV or not try: @@ -71,7 +130,8 @@ except: sys.exit(1) if (args.list): - pass + make_the_list() + print_the_list() # arg_list has to be defined otherwise will cause an exception @@ -82,12 +142,18 @@ if (args.arguments): # We need the user to tell us the module they want to proceed on if (args.module): - arg = method_create() - if callable(arg): - if arg_list: - arg(arg_list) - else: - arg() + 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