From b00ee271ff9012ec39073925bcdf609593bc0a29 Mon Sep 17 00:00:00 2001 From: cktricky Date: Thu, 13 Sep 2018 20:09:26 -0400 Subject: [PATCH 1/9] more shuffling --- modules/{ => aws}/aws_lambda.py | 0 modules/{ => aws}/ce.py | 0 modules/{ => aws}/cloudfront.py | 0 modules/{ => aws}/cloudtrail.py | 0 modules/{ => aws}/cloudwatch.py | 0 modules/{ => aws}/config.py | 0 modules/{ => aws}/datapipeline.py | 0 modules/{ => aws}/db.py | 0 modules/{ => aws}/dynamodb.py | 0 modules/{ => aws}/dynamodbstreams.py | 0 modules/{ => aws}/ec2.py | 0 modules/{ => aws}/ecr.py | 0 modules/{ => aws}/elasticbeanstalk.py | 0 modules/{ => aws}/emr.py | 0 modules/{ => aws}/firehose.py | 0 modules/{ => aws}/iam.py | 0 modules/{ => aws}/iam_pwn.py | 0 modules/{ => aws}/lightsail.py | 0 modules/{ => aws}/opsworks.py | 0 modules/{ => aws}/pricing.py | 0 modules/{ => aws}/rds.py | 0 modules/{ => aws}/recon.py | 0 modules/{ => aws}/route53.py | 0 modules/{ => aws}/s3.py | 0 modules/{ => aws}/ses.py | 0 modules/{ => aws}/sns.py | 0 modules/{ => aws}/sqs.py | 0 modules/{ => aws}/sts.py | 0 modules/{ => aws}/translate.py | 0 weirdAAL.py | 2 +- 30 files changed, 1 insertion(+), 1 deletion(-) rename modules/{ => aws}/aws_lambda.py (100%) rename modules/{ => aws}/ce.py (100%) rename modules/{ => aws}/cloudfront.py (100%) rename modules/{ => aws}/cloudtrail.py (100%) rename modules/{ => aws}/cloudwatch.py (100%) rename modules/{ => aws}/config.py (100%) rename modules/{ => aws}/datapipeline.py (100%) rename modules/{ => aws}/db.py (100%) rename modules/{ => aws}/dynamodb.py (100%) rename modules/{ => aws}/dynamodbstreams.py (100%) rename modules/{ => aws}/ec2.py (100%) rename modules/{ => aws}/ecr.py (100%) rename modules/{ => aws}/elasticbeanstalk.py (100%) rename modules/{ => aws}/emr.py (100%) rename modules/{ => aws}/firehose.py (100%) rename modules/{ => aws}/iam.py (100%) rename modules/{ => aws}/iam_pwn.py (100%) rename modules/{ => aws}/lightsail.py (100%) rename modules/{ => aws}/opsworks.py (100%) rename modules/{ => aws}/pricing.py (100%) rename modules/{ => aws}/rds.py (100%) rename modules/{ => aws}/recon.py (100%) rename modules/{ => aws}/route53.py (100%) rename modules/{ => aws}/s3.py (100%) rename modules/{ => aws}/ses.py (100%) rename modules/{ => aws}/sns.py (100%) rename modules/{ => aws}/sqs.py (100%) rename modules/{ => aws}/sts.py (100%) rename modules/{ => aws}/translate.py (100%) 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/weirdAAL.py b/weirdAAL.py index 9771525..f7c8be0 100755 --- a/weirdAAL.py +++ b/weirdAAL.py @@ -19,7 +19,7 @@ os.environ['AWS_SHARED_CREDENTIALS_FILE'] = '.env' # 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") +sys.path.append("modules/aws/") for module in all_modules: exec("from %s import *" % module) From cec955c3c8d77f976f4a9bf12baa6bb014da91ed Mon Sep 17 00:00:00 2001 From: cktricky Date: Fri, 14 Sep 2018 11:52:27 -0400 Subject: [PATCH 2/9] still futzing around --- libs/utils/common.py | 13 +++++++++---- weirdAAL.py | 8 +++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/libs/utils/common.py b/libs/utils/common.py index e7136e6..424f965 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('__')) ): + if filenames: + list_path_name = dirpath.split('/') + array.append(".".join(list_path_name)) + #array.append(directory.split) return array diff --git a/weirdAAL.py b/weirdAAL.py index f7c8be0..27b827b 100755 --- a/weirdAAL.py +++ b/weirdAAL.py @@ -19,10 +19,11 @@ os.environ['AWS_SHARED_CREDENTIALS_FILE'] = '.env' # 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/aws/") -for module in all_modules: - exec("from %s import *" % module) +sys.path.append("modules") +#for module in all_modules: +# exec("from %s import *" % module) +from modules import * parser = argparse.ArgumentParser() parser.add_argument("-m", "--module", help="list the module you would like to run", action="store", type=str, required=True) @@ -56,6 +57,7 @@ def perform_credential_check(): def method_create(): try: + print(globals()) arg = globals()["module_" + args.module] return arg except KeyError: From 16f11bbd8c77c8bd9a81072f19b40ea2f0bfa531 Mon Sep 17 00:00:00 2001 From: cktricky Date: Fri, 14 Sep 2018 12:30:01 -0400 Subject: [PATCH 3/9] woohoo, can still invoke commands --- libs/utils/common.py | 5 ++--- weirdAAL.py | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/libs/utils/common.py b/libs/utils/common.py index 424f965..069c258 100644 --- a/libs/utils/common.py +++ b/libs/utils/common.py @@ -10,8 +10,7 @@ def list_all_files(directory): if ( not (dirpath == os.path.basename(directory)) and (os.path.isdir(dirpath)) and not (os.path.basename(dirpath).startswith('__')) ): - if filenames: + for file in filenames: list_path_name = dirpath.split('/') - array.append(".".join(list_path_name)) - #array.append(directory.split) + array.append(".".join(list_path_name) + "." + os.path.splitext(file)[0]) return array diff --git a/weirdAAL.py b/weirdAAL.py index 27b827b..fd57f12 100755 --- a/weirdAAL.py +++ b/weirdAAL.py @@ -20,10 +20,9 @@ os.environ['AWS_SHARED_CREDENTIALS_FILE'] = '.env' # os.environ['HTTPS_PROXY'] = 'https://127.0.0.1:3128' sys.path.append("modules") -#for module in all_modules: -# exec("from %s import *" % module) +for module in all_modules: + exec("from %s import *" % module) -from modules import * parser = argparse.ArgumentParser() parser.add_argument("-m", "--module", help="list the module you would like to run", action="store", type=str, required=True) From 677936cab5e2374ed73348f1cc1b04fee6484d78 Mon Sep 17 00:00:00 2001 From: cktricky Date: Fri, 14 Sep 2018 12:30:18 -0400 Subject: [PATCH 4/9] removing the print debug statement --- weirdAAL.py | 1 - 1 file changed, 1 deletion(-) diff --git a/weirdAAL.py b/weirdAAL.py index fd57f12..9771525 100755 --- a/weirdAAL.py +++ b/weirdAAL.py @@ -56,7 +56,6 @@ def perform_credential_check(): def method_create(): try: - print(globals()) arg = globals()["module_" + args.module] return arg except KeyError: From 378135e799cb8ec84c4a36ba8fc8f5e10d062b5f Mon Sep 17 00:00:00 2001 From: cktricky Date: Fri, 14 Sep 2018 20:34:46 -0400 Subject: [PATCH 5/9] reworked the logic of modules and what not --- weirdAAL.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/weirdAAL.py b/weirdAAL.py index 9771525..b448f7b 100755 --- a/weirdAAL.py +++ b/weirdAAL.py @@ -25,19 +25,16 @@ for module in all_modules: 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(): ''' Check that the AWS keys work before we go any further. It picks the keys up from the local .env file @@ -71,7 +68,7 @@ except: sys.exit(1) if (args.list): - pass + print(all_modules) # arg_list has to be defined otherwise will cause an exception @@ -82,12 +79,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 From 223ce8870515305ce3ee0624f0b3a06ee83a6253 Mon Sep 17 00:00:00 2001 From: cktricky Date: Thu, 20 Sep 2018 09:39:56 -0400 Subject: [PATCH 6/9] listing is in progress but needed to add a .keep to the gcp folder --- modules/gcp/.keep | 0 weirdAAL.py | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 modules/gcp/.keep diff --git a/modules/gcp/.keep b/modules/gcp/.keep new file mode 100644 index 0000000..e69de29 diff --git a/weirdAAL.py b/weirdAAL.py index b448f7b..61d041a 100755 --- a/weirdAAL.py +++ b/weirdAAL.py @@ -68,7 +68,8 @@ except: sys.exit(1) if (args.list): - print(all_modules) + for module in all_modules: + print(module) # arg_list has to be defined otherwise will cause an exception From 7d04eaea7bdced81581e8436ce14f8c276b30c9d Mon Sep 17 00:00:00 2001 From: cktricky Date: Thu, 20 Sep 2018 09:57:03 -0400 Subject: [PATCH 7/9] fix so that files like .keep are not imported --- libs/utils/common.py | 3 ++- weirdAAL.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/utils/common.py b/libs/utils/common.py index 069c258..ecfc882 100644 --- a/libs/utils/common.py +++ b/libs/utils/common.py @@ -12,5 +12,6 @@ def list_all_files(directory): and not (os.path.basename(dirpath).startswith('__')) ): for file in filenames: list_path_name = dirpath.split('/') - array.append(".".join(list_path_name) + "." + os.path.splitext(file)[0]) + if not (file.startswith('.')): + array.append(".".join(list_path_name) + "." + os.path.splitext(file)[0]) return array diff --git a/weirdAAL.py b/weirdAAL.py index 61d041a..efabcfb 100755 --- a/weirdAAL.py +++ b/weirdAAL.py @@ -69,7 +69,7 @@ except: if (args.list): for module in all_modules: - print(module) + print(dir(module)) # arg_list has to be defined otherwise will cause an exception From 69526ba18c57ae15291034fd6b0be926a4b9f43e Mon Sep 17 00:00:00 2001 From: cktricky Date: Fri, 21 Sep 2018 20:59:32 -0400 Subject: [PATCH 8/9] sweeeeet. now i just need the table formatted correctly and we are rockin and rollin --- weirdAAL.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/weirdAAL.py b/weirdAAL.py index efabcfb..b16bbd4 100755 --- a/weirdAAL.py +++ b/weirdAAL.py @@ -13,6 +13,7 @@ from botocore.exceptions import ClientError from modules import * import sys import builtins +import re os.environ['AWS_SHARED_CREDENTIALS_FILE'] = '.env' @@ -24,6 +25,7 @@ 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=False) parser.add_argument("-t", "--target", help="Give your target a name so we can track results", action="store", type=str, required=False) @@ -35,6 +37,7 @@ 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 @@ -59,6 +62,48 @@ 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 print_the_list(): + print("AWS") + print("---") + for (k) in aws_module_methods_info: + print(k) + print(aws_module_methods_info[k]) + print("....") # Need to figure out if we have keys in the ENV or not try: @@ -68,8 +113,8 @@ except: sys.exit(1) if (args.list): - for module in all_modules: - print(dir(module)) + make_the_list() + print_the_list() # arg_list has to be defined otherwise will cause an exception From 859d2e3d52e26067319104cfebc0bf9722781ece Mon Sep 17 00:00:00 2001 From: cktricky Date: Fri, 21 Sep 2018 22:52:30 -0400 Subject: [PATCH 9/9] kewl printing now --- requirements.txt | 1 + weirdAAL.py | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) 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 b16bbd4..c79be88 100755 --- a/weirdAAL.py +++ b/weirdAAL.py @@ -14,6 +14,8 @@ from modules import * import sys import builtins import re +from tabulate import tabulate +import textwrap os.environ['AWS_SHARED_CREDENTIALS_FILE'] = '.env' @@ -97,13 +99,28 @@ def make_the_list(): 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(): - print("AWS") - print("---") - for (k) in aws_module_methods_info: - print(k) - print(aws_module_methods_info[k]) - print("....") + 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: