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

chore(mitre azure): add mapping to mitre for azure provider #3857

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions dashboard/compliance/mitre_attack_azure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import warnings

from dashboard.common_methods import get_section_containers_format2

warnings.filterwarnings("ignore")


def get_table(data):
aux = data[
n4ch04 marked this conversation as resolved.
Show resolved Hide resolved
[
"REQUIREMENTS_ID",
"REQUIREMENTS_SUBTECHNIQUES",
"CHECKID",
"STATUS",
"REGION",
"ACCOUNTID",
"RESOURCEID",
]
].copy()
n4ch04 marked this conversation as resolved.
Show resolved Hide resolved

return get_section_containers_format2(
aux, "REQUIREMENTS_ID", "REQUIREMENTS_SUBTECHNIQUES"
)
7 changes: 7 additions & 0 deletions dashboard/pages/compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def load_csv_files(files):
# Rename the column SUBSCRIPTIONID to ACCOUNTID for Azure
if data.columns.str.contains("SUBSCRIPTIONID").any():
data.rename(columns={"SUBSCRIPTIONID": "ACCOUNTID"}, inplace=True)
data["REGION"] = "-"
# Handle v3 azure cis compliance
if data.columns.str.contains("SUBSCRIPTION").any():
data.rename(columns={"SUBSCRIPTION": "ACCOUNTID"}, inplace=True)
Expand Down Expand Up @@ -433,6 +434,12 @@ def load_csv_files(files):
):
pie_2 = get_bar_graph(df, "REQUIREMENTS_ATTRIBUTES_SERVICE")
current_filter = "services"
elif (
"REQUIREMENTS_ID" in df.columns
and not df["REQUIREMENTS_ID"].isnull().values.any()
):
pie_2 = get_bar_graph(df, "REQUIREMENTS_ID")
current_filter = "techniques"
else:
fig = px.pie()
fig.update_layout(
Expand Down
3 changes: 1 addition & 2 deletions prowler/lib/outputs/compliance/compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,9 @@
file_descriptors, finding, compliance, output_options, provider
)

elif compliance.Framework == "MITRE-ATTACK" and compliance.Version == "":
# print(file_descriptors)
write_compliance_row_mitre_attack(

Check warning on line 128 in prowler/lib/outputs/compliance/compliance.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/compliance/compliance.py#L127-L128

Added lines #L127 - L128 were not covered by tests
file_descriptors, finding, compliance, output_options, provider
file_descriptors, finding, compliance, provider
)

else:
Expand Down
6 changes: 2 additions & 4 deletions prowler/lib/outputs/compliance/mitre_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,54 +11,52 @@
from prowler.lib.utils.utils import outputs_unix_timestamp


def write_compliance_row_mitre_attack(
file_descriptors, finding, compliance, output_options, provider
):
def write_compliance_row_mitre_attack(file_descriptors, finding, compliance, provider):
try:
compliance_output = compliance.Framework
if compliance.Version != "":
compliance_output += "_" + compliance.Version
if compliance.Provider != "":
compliance_output += "_" + compliance.Provider

Check warning on line 20 in prowler/lib/outputs/compliance/mitre_attack.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/compliance/mitre_attack.py#L15-L20

Added lines #L15 - L20 were not covered by tests

mitre_attack_model_name = "Check_Output_MITRE_ATTACK_" + compliance.Provider
module = import_module("prowler.lib.outputs.compliance.models")
mitre_attack_model = getattr(module, mitre_attack_model_name)
compliance_output = compliance_output.lower().replace("-", "_")
csv_header = generate_csv_fields(mitre_attack_model)
csv_writer = DictWriter(

Check warning on line 27 in prowler/lib/outputs/compliance/mitre_attack.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/compliance/mitre_attack.py#L22-L27

Added lines #L22 - L27 were not covered by tests
file_descriptors[compliance_output],
fieldnames=csv_header,
delimiter=";",
)
for requirement in compliance.Requirements:

Check warning on line 32 in prowler/lib/outputs/compliance/mitre_attack.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/compliance/mitre_attack.py#L32

Added line #L32 was not covered by tests

if compliance.Provider == "AWS":
attributes_services = ", ".join(

Check warning on line 35 in prowler/lib/outputs/compliance/mitre_attack.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/compliance/mitre_attack.py#L34-L35

Added lines #L34 - L35 were not covered by tests
attribute.AWSService for attribute in requirement.Attributes
)
elif compliance.Provider == "Azure":
attributes_services = ", ".join(

Check warning on line 39 in prowler/lib/outputs/compliance/mitre_attack.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/compliance/mitre_attack.py#L38-L39

Added lines #L38 - L39 were not covered by tests
attribute.AzureService for attribute in requirement.Attributes
)
requirement_description = requirement.Description
requirement_id = requirement.Id
requirement_name = requirement.Name
attributes_categories = ", ".join(

Check warning on line 45 in prowler/lib/outputs/compliance/mitre_attack.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/compliance/mitre_attack.py#L42-L45

Added lines #L42 - L45 were not covered by tests
attribute.Category for attribute in requirement.Attributes
)
attributes_values = ", ".join(

Check warning on line 48 in prowler/lib/outputs/compliance/mitre_attack.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/compliance/mitre_attack.py#L48

Added line #L48 was not covered by tests
attribute.Value for attribute in requirement.Attributes
)
attributes_comments = ", ".join(

Check warning on line 51 in prowler/lib/outputs/compliance/mitre_attack.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/compliance/mitre_attack.py#L51

Added line #L51 was not covered by tests
attribute.Comment for attribute in requirement.Attributes
)

common_data = {

Check warning on line 55 in prowler/lib/outputs/compliance/mitre_attack.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/compliance/mitre_attack.py#L55

Added line #L55 was not covered by tests
"Provider": finding.check_metadata.Provider,
"Description": compliance.Description,
"AssessmentDate": outputs_unix_timestamp(
output_options.unix_timestamp, timestamp
provider.output_options.unix_timestamp, timestamp
),
"Requirements_Id": requirement_id,
"Requirements_Name": requirement_name,
Expand All @@ -77,19 +75,19 @@
"CheckId": finding.check_metadata.CheckID,
"Muted": finding.muted,
}
if compliance.Provider == "AWS":
common_data["AccountId"] = provider.identity.account
common_data["Region"] = finding.region
elif compliance.Provider == "Azure":
common_data["SubscriptionId"] = unroll_list(

Check warning on line 82 in prowler/lib/outputs/compliance/mitre_attack.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/compliance/mitre_attack.py#L78-L82

Added lines #L78 - L82 were not covered by tests
provider.identity.subscriptions
)

compliance_row = mitre_attack_model(**common_data)

Check warning on line 86 in prowler/lib/outputs/compliance/mitre_attack.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/compliance/mitre_attack.py#L86

Added line #L86 was not covered by tests

csv_writer.writerow(compliance_row.__dict__)
except Exception as error:
logger.critical(

Check warning on line 90 in prowler/lib/outputs/compliance/mitre_attack.py

View check run for this annotation

Codecov / codecov/patch

prowler/lib/outputs/compliance/mitre_attack.py#L88-L90

Added lines #L88 - L90 were not covered by tests
n4ch04 marked this conversation as resolved.
Show resolved Hide resolved
f"{error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)

Expand Down