Home
%3CLINGO-SUB%20id%3D%22lingo-sub-768747%22%20slang%3D%22en-US%22%3ETip%3A%20Easily%20use%20JSON%20fields%20in%20Sentinel%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-768747%22%20slang%3D%22en-US%22%3E%3CP%3EOne%20of%20the%20great%20features%20with%20Azure%20Sentinel%20is%20that%20you%20can%20ingest%20any%20type%20of%20data%20and%20take%20care%20of%20parsing%20it%20later%20on%20at%20query%20time.%20Specifically%2C%20events%20originating%20from%20cloud%20sources%20often%20include%20%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FJSON%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EJSON%3C%2FA%3Ecompound%20elements%20that%20provide%20wealthy%20information%20about%20the%20event.%20This%20is%20a%20far%20cry%20from%20traditional%20SIEM%20systems%20that%20support%20a%20rigid%20event%20format%20and%2C%20in%20many%20cases%2C%20require%20reducing%20events%20to%20fit%20in%20the%20schema.%26nbsp%3BAnother%20common%20source%20of%20JSON%20data%20in%20Azure%20Sentinel%20would%20be%20enrichment%20data%20collected%20using%20playbooks%20as%20demonstrated%20by%20Tiander%20Turpin%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FSecurity-Identity%2FSending-REST-API-data-to-Azure-Sentinel%2Fm-p%2F558896%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3Ehere%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20brings%20us%20to%20the%20question%20of%20how%20to%20write%20a%20query%20to%20use%20JSON%20fields.%20Sentinel%E2%80%99s%20query%20language%2C%20KQL%2C%20uses%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fkusto%2Fquery%2Fparsejsonfunction%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eparse_json%3C%2FA%3Efunction%20to%20provide%20access%20to%20JSON%20field%20elements.%20However%2C%20when%20the%20JSON%20structure%20becomes%20deeper%2C%20using%20this%20function%20can%20become%20cumbersome.%20Luckily%2C%20Sentinel%20provides%20new%20tools%20to%20help%20you%20write%20those%20queries.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20use%20Microsoft%20Cloud%20App%20Security%20(MCAS)%20alerts%20as%20an%20example.%20Using%20the%20following%20query%2C%20we%20get%20MCAS%20alerts%20on%20impossible%20travel%3A%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%0A%3CP%3ESecurityAlert%3C%2FP%3E%0A%3CP%3E%7C%20where%20ProviderName%20%3D%3D%20%22MCAS%22%3C%2FP%3E%0A%3CP%3E%7C%20where%20DisplayName%20%3D%3D%20%22Impossible%20travel%20activity%22%3C%2FP%3E%0A%3CP%3E%7C%20limit%2010%3C%2FP%3E%0A%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F124145i629F80290D14610D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%221.png%22%20title%3D%221.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EExpanding%20one%20of%20the%20events%2C%20we%20can%20see%20that%20the%20countries%20Alex%20visited%20are%20located%20in%20the%20%3CSTRONG%3EExtended%20Properties%3C%2FSTRONG%3EJSON%20compound%20field%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F124142i7CBD6CE8DCF8CBEE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%222.png%22%20title%3D%222.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20use%20the%20countries%20just%20visited%20value%2C%20we%20can%20use%20the%20ellipsis%20on%20the%20left%20side%20of%20it%20automatically%20add%20a%20JSON%20parsing%20function%20to%20our%20query.%20Selecting%20the%20%3CSTRONG%3Einclude%3C%2FSTRONG%3Eoption%20updates%20the%20query%20automatically%20to%20the%20one%20below%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20421px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F124143i1D0CADFF8E23591B%2Fimage-dimensions%2F421x139%3Fv%3D1.0%22%20width%3D%22421%22%20height%3D%22139%22%20alt%3D%223.png%22%20title%3D%223.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%0A%3CP%3ESecurityAlert%3C%2FP%3E%0A%3CP%3E%7C%20where%20ProviderName%20%3D%3D%20%22MCAS%22%3C%2FP%3E%0A%3CP%3E%7C%20where%20DisplayName%20%3D%3D%20%22Impossible%20travel%20activity%22%3C%2FP%3E%0A%3CP%3E%7C%20limit%2010%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%7C%20where%20parse_json(ExtendedProperties).Countries%20%3D%3D%20%22AU%2C%20DE%2C%20FR%2C%20GB%2C%20JP%2C%20US%22%3C%2FP%3E%0A%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHowever%2C%20since%20the%20Counties%20field%20is%20a%20list%2C%20include%20and%20exclude%20might%20not%20be%20particularly%20useful%20as%20they%20add%20a%20condition%20that%20would%20require%20the%20entire%20list%20of%20counties%20to%20be%20identical.%20You%20can%20change%20the%20%E2%80%9C%3D%3D%E2%80%9D%20or%20%E2%80%9C!%3D%E2%80%9D%20operators%20automatically%20generated%20to%20a%20%3CSTRONG%3Econtains%3C%2FSTRONG%3Eor%20%3CSTRONG%3E!contains%20%3C%2FSTRONG%3Eoperators%3A%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%0A%3CP%3ESecurityAlert%3C%2FP%3E%0A%3CP%3E%7C%20where%20ProviderName%20%3D%3D%20%22MCAS%22%3C%2FP%3E%0A%3CP%3E%7C%20where%20DisplayName%20%3D%3D%20%22Impossible%20travel%20activity%22%3C%2FP%3E%0A%3CP%3E%7C%20limit%2010%3C%2FP%3E%0A%3CP%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3E%7C%20where%20parse_json(ExtendedProperties).Countries%20contains%20%22AU%22%3C%2FSPAN%3E%3C%2FP%3E%0A%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20better%20option%20would%20be%20to%20use%20the%20%3CSTRONG%3Eextend%20column%3C%2FSTRONG%3Eoption%2C%20which%20allows%20to%20filter%20further%20and%20process%20the%20new%20field%20and%20also%20ensures%20it%20is%20presented%20as%20a%20field%20in%20the%20results.%26nbsp%3BUsing%20%3CSTRONG%3Eextend%20column%3C%2FSTRONG%3Einstead%20of%20%3CSTRONG%3Einclude%3C%2FSTRONG%3E%2C%20the%20query%20is%20automatically%20updated%20as%20follows%3A%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%0A%3CP%3ESecurityAlert%3C%2FP%3E%0A%3CP%3E%7C%20where%20ProviderName%20%3D%3D%20%22MCAS%22%3C%2FP%3E%0A%3CP%3E%7C%20where%20DisplayName%20%3D%3D%20%22Impossible%20travel%20activity%22%3C%2FP%3E%0A%3CP%3E%7C%20limit%2010%3C%2FP%3E%0A%3CP%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3E%7C%20extend%20Countries_%20%3D%20tostring(parse_json(ExtendedProperties).Countries)%3C%2FSPAN%3E%3C%2FP%3E%0A%3C%2FBLOCKQUOTE%3E%0A%3CP%3EWill%20result%20in%20the%20following%20output%2C%20adding%20a%20Countries_%20field%20to%20the%20result%20set%20for%20easy%20viewing%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F124144i4A81CADEC5B6C299%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%224.png%22%20title%3D%224.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-768747%22%20slang%3D%22en-US%22%3E%3CP%3ELearn%20how%20to%20easily%20extract%20values%20embedded%20in%20JSON%20constructs%20in%20Sentinel%20as%20primary%20fields%20for%20easy%20viewing%2C%20filtering%20and%20further%20processing.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-768747%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EQuery%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

One of the great features with Azure Sentinel is that you can ingest any type of data and take care of parsing it later on at query time. Specifically, events originating from cloud sources often include JSON compound elements that provide wealthy information about the event. This is a far cry from traditional SIEM systems that support a rigid event format and, in many cases, require reducing events to fit in the schema. Another common source of JSON data in Azure Sentinel would be enrichment data collected using playbooks as demonstrated by Tiander Turpin here.

 

This brings us to the question of how to write a query to use JSON fields. Sentinel’s query language, KQL, uses the parse_json function to provide access to JSON field elements. However, when the JSON structure becomes deeper, using this function can become cumbersome. Luckily, Sentinel provides new tools to help you write those queries.

 

Let’s use Microsoft Cloud App Security (MCAS) alerts as an example. Using the following query, we get MCAS alerts on impossible travel:

SecurityAlert

| where ProviderName == "MCAS"

| where DisplayName == "Impossible travel activity"

| limit 10

1.png

 

Expanding one of the events, we can see that the countries Alex visited are located in the Extended Properties JSON compound field:

 

2.png

 

To use the countries just visited value, we can use the ellipsis on the left side of it automatically add a JSON parsing function to our query. Selecting the include option updates the query automatically to the one below:

 

3.png

 

SecurityAlert

| where ProviderName == "MCAS"

| where DisplayName == "Impossible travel activity"

| limit 10 

| where parse_json(ExtendedProperties).Countries == "AU, DE, FR, GB, JP, US"

 

However, since the Counties field is a list, include and exclude might not be particularly useful as they add a condition that would require the entire list of counties to be identical. You can change the “==” or “!=” operators automatically generated to a contains or !contains operators:

SecurityAlert

| where ProviderName == "MCAS"

| where DisplayName == "Impossible travel activity"

| limit 10

| where parse_json(ExtendedProperties).Countries contains "AU"

 

A better option would be to use the extend column option, which allows to filter further and process the new field and also ensures it is presented as a field in the results. Using extend column instead of include, the query is automatically updated as follows:

SecurityAlert

| where ProviderName == "MCAS"

| where DisplayName == "Impossible travel activity"

| limit 10

| extend Countries_ = tostring(parse_json(ExtendedProperties).Countries)

Will result in the following output, adding a Countries_ field to the result set for easy viewing:

 

4.png