在 Microsoft 安全性暴露風險管理中,利用企業暴露圖表,主動在端點、雲端環境及混合基礎設施中,透過 Microsoft Defender 入口網站進行進階搜尋,搜尋企業暴露威脅。 隨著 適用於雲端的 Defender 在 Defender 入口網站的整合,曝光圖現在包含來自 Azure、AWS 和 GCP 環境的雲端節點類型與實體。
以下章節提供企業曝險圖中查詢的範例、技巧與提示。
必要條件
建立進階的狩獵查詢
- 檢視 建立進階狩獵查詢的最佳實務
- 開始使用 Kusto 查詢語言 (KQL)
使用造圖運算子
Kusto 的 make-graph 運算子會將節點和邊資料載入記憶體。
- 因為 Kusto 只載入正在使用的欄位,所以不需要明確選取欄位。
- 然而,欄位
NodeProperties包含所有節點資訊,因此欄位很大。 - 在大多數情況下,先擷取出所需的資訊,再將其輸入至
make-graph運算子,通常會比較有用。
範例
let FilteredNodes = ExposureGraphNodes
| extend ContainsSensetiveData = NodeProperties has "containsSensitiveData"
| project Id, ContainsSensetiveData, Label, EntityIds, Categories;
Edges
| make-graph SourceNodeId --> TargetNodeId with FilteredNodes on Id
..
使用動態欄位與智慧索引
NodeProperties 和 Categories 是動態欄位。
- Kusto 知道這些欄位包含類似 json 的內容,並應用智慧索引。
- 然而,並非所有 Kusto 營運商都使用該索引。 例如,
set_has_element、isempty和isnotnull在套用至動態欄位時不使用索引,而isnotnull(Properties["containsSensitiveData"]則不使用索引。 - 相反地,使用
has()運算子,因為它總是使用索引。
範例
在以下查詢中,has 運算子會檢查 data 字串,而 set_has_element 會檢查 data 元素。
同時使用這兩個運算子很重要,因為 has() 運算子即使對於類別 prefix_data 也會傳回 true。
Categories has('data') and set_has_element(Categories, 'data')
深入了解字串詞彙。
曝光查詢範例
以下範例可協助你撰寫查詢,以了解租戶中的安全暴露資料。
列出租用戶中的所有節點標籤
以下查詢將資料表中的 ExposureGraphNodes 資料分組,並使用 Kusto summarize 運算子將資料列為 NodeLabel。
ExposureGraphNodes
| summarize by NodeLabel
列出租用戶中的所有邊緣標籤
以下查詢會將 ExposureGraphEdges 資料表中的資料分組,並使用 Kusto 的 summarize 運算子依邊緣標籤 (EdgeLabel) 將其列出。
ExposureGraphEdges
| summarize by EdgeLabel
列出從指定節點標籤連出的所有連線
以下查詢將資料表中的 ExposureGraphEdges 資料分組,其中來源節點標籤為 microsoft.compute/virtualmachines,它將虛擬機的資料彙整為 EdgeLabel。 它總結了將資產連接至安全性暴露風險圖表中虛擬機器的邊緣。 隨著 適用於雲端的 Defender 在 Defender 入口網站的整合,現在涵蓋了來自多個環境的雲端資源。
ExposureGraphEdges
| where SourceNodeLabel == "microsoft.compute/virtualmachines"
| summarize by EdgeLabel
列出所有連接到特定節點標籤的連線
下列查詢總結了將虛擬機器連接至其他安全性暴露風險圖表資產的邊緣。 它將資料表中的 ExposureGraphEdges 資料分組,當目標節點標籤為 microsoft.compute/virtualmachines時,使用 Kusto summarize 運算子將目標節點標籤列為 EdgeLabel。
ExposureGraphEdges
| where TargetNodeLabel == "microsoft.compute/virtualmachines"
| summarize by EdgeLabel
列出特定節點標籤的屬性
以下查詢列出虛擬機節點標籤的屬性。 它會將資料表中的 ExposureGraphNodes 資料分組,並篩選出只顯示節點標籤為「microsoft.compute/virtualmachines」的結果。 使用 project-keep 運算子時,查詢會保留 NodeProperties 欄位。 回傳的資料限制於一列。 隨著 適用於雲端的 Defender 在 Defender 入口網站的整合,NodeProperties 現在包含更多雲端專屬的屬性與關聯。
ExposureGraphNodes
| where NodeLabel == "microsoft.compute/virtualmachines"
| project-keep NodeProperties
| take 1
範例:跨多個環境查詢雲端資源
下列查詢示範如何從不同環境查詢雲端資源;隨著在 Defender 入口網站中整合 適用於雲端的 Defender,現已可使用這項功能:
ExposureGraphNodes
| where NodeLabel contains "microsoft.compute" or NodeLabel contains "aws." or NodeLabel contains "gcp."
| summarize count() by NodeLabel
| order by count_ desc
查詢曝光圖
查詢曝光圖:
在 Microsoft Defender 入口網站中,選擇「狩獵>進階狩獵」。
在查詢區輸入你的查詢。 使用圖結構、函數和運算子表,或以下範例來幫助你建立查詢。
請選擇執行查詢。
面向圖形的查詢範例
利用這些圖形導向查詢範例,幫助你撰寫更完善的安全暴露查詢。 範例中尋找模式,以揭示實體間的關係,從而揭示風險。 他們教你如何將情境與事件/警示訊號相關聯。
列出所有與特定節點標籤相連的節點標籤
以下查詢會傳回所有與虛擬機器節點標籤相連的傳入節點標籤清單。 它會使用 SourceNodeId 運算子,將 ExposureGraphEdges 表格中的 TargetNodeId 欄位資料對應到 ExposureGraphNodes 表格中的 make-graph 欄位,以建立圖結構。
接著利用運算 graph-match 子繪製一個圖樣,使目標節點 TargetNode 與 NodeLabel 相符 microsoft.compute/virtualmachines。
project運算子只用來保留 IncomingNodeLabels。 它依據IncomingNodeLabels列出結果。
ExposureGraphEdges
| make-graph SourceNodeId --> TargetNodeId with ExposureGraphNodes
on NodeId
| graph-match (SourceNode)-[edges]->(TargetNode)
where TargetNode.NodeLabel == "microsoft.compute/virtualmachines"
project IncomingNodeLabels = SourceNode.NodeLabel
| summarize by IncomingNodeLabels
列出所有與特定節點標籤相連的節點標籤
以下查詢會產生一份清單,列出所有透過連接器連接到虛擬機器節點標籤的外向節點標籤。
- 它會透過使用
SourceNodeId資料表中的資料,將ExposureGraphEdges資料行對應至TargetNodeId資料表中的ExposureGraphNodes資料行,並使用make-graph運算子來建立圖形結構。 - 接著,它使用
graph-match運算子來比對圖形模式,其中SourceNode和NodeLabel會匹配microsoft.compute/virtualmachines。 -
project運算子只用來保留OutgoingNodeLabels。 它依據OutgoingNodeLabels列出結果。
ExposureGraphEdges
| make-graph SourceNodeId --> TargetNodeId with ExposureGraphNodes
on NodeId
| graph-match (SourceNode)-[edges]->(TargetNode)
where SourceNode.NodeLabel == "microsoft.compute/virtualmachines"
project OutgoingNodeLabels = SourceNode.NodeLabel
| summarize by OutgoingNodeLabels
發現暴露於網際網路且存在 RCE 漏洞的虛擬機
以下查詢可讓您發現暴露於網際網路及遠端程式碼執行 (RCE) 雲端環境中的虛擬機。
- 它使用
ExposureGraphNodes結構表。 - 當
NodePropertiesexposedToInternet和vulnerableToRCE都為真時,會檢查類別(Categories)是否為虛擬機器(virtual_machine)。 - 隨著 適用於雲端的 Defender 在 Defender 入口網站的整合,現在還包括來自 Azure、AWS 和 GCP 環境的虛擬機。
ExposureGraphNodes
| where isnotnull(NodeProperties.rawData.exposedToInternet)
| where isnotnull(NodeProperties.rawData.vulnerableToRCE)
| where Categories has "virtual_machine" and set_has_element(Categories, "virtual_machine")
範例:尋找雲端與本地資產之間的混合攻擊路徑
以下查詢說明如何在 Defender 入口網站整合 適用於雲端的 Defender 時,辨識潛在的混合攻擊路徑:
let CloudAssets = ExposureGraphNodes
| where Categories has "virtual_machine" and (NodeLabel contains "microsoft.compute" or NodeLabel contains "aws." or NodeLabel contains "gcp.");
let OnPremAssets = ExposureGraphNodes
| where Categories has "device" and not(NodeLabel contains "microsoft.compute" or NodeLabel contains "aws." or NodeLabel contains "gcp.");
ExposureGraphEdges
| make-graph SourceNodeId --> TargetNodeId with ExposureGraphNodes on NodeId
| graph-match (CloudVM)-[edge1]->(Identity)-[edge2]->(OnPremDevice)
where set_has_element(CloudVM.Categories, "virtual_machine") and
(CloudVM.NodeLabel contains "microsoft.compute" or CloudVM.NodeLabel contains "aws." or CloudVM.NodeLabel contains "gcp.") and
set_has_element(Identity.Categories, "identity") and
set_has_element(OnPremDevice.Categories, "device") and
not(OnPremDevice.NodeLabel contains "microsoft.compute" or OnPremDevice.NodeLabel contains "aws." or OnPremDevice.NodeLabel contains "gcp.")
project CloudVMName=CloudVM.NodeName, IdentityName=Identity.NodeName, OnPremDeviceName=OnPremDevice.NodeName
找出存在權限提升漏洞的面向網際網路裝置
以下查詢尋找暴露於權限升級漏洞的網路裝置,該漏洞可能允許系統內存取更高階的權限。
- 它使用
ExposureGraphNodes結構表。 - 當
NodeProperties同時為面向網際網路(IsInternetFacing)且VulnerableToPrivilegeEscalation時,查詢會檢查Categories中的項目是否確實為裝置(device)。
ExposureGraphNodes
| where isnotnull(NodeProperties.rawData.IsInternetFacing)
| where isnotnull(NodeProperties.rawData.VulnerableToPrivilegeEscalation)
| where set_has_element(Categories, "device")
顯示所有登入多個重要裝置的使用者
此查詢會顯示登入多個關鍵裝置的使用者清單,以及他們登入的裝置數量。
- 它使用經過篩選的
IdentitiesAndCriticalDevices資料建立ExposureGraphNodes資料表,篩選條件為關鍵性等級高於 4 的裝置,或依identity篩選。 - 接著它用算
make-graph符建立一個圖結構,其中EdgeLabel為Can Authenticate As。 - 它使用
graph-match運算子來比對device符合identity的實例。 - 接著它會利用
project操作員來保存身份 ID 和裝置 ID。 - 操作員
mv-apply會依類型過濾裝置 ID 與身份 ID。 它會將它們彙總,並以表格顯示結果,表頭為Number Of devices user is logged-in to和User Id。
let IdentitiesAndCriticalDevices = ExposureGraphNodes
| where
// Critical Device
(set_has_element(Categories, "device") and isnotnull(NodeProperties.rawData.criticalityLevel) and NodeProperties.rawData.criticalityLevel.criticalityLevel > 4)
// or identity
or set_has_element(Categories, "identity");
ExposureGraphEdges
| where EdgeLabel == "Can Authenticate As"
| make-graph SourceNodeId --> TargetNodeId with IdentitiesAndCriticalDevices on NodeId
| graph-match (Device)-[canConnectAs]->(Identity)
where set_has_element(Identity.Categories, "identity") and set_has_element(Device.Categories, "device")
project IdentityIds=Identity.EntityIds, DeviceIds=Device.EntityIds
| mv-apply DeviceIds on (
where DeviceIds.type == "DeviceInventoryId")
| mv-apply IdentityIds on (
where IdentityIds.type == "SecurityIdentifier")
| summarize NumberOfDevicesUserLoggedinTo=count() by tostring(IdentityIds.id)
| where NumberOfDevicesUserLoggedinTo > 1
| project ["Number Of devices user is logged-in to"]=NumberOfDevicesUserLoggedinTo, ["User Id"]=IdentityIds_id
顯示有關鍵漏洞的客戶端裝置/有權限存取高價值伺服器的使用者
以下查詢會得到包含 RCE 漏洞及其裝置 ID 的裝置清單,以及具有高關鍵漏洞的裝置及其裝置 ID 的清單。
- 它會建立一個
IdentitiesAndCriticalDevices表格,其中包含具有嚴重性低於四之 RCE 漏洞的裝置(device),以及可透過篩選與模式比對來顯示具有重大漏洞之裝置的身分(identity)。 - 此列表經過篩選後,只顯示具有邊標籤
Can Authenticate As和CanRemoteInteractiveLogonTo的連線。
let IdentitiesAndCriticalDevices = ExposureGraphNodes // Reduce the number of nodes to match
| where
// Critical devices & devices with RCE vulnerabilities
(set_has_element(Categories, "device") and
(
// Critical devices
(isnotnull(NodeProperties.rawData.criticalityLevel) and NodeProperties.rawData.criticalityLevel.criticalityLevel < 4)
or
// Devices with RCE vulnerability
isnotnull(NodeProperties.rawData.vulnerableToRCE)
)
)
or
// identity
set_has_element(Categories, "identity");
ExposureGraphEdges
| where EdgeLabel in~ ("Can Authenticate As", "CanRemoteInteractiveLogonTo") // Reduce the number of edges to match
| make-graph SourceNodeId --> TargetNodeId with IdentitiesAndCriticalDevices on NodeId
| graph-match (DeviceWithRCE)-[CanConnectAs]->(Identity)-[CanRemoteLogin]->(CriticalDevice)
where
CanConnectAs.EdgeLabel =~ "Can Authenticate As" and
CanRemoteLogin.EdgeLabel =~ "CanRemoteInteractiveLogonTo" and
set_has_element(Identity.Categories, "identity") and
set_has_element(DeviceWithRCE.Categories, "device") and isnotnull(DeviceWithRCE.NodeProperties.rawData.vulnerableToRCE) and
set_has_element(CriticalDevice.Categories, "device") and isnotnull(CriticalDevice.NodeProperties.rawData.criticalityLevel)
project DeviceWithRCEIds=DeviceWithRCE.EntityIds, DeviceWithRCEName=DeviceWithRCE.NodeName, CriticalDeviceIds=CriticalDevice.EntityIds, CriticalDeviceName=CriticalDevice.NodeName
提供從特定節點 ID 到特定標籤節點的所有路徑
此查詢顯示從特定 IP 節點出發的路徑,經過最多三個資產,最終連接到虛擬機節點標籤。
- 它使用
ExposureGraphNodes和ExposureGraphEdgesschema 表格以及make-graphandgraph-match運算子來建立圖結構。 - 使用
project運算子時,會顯示 IP ID、IP 屬性、虛擬機器 ID 和虛擬機器屬性的清單。
let IPsAndVMs = ExposureGraphNodes
| where (set_has_element(Categories, "ip_address") or set_has_element(Categories, "virtual_machine"));
ExposureGraphEdges
| make-graph SourceNodeId --> TargetNodeId with IPsAndVMs on NodeId
| graph-match (IP)-[anyEdge*1..3]->(VM)
where set_has_element(IP.Categories, "ip_address") and set_has_element(VM.Categories, "virtual_machine")
project IpIds=IP.EntityIds, IpProperties=IP.NodeProperties.rawData, VmIds=VM.EntityIds, VmProperties=VM.NodeProperties.rawData