How to compare a array values in a column against another array from a watchlist in Kusto

%3CLINGO-SUB%20id%3D%22%5C%26quot%3Blingo-sub-3167009%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Ben-US%5C%26quot%3B%22%3EHow%20to%20compare%20a%20array%20values%20in%20a%20column%20against%20another%20array%20from%20a%20watchlist%20in%20Kusto%26lt%3B%5C%2Flingo-sub%26gt%3B%3CLINGO-BODY%20id%3D%22%5C%26quot%3Blingo-body-3167009%5C%26quot%3B%22%20slang%3D%22%5C%26quot%3Ben-US%5C%26quot%3B%22%3E%3CP%3EI%20am%20getting%20results%20with%20a%20column%20named%20IPAddresses%20having%20values%20in%20array.%20I%20want%20to%20compare%20each%20value%20in%20this%20array%20to%20a%20list%20(another%20array%20from%20a%20watch%20list).%20I%20have%20been%20trying%20to%20make%20use%20of%20mv-apply%20but%20with%20no%20success%2C%20can%20any%20guide%20me%20in%20this.%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3EHere%20is%20my%20code%20snippet%3A%26lt%3B%5C%2FP%26gt%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26lt%3B%5C%2FP%26gt%3B%3CPRE%20class%3D%22%5C%26quot%3Blia-code-sample%22%20language-yaml%3D%22%22%3E%3CCODE%3Elet%20timeframe%20%3D%20ago(3h)%3B%5Cnlet%20threshold%20%3D%202%3B%5Cnlet%20ZSwatchlist%20%3D%20(_GetWatchlist(%5C'zscaler%5C')%5Cn%7C%20project%20SearchKey)%3B%5Cnlet%20zarray%20%3D%20(ZSwatchlist%5Cn%7C%20summarize%20zlist%20%3D%20make_list(SearchKey))%3B%5Cnlet%20users%20%3D%20(imAuthentication%5Cn%7C%20where%20TargetUserType%20!%3D%20%5C'ServicePrincipal%5C'%5Cn%7C%20where%20TimeGenerated%20%26gt%3B%20timeframe%5Cn%7C%20where%20EventType%20%3D%3D%20%5C'Logon%5C'%20and%20EventResult%20%3D%3D%20%5C'Success%5C'%5Cn%7C%20where%20isnotempty(SrcGeoCountry)%5Cn%7C%20summarize%20StartTime%20%3D%20min(TimeGenerated)%2C%20EndTime%20%3D%20max(TimeGenerated)%2C%20Vendors%3Dmake_set(EventVendor)%2C%20Products%3Dmake_set(EventProduct)%2C%20Countries%20%3D%20make_set(SrcGeoCountry)%2C%20IPAddresses%20%3D%20make_set(SrcDvcIpAddr)%5Cn%2C%20NumOfCountries%20%3D%20dcount(SrcGeoCountry)%5Cnby%20TargetUserId%2C%20TargetUsername%2C%20TargetUserType)%3B%5Cnusers%5Cn%7C%20mv-apply%20ipscaler%3Dtoscalar(IPAddresses)%20to%20typeof(string)%20on(%5Cnwhere%20not(ipv4_is_in_range(IPAddresses%2Czarray))%5Cn)%26lt%3B%5C%2Fcode%26gt%3B%26lt%3B%5C%2Fpre%26gt%3B%26lt%3B%5C%2Flingo-body%26gt%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3C%2FLINGO-SUB%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3167009%22%20slang%3D%22en-US%22%3EHow%20to%20compare%20a%20array%20values%20in%20a%20column%20against%20another%20array%20from%20a%20watchlist%20in%20Kusto%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3167009%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20getting%20results%20with%20a%20column%20named%20IPAddresses%20having%20values%20in%20array.%20I%20want%20to%20compare%20each%20value%20in%20this%20array%20to%20a%20list%20(another%20array%20from%20a%20watch%20list).%20I%20have%20been%20trying%20to%20make%20use%20of%20mv-apply%20but%20with%20no%20success%2C%20can%20any%20guide%20me%20in%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20is%20my%20code%20snippet%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-yaml%22%3E%3CCODE%3Elet%20timeframe%20%3D%20ago(3h)%3B%0Alet%20threshold%20%3D%202%3B%0Alet%20ZSwatchlist%20%3D%20(_GetWatchlist('zscaler')%0A%7C%20project%20SearchKey)%3B%0Alet%20zarray%20%3D%20(ZSwatchlist%0A%7C%20summarize%20zlist%20%3D%20make_list(SearchKey))%3B%0Alet%20users%20%3D%20(imAuthentication%0A%7C%20where%20TargetUserType%20!%3D%20'ServicePrincipal'%0A%7C%20where%20TimeGenerated%20%26gt%3B%20timeframe%0A%7C%20where%20EventType%20%3D%3D%20'Logon'%20and%20EventResult%20%3D%3D%20'Success'%0A%7C%20where%20isnotempty(SrcGeoCountry)%0A%7C%20summarize%20StartTime%20%3D%20min(TimeGenerated)%2C%20EndTime%20%3D%20max(TimeGenerated)%2C%20Vendors%3Dmake_set(EventVendor)%2C%20Products%3Dmake_set(EventProduct)%2C%20Countries%20%3D%20make_set(SrcGeoCountry)%2C%20IPAddresses%20%3D%20make_set(SrcDvcIpAddr)%0A%2C%20NumOfCountries%20%3D%20dcount(SrcGeoCountry)%0Aby%20TargetUserId%2C%20TargetUsername%2C%20TargetUserType)%3B%0Ausers%0A%7C%20mv-apply%20ipscaler%3Dtoscalar(IPAddresses)%20to%20typeof(string)%20on(%0Awhere%20not(ipv4_is_in_range(IPAddresses%2Czarray))%0A)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3167009%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Sentinel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Contributor

I am getting results with a column named IPAddresses having values in array. I want to compare each value in this array to a list (another array from a watch list). I have been trying to make use of mv-apply but with no success, can any guide me in this.

 

Here is my code snippet:

 

 

let timeframe = ago(3h);
let threshold = 2;
let ZSwatchlist = (_GetWatchlist('zscaler')
| project SearchKey);
let zarray = (ZSwatchlist
| summarize zlist = make_list(SearchKey));
let users = (imAuthentication
| where TargetUserType != 'ServicePrincipal'
| where TimeGenerated > timeframe
| where EventType == 'Logon' and EventResult == 'Success'
| where isnotempty(SrcGeoCountry)
| summarize StartTime = min(TimeGenerated), EndTime = max(TimeGenerated), Vendors=make_set(EventVendor), Products=make_set(EventProduct), Countries = make_set(SrcGeoCountry), IPAddresses = make_set(SrcDvcIpAddr)
, NumOfCountries = dcount(SrcGeoCountry)
by TargetUserId, TargetUsername, TargetUserType);
users
| mv-apply ipscaler=toscalar(IPAddresses) to typeof(string) on(
where not(ipv4_is_in_range(IPAddresses,zarray))
)

 

4 Replies

@Ashish Raj Your  ZSWatchlist variable is a table so normally I would say to use a join but since you are using ipv4_is_in_range for your comparison, that will not work.    Have you tried a union command between the ZSWatchlist and users?   Then perform the comparison to weed out just those values you want.   Not sure how many IP Addresses you have in the watchlist so not sure if this will be feasible or not.

Let me try this, I do remember trying union but not sure if I did finish till the comparison.

@Ashish Raj

 

I had a similar task recently, and it's still a work in progress - its simplified compared to yours to get to the main task. 

//watchlist array
let ZSwatchlist = (_GetWatchlist('ipa')
    | project SearchKey 
    | summarize zlist = make_list(SearchKey));
let users = (
    // Get IP addresses for a named Table and make as an array
    AWSVPCFlow
    | where TimeGenerated > ago(30d)
    | where isnotempty(SrcAddr)
    // testing - there is a point when too many IPs fills the array, keep it small 
    | limit 1048
    | summarize IPAddresses = make_set(SrcAddr)
);
union users, ZSwatchlist
| project IPAddresses ,tostring(zlist)
| mv-apply ipscaler=IPAddresses to typeof(string) on
    (
        where not(ipv4_is_in_range(ipscaler,zlist))
    )  

 

Trying exactly this. Does not throw a terminal error but does not show valid results either. Trying to tweak it further.