DEV Community

Cover image for Detecting and Mitigating Threats with AWS Security Hub and GuardDuty.
Goodluck Ekeoma Adiole
Goodluck Ekeoma Adiole

Posted on

Detecting and Mitigating Threats with AWS Security Hub and GuardDuty.

In today’s digital age, where attacks can be automated, the battle against evolving cyber threats demands robust tools and proactive measures. AWS Security Hub and Amazon GuardDuty are two vital services that empower organizations to strengthen their security posture in the cloud.
Together, they provide a seamless ecosystem for detecting, analyzing, and mitigating threats, ensuring that your AWS environment remains resilient against malicious actors.

What is AWS Security Hub?
AWS Security Hub acts as a centralized security management tool that aggregates and prioritizes security alerts across your AWS environment. It offers a comprehensive view of your security posture by integrating findings from various AWS services such as GuardDuty, Inspector, and IAM Access Analyzer, as well as third-party tools.

By adhering to industry best practices like CIS Benchmarks and AWS Foundational Security Best Practices, Security Hub enables continuous compliance checks, ensuring that your cloud environment remains secure and compliant.

What is Amazon GuardDuty?
Amazon GuardDuty is an intelligent threat detection service that leverages machine learning, anomaly detection, and integrated threat intelligence to monitor your AWS environment for malicious or unauthorized activity.

From identifying unusual data exfiltration attempts to detecting reconnaissance scans on your instances, GuardDuty provides actionable insights that help you respond quickly to security incidents.

How Security Hub and GuardDuty Work Together

The integration of Security Hub and GuardDuty creates a powerful synergy. While GuardDuty detects threats and generates findings, Security Hub consolidates and prioritizes those findings, giving you a holistic view of your environment’s security status.

For instance, GuardDuty might detect unusual API calls from a compromised IAM user. Security Hub will then aggregate this finding with insights from other services, enabling you to see the broader context and take informed action.

Steps to Detect and Mitigate Threats Using Security Hub and GuardDuty
1. Enabling GuardDuty and Security Hub
Before leveraging their capabilities, you need to activate both services.

# Enable GuardDuty in a specific region
aws guardduty create-detector --enable  

# Enable Security Hub
aws securityhub enable-security-hub
Enter fullscreen mode Exit fullscreen mode

2. Understanding GuardDuty Findings
GuardDuty findings are categorized by severity: Low, Medium, and High. They include detailed information such as the affected resource, threat type, and recommended actions.

Here’s a sample finding in JSON format:

{
  "Severity": 8,
  "Title": "Recon:EC2/PortProbeUnprotectedPort",
  "Description": "EC2 instance i-0123456789abcdef was probed for open ports.",
  "Resources": [
    {
      "Type": "Instance",
      "Id": "i-0123456789abcdef"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

3. Aggregating Findings in Security Hub
Once enabled, Security Hub consolidates GuardDuty findings with data from other services, providing a unified dashboard for security operations.

You can retrieve findings using the AWS CLI:

aws securityhub get-findings --filters '{"SeverityLabel": [{"Value": "HIGH", "Comparison": "EQUALS"}]}'
Enter fullscreen mode Exit fullscreen mode

4. Automating Threat Mitigation with Lambda
To streamline your response to threats, you can integrate Security Hub and GuardDuty with AWS Lambda for automated remediation.

For example, if GuardDuty detects an unauthorized IP scanning your EC2 instances, you can automate the blocking of that IP using AWS WAF:

import boto3

def lambda_handler(event, context):
    waf = boto3.client('wafv2')
    ip_set_id = 'your-ip-set-id'
    ip_to_block = event['detail']['service']['action']['networkConnectionAction']['remoteIpDetails']['ipAddressV4']

    response = waf.update_ip_set(
        Name='BlockedIPs',
        Scope='REGIONAL',
        Id=ip_set_id,
        Addresses=[ip_to_block + "/32"]
    )
    print(f"Blocked IP: {ip_to_block}")
Enter fullscreen mode Exit fullscreen mode

Best Practices for Using Security Hub and GuardDuty
Enable Multi-Region Protection: Threats don’t adhere to regional boundaries. Enable GuardDuty and Security Hub in all AWS regions to ensure comprehensive coverage.

Set Up CloudWatch Alerts: Use CloudWatch to create alarms for high-severity findings. This ensures your security team is immediately notified of critical threats.

Regularly Review Findings: While automation is powerful, periodic manual reviews of findings can uncover patterns and anomalies that automated tools might miss.

Integrate with SIEM Tools: Enhance your incident response capabilities by integrating Security Hub with third-party SIEM tools such as Splunk or QRadar.

Conclusion
AWS Security Hub and GuardDuty form a dynamic duo in the quest for a secure cloud environment. By leveraging their capabilities, organizations can detect, analyze, and mitigate threats efficiently, ensuring minimal disruption to their operations.

Adopting these tools isn’t just about compliance—it’s about creating a proactive and resilient security strategy that evolves with the ever-changing threat landscape.

> Start your journey with AWS Security Hub and GuardDuty today and take control of your cloud security!

Top comments (0)