-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
136 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.5.12 | ||
1.5.13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
|
||
# Fetch the list of all enabled AWS regions | ||
REGIONS=$(aws ec2 describe-regions --query "Regions[].RegionName" --output text) | ||
|
||
# Function to disable Security Hub | ||
disable_securityhub() { | ||
echo "Disabling Security Hub in region: $1" | ||
|
||
# Check if Security Hub is enabled | ||
STATUS=$(aws securityhub get-findings --region $1 --max-items 1 2>&1) | ||
if [[ "$STATUS" == *"Security Hub is not enabled"* ]]; then | ||
echo "Security Hub is already disabled in region: $1" | ||
return | ||
fi | ||
|
||
# Disable Security Hub | ||
aws securityhub disable-security-hub --region $1 > /dev/null 2>&1 | ||
|
||
if [ $? -eq 0 ]; then | ||
echo "Successfully disabled Security Hub in region: $1" | ||
else | ||
echo "Failed to disable Security Hub in region: $1" | ||
fi | ||
} | ||
|
||
# Function to disable GuardDuty | ||
disable_guardduty() { | ||
echo "Disabling GuardDuty in region: $1" | ||
|
||
# Retrieve the GuardDuty Detector ID | ||
DETECTOR_ID=$(aws guardduty list-detectors --region $1 --query "DetectorIds[0]" --output text) | ||
|
||
if [ -z "$DETECTOR_ID" ] || [ "$DETECTOR_ID" == "None" ]; then | ||
echo "GuardDuty is already disabled in region: $1" | ||
return | ||
fi | ||
|
||
# Disable GuardDuty | ||
aws guardduty delete-detector --detector-id $DETECTOR_ID --region $1 > /dev/null 2>&1 | ||
|
||
if [ $? -eq 0 ]; then | ||
echo "Successfully disabled GuardDuty in region: $1" | ||
else | ||
echo "Failed to disable GuardDuty in region: $1" | ||
fi | ||
} | ||
|
||
# Loop through all regions and disable Security Hub and GuardDuty | ||
for REGION in $REGIONS; do | ||
echo "Processing region: $REGION" | ||
|
||
# Disable Security Hub | ||
disable_securityhub $REGION | ||
|
||
# Disable GuardDuty | ||
disable_guardduty $REGION | ||
|
||
done | ||
|
||
echo "Decommissioning Security Hub and GuardDuty completed in all regions." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/bash | ||
|
||
# Check if an Account ID is provided as a parameter | ||
if [ -z "$1" ]; then | ||
echo "Usage: $0 <MEMBER_ACCOUNT_ID>" | ||
exit 1 | ||
fi | ||
|
||
# Assign the passed Account ID to a variable | ||
MEMBER_ACCOUNT_ID="$1" | ||
|
||
# Fetch the list of all enabled AWS regions | ||
REGIONS=$(aws ec2 describe-regions --query "Regions[].RegionName" --output text) | ||
|
||
# Function to disassociate Security Hub member accounts | ||
disassociate_securityhub() { | ||
echo "Disassociating Security Hub members in region: $1" | ||
|
||
aws securityhub disassociate-members \ | ||
--account-ids $MEMBER_ACCOUNT_ID \ | ||
--region $1 | ||
|
||
if [ $? -eq 0 ]; then | ||
echo "Successfully disassociated Security Hub member in region: $1" | ||
else | ||
echo "Failed to disassociate Security Hub member in region: $1" | ||
fi | ||
} | ||
|
||
# Function to disassociate GuardDuty member accounts | ||
disassociate_guardduty() { | ||
echo "Disassociating GuardDuty members in region: $1" | ||
|
||
# Retrieve the GuardDuty detector ID | ||
DETECTOR_ID=$(aws guardduty list-detectors --region $1 --query "DetectorIds[0]" --output text) | ||
|
||
if [ "$DETECTOR_ID" == "None" ] || [ -z "$DETECTOR_ID" ]; then | ||
echo "No GuardDuty detector found in region: $1. Skipping." | ||
return | ||
fi | ||
|
||
aws guardduty disassociate-members \ | ||
--detector-id $DETECTOR_ID \ | ||
--account-ids $MEMBER_ACCOUNT_ID \ | ||
--region $1 | ||
|
||
if [ $? -eq 0 ]; then | ||
echo "Successfully disassociated GuardDuty member in region: $1" | ||
else | ||
echo "Failed to disassociate GuardDuty member in region: $1" | ||
fi | ||
} | ||
|
||
# Loop through each region and disassociate members | ||
for REGION in $REGIONS; do | ||
echo "Processing region: $REGION" | ||
|
||
# Disassociate Security Hub member | ||
disassociate_securityhub $REGION | ||
|
||
# Disassociate GuardDuty member | ||
disassociate_guardduty $REGION | ||
done | ||
|
||
echo "Disassociation process for Security Hub and GuardDuty completed." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters