Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New module: mq__enum #431

Merged
merged 10 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pacu/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class AWSKey(Base, ModelUpdateMixin):
permissions_confirmed = Column(JSONType)
allow_permissions = Column(JSONType, nullable=False, default=dict)
deny_permissions = Column(JSONType, nullable=False, default=dict)
mq = Column(JSONType)

def __repr__(self):
return '<AWSKey #{}: {}>'.format(self.id, self.key_alias)
Expand All @@ -60,6 +61,7 @@ def get_fields_as_camel_case_dictionary(self) -> dict:
'Allow': remove_empty_from_dict(self.allow_permissions),
'Deny': remove_empty_from_dict(self.deny_permissions),
},
'MQ':self.mq
})


Expand All @@ -84,6 +86,7 @@ class PacuSession(Base, ModelUpdateMixin):
'Inspector',
'Lambda',
'Lightsail',
'MQ',
'S3',
'SecretsManager',
'Shield',
Expand Down Expand Up @@ -129,6 +132,7 @@ class PacuSession(Base, ModelUpdateMixin):
Inspector = Column(JSONType, nullable=False, default=dict)
Lambda = Column(JSONType, nullable=False, default=dict)
Lightsail = Column(JSONType, nullable=False, default=dict)
MQ = Column(JSONType, nullable=False, default=dict)
RDS = Column(JSONType, nullable=False, default=dict)
S3 = Column(JSONType, nullable=False, default=dict)
SecretsManager = Column(JSONType, nullable=False, default=dict)
Expand Down
Empty file.
136 changes: 136 additions & 0 deletions pacu/modules/mq__enum/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#!/usr/bin/env python3
import argparse
import time
import json

from pacu.core.lib import downloads_dir
from pacu.core.lib import strip_lines
from pacu import Main
from copy import deepcopy

module_info = {
"name": "mq__enum",
"author": "6a6f656c & h00die of nDepth Security",
"category": "ENUM",
"one_liner": "Listo and describe brokers",
6a6f656c marked this conversation as resolved.
Show resolved Hide resolved
"description": strip_lines(
"""
This module will attempt to list and gather information from available brokers.
"""
),
"services": ["MQ"],
"prerequisite_modules": [],
"arguments_to_autocomplete": [],
}

parser = argparse.ArgumentParser(add_help=False, description=module_info["description"])

parser.add_argument(
"--regions",
required=False,
default=None,
help=strip_lines(
"""
One or more (comma separated) AWS regions in the format "us-east-1". Defaults to all session regions.
"""
),
)


def main(args, pacu_main: "Main"):
session = pacu_main.get_active_session()

# Don't modify these. They can be removed if you are not using the function.
args = parser.parse_args(args)
print = pacu_main.print

key_info = pacu_main.key_info
fetch_data = pacu_main.fetch_data

# End don't modify
get_regions = pacu_main.get_regions
if not args.regions:
regions = get_regions("mq")
else:
regions = args.regions.split(",")

summary_data = {}
summary_data["mq"] = {}

for region in regions:
print("Starting region {}...".format(region))
summary_data["mq"][region] = {}

try:
client = pacu_main.get_boto3_client("mq", region)
except Exception as error:
print("Unable to connect to MQ service. Error: {}".format(error))
continue

# Prepare output file to store MQ data
now = time.time()
outfile_path = str(downloads_dir() / f"mq_enum_{now}.json")
6a6f656c marked this conversation as resolved.
Show resolved Hide resolved

try:
response = client.list_brokers(
MaxResults=100,
)
6a6f656c marked this conversation as resolved.
Show resolved Hide resolved

except Exception as error:
print(
"Unable to list brokers; Check credentials or No brokers are available. Error: {}".format(
error
)
)
continue
print(" Found {} brokers".format(len(response["BrokerSummaries"])))
for broker in response["BrokerSummaries"]:
6a6f656c marked this conversation as resolved.
Show resolved Hide resolved
6a6f656c marked this conversation as resolved.
Show resolved Hide resolved
broker_details = client.describe_broker(BrokerId=broker["BrokerId"])
6a6f656c marked this conversation as resolved.
Show resolved Hide resolved
summary_data["mq"][region][broker["BrokerId"]] = {}
summary_data["mq"][region][broker["BrokerId"]]["AuthenticationStrategy"] = (
broker_details["AuthenticationStrategy"]
)
summary_data["mq"][region][broker["BrokerId"]]["PubliclyAccessible"] = (
broker_details["PubliclyAccessible"]
)
summary_data["mq"][region][broker["BrokerId"]]["BrokerName"] = (
broker_details["BrokerName"]
)
summary_data["mq"][region][broker["BrokerId"]]["BrokerState"] = (
broker_details["BrokerState"]
)
summary_data["mq"][region][broker["BrokerId"]]["Users"] = broker_details[
"Users"
]
summary_data["mq"][region][broker["BrokerId"]]["EngineType"] = (
broker_details["EngineType"]
)
summary_data["mq"][region][broker["BrokerId"]]["ConsoleURL"] = [
url["ConsoleURL"] for url in broker_details["BrokerInstances"]
]

# Write all the data to the output file
print("Writing all MQ results to file: {}".format(outfile_path))
with open(outfile_path, "w+") as f:
f.write(json.dumps(summary_data, indent=4, default=str))
6a6f656c marked this conversation as resolved.
Show resolved Hide resolved

mq_data = deepcopy(session.MQ)
for key, value in summary_data.items():
mq_data[key] = value
session.update(pacu_main.database, MQ=mq_data)

return summary_data


def summary(data, pacu_main):
out = ""

total_users = 0
total_brokers = 0
for region in data["mq"]:
total_brokers += len(data["mq"][region])
for broker in data["mq"][region]:
total_users += len(data["mq"][region][broker]["Users"])
out += "Num of MQ brokers found: {} \n".format(total_brokers)
out += "Num of MQ users found: {} \n".format(total_users)
return out