Azure-Sentinel/Playbooks/Enrich-Sentinel-Incident-HY.../azuredeploy.json

369 строки
20 KiB
JSON

{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"comments": "This playbook uses the HYAS Insight connector to automatically enrich incidents generated by Sentinel with current WHOIS information. You need a valid subscription in order to use the connector and playbook. Learn more about the integration via the https://docs.microsoft.com/connectors/hyasinsight/ or visit https://www.hyas.com/contact to request a trial key.",
"author": "Paul van Gool, HYAS Infosec"
},
"parameters": {
"PlaybookName": {
"defaultValue": "Enrich-Sentinel-Incident-HYAS-Insight-Domain-Current-WHOIS",
"type": "string"
},
"UserName": {
"defaultValue": "<username>@<domain>",
"type": "string"
}
},
"variables": {
"HYASInsightApiKey": "[concat('hyasinsight-', parameters('PlaybookName'))]",
"AzureSentinelConnectionName": "[concat('azuresentinel-', parameters('PlaybookName'))]"
},
"resources": [
{
"type": "Microsoft.Web/connections",
"apiVersion": "2016-06-01",
"name": "[variables('AzureSentinelConnectionName')]",
"location": "[resourceGroup().location]",
"properties": {
"customParameterValues": {},
"api": {
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/azuresentinel')]"
}
}
},
{
"type": "Microsoft.Web/connections",
"apiVersion": "2016-06-01",
"name": "[variables('HYASInsightApiKey')]",
"location": "[resourceGroup().location]",
"properties": {
"displayName": "[parameters('UserName')]",
"customParameterValues": {},
"api": {
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/hyasinsight')]"
}
}
},
{
"type": "Microsoft.Logic/workflows",
"apiVersion": "2017-07-01",
"name": "[parameters('PlaybookName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Web/connections', variables('HYASInsightApiKey'))]",
"[resourceId('Microsoft.Web/connections', variables('AzureSentinelConnectionName'))]"
],
"properties": {
"state": "Enabled",
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"When_a_response_to_an_Azure_Sentinel_alert_is_triggered": {
"type": "ApiConnectionWebhook",
"inputs": {
"body": {
"callback_url": "@{listCallbackUrl()}"
},
"host": {
"connection": {
"name": "@parameters('$connections')['azuresentinel']['connectionId']"
}
},
"path": "/subscribe"
}
}
},
"actions": {
"Contact_Info_Variable": {
"runAfter": {
"Sentinel_Incident_Comment_Variable": [
"Succeeded"
]
},
"type": "InitializeVariable",
"inputs": {
"variables": [
{
"name": "Contact Info",
"type": "array"
}
]
}
},
"Entities_-_Get_Hosts": {
"runAfter": {},
"type": "ApiConnection",
"inputs": {
"body": "@triggerBody()?['Entities']",
"host": {
"connection": {
"name": "@parameters('$connections')['azuresentinel']['connectionId']"
}
},
"method": "post",
"path": "/entities/host"
}
},
"JSON_Output_Variable": {
"runAfter": {
"Entities_-_Get_Hosts": [
"Succeeded"
]
},
"type": "InitializeVariable",
"inputs": {
"variables": [
{
"name": "Json Output",
"type": "array"
}
]
}
},
"Looping_through_Hosts_Object": {
"foreach": "@body('Entities_-_Get_Hosts')?['Hosts']",
"actions": {
"Add_comment_to_incident_(V2)_2": {
"runAfter": {
"Checking_If_the_Response_Returned_Data": [
"Succeeded"
]
},
"type": "ApiConnection",
"inputs": {
"body": {
"Value": "HYAS Insight Current WHOIS enrichment data for the domain \"@{items('Looping_through_Hosts_Object')?['HostName']}.@{items('Looping_through_Hosts_Object')?['DnsDomain']}\" :\n\n@{replace(replace(replace(replace(replace(variables('Comment'),'&quot;',''),'{',''),'}',''),'[',''),']','')}\n\nFor detailed information, see https://insight.hyas.com/static/details?domain=@{items('Looping_through_Hosts_Object')?['HostName']}.@{items('Looping_through_Hosts_Object')?['DnsDomain']}"
},
"host": {
"connection": {
"name": "@parameters('$connections')['azuresentinel']['connectionId']"
}
},
"method": "put",
"path": "/Comment/@{encodeURIComponent(triggerBody()?['WorkspaceSubscriptionId'])}/@{encodeURIComponent(triggerBody()?['WorkspaceId'])}/@{encodeURIComponent(triggerBody()?['WorkspaceResourceGroup'])}/@{encodeURIComponent('Alert')}/@{encodeURIComponent(triggerBody()?['SystemAlertId'])}"
}
},
"Checking_If_the_Response_Returned_Data": {
"actions": {
"Assigning_Table_Formatted_Output_to_Incident_Comment_Variable": {
"runAfter": {
"Create_HTML_table": [
"Succeeded"
]
},
"type": "SetVariable",
"inputs": {
"name": "Comment",
"value": "@body('Create_HTML_table')"
}
},
"Checking_If_The_Length_Of_The_Data_Is_More_Than_Max_Comment_Length": {
"actions": {
"Truncating_the_Table_to_Match_the_Required_Length_for_the_Incident_Comment": {
"runAfter": {},
"type": "SetVariable",
"inputs": {
"name": "Comment",
"value": "@{concat(substring(body('Create_HTML_table'), 0, 2800), '...')}"
}
}
},
"runAfter": {
"Assigning_Table_Formatted_Output_to_Incident_Comment_Variable": [
"Succeeded"
]
},
"expression": {
"and": [
{
"greater": [
"@length(body('Create_HTML_table'))",
3000
]
}
]
},
"type": "If"
},
"Create_HTML_table": {
"runAfter": {
"Looping_Through_Response_Object": [
"Succeeded"
]
},
"type": "Table",
"inputs": {
"format": "HTML",
"from": "@variables('Json Output')"
}
},
"Looping_Through_Response_Object": {
"foreach": "@body('Retrieve_Current_WHOIS_information_for_domain')?['items']",
"actions": {
"Creating_Contact_Object": {
"runAfter": {},
"type": "AppendToArrayVariable",
"inputs": {
"name": "Contact Info",
"value": {
"Email": "@items('Looping_Through_Response_Object')?['email']",
"Phone Number": "@items('Looping_Through_Response_Object')?['phone']"
}
}
},
"Creating_JSON_Output_Variable_Object": {
"runAfter": {
"Creating_Contact_Object": [
"Succeeded"
]
},
"type": "AppendToArrayVariable",
"inputs": {
"name": "Json Output",
"value": {
"Contact Info": "@variables('Contact Info')",
"Creation Date": "@items('Looping_Through_Response_Object')?['domain_created_datetime']",
"Expire Date": "@items('Looping_Through_Response_Object')?['domain_expires_datetime']",
"Nameservers": "@items('Looping_Through_Response_Object')?['nameserver']",
"Registrar": "@items('Looping_Through_Response_Object')?['registrar']"
}
}
}
},
"runAfter": {},
"type": "Foreach"
}
},
"runAfter": {
"Setting_Response_Length_Variable": [
"Succeeded"
]
},
"else": {
"actions": {
"No_Records_Found": {
"runAfter": {},
"type": "SetVariable",
"inputs": {
"name": "Comment",
"value": "No records found in HYAS Insight for domain \"@{items('Looping_through_Hosts_Object')?['HostName']}@{items('Looping_through_Hosts_Object')?['DnsDomain']}.\""
}
}
}
},
"expression": {
"and": [
{
"greater": [
"@variables('RecordsLength')",
0
]
}
]
},
"type": "If"
},
"Retrieve_Current_WHOIS_information_for_domain": {
"runAfter": {},
"type": "ApiConnection",
"inputs": {
"body": {
"applied_filters": {
"current": true,
"domain": "@{items('Looping_through_Hosts_Object')?['HostName']}.@{items('Looping_through_Hosts_Object')?['DnsDomain']}"
}
},
"host": {
"connection": {
"name": "@parameters('$connections')['hyasinsight']['connectionId']"
}
},
"method": "post",
"path": "/whois"
}
},
"Setting_Response_Length_Variable": {
"runAfter": {
"Retrieve_Current_WHOIS_information_for_domain": [
"Succeeded"
]
},
"type": "SetVariable",
"inputs": {
"name": "RecordsLength",
"value": "@length(body('Retrieve_Current_WHOIS_information_for_domain')?['items'])"
}
}
},
"runAfter": {
"Contact_Info_Variable": [
"Succeeded"
]
},
"type": "Foreach"
},
"Response_Length_Variable": {
"runAfter": {
"JSON_Output_Variable": [
"Succeeded"
]
},
"type": "InitializeVariable",
"inputs": {
"variables": [
{
"name": "RecordsLength",
"type": "integer",
"value": 0
}
]
}
},
"Sentinel_Incident_Comment_Variable": {
"runAfter": {
"Response_Length_Variable": [
"Succeeded"
]
},
"type": "InitializeVariable",
"inputs": {
"variables": [
{
"name": "Comment",
"type": "string"
}
]
}
}
},
"outputs": {}
},
"parameters": {
"$connections": {
"value": {
"azuresentinel": {
"connectionId": "[resourceId('Microsoft.Web/connections', variables('AzureSentinelConnectionName'))]",
"connectionName": "[variables('AzureSentinelConnectionName')]",
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/azuresentinel')]"
},
"hyasinsight": {
"connectionId": "[resourceId('Microsoft.Web/connections', variables('HYASInsightApiKey'))]",
"connectionName": "[variables('HYASInsightApiKey')]",
"id": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/hyasinsight')]"
}
}
}
}
}
}
]
}