Skip to content

Commit 2ca9945

Browse files
authored
feat: Added support for GuardDuty Findings format (#143)
1 parent 8abda9f commit 2ca9945

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Doing serverless with Terraform? Check out [serverless.tf framework](https://ser
1515
- Support different types of SNS messages:
1616
- AWS CloudWatch Alarms
1717
- AWS CloudWatch LogMetrics Alarms
18+
- AWS GuardDuty Findings
1819
- Local pytest driven testing of the lambda to a Slack sandbox channel
1920

2021
## Feature Roadmap

functions/notify_slack.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,39 @@ def cloudwatch_notification(message, region):
4141
}
4242

4343

44+
def guardduty_finding(message, region):
45+
states = {'Low': '#777777', 'Medium': 'warning', 'High': 'danger'}
46+
if region.startswith("us-gov-"):
47+
guardduty_url = "https://console.amazonaws-us-gov.com/guardduty/home?region="
48+
else:
49+
guardduty_url = "https://console.aws.amazon.com/guardduty/home?region="
50+
51+
if message['detail']['severity'] < 4.0:
52+
severity = 'Low'
53+
elif message['detail']['severity'] < 7.0:
54+
severity = 'Medium'
55+
else:
56+
severity = 'High'
57+
58+
return {
59+
"color": states[severity],
60+
"fallback": "GuardDuty Finding: {}".format(message['detail']['title']),
61+
"fields": [
62+
{"title": "Description", "value": message['detail']['description'], "short": False },
63+
{"title": "Finding type", "value": message['detail']['type'], "short": False},
64+
{"title": "First Seen", "value": message['detail']['service']['eventFirstSeen'], "short": True},
65+
{"title": "Last Seen", "value": message['detail']['service']['eventLastSeen'], "short": True},
66+
{"title": "Severity", "value": severity, "short": True},
67+
{"title": "Count", "value": message['detail']['service']['count'], "short": True},
68+
{
69+
"title": "Link to Finding",
70+
"value": guardduty_url + region + "#/findings?search=id%3D" + message['detail']['id'],
71+
"short": False
72+
}
73+
]
74+
}
75+
76+
4477
def default_notification(subject, message):
4578
attachments = {
4679
"fallback": "A new message",
@@ -91,6 +124,10 @@ def notify_slack(subject, message, region):
91124
notification = cloudwatch_notification(message, region)
92125
payload['text'] = "AWS CloudWatch notification - " + message["AlarmName"]
93126
payload['attachments'].append(notification)
127+
elif "detail-type" in message and message["detail-type"] == "GuardDuty Finding":
128+
notification = guardduty_finding(message, message["region"])
129+
payload['text'] = "Amazon GuardDuty Finding - " + message["detail"]["title"]
130+
payload['attachments'].append(notification)
94131
elif "attachments" in message or "text" in message:
95132
payload = {**payload, **message}
96133
else:

functions/notify_slack_test.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,25 @@
158158
}
159159
]
160160
}
161-
)
161+
),
162+
(
163+
{
164+
"detail-type": "GuardDuty Finding",
165+
"region": "us-east-1",
166+
"detail": {
167+
"id": "sample-id-2",
168+
"title": "SAMPLE Unprotected port on EC2 instance i-123123123 is being probed",
169+
"severity": 9,
170+
"description": "EC2 instance has an unprotected port which is being probed by a known malicious host.",
171+
"type": "Recon:EC2/PortProbeUnprotectedPort",
172+
"service": {
173+
"eventFirstSeen":"2020-01-02T01:02:03Z",
174+
"eventLastSeen":"2020-01-03T01:02:03Z",
175+
"count": 1234
176+
}
177+
},
178+
}
179+
),
162180
)
163181

164182

0 commit comments

Comments
 (0)