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

Bug fixes on GuardDuty checked, and MFA Enabled Checks #108

Merged
merged 8 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"apigateway": 9, "cloudfront": 8, "cloudtrail": 18, "cloudwatch": 18, "dynamodb": 24, "ec2": 54, "efs": 3, "eks": 7, "elasticache": 10, "guardduty": 4, "iam": 37, "kms": 4, "lambda": 15, "opensearch": 22, "rds": 82, "redshift": 9, "s3": 16}
{"apigateway": 9, "cloudfront": 8, "cloudtrail": 18, "cloudwatch": 18, "dynamodb": 24, "ec2": 54, "efs": 3, "eks": 7, "elasticache": 10, "guardduty": 4, "iam": 37, "kms": 4, "lambda": 15, "opensearch": 22, "rds": 82, "redshift": 9, "s3": 16}
2 changes: 1 addition & 1 deletion services/dashboard/DashboardPageBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def buildContentDetail_dashboard(self):

output.append(self.generateRowWithCol(size=6, items=items, rowHtmlAttr="data-context='chartCount'"))

output.append("<h6>Report generated at <u>{}</u>, timezone setting: {}</h6>".format(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), datetime.datetime.now().tzname()))
output.append("<h6>Report generated at <u>{}</u>, timezone setting: {}</h6>".format(datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%d %H:%M:%S"), 'UTC'))
return output

def getDashboardCategoryTiles(self, key, cnt):
Expand Down
24 changes: 12 additions & 12 deletions services/ec2/Ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,18 @@ def advise(self):

# EC2 instance checks
instances = self.getResources()
for instance in instances:
instanceData = instance['Instances'][0]
print('... (EC2) inspecting ' + instanceData['InstanceId'])
obj = Ec2Instance(instanceData,self.ec2Client, self.cwClient)
obj.run(self.__class__)

objs[f"EC2::{instanceData['InstanceId']}"] = obj.getInfo()

## Gather SecGroups in dict first to prevent check same sec groups multiple time
instanceSG = self.getEC2SecurityGroups(instanceData)
for group in instanceSG:
secGroups[group['GroupId']] = group
for instanceArr in instances:
for instanceData in instanceArr['Instances']:
print('... (EC2) inspecting ' + instanceData['InstanceId'])
obj = Ec2Instance(instanceData,self.ec2Client, self.cwClient)
obj.run(self.__class__)
objs[f"EC2::{instanceData['InstanceId']}"] = obj.getInfo()
## Gather SecGroups in dict first to prevent check same sec groups multiple time
instanceSG = self.getEC2SecurityGroups(instanceData)
for group in instanceSG:
secGroups[group['GroupId']] = group

#EBS checks
volumes = self.getEBSResources()
Expand Down
2 changes: 1 addition & 1 deletion services/iam/Iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, region):
'orgClient': ssBoto.client('organizations'),
'accClient': ssBoto.client('account', config=self.bConfig),
'sppClient': ssBoto.client('support', config=self.bConfig),
'gdClient': ssBoto.client('guardduty', config=self.bConfig),
# 'gdClient': ssBoto.client('guardduty', config=self.bConfig),
'budgetClient': ssBoto.client('budgets', config=self.bConfig),
'curClient': ssBoto.client('cur', config=self.bConfig),
'ctClient': ssBoto.client('cloudtrail', config=self.bConfig)
Expand Down
25 changes: 19 additions & 6 deletions services/iam/drivers/IamAccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, none, awsClients, users, roles, ssBoto):
self.iamClient = awsClients['iamClient']
self.accClient = awsClients['accClient']
self.sppClient = awsClients['sppClient']
self.gdClient = awsClients['gdClient']
# self.gdClient = awsClients['gdClient']
self.budgetClient = awsClients['budgetClient']
self.orgClient = awsClients['orgClient']

Expand Down Expand Up @@ -169,11 +169,24 @@ def _checkHasExternalProvider(self):
self.results['hasExternalIdentityProvider'] = [-1, '']

def _checkHasGuardDuty(self):
resp = self.gdClient.list_detectors()
if 'DetectorIds' in resp:
ids = resp.get('DetectorIds')
if len(ids) > 0:
return
ssBoto = self.ssBoto
regions = Config.get("REGIONS_SELECTED")

results = {}
badResults = []
cnt = 0
for region in regions:
if region == 'GLOBAL':
continue

conf = bConfig(region_name = region)
gdClient = ssBoto.client('guardduty', config=conf)

resp = self.gdClient.list_detectors()
if 'DetectorIds' in resp:
ids = resp.get('DetectorIds')
if len(ids) > 0:
return

self.results["enableGuardDuty"] = [-1, ""]

Expand Down
38 changes: 22 additions & 16 deletions services/iam/drivers/IamUser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import boto3
import boto3, botocore
import datetime
from dateutil.tz import tzlocal

Expand All @@ -16,9 +16,9 @@ def __init__(self, user, iamClient):

def _checkHasMFA(self):
xkey = "rootMfaActive" if self.user['user'] == "<root_account>" else "mfaActive"
if self.user['mfa_active'] == 'false':
if self.user['mfa_active'] == 'false' and (self.user['user'] == "<root_account>" or self.user['password_enabled'] == 'true'):
self.results[xkey] = [-1, 'Inactive']

def _checkConsoleLastAccess(self):
key = ''

Expand Down Expand Up @@ -52,25 +52,31 @@ def _checkUserInGroup(self):
if user == '<root_account>':
return

resp = self.iamClient.list_groups_for_user(UserName = user)
groups = resp.get('Groups')
if not groups:
self.results['userNotUsingGroup'] = [-1, '-']

try:
resp = self.iamClient.list_groups_for_user(UserName = user)
groups = resp.get('Groups')
if not groups:
self.results['userNotUsingGroup'] = [-1, '-']
except botocore.exceptions.ClientError as e:
print(e.response['Error']['Code'], e.response['Error']['Message'])

def _checkUserPolicy(self):
user = self.user['user']
if user == '<root_account>':
return

## Managed Policy
resp = self.iamClient.list_attached_user_policies(UserName = user)
policies = resp.get('AttachedPolicies')
self.evaluateManagePolicy(policies) ## code in iam_common.class.php

## Inline Policy
resp = self.iamClient.list_user_policies(UserName = user)
inlinePolicies = resp.get('PolicyNames')
self.evaluateInlinePolicy(inlinePolicies, user, 'user')
try:
resp = self.iamClient.list_attached_user_policies(UserName = user)
policies = resp.get('AttachedPolicies')
self.evaluateManagePolicy(policies) ## code in iam_common.class.php

## Inline Policy
resp = self.iamClient.list_user_policies(UserName = user)
inlinePolicies = resp.get('PolicyNames')
self.evaluateInlinePolicy(inlinePolicies, user, 'user')
except botocore.exceptions.ClientError as e:
print(e.response['Error']['Code'], e.response['Error']['Message'])

def _checkAccessKeyRotate(self):
user = self.user
Expand Down
Loading