-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandler.py
81 lines (65 loc) · 2.75 KB
/
handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import urllib3
import json
import os
http = urllib3.PoolManager()
import textwrap
def lambda_handler(event, context):
url = os.environ['TEAMS_URL']
channel = os.environ['TEAMS_CHANNEL']
for record in event['Records']:
#Message details from SNS event
message = json.loads(record['Sns']['Message'])
findings = message['scanning_result'].get('Findings')
#ARN info to get AWS Account ID
arn = json.dumps(record['EventSubscriptionArn'])
account_id = arn.split(":")[4].strip()
if findings:
malwares = []
types = []
for finding in message['scanning_result']['Findings']:
malwares.append(finding.get('malware'))
types.append(finding.get('type'))
account=str(account_id)
malwares=', '.join(malwares)
types=', '.join(types)
file_url=str(message['file_url'])
payload = {
"summary":"Malicious Object Detected",
"sections":[
{
"activityTitle":"A <b>Malicious object</b> has been detected!"
},
{
"facts":[
{
"name":"Account ID:",
"value":account
},
{
"name":"File Name:",
"value":malwares
},
{
"name":"Malware Type:",
"value":types
},
{
"name":"Location:",
"value":file_url
}
]
}
],
"potentialAction":[
{
"@context":"http://schema.org",
"@type":"ViewAction",
"name":"View Object",
"target":[
file_url
]
}
]
}
encoded_msg = json.dumps(payload).encode('utf-8')
resp = http.request('POST',url, body=encoded_msg)