Forum Discussion
Kusto Query to extract the number of exploitable vulnerabilities
- Jan 05, 2023
Thanks for the reference. But I found out what was the issue. Now it works as expected, like this:
$vulnUrl = '{ "query": "DeviceTvmSoftwareVulnerabilities | join (DeviceTvmSoftwareVulnerabilitiesKB) on CveId | where IsExploitable == 1 | count" }' $vulnUrlUri = "https://graph.microsoft.com/beta/security/runHuntingQuery" $vulnResponse = Invoke-WebRequest -Method Post -Uri $vulnUrlUri -Body $vulnUrl -Headers $headers -ErrorAction Stop
The difference was the " surrounding the 1 value. So I guess it doesn't deal well with multiple " on the variable.
Hi,
Thanks, that was about what I need, but reversing the tables:
DeviceTvmSoftwareVulnerabilities
| join (DeviceTvmSoftwareVulnerabilitiesKB) on CveId
| where IsExploitAvailable == "1"
| count
One other question, just to give a next step. The goal is to use this programatically to extract this value into a set of values for reporting. For that I have a Powershell to run this queries and extract the values to be used on a report. But while some other queries are working fine, this one is outputing "Bad Request" error.
My script is more or less this (the part that matters for the case):
$vulnUrl = '{ "query": "DeviceTvmSoftwareVulnerabilities | join (DeviceTvmSoftwareVulnerabilitiesKB) on CveId | where IsExploitable == "1" | count" }'
$vulnUrlUri = "https://graph.microsoft.com/beta/security/runHuntingQuery"
$vulnResponse = Invoke-WebRequest -Method Post -Uri $vulnUrlUri -Body $vulnUrl -Headers $headers -ErrorAction Stop
And the error is: Invoke-WebRequest : The remote server returned an error: (400) Bad Request.
But for example, this ones work fine:
Thanks again!
- dmarquesgnJan 04, 2023Iron Contributor
Yes, I always check first on the data on 365 Defender interface. Screenshot below confirms that.
So I guess it's something that is not being correctly parsed on the query.
- Rod_TrentJan 04, 2023
Microsoft
Looking at the following: https://learningbydoing.cloud/blog/query-log-analytics-with-kql-from-powershell/
There is an Invoke-AzOperationalInsightsQuery- dmarquesgnJan 05, 2023Iron Contributor
Thanks for the reference. But I found out what was the issue. Now it works as expected, like this:
$vulnUrl = '{ "query": "DeviceTvmSoftwareVulnerabilities | join (DeviceTvmSoftwareVulnerabilitiesKB) on CveId | where IsExploitable == 1 | count" }' $vulnUrlUri = "https://graph.microsoft.com/beta/security/runHuntingQuery" $vulnResponse = Invoke-WebRequest -Method Post -Uri $vulnUrlUri -Body $vulnUrl -Headers $headers -ErrorAction Stop
The difference was the " surrounding the 1 value. So I guess it doesn't deal well with multiple " on the variable.