Azure-Sentinel icon indicating copy to clipboard operation
Azure-Sentinel copied to clipboard

Unable to create analytic rule from sysmon parse xml - extend operator failed to resolve scalar

Open CraigCloudITPro opened this issue 5 years ago • 12 comments

hello, i'm trying to create the below analytic rule, the results appear absolutely fine within the logs pane when qorking on the query, the minute i goto create the analytic rule, i get the following error message:

Screenshot 2021-05-11 141148

"'extend' operator: Failed to resolve scalar expression named '["@Name"]'."

Steps to reproduce the behavior:

Go to 'Analytics' Click on 'Create Scheduled Query ' Click "Set Rule logic" Paste the below query Try to enable this rule See error

Event | where Source == "Microsoft-Windows-Sysmon" | extend RenderedDescription = tostring(split(RenderedDescription, ":")[0]) | extend EventData = parse_xml(EventData).DataItem.EventData.Data | mv-expand bagexpansion=array EventData | evaluate bag_unpack(EventData) | extend Key=tostring(['@Name']), Value=['#text'] | evaluate pivot(Key, any(Value), TimeGenerated, Source, EventLog, Computer, EventID, RenderedDescription, MG, ManagementGroupName, Type, _ResourceId)

CraigCloudITPro avatar May 11 '21 13:05 CraigCloudITPro

Thank you for submitting an Issue to the Azure Sentinel GitHub repo! You should expect an initial response to your Issue from the team within 5 business days. Note that this response may be delayed during holiday periods. For urgent, production-affecting issues please raise a support ticket via the Azure Portal.

github-actions[bot] avatar May 11 '21 13:05 github-actions[bot]

Hi @CraigCloudITPro, I had this exact same problem, try the change found in this pull: https://github.com/Azure/Azure-Sentinel/pull/2191/files

Lodewyk-Git avatar May 11 '21 16:05 Lodewyk-Git

Hi @CraigCloudITPro, I had this exact same problem, try the change found in this pull: https://github.com/Azure/Azure-Sentinel/pull/2191/files

Hello Lodewyk, this still doesn't seem to work, i am now getting the below:

"'where' operator: Failed to resolve column or scalar expression named 'OriginalFileName'."

Event | where Source == "Microsoft-Windows-Sysmon" | extend RenderedDescription = tostring(split(RenderedDescription, ":")[0]) | extend EventData = parse_xml(EventData).DataItem.EventData.Data | mv-expand bagexpansion=array EventData | evaluate bag_unpack(EventData) | extend Key = tostring(column_ifexists('@Name', "")), Value = column_ifexists('#text', "") | evaluate pivot(Key, any (Value), TimeGenerated, Source, EventLog, Computer, EventID, RenderedDescription, Type, _ResourceId) | where OriginalFileName == "Cmd.Exe"

CraigCloudITPro avatar May 12 '21 08:05 CraigCloudITPro

Try this to pass evaluation, there should be a better way, but this will let it work for now.

|where column_ifexists('OriginalFileName', "") == "Cmd.Exe"

@shainw Any other Ideas?

Lodewyk-Git avatar May 12 '21 10:05 Lodewyk-Git

Try this to pass evaluation, there should be a better way, but this will let it work for now.

|where column_ifexists('OriginalFileName', "") == "Cmd.Exe"

@shainw Any other Ideas?

Thanks that seems to work now Lodewyk.

I agree there has to be a more efficient way to reduce the syntax character count here, otherwise it's going to get extremely complicated for a simple query.

CraigCloudITPro avatar May 12 '21 11:05 CraigCloudITPro

@CraigCloudITPro - This is the current work around. The challenge here is that the required event may not be there for which the unpack iterates over, which means the subsequent fields are not available and hence the error. We are investigating to see if there is any better solution, but you can think of it as similar to not having a table in your workspace and attempting to query against that table, this is just one level deeper and requiring a specific event type to be available. Agreed, it is not a great experience and we will see what we can do.

shainw avatar May 13 '21 16:05 shainw

@CraigCloudITPro - This is the current work around. The challenge here is that the required event may not be there for which the unpack iterates over, which means the subsequent fields are not available and hence the error. We are investigating to see if there is any better solution, but you can think of it as similar to not having a table in your workspace and attempting to query against that table, this is just one level deeper and requiring a specific event type to be available. Agreed, it is not a great experience and we will see what we can do.

But using my original code in the “Logs” when searching populates the exact results I want to see, it’s only when I goto create the Analytic Rule that it throws the errors.

What’s the differences between running the query in the Logs pane of LAWS or Sentinel vs actually creating the Analytic Rule?

CraigCloudITPro avatar May 13 '21 17:05 CraigCloudITPro

@Ronmarsiano - Can you check on what might be causing this? It seems the table lookup is likely a very short time frame and if there is no event then the error occurs. In other words, it only looks at the last 10 minutes and if the correct Sysmon event is not there it doesn't work. Just a thought, Ron should be able to track down the reason. ;)

shainw avatar Jun 03 '21 19:06 shainw

Thank you for submitting an Issue to the Azure Sentinel GitHub repo! You should expect an initial response to your Issue from the team within 5 business days. Note that this response may be delayed during holiday periods. For urgent, production-affecting issues please raise a support ticket via the Azure Portal.

github-actions[bot] avatar Jun 03 '21 19:06 github-actions[bot]

As mentioned in our documentation when using bag_unpack in scheduled alert rules we require using "column_ifexists"

  • https://docs.microsoft.com/en-us/azure/sentinel/tutorial-detect-threats-custom#define-the-rule-query-logic-and-configure-settings

This is how the rule should look like - Event | where Source == "Microsoft-Windows-Sysmon" | extend RenderedDescription = tostring(split(RenderedDescription, ":")[0]) | extend EventData = parse_xml(EventData).DataItem.EventData.Data | mv-expand bagexpansion=array EventData | evaluate bag_unpack(EventData) | extend NameColumn = tostring(column_ifexists("@Name","")) | extend Key=tostring(column_ifexists("@Name","")), Value=tostring(column_ifexists("#text","")) | evaluate pivot(Key, any(Value), TimeGenerated, Source, EventLog, Computer, EventID, RenderedDescription, MG, ManagementGroupName, Type, _ResourceId)

Ronmarsiano avatar Jun 06 '21 06:06 Ronmarsiano

Solution provided

sarah-yo avatar Jun 25 '21 00:06 sarah-yo

Thank you for submitting an Issue to the Azure Sentinel GitHub repo! You should expect an initial response to your Issue from the team within 5 business days. Note that this response may be delayed during holiday periods. For urgent, production-affecting issues please raise a support ticket via the Azure Portal.

github-actions[bot] avatar Jun 25 '21 00:06 github-actions[bot]