TrendMicroCAS:first commit
This commit is contained in:
Родитель
77c03bb010
Коммит
43bb8fcedc
|
@ -0,0 +1,133 @@
|
|||
{
|
||||
"Name":"TrendMicroCAS_CL",
|
||||
"Properties":[
|
||||
{
|
||||
"Name":"log_item_id_g",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"service_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"event_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_scan_type_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_affected_user_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_location_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_detection_time_t",
|
||||
"Type":"DateTime"
|
||||
},
|
||||
{
|
||||
"Name":"message_triggered_policy_name_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_triggered_security_filter_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_action_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_action_result_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_mail_message_id_g",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_mail_message_sender_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_mail_message_recipient_d",
|
||||
"Type":"Double"
|
||||
},
|
||||
{
|
||||
"Name":"message_mail_message_submit_time_t",
|
||||
"Type":"DateTime"
|
||||
},
|
||||
{
|
||||
"Name":"message_mail_message_delivery_time_t",
|
||||
"Type":"DateTime"
|
||||
},
|
||||
{
|
||||
"Name":"message_mail_message_subject_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_mail_message_file_name_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_file_name_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_file_upload_time_t",
|
||||
"Type":"DateTime"
|
||||
},
|
||||
{
|
||||
"Name":"message_security_risk_name_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_detected_by_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_risk_level_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_file_sha1_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_file_sha256_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_virus_name_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_file_sha1_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_risk_level_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_detection_type_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_file_sha256_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_ransomware_name_s",
|
||||
"Type":"String"
|
||||
},
|
||||
{
|
||||
"Name":"message_triggered_dlp_template_d",
|
||||
"Type":"Double"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
[
|
||||
{
|
||||
"log_item_id":"f8ce2cee-7259-48a2-83b9-eb756cb0a491",
|
||||
"service":"Dropbox",
|
||||
"event":"security_risk_scan",
|
||||
"message":{
|
||||
"scan_type":"Manual scan",
|
||||
"affected_user":"sanitized@sanitized.com",
|
||||
"location":"/eicar_com.zip",
|
||||
"detection_time":"2021-09-08T08:31:55.000Z",
|
||||
"triggered_policy_name":"Default Dropbox Policy ATP (Monitor Only)",
|
||||
"triggered_security_filter":"Malware Scanning",
|
||||
"action":"Pass",
|
||||
"action_result":"success",
|
||||
"file_name":"eicar_com.zip",
|
||||
"file_upload_time":"2021-09-08T08:31:07.000Z",
|
||||
"file_sha1":"d27265074c9eac2e2122ed69294dbc4d7cce9141",
|
||||
"file_sha256":"2546dcffc5ad854d4ddc64fbf056871cd5a00f2471cb7a5bfd4ac23b6e9eedad",
|
||||
"security_risk_name":"Malware: Eicar_test_file",
|
||||
"detected_by":"Pattern-based scanning",
|
||||
"risk_level":""
|
||||
}
|
||||
},
|
||||
{
|
||||
"log_item_id":"f8ce2cee-7259-48a2-83b9-eb756cb0a5491",
|
||||
"service":"Dropbox",
|
||||
"event":"security_risk_scan",
|
||||
"message":{
|
||||
"scan_type":"Manual scan",
|
||||
"affected_user":"sanitized@sanitized.com",
|
||||
"location":"/eicar_com.zip",
|
||||
"detection_time":"2021-09-09T08:31:55.000Z",
|
||||
"triggered_policy_name":"ATP (Monitor Only)",
|
||||
"triggered_security_filter":"Malware Scanning",
|
||||
"action":"Pass",
|
||||
"action_result":"success",
|
||||
"file_name":"test.zip",
|
||||
"file_upload_time":"2021-09-09T08:31:07.000Z",
|
||||
"file_sha1":"d27265074c9eac2e233122ed69294dbc4d7cce9141",
|
||||
"file_sha256":"2546dcffc5ad854d4344ddc64fbf056871cd5a00f2471cb7a5bfd4ac23b6e9eedad",
|
||||
"security_risk_name":"Malware",
|
||||
"detected_by":"Pattern-based scanning",
|
||||
"risk_level":""
|
||||
}
|
||||
},
|
||||
{
|
||||
"log_item_id":"f8ce2cee-7259-48a2-84b9-eb756cb0a491",
|
||||
"service":"Dropbox",
|
||||
"event":"security_risk_scan",
|
||||
"message":{
|
||||
"scan_type":"Manual scan",
|
||||
"affected_user":"sanitized@sanitized.com",
|
||||
"location":"test2.zip",
|
||||
"detection_time":"2021-09-09T08:32:55.000Z",
|
||||
"triggered_policy_name":"Default(Monitor Only)",
|
||||
"triggered_security_filter":"Malware Scanning",
|
||||
"action":"Pass",
|
||||
"action_result":"success",
|
||||
"file_name":"test2.zip",
|
||||
"file_upload_time":"2021-09-08T08:31:07.000Z",
|
||||
"file_sha1":"d2734r5074c9eac2e2122ed69294dbc4d7cce9141",
|
||||
"file_sha256":"253434dcffc5ad854d4ddc64fbf056871cd5a00f2471cb7a5bfd4ac23b6e9eedad",
|
||||
"security_risk_name":"Malware: test2 file",
|
||||
"detected_by":"Pattern-based scanning",
|
||||
"risk_level":""
|
||||
}
|
||||
}
|
||||
]
|
|
@ -0,0 +1,121 @@
|
|||
{
|
||||
"id": "TrendMicroCAS",
|
||||
"title": "Trend Micro Cloud App Security",
|
||||
"publisher": "Trend Micro",
|
||||
"descriptionMarkdown": "The [Trend Micro Cloud App Security](https://www.trendmicro.com/en_be/business/products/user-protection/sps/email-and-collaboration/cloud-app-security.html) data connector provides the capability to retrieve security event logs of the services that Cloud App Security protects and more events into Azure Sentinel through the Log Retrieval API. Refer to API [documentation](https://docs.trendmicro.com/en-us/enterprise/cloud-app-security-integration-api-online-help/supported-cloud-app-/log-retrieval-api/get-security-logs.aspx) for more information. The connector provides ability to get events which helps to examine potential security risks, analyze your team's use of collaboration, diagnose configuration problems and more.",
|
||||
"additionalRequirementBanner": ">This data connector depends on a parser based on a Kusto Function to work as expected [**TrendMicroCAS**](https://aka.ms/sentinel-TMCAS-parser) which is deployed with the Azure Sentinel Solution.",
|
||||
"graphQueries": [{
|
||||
"metricName": "Total data received",
|
||||
"legend": "TrendMicroCAS_CL",
|
||||
"baseQuery": "TrendMicroCAS_CL"
|
||||
}
|
||||
],
|
||||
"sampleQueries": [{
|
||||
"description": "Trend Micro Cloud App Security Events - All Activities.",
|
||||
"query": "TrendMicroCAS\n | sort by TimeGenerated desc"
|
||||
}
|
||||
],
|
||||
"dataTypes": [{
|
||||
"name": "TrendMicroCAS_CL",
|
||||
"lastDataReceivedQuery": "TrendMicroCAS_CL\n | summarize Time = max(TimeGenerated)\n | where isnotempty(Time)"
|
||||
}
|
||||
],
|
||||
"connectivityCriterias": [{
|
||||
"type": "IsConnectedQuery",
|
||||
"value": [
|
||||
"TrendMicroCAS_CL\n | summarize LastLogReceived = max(TimeGenerated)\n | project IsConnected = LastLogReceived > ago(30d)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"availability": {
|
||||
"status": 1,
|
||||
"isPreview": true
|
||||
},
|
||||
"permissions": {
|
||||
"resourceProvider": [{
|
||||
"provider": "Microsoft.OperationalInsights/workspaces",
|
||||
"permissionsDisplayText": "read and write permissions on the workspace are required.",
|
||||
"providerDisplayName": "Workspace",
|
||||
"scope": "Workspace",
|
||||
"requiredPermissions": {
|
||||
"write": true,
|
||||
"read": true,
|
||||
"delete": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"provider": "Microsoft.OperationalInsights/workspaces/sharedKeys",
|
||||
"permissionsDisplayText": "read permissions to shared keys for the workspace are required. [See the documentation to learn more about workspace keys](https://docs.microsoft.com/azure/azure-monitor/platform/agent-windows#obtain-workspace-id-and-key).",
|
||||
"providerDisplayName": "Keys",
|
||||
"scope": "Workspace",
|
||||
"requiredPermissions": {
|
||||
"action": true
|
||||
}
|
||||
}
|
||||
],
|
||||
"customs": [{
|
||||
"name": "Microsoft.Web/sites permissions",
|
||||
"description": "Read and write permissions to Azure Functions to create a Function App is required. [See the documentation to learn more about Azure Functions](https://docs.microsoft.com/azure/azure-functions/)."
|
||||
},
|
||||
{
|
||||
"name": "REST API Credentials/permissions",
|
||||
"description": "**TrendMicroCASToken** and **TrendMicroCASServiceURL** are required for making API calls. See the [documentation](https://docs.trendmicro.com/en-us/enterprise/cloud-app-security-integration-api-online-help/getting-started-with/using-cloud-app-secu.aspx) to learn more about API."
|
||||
}
|
||||
]
|
||||
},
|
||||
"instructionSteps": [{
|
||||
"title": "",
|
||||
"description": ">**NOTE:** This connector uses Azure Functions to connect to the Azure Blob Storage API to pull logs into Azure Sentinel. This might result in additional costs for data ingestion and for storing data in Azure Blob Storage costs. Check the [Azure Functions pricing page](https://azure.microsoft.com/pricing/details/functions/) and [Azure Blob Storage pricing page](https://azure.microsoft.com/pricing/details/storage/blobs/) for details."
|
||||
},
|
||||
{
|
||||
"title": "",
|
||||
"description": ">**(Optional Step)** Securely store workspace and API authorization key(s) or token(s) in Azure Key Vault. Azure Key Vault provides a secure mechanism to store and retrieve key values. [Follow these instructions](https://docs.microsoft.com/azure/app-service/app-service-key-vault-references) to use Azure Key Vault with an Azure Function App."
|
||||
},
|
||||
{
|
||||
"description": ">**NOTE:** This data connector depends on a parser based on a Kusto Function to work as expected [**TrendMicroCAS**](https://aka.ms/sentinel-TMCAS-parser) which is deployed with the Azure Sentinel Solution."
|
||||
},
|
||||
{
|
||||
"title": "",
|
||||
"description": "**STEP 1 - Configuration steps for the Trend Micro Log Retrieval API**\n\n Follow the instructions to obtain the credentials.\n\n1. Obtain the **TrendMicroCASToken** using the [documentation](https://docs.trendmicro.com/en-us/enterprise/cloud-app-security-integration-api-online-help/getting-started-with/generating-an-authen.aspx).\n2. Save credentials for using in the data connector."
|
||||
},
|
||||
{
|
||||
"title": "",
|
||||
"description": "**STEP 2 - Choose ONE from the following two deployment options to deploy the connector and the associated Azure Function**\n\n>**IMPORTANT:** Before deploying the Trend Micro Cloud App Security data connector, have the Workspace ID and Workspace Primary Key (can be copied from the following).",
|
||||
"instructions": [{
|
||||
"parameters": {
|
||||
"fillWith": [
|
||||
"WorkspaceId"
|
||||
],
|
||||
"label": "Workspace ID"
|
||||
},
|
||||
"type": "CopyableLabel"
|
||||
},
|
||||
{
|
||||
"parameters": {
|
||||
"fillWith": [
|
||||
"PrimaryKey"
|
||||
],
|
||||
"label": "Primary Key"
|
||||
},
|
||||
"type": "CopyableLabel"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Option 1 - Azure Resource Manager (ARM) Template",
|
||||
"description": "Use this method for automated deployment of the Trend Micro Cloud App Security data connector using an ARM Tempate.\n\n1. Click the **Deploy to Azure** button below. \n\n\t[![Deploy To Azure](https://aka.ms/deploytoazurebutton)](https://aka.ms/sentinel-TMCASAPI-azuredeploy)\n2. Select the preferred **Subscription**, **Resource Group** and **Location**. \n> **NOTE:** Within the same resource group, you can't mix Windows and Linux apps in the same region. Select existing resource group without Windows apps in it or create new resource group.\n3. Enter the **TrendMicroCASToken**, **TrendMicroCASServiceURL** and deploy. \n4. Mark the checkbox labeled **I agree to the terms and conditions stated above**. \n5. Click **Purchase** to deploy."
|
||||
},
|
||||
{
|
||||
"title": "Option 2 - Manual Deployment of Azure Functions",
|
||||
"description": "Use the following step-by-step instructions to deploy the Trend Micro Cloud App Security data connector manually with Azure Functions (Deployment via Visual Studio Code)."
|
||||
},
|
||||
{
|
||||
"title": "",
|
||||
"description": "**1. Deploy a Function App**\n\n> **NOTE:** You will need to [prepare VS code](https://docs.microsoft.com/azure/azure-functions/functions-create-first-function-python#prerequisites) for Azure function development.\n\n1. Download the [Azure Function App](https://aka.ms/sentinel-TMCASAPI-functionapp) file. Extract archive to your local development computer.\n2. Start VS Code. Choose File in the main menu and select Open Folder.\n3. Select the top level folder from extracted files.\n4. Choose the Azure icon in the Activity bar, then in the **Azure: Functions** area, choose the **Deploy to function app** button.\nIf you aren't already signed in, choose the Azure icon in the Activity bar, then in the **Azure: Functions** area, choose **Sign in to Azure**\nIf you're already signed in, go to the next step.\n5. Provide the following information at the prompts:\n\n\ta. **Select folder:** Choose a folder from your workspace or browse to one that contains your function app.\n\n\tb. **Select Subscription:** Choose the subscription to use.\n\n\tc. Select **Create new Function App in Azure** (Don't choose the Advanced option)\n\n\td. **Enter a globally unique name for the function app:** Type a name that is valid in a URL path. The name you type is validated to make sure that it's unique in Azure Functions. (e.g. TMCASXXXXX).\n\n\te. **Select a runtime:** Choose Python 3.8.\n\n\tf. Select a location for new resources. For better performance and lower costs choose the same [region](https://azure.microsoft.com/regions/) where Azure Sentinel is located.\n\n6. Deployment will begin. A notification is displayed after your function app is created and the deployment package is applied.\n7. Go to Azure Portal for the Function App configuration."
|
||||
},
|
||||
{
|
||||
"title": "",
|
||||
"description": "**2. Configure the Function App**\n\n1. In the Function App, select the Function App Name and select **Configuration**.\n2. In the **Application settings** tab, select ** New application setting**.\n3. Add each of the following application settings individually, with their respective string values (case-sensitive): \n\t\tTrendMicroCASToken\n\t\tTrendMicroCASServiceURL\n\t\tWorkspaceID\n\t\tWorkspaceKey\n\t\tlogAnalyticsUri (optional)\n> - Use logAnalyticsUri to override the log analytics API endpoint for dedicated cloud. For example, for public cloud, leave the value empty; for Azure GovUS cloud environment, specify the value in the following format: `https://<CustomerId>.ods.opinsights.azure.us`.\n4. Once all application settings have been entered, click **Save**."
|
||||
}
|
||||
]
|
||||
}
|
Двоичные данные
Solutions/Trend Micro Cloud App Security/Data Connectors/TrendMicroCASAPISentinelConn.zip
Normal file
Двоичные данные
Solutions/Trend Micro Cloud App Security/Data Connectors/TrendMicroCASAPISentinelConn.zip
Normal file
Двоичный файл не отображается.
|
@ -0,0 +1,200 @@
|
|||
import logging
|
||||
import azure.functions as func
|
||||
import requests
|
||||
import itertools
|
||||
import datetime
|
||||
from requests.packages.urllib3.util.retry import Retry
|
||||
import os
|
||||
import base64
|
||||
import hashlib
|
||||
import hmac
|
||||
import json
|
||||
import re
|
||||
import time
|
||||
from .state_manager import StateManager
|
||||
|
||||
|
||||
cas_token = os.environ['TrendMicroCASToken']
|
||||
serviceURL = os.environ['TrendMicroCASServiceURL']
|
||||
customer_id = os.environ['WorkspaceID']
|
||||
shared_key = os.environ['WorkspaceKey']
|
||||
connection_string = os.environ['AzureWebJobsStorage']
|
||||
logAnalyticsUri = os.environ.get('logAnalyticsUri')
|
||||
table_name = "TrendMicroCAS"
|
||||
chunksize = 10000
|
||||
|
||||
if ((logAnalyticsUri in (None, '') or str(logAnalyticsUri).isspace())):
|
||||
logAnalyticsUri = 'https://' + customer_id + '.ods.opinsights.azure.com'
|
||||
|
||||
pattern = r'https:\/\/([\w\-]+)\.ods\.opinsights\.azure.([a-zA-Z\.]+)$'
|
||||
match = re.match(pattern,str(logAnalyticsUri))
|
||||
if(not match):
|
||||
raise Exception("Trend Micro CAS Data Connector: Invalid Log Analytics Uri.")
|
||||
|
||||
class TD_CAS():
|
||||
|
||||
def __init__(self, tuple, from_time, to_time):
|
||||
self.event = tuple[1]
|
||||
self.service = tuple[0]
|
||||
self.token = cas_token
|
||||
self.url = f'https://{serviceURL}/v1/siem/security_events'
|
||||
self.params = {
|
||||
"start": from_time,
|
||||
"end": to_time,
|
||||
"service": self.service,
|
||||
"event": self.event
|
||||
}
|
||||
self.headers = {
|
||||
'Authorization': 'Bearer {}'.format(cas_token),
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
def get_query(self, url):
|
||||
retries = Retry(
|
||||
total=3,
|
||||
status_forcelist={429, 500, 503},
|
||||
backoff_factor=1,
|
||||
respect_retry_after_header=True
|
||||
)
|
||||
adapter = requests.adapters.HTTPAdapter(max_retries=retries)
|
||||
session = requests.Session()
|
||||
session.mount('https://', adapter)
|
||||
try:
|
||||
r = session.get(url=url,
|
||||
headers=self.headers,
|
||||
params=self.params
|
||||
)
|
||||
if r.status_code == 200:
|
||||
return r.json()
|
||||
elif r.status_code == 401:
|
||||
logging.error("The authentication credentials are incorrect or missing. Error code: {}".format(r.status_code))
|
||||
else:
|
||||
logging.error("Something wrong. Error: {}".format(r.text))
|
||||
except Exception as err:
|
||||
logging.error("Something wrong. Exception error text: {}".format(err))
|
||||
|
||||
def get_result(self):
|
||||
r = self.get_query(self.url)
|
||||
if "security_events" in r:
|
||||
result_array = r.get("security_events")
|
||||
next_page = r.get("next_link")
|
||||
while next_page != '':
|
||||
r = self.get_query(next_page)
|
||||
if "security_events" in r:
|
||||
result_array_next_page = r.get("security_events")
|
||||
next_page = r.get("next_link")
|
||||
if len(result_array_next_page) > 0:
|
||||
result_array += result_array_next_page
|
||||
return result_array
|
||||
|
||||
def generate_date():
|
||||
current_time = datetime.datetime.utcnow()
|
||||
state = StateManager(connection_string=connection_string)
|
||||
past_time = state.get()
|
||||
if past_time is not None:
|
||||
logging.info("The last time point is: {}".format(past_time))
|
||||
else:
|
||||
logging.info("There is no last time point, trying to get scans information for last 24 hours.")
|
||||
past_time = (current_time - datetime.timedelta(hours=24)).strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
||||
state.post(current_time.strftime("%Y-%m-%dT%H:%M:%S.000Z"))
|
||||
return (past_time, current_time.strftime("%Y-%m-%dT%H:%M:%S.000Z"))
|
||||
|
||||
|
||||
class Sentinel:
|
||||
|
||||
def __init__(self):
|
||||
self.logAnalyticsUri = logAnalyticsUri
|
||||
self.success_processed = 0
|
||||
self.fail_processed = 0
|
||||
self.table_name = table_name
|
||||
self.chunksize = chunksize
|
||||
|
||||
def gen_chunks_to_object(self, data, chunksize=100):
|
||||
chunk = []
|
||||
for index, line in enumerate(data):
|
||||
if (index % chunksize == 0 and index > 0):
|
||||
yield chunk
|
||||
del chunk[:]
|
||||
chunk.append(line)
|
||||
yield chunk
|
||||
|
||||
def gen_chunks(self, data):
|
||||
for chunk in self.gen_chunks_to_object(data, chunksize=self.chunksize):
|
||||
obj_array = []
|
||||
for row in chunk:
|
||||
if row != None and row != '':
|
||||
obj_array.append(row)
|
||||
body = json.dumps(obj_array)
|
||||
self.post_data(body, len(obj_array))
|
||||
|
||||
def build_signature(self, date, content_length, method, content_type, resource):
|
||||
x_headers = 'x-ms-date:' + date
|
||||
string_to_hash = method + "\n" + str(content_length) + "\n" + content_type + "\n" + x_headers + "\n" + resource
|
||||
bytes_to_hash = bytes(string_to_hash, encoding="utf-8")
|
||||
decoded_key = base64.b64decode(shared_key)
|
||||
encoded_hash = base64.b64encode(
|
||||
hmac.new(decoded_key, bytes_to_hash, digestmod=hashlib.sha256).digest()).decode()
|
||||
authorization = "SharedKey {}:{}".format(customer_id, encoded_hash)
|
||||
return authorization
|
||||
|
||||
def post_data(self, body, chunk_count):
|
||||
method = 'POST'
|
||||
content_type = 'application/json'
|
||||
resource = '/api/logs'
|
||||
rfc1123date = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
|
||||
content_length = len(body)
|
||||
signature = self.build_signature(rfc1123date, content_length, method, content_type,
|
||||
resource)
|
||||
uri = self.logAnalyticsUri + resource + '?api-version=2016-04-01'
|
||||
headers = {
|
||||
'content-type': content_type,
|
||||
'Authorization': signature,
|
||||
'Log-Type': self.table_name,
|
||||
'x-ms-date': rfc1123date
|
||||
}
|
||||
response = requests.post(uri, data=body, headers=headers)
|
||||
if (response.status_code >= 200 and response.status_code <= 299):
|
||||
logging.info("Chunk was processed({} events)".format(chunk_count))
|
||||
self.success_processed = self.success_processed + chunk_count
|
||||
else:
|
||||
logging.info("Error during sending events to Azure Sentinel. Response code:{}".format(response.status_code))
|
||||
self.fail_processed = self.fail_processed + chunk_count
|
||||
|
||||
def main(mytimer: func.TimerRequest) -> None:
|
||||
utc_timestamp = datetime.datetime.utcnow().replace(
|
||||
tzinfo=datetime.timezone.utc).isoformat()
|
||||
if mytimer.past_due:
|
||||
logging.info("The timer is past due!")
|
||||
logging.info("Python timer trigger function ran at %s", utc_timestamp)
|
||||
logging.info("Starting program")
|
||||
service_array = [
|
||||
"exchange", "sharepoint",
|
||||
"onedrive", "dropbox",
|
||||
"box", "googledrive",
|
||||
"gmail", "teams",
|
||||
"exchangeserver", "salesforce_sandbox",
|
||||
"salesforce_production", "teams_chat"
|
||||
]
|
||||
event_array = [
|
||||
"securityrisk",
|
||||
"virtualanalyzer",
|
||||
"ransomware",
|
||||
"dlp"
|
||||
]
|
||||
from_time,to_time = generate_date()
|
||||
all_combinations = list(itertools.product(service_array, event_array))
|
||||
map_iterator = map(lambda x: TD_CAS(x, from_time, to_time),all_combinations)
|
||||
for elem in map_iterator:
|
||||
sentinel = Sentinel()
|
||||
results_array = elem.get_result()
|
||||
if len(results_array) > 0:
|
||||
sentinel.gen_chunks(results_array)
|
||||
sentinel_class_vars = vars(sentinel)
|
||||
success_processed, fail_processed = sentinel_class_vars["success_processed"], \
|
||||
sentinel_class_vars["fail_processed"]
|
||||
logging.info('Service: {}. Event type: {}. Total events processed successfully: {}, failed: {}. Period: {} - {}'
|
||||
.format(elem.service, elem.event, success_processed, fail_processed, from_time, to_time))
|
||||
else:
|
||||
logging.info('Service: {}. Event type: {}. There are no events for processing. Period: {} - {}'
|
||||
.format(elem.service, elem.event, from_time, to_time))
|
||||
time.sleep(3)
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"scriptFile": "__init__.py",
|
||||
"bindings": [
|
||||
{
|
||||
"name": "mytimer",
|
||||
"type": "timerTrigger",
|
||||
"direction": "in",
|
||||
"schedule": "0 */10 * * * *"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
from azure.storage.fileshare import ShareClient
|
||||
from azure.storage.fileshare import ShareFileClient
|
||||
from azure.core.exceptions import ResourceNotFoundError
|
||||
|
||||
|
||||
class StateManager:
|
||||
def __init__(self, connection_string, share_name='funcstatemarkershare', file_path='funcstatemarkerfile'):
|
||||
self.share_cli = ShareClient.from_connection_string(conn_str=connection_string, share_name=share_name)
|
||||
self.file_cli = ShareFileClient.from_connection_string(conn_str=connection_string, share_name=share_name, file_path=file_path)
|
||||
|
||||
def post(self, marker_text: str):
|
||||
try:
|
||||
self.file_cli.upload_file(marker_text)
|
||||
except ResourceNotFoundError:
|
||||
self.share_cli.create_share()
|
||||
self.file_cli.upload_file(marker_text)
|
||||
|
||||
def get(self):
|
||||
try:
|
||||
return self.file_cli.download_file().readall().decode()
|
||||
except ResourceNotFoundError:
|
||||
return None
|
|
@ -0,0 +1,200 @@
|
|||
{
|
||||
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
|
||||
"contentVersion": "1.0.0.0",
|
||||
"parameters": {
|
||||
"FunctionName": {
|
||||
"defaultValue": "TMCAS",
|
||||
"minLength": 1,
|
||||
"maxLength": 11,
|
||||
"type": "string"
|
||||
},
|
||||
"WorkspaceID": {
|
||||
"type": "string",
|
||||
"defaultValue": "<workspaceID>"
|
||||
},
|
||||
"WorkspaceKey": {
|
||||
"type": "securestring",
|
||||
"defaultValue": "<workspaceKey>"
|
||||
},
|
||||
"TrendMicroCASToken": {
|
||||
"type": "securestring",
|
||||
"defaultValue": "<TrendMicroCASToken>"
|
||||
},
|
||||
"TrendMicroCASServiceURL": {
|
||||
"type": "string",
|
||||
"defaultValue": "api.tmcas.trendmicro.com"
|
||||
}
|
||||
},
|
||||
"variables": {
|
||||
"FunctionName": "[concat(toLower(parameters('FunctionName')), uniqueString(resourceGroup().id))]",
|
||||
"StorageSuffix": "[environment().suffixes.storage]",
|
||||
"LogAnaltyicsUri": "[replace(environment().portal, 'https://portal', concat('https://', toLower(parameters('WorkspaceID')), '.ods.opinsights'))]"
|
||||
},
|
||||
"resources": [
|
||||
{
|
||||
"type": "Microsoft.Insights/components",
|
||||
"apiVersion": "2015-05-01",
|
||||
"name": "[variables('FunctionName')]",
|
||||
"location": "[resourceGroup().location]",
|
||||
"kind": "web",
|
||||
"properties": {
|
||||
"Application_Type": "web",
|
||||
"ApplicationId": "[variables('FunctionName')]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Microsoft.Storage/storageAccounts",
|
||||
"apiVersion": "2019-06-01",
|
||||
"name": "[tolower(variables('FunctionName'))]",
|
||||
"location": "[resourceGroup().location]",
|
||||
"sku": {
|
||||
"name": "Standard_LRS",
|
||||
"tier": "Standard"
|
||||
},
|
||||
"kind": "StorageV2",
|
||||
"properties": {
|
||||
"networkAcls": {
|
||||
"bypass": "AzureServices",
|
||||
"virtualNetworkRules": [],
|
||||
"ipRules": [],
|
||||
"defaultAction": "Allow"
|
||||
},
|
||||
"supportsHttpsTrafficOnly": true,
|
||||
"encryption": {
|
||||
"services": {
|
||||
"file": {
|
||||
"keyType": "Account",
|
||||
"enabled": true
|
||||
},
|
||||
"blob": {
|
||||
"keyType": "Account",
|
||||
"enabled": true
|
||||
}
|
||||
},
|
||||
"keySource": "Microsoft.Storage"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Microsoft.Storage/storageAccounts/blobServices",
|
||||
"apiVersion": "2019-06-01",
|
||||
"name": "[concat(variables('FunctionName'), '/default')]",
|
||||
"dependsOn": [
|
||||
"[resourceId('Microsoft.Storage/storageAccounts', tolower(variables('FunctionName')))]"
|
||||
],
|
||||
"sku": {
|
||||
"name": "Standard_LRS",
|
||||
"tier": "Standard"
|
||||
},
|
||||
"properties": {
|
||||
"cors": {
|
||||
"corsRules": []
|
||||
},
|
||||
"deleteRetentionPolicy": {
|
||||
"enabled": false
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Microsoft.Storage/storageAccounts/fileServices",
|
||||
"apiVersion": "2019-06-01",
|
||||
"name": "[concat(variables('FunctionName'), '/default')]",
|
||||
"dependsOn": [
|
||||
"[resourceId('Microsoft.Storage/storageAccounts', tolower(variables('FunctionName')))]"
|
||||
],
|
||||
"sku": {
|
||||
"name": "Standard_LRS",
|
||||
"tier": "Standard"
|
||||
},
|
||||
"properties": {
|
||||
"cors": {
|
||||
"corsRules": []
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Microsoft.Web/sites",
|
||||
"apiVersion": "2018-11-01",
|
||||
"name": "[variables('FunctionName')]",
|
||||
"location": "[resourceGroup().location]",
|
||||
"dependsOn": [
|
||||
"[resourceId('Microsoft.Storage/storageAccounts', tolower(variables('FunctionName')))]",
|
||||
"[resourceId('Microsoft.Insights/components', variables('FunctionName'))]"
|
||||
],
|
||||
"kind": "functionapp,linux",
|
||||
"identity": {
|
||||
"type": "SystemAssigned"
|
||||
},
|
||||
"properties": {
|
||||
"name": "[variables('FunctionName')]",
|
||||
"httpsOnly": true,
|
||||
"clientAffinityEnabled": true,
|
||||
"alwaysOn": true,
|
||||
"reserved": true,
|
||||
"siteConfig": {
|
||||
"linuxFxVersion": "python|3.8"
|
||||
}
|
||||
},
|
||||
"resources": [
|
||||
{
|
||||
"apiVersion": "2018-11-01",
|
||||
"type": "config",
|
||||
"name": "appsettings",
|
||||
"dependsOn": [
|
||||
"[concat('Microsoft.Web/sites/', variables('FunctionName'))]"
|
||||
],
|
||||
"properties": {
|
||||
"FUNCTIONS_EXTENSION_VERSION": "~3",
|
||||
"FUNCTIONS_WORKER_RUNTIME": "python",
|
||||
"APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId('Microsoft.insights/components', variables('FunctionName')), '2015-05-01').InstrumentationKey]",
|
||||
"APPLICATIONINSIGHTS_CONNECTION_STRING": "[reference(resourceId('microsoft.insights/components', variables('FunctionName')), '2015-05-01').ConnectionString]",
|
||||
"AzureWebJobsStorage": "[concat('DefaultEndpointsProtocol=https;AccountName=', toLower(variables('FunctionName')),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', toLower(variables('FunctionName'))), '2019-06-01').keys[0].value, ';EndpointSuffix=',toLower(variables('StorageSuffix')))]",
|
||||
"logAnalyticsUri": "[variables('LogAnaltyicsUri')]",
|
||||
"WorkspaceID": "[parameters('WorkspaceID')]",
|
||||
"WorkspaceKey": "[parameters('WorkspaceKey')]",
|
||||
"TrendMicroCASToken": "[parameters('TrendMicroCASToken')]",
|
||||
"TrendMicroCASServiceURL": "[parameters('TrendMicroCASServiceURL')]",
|
||||
"WEBSITE_RUN_FROM_PACKAGE": "https://github.com/averbn/azure_sentinel_data_connectors/raw/main/tmcas-azure-sentinel-data-connector/TrendMicroCASAPISentinelConn.zip?raw=true"
|
||||
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "Microsoft.Storage/storageAccounts/blobServices/containers",
|
||||
"apiVersion": "2019-06-01",
|
||||
"name": "[concat(variables('FunctionName'), '/default/azure-webjobs-hosts')]",
|
||||
"dependsOn": [
|
||||
"[resourceId('Microsoft.Storage/storageAccounts/blobServices', variables('FunctionName'), 'default')]",
|
||||
"[resourceId('Microsoft.Storage/storageAccounts', variables('FunctionName'))]"
|
||||
],
|
||||
"properties": {
|
||||
"publicAccess": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Microsoft.Storage/storageAccounts/blobServices/containers",
|
||||
"apiVersion": "2019-06-01",
|
||||
"name": "[concat(variables('FunctionName'), '/default/azure-webjobs-secrets')]",
|
||||
"dependsOn": [
|
||||
"[resourceId('Microsoft.Storage/storageAccounts/blobServices', variables('FunctionName'), 'default')]",
|
||||
"[resourceId('Microsoft.Storage/storageAccounts', variables('FunctionName'))]"
|
||||
],
|
||||
"properties": {
|
||||
"publicAccess": "None"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Microsoft.Storage/storageAccounts/fileServices/shares",
|
||||
"apiVersion": "2019-06-01",
|
||||
"name": "[concat(variables('FunctionName'), '/default/', tolower(variables('FunctionName')))]",
|
||||
"dependsOn": [
|
||||
"[resourceId('Microsoft.Storage/storageAccounts/fileServices', variables('FunctionName'), 'default')]",
|
||||
"[resourceId('Microsoft.Storage/storageAccounts', variables('FunctionName'))]"
|
||||
],
|
||||
"properties": {
|
||||
"shareQuota": 5120
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"version": "2.0",
|
||||
"logging": {
|
||||
"applicationInsights": {
|
||||
"samplingSettings": {
|
||||
"isEnabled": true,
|
||||
"excludedTypes": "Request"
|
||||
}
|
||||
}
|
||||
},
|
||||
"extensionBundle": {
|
||||
"id": "Microsoft.Azure.Functions.ExtensionBundle",
|
||||
"version": "[1.*, 2.0.0)"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "http://json.schemastore.org/proxies",
|
||||
"proxies": {}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
# DO NOT include azure-functions-worker in this file
|
||||
# The Python Worker is managed by Azure Functions platform
|
||||
# Manually managing azure-functions-worker may cause unexpected issues
|
||||
|
||||
azure-storage-file-share==12.3.0
|
||||
azure-functions
|
||||
requests
|
|
@ -0,0 +1,76 @@
|
|||
// Usage Instruction :
|
||||
// Paste below query in log analytics, click on Save button and select as Function from drop down by specifying function name and alias (e.g. TrendMicroCAS).
|
||||
// Function usually takes 10-15 minutes to activate. You can then use function alias from any other queries (e.g. TrendMicroCAS | take 10).
|
||||
// References :
|
||||
// Using functions in Azure monitor log queries : https://docs.microsoft.com/azure/azure-monitor/log-query/functions
|
||||
// Tech Community Blog on KQL Functions : https://techcommunity.microsoft.com/t5/Azure-Sentinel/Using-KQL-functions-to-speed-up-analysis-in-Azure-Sentinel/ba-p/712381
|
||||
//
|
||||
let TMCAS_view = view () {
|
||||
TrendMicroCAS_CL
|
||||
| extend
|
||||
EventVendor="Trend Micro",
|
||||
EventProduct="Cloud App Security ",
|
||||
EventOriginalUid=column_ifexists('log_item_id_g', ''),
|
||||
EventCategoryType=column_ifexists('service_s', ''),
|
||||
EventType=column_ifexists('event_s', ''),
|
||||
ScanType=column_ifexists('message_scan_type_s', ''),
|
||||
DstUserName=column_ifexists('message_affected_user_s', ''),
|
||||
SrcFilePath=column_ifexists('message_location_s', ''),
|
||||
DetectionTime=column_ifexists('message_detection_time_t', ''),
|
||||
TriggeredPolicyName=column_ifexists('message_triggered_policy_name_s', ''),
|
||||
TriggeredSecurityFilter=column_ifexists('message_triggered_security_filter_s', ''),
|
||||
EventOriginalResultDetails=column_ifexists('message_action_s', ''),
|
||||
EventResult=column_ifexists('message_action_result_s', ''),
|
||||
MailMessageId=column_ifexists('message_mail_message_id_g', ''),
|
||||
MailMessageSender=column_ifexists('message_mail_message_sender_s', ''),
|
||||
MailMessageRecipient=column_ifexists('message_mail_message_recipient_d', ''),
|
||||
MailMessageSubmitTime=column_ifexists('message_mail_message_submit_time_t', ''),
|
||||
MailMessageDeliveryTime=column_ifexists('message_mail_message_delivery_time_t', ''),
|
||||
MailMessageSubject=column_ifexists('message_mail_message_subject_s', ''),
|
||||
MailMessageFileName=column_ifexists('message_mail_message_file_name_s', ''),
|
||||
SrcFileName=column_ifexists('message_file_name_s', ''),
|
||||
FileUploadTime=column_ifexists('message_file_upload_time_t', ''),
|
||||
SecurityRiskName=column_ifexists('message_security_risk_name_s', ''),
|
||||
DetectedBy=column_ifexists('message_detected_by_s', ''),
|
||||
RiskLevel=column_ifexists('message_risk_level_s', ''),
|
||||
SrcFileSHA1=column_ifexists('message_file_sha1_s', ''),
|
||||
SrcFileSHA256=column_ifexists('message_file_sha256_s', ''),
|
||||
VirusName=column_ifexists('message_virus_name_s', ''),
|
||||
DetectionType=column_ifexists('message_detection_type_s', ''),
|
||||
RansomwareName=column_ifexists('message_ransomware_name_s', ''),
|
||||
TriggeredDlpTemplate=column_ifexists('message_triggered_dlp_template_d', '')
|
||||
| project
|
||||
TimeGenerated,
|
||||
EventVendor,
|
||||
EventProduct,
|
||||
EventOriginalUid,
|
||||
EventCategoryType,
|
||||
EventType,
|
||||
ScanType,
|
||||
DstUserName,
|
||||
SrcFilePath,
|
||||
DetectionTime,
|
||||
TriggeredPolicyName,
|
||||
TriggeredSecurityFilter,
|
||||
EventOriginalResultDetails,
|
||||
EventResult,
|
||||
MailMessageId,
|
||||
MailMessageSender,
|
||||
MailMessageRecipient,
|
||||
MailMessageSubmitTime,
|
||||
MailMessageDeliveryTime,
|
||||
MailMessageSubject,
|
||||
MailMessageFileName,
|
||||
SrcFileName,
|
||||
FileUploadTime,
|
||||
SecurityRiskName,
|
||||
DetectedBy,
|
||||
RiskLevel,
|
||||
SrcFileSHA1,
|
||||
SrcFileSHA256,
|
||||
VirusName,
|
||||
DetectionType,
|
||||
RansomwareName,
|
||||
TriggeredDlpTemplate
|
||||
};
|
||||
TMCAS_view
|
Загрузка…
Ссылка в новой задаче