mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-09 21:14:22 +00:00
feat(guardduty): add new check guardduty_rds_protection_enabled (#5100)
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"Provider": "aws",
|
||||||
|
"CheckID": "guardduty_rds_protection_enabled",
|
||||||
|
"CheckTitle": "Check if GuardDuty RDS Protection is enabled.",
|
||||||
|
"CheckType": [
|
||||||
|
"Software and Configuration Checks/AWS Security Best Practices"
|
||||||
|
],
|
||||||
|
"ServiceName": "guardduty",
|
||||||
|
"SubServiceName": "",
|
||||||
|
"ResourceIdTemplate": "arn:aws:guardduty:<region>:<account-id>:detector/<detector-id>",
|
||||||
|
"Severity": "high",
|
||||||
|
"ResourceType": "AwsGuardDutyDetector",
|
||||||
|
"Description": "Check if GuardDuty RDS Protection is enabled to ensure monitoring and threat detection for RDS activity.",
|
||||||
|
"Risk": "Without GuardDuty RDS Protection enabled, suspicious login activities to your databases may go undetected, increasing the risk of unauthorized access, data breaches, or compromised database security.",
|
||||||
|
"RelatedUrl": "https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/guard-duty-rds-protection.html",
|
||||||
|
"Remediation": {
|
||||||
|
"Code": {
|
||||||
|
"CLI": "",
|
||||||
|
"NativeIaC": "",
|
||||||
|
"Other": "https://docs.aws.amazon.com/securityhub/latest/userguide/guardduty-controls.html#guardduty-9",
|
||||||
|
"Terraform": ""
|
||||||
|
},
|
||||||
|
"Recommendation": {
|
||||||
|
"Text": "Enable GuardDuty RDS Protection to continuously monitor and detect anomalous login behaviors on your Aurora databases, helping to identify and respond to potential access threats without impacting database performance.",
|
||||||
|
"Url": "https://docs.aws.amazon.com/guardduty/latest/ug/rds-protection.html"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Categories": [],
|
||||||
|
"DependsOn": [],
|
||||||
|
"RelatedTo": [],
|
||||||
|
"Notes": ""
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
from prowler.lib.check.models import Check, Check_Report_AWS
|
||||||
|
from prowler.providers.aws.services.guardduty.guardduty_client import guardduty_client
|
||||||
|
|
||||||
|
|
||||||
|
class guardduty_rds_protection_enabled(Check):
|
||||||
|
def execute(self):
|
||||||
|
findings = []
|
||||||
|
for detector in guardduty_client.detectors:
|
||||||
|
if detector.status:
|
||||||
|
report = Check_Report_AWS(self.metadata())
|
||||||
|
report.region = detector.region
|
||||||
|
report.resource_id = detector.id
|
||||||
|
report.resource_arn = detector.arn
|
||||||
|
report.resource_tags = detector.tags
|
||||||
|
report.status = "FAIL"
|
||||||
|
report.status_extended = (
|
||||||
|
"GuardDuty detector does not have RDS Protection enabled."
|
||||||
|
)
|
||||||
|
if detector.rds_protection:
|
||||||
|
report.status = "PASS"
|
||||||
|
report.status_extended = (
|
||||||
|
"GuardDuty detector has RDS Protection enabled."
|
||||||
|
)
|
||||||
|
findings.append(report)
|
||||||
|
return findings
|
||||||
@@ -7,7 +7,6 @@ from prowler.lib.scan_filters.scan_filters import is_resource_filtered
|
|||||||
from prowler.providers.aws.lib.service.service import AWSService
|
from prowler.providers.aws.lib.service.service import AWSService
|
||||||
|
|
||||||
|
|
||||||
################################ GuardDuty
|
|
||||||
class GuardDuty(AWSService):
|
class GuardDuty(AWSService):
|
||||||
def __init__(self, provider):
|
def __init__(self, provider):
|
||||||
# Call AWSService's __init__
|
# Call AWSService's __init__
|
||||||
@@ -72,6 +71,13 @@ class GuardDuty(AWSService):
|
|||||||
if s3_logs.get("Status") == "ENABLED":
|
if s3_logs.get("Status") == "ENABLED":
|
||||||
detector.s3_protection = True
|
detector.s3_protection = True
|
||||||
|
|
||||||
|
for feat in detector_info.get("Features", []):
|
||||||
|
if (
|
||||||
|
feat.get("Name") == "RDS_LOGIN_EVENTS"
|
||||||
|
and feat.get("Status", "DISABLED") == "ENABLED"
|
||||||
|
):
|
||||||
|
detector.rds_protection = True
|
||||||
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
logger.error(
|
logger.error(
|
||||||
f"{error.__class__.__name__}:{error.__traceback__.tb_lineno} -- {error}"
|
f"{error.__class__.__name__}:{error.__traceback__.tb_lineno} -- {error}"
|
||||||
@@ -197,3 +203,4 @@ class Detector(BaseModel):
|
|||||||
administrator_account: str = None
|
administrator_account: str = None
|
||||||
tags: Optional[list] = []
|
tags: Optional[list] = []
|
||||||
s3_protection: bool = False
|
s3_protection: bool = False
|
||||||
|
rds_protection: bool = False
|
||||||
|
|||||||
+139
@@ -0,0 +1,139 @@
|
|||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
from prowler.providers.aws.services.guardduty.guardduty_service import Detector
|
||||||
|
from tests.providers.aws.utils import AWS_ACCOUNT_NUMBER, AWS_REGION_US_EAST_1
|
||||||
|
|
||||||
|
|
||||||
|
class Test_guardduty_rds_protection_enabled:
|
||||||
|
def test_no_detectors(self):
|
||||||
|
guardduty_client = mock.MagicMock()
|
||||||
|
guardduty_client.detectors = []
|
||||||
|
|
||||||
|
with mock.patch(
|
||||||
|
"prowler.providers.aws.services.guardduty.guardduty_service.GuardDuty",
|
||||||
|
new=guardduty_client,
|
||||||
|
), mock.patch(
|
||||||
|
"prowler.providers.aws.services.guardduty.guardduty_rds_protection_enabled.guardduty_rds_protection_enabled.guardduty_client",
|
||||||
|
new=guardduty_client,
|
||||||
|
):
|
||||||
|
|
||||||
|
from prowler.providers.aws.services.guardduty.guardduty_rds_protection_enabled.guardduty_rds_protection_enabled import (
|
||||||
|
guardduty_rds_protection_enabled,
|
||||||
|
)
|
||||||
|
|
||||||
|
check = guardduty_rds_protection_enabled()
|
||||||
|
result = check.execute()
|
||||||
|
|
||||||
|
assert len(result) == 0
|
||||||
|
|
||||||
|
def test_detector_disabled(self):
|
||||||
|
guardduty_client = mock.MagicMock()
|
||||||
|
detector_arn = f"arn:aws:guardduty:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:detector/1234567890"
|
||||||
|
guardduty_client.detectors = [
|
||||||
|
Detector(
|
||||||
|
id="1234567890",
|
||||||
|
arn=detector_arn,
|
||||||
|
region=AWS_REGION_US_EAST_1,
|
||||||
|
tags=[],
|
||||||
|
enabled_in_account=False,
|
||||||
|
rds_protection=False,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
with mock.patch(
|
||||||
|
"prowler.providers.aws.services.guardduty.guardduty_service.GuardDuty",
|
||||||
|
new=guardduty_client,
|
||||||
|
), mock.patch(
|
||||||
|
"prowler.providers.aws.services.guardduty.guardduty_rds_protection_enabled.guardduty_rds_protection_enabled.guardduty_client",
|
||||||
|
new=guardduty_client,
|
||||||
|
):
|
||||||
|
|
||||||
|
from prowler.providers.aws.services.guardduty.guardduty_rds_protection_enabled.guardduty_rds_protection_enabled import (
|
||||||
|
guardduty_rds_protection_enabled,
|
||||||
|
)
|
||||||
|
|
||||||
|
check = guardduty_rds_protection_enabled()
|
||||||
|
result = check.execute()
|
||||||
|
|
||||||
|
assert len(result) == 0
|
||||||
|
|
||||||
|
def test_detector_enabled_rds_protection_disabled(self):
|
||||||
|
guardduty_client = mock.MagicMock()
|
||||||
|
detector_arn = f"arn:aws:guardduty:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:detector/1234567890"
|
||||||
|
guardduty_client.detectors = [
|
||||||
|
Detector(
|
||||||
|
id="1234567890",
|
||||||
|
arn=detector_arn,
|
||||||
|
region=AWS_REGION_US_EAST_1,
|
||||||
|
tags=[],
|
||||||
|
enabled_in_account=True,
|
||||||
|
rds_protection=False,
|
||||||
|
status=True,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
with mock.patch(
|
||||||
|
"prowler.providers.aws.services.guardduty.guardduty_service.GuardDuty",
|
||||||
|
new=guardduty_client,
|
||||||
|
), mock.patch(
|
||||||
|
"prowler.providers.aws.services.guardduty.guardduty_rds_protection_enabled.guardduty_rds_protection_enabled.guardduty_client",
|
||||||
|
new=guardduty_client,
|
||||||
|
):
|
||||||
|
|
||||||
|
from prowler.providers.aws.services.guardduty.guardduty_rds_protection_enabled.guardduty_rds_protection_enabled import (
|
||||||
|
guardduty_rds_protection_enabled,
|
||||||
|
)
|
||||||
|
|
||||||
|
check = guardduty_rds_protection_enabled()
|
||||||
|
result = check.execute()
|
||||||
|
|
||||||
|
assert len(result) == 1
|
||||||
|
assert result[0].status == "FAIL"
|
||||||
|
assert (
|
||||||
|
result[0].status_extended
|
||||||
|
== "GuardDuty detector does not have RDS Protection enabled."
|
||||||
|
)
|
||||||
|
assert result[0].resource_id == "1234567890"
|
||||||
|
assert result[0].region == AWS_REGION_US_EAST_1
|
||||||
|
assert result[0].resource_arn == detector_arn
|
||||||
|
assert result[0].resource_tags == []
|
||||||
|
|
||||||
|
def test_detector_enabled_rds_protection_enabled(self):
|
||||||
|
guardduty_client = mock.MagicMock()
|
||||||
|
detector_arn = f"arn:aws:guardduty:{AWS_REGION_US_EAST_1}:{AWS_ACCOUNT_NUMBER}:detector/1234567890"
|
||||||
|
guardduty_client.detectors = [
|
||||||
|
Detector(
|
||||||
|
id="1234567890",
|
||||||
|
arn=detector_arn,
|
||||||
|
region=AWS_REGION_US_EAST_1,
|
||||||
|
tags=[],
|
||||||
|
enabled_in_account=True,
|
||||||
|
rds_protection=True,
|
||||||
|
status=True,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
with mock.patch(
|
||||||
|
"prowler.providers.aws.services.guardduty.guardduty_service.GuardDuty",
|
||||||
|
new=guardduty_client,
|
||||||
|
), mock.patch(
|
||||||
|
"prowler.providers.aws.services.guardduty.guardduty_rds_protection_enabled.guardduty_rds_protection_enabled.guardduty_client",
|
||||||
|
new=guardduty_client,
|
||||||
|
):
|
||||||
|
from prowler.providers.aws.services.guardduty.guardduty_rds_protection_enabled.guardduty_rds_protection_enabled import (
|
||||||
|
guardduty_rds_protection_enabled,
|
||||||
|
)
|
||||||
|
|
||||||
|
check = guardduty_rds_protection_enabled()
|
||||||
|
result = check.execute()
|
||||||
|
|
||||||
|
assert len(result) == 1
|
||||||
|
assert result[0].status == "PASS"
|
||||||
|
assert (
|
||||||
|
result[0].status_extended
|
||||||
|
== "GuardDuty detector has RDS Protection enabled."
|
||||||
|
)
|
||||||
|
assert result[0].resource_id == "1234567890"
|
||||||
|
assert result[0].region == AWS_REGION_US_EAST_1
|
||||||
|
assert result[0].resource_arn == detector_arn
|
||||||
|
assert result[0].resource_tags == []
|
||||||
@@ -109,7 +109,10 @@ class Test_GuardDuty_Service:
|
|||||||
# Test GuardDuty session
|
# Test GuardDuty session
|
||||||
def test_get_detector(self):
|
def test_get_detector(self):
|
||||||
guardduty_client = client("guardduty", region_name=AWS_REGION_EU_WEST_1)
|
guardduty_client = client("guardduty", region_name=AWS_REGION_EU_WEST_1)
|
||||||
response = guardduty_client.create_detector(Enable=True)
|
response = guardduty_client.create_detector(
|
||||||
|
Enable=True,
|
||||||
|
DataSources={"S3Logs": {"Enable": True}},
|
||||||
|
)
|
||||||
|
|
||||||
aws_provider = set_mocked_aws_provider()
|
aws_provider = set_mocked_aws_provider()
|
||||||
guardduty = GuardDuty(aws_provider)
|
guardduty = GuardDuty(aws_provider)
|
||||||
@@ -124,6 +127,8 @@ class Test_GuardDuty_Service:
|
|||||||
assert len(guardduty.detectors[0].findings) == 1
|
assert len(guardduty.detectors[0].findings) == 1
|
||||||
assert guardduty.detectors[0].member_accounts == ["123456789012"]
|
assert guardduty.detectors[0].member_accounts == ["123456789012"]
|
||||||
assert guardduty.detectors[0].administrator_account == "123456789013"
|
assert guardduty.detectors[0].administrator_account == "123456789013"
|
||||||
|
assert guardduty.detectors[0].s3_protection
|
||||||
|
assert not guardduty.detectors[0].rds_protection
|
||||||
assert guardduty.detectors[0].region == AWS_REGION_EU_WEST_1
|
assert guardduty.detectors[0].region == AWS_REGION_EU_WEST_1
|
||||||
assert guardduty.detectors[0].tags == [{"test": "test"}]
|
assert guardduty.detectors[0].tags == [{"test": "test"}]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user