Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import boto3
- import botocore
- import sys
- # save file
- def save_file(file_name, file_content):
- with open(file_name, "a") as file:
- file.write(file_content + "\n")
- file.close()
- def build_aws_key(key, secret):
- aws_key = key + "|" + secret + "|" + "us-east-1"
- return aws_key
- # configure aws
- def check_aws(key, secret):
- aws_key = build_aws_key(key, secret)
- try:
- session = boto3.Session(
- aws_access_key_id=key,
- aws_secret_access_key=secret,
- region_name="us-east-1"
- )
- check_identity = session.client("sts").get_caller_identity()
- check = Check(aws_key, session)
- if "root" in check_identity["Arn"]:
- print("Root Aws Key > " + key)
- save_file("root_aws_key.txt", aws_key)
- check.check_ses()
- check.check_ec2()
- else:
- print("Valid Aws Key > " + key)
- save_file("valid_aws_key.txt", aws_key)
- check.check_ses()
- check.check_ec2()
- except botocore.exceptions.ClientError as error:
- er = error.response["Error"]["Code"]
- if er == "InvalidClientTokenId":
- print("Invalid Aws Key > " + key)
- elif er == "SignatureDoesNotMatch":
- print("Signature Does Not Match > " + key)
- else:
- print(er + " > " + key)
- except Exception as e:
- print(str(e))
- class Check(object):
- def __init__(self, aws_key, session):
- self.aws_key = aws_key
- self.session = session
- self.region_list = [
- "us-east-1",
- "us-east-2",
- "us-west-1",
- "us-west-2",
- "ap-south-1",
- "ap-southeast-1",
- "ap-southeast-2",
- "ap-northeast-1",
- "ap-northeast-2",
- "ap-northeast-3",
- "ca-central-1",
- "eu-south-1",
- "eu-central-1",
- "eu-north-1",
- "eu-west-1",
- "eu-west-2",
- "eu-west-3",
- "sa-east-1",
- "me-south-1",
- ]
- def check_ec2(self):
- print("\nChecking EC2 List Quotas in all regions\n")
- all_save = self.aws_key + "\n"
- for reg in self.region_list:
- try:
- service_quotas = self.session.client(
- "service-quotas", region_name=reg).list_service_quotas(ServiceCode="ec2")
- quotas_list = service_quotas["Quotas"]
- Result = "Region: " + reg + "\n"
- for quotas in quotas_list:
- if "All" in str(quotas):
- quotaname = quotas["QuotaName"]
- value = quotas["Value"]
- Result += quotaname + ": " + str(value) + "\n"
- all_save += Result + "\n"
- print(Result)
- except botocore.exceptions.ClientError as error:
- er = error.response["Error"]["Code"]
- if er == "AccessDeniedException":
- print("Access Denied for EC2\n")
- break
- elif er == "UnrecognizedClientException":
- print("Region " + reg + " locked for EC2\n")
- else:
- print(str(error))
- except botocore.exceptions.ReadTimeoutError:
- print("Cant connect to EC2 " + reg + " endpoint\n")
- except KeyboardInterrupt:
- continue
- except Exception as e:
- print(str(e))
- if "Region" in all_save:
- save_file("ec2_quotas.txt", all_save)
- def check_ses(self):
- print("\nChecking SES in all regions\n")
- all_save = self.aws_key + "\n"
- for reg in self.region_list:
- try:
- sesv2 = self.session.client("sesv2", region_name=reg)
- check_account = sesv2.get_account()
- status = check_account["EnforcementStatus"]
- quota = check_account["SendQuota"]
- max24 = quota["Max24HourSend"]
- maxsend = quota["MaxSendRate"]
- sentlast = quota["SentLast24Hours"]
- # checking identity
- identity = ""
- identities = self.session.client(
- "ses", region_name=reg).list_identities()["Identities"]
- if len(identities) > 0:
- identity = "SES Identity : " + ", ".join(identities)
- else:
- identity = "No SES Identities found"
- Result = "Region: " + reg + "\nStatus: " + status + "\nMax24HourSend: " + \
- str(max24) + "\nMaxSendRate: " + str(maxsend) + \
- "\nSentLast24Hours: " + \
- str(sentlast) + "\n" + identity + "\n"
- all_save += Result + "\n"
- print(Result)
- except botocore.exceptions.ClientError as error:
- er = error.response["Error"]["Code"]
- if er == "AccessDeniedException":
- print("Access Denied for SESV2\n")
- break
- elif er == "UnrecognizedClientException":
- print("Region " + reg + " locked for SESV2\n")
- else:
- print(str(error))
- except botocore.exceptions.ReadTimeoutError:
- print("Cant connect to SESV2 " + reg + " endpoint\n")
- except KeyboardInterrupt:
- continue
- except Exception as e:
- print(str(e))
- if "Region" in all_save:
- save_file("sesv2_aws_key.txt", all_save)
- if __name__ == "__main__":
- key = input("Enter your aws key: ")
- secret = input("Enter your aws secret: ")
- check_aws(key, secret)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement