在 Microsoft 安全性暴露風險管理中,利用企業暴露圖表,主動在端點、雲端環境及混合基礎設施中,透過 Microsoft Defender 入口網站進行進階搜尋,搜尋企業暴露威脅。 隨著 Defender for Cloud 在 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_elementisempty, , 在isnotnull應用於動態欄位時不使用索引,也不isnotnull(Properties["containsSensitiveData"]使用索引。 - 相反地,使用
has()運算子,因為它總是使用索引。
範例
在以下查詢中,has運算子檢查data字串,並set_has_element檢查元素。data
同時使用兩個算子非常重要,因為即使對範疇 prefix_data,算has()子也會返回為真。
Categories has('data') and set_has_element(Categories, 'data')
了解更多 關於理解弦詞的知識。
範例曝光查詢
以下範例可協助你撰寫查詢,以了解租戶中的安全暴露資料。
列出租戶中所有節點標籤
以下查詢將資料表中的 ExposureGraphNodes 資料分組,並使用 Kusto summarize 運算子將資料列為 NodeLabel。
ExposureGraphNodes
| summarize by NodeLabel
列出租戶中所有邊緣標籤
以下查詢將資料表中的 ExposureGraphEdges 資料分組,並使用 Kubernetes 運算 summarize 子依邊標籤 (EdgeLabel) 列出。
ExposureGraphEdges
| summarize by EdgeLabel
列出指定節點標籤的所有連接
以下查詢將資料表中的 ExposureGraphEdges 資料分組,其中來源節點標籤為 microsoft.compute/virtualmachines,它將虛擬機的資料彙整為 EdgeLabel。 它總結了將資產與安全暴露圖中虛擬機連結的邊。 隨著 Defender for Cloud 在 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 for Cloud 在 Defender 入口網站的整合,NodeProperties 現在包含更多雲端專屬的屬性與關聯。
ExposureGraphNodes
| where NodeLabel == "microsoft.compute/virtualmachines"
| project-keep NodeProperties
| take 1
範例:跨多個環境查詢雲端資源
以下查詢說明如何查詢 Defender for Cloud 整合後,從不同環境中的雲端資源查詢:
ExposureGraphNodes
| where NodeLabel contains "microsoft.compute" or NodeLabel contains "aws." or NodeLabel contains "gcp."
| summarize count() by NodeLabel
| order by count_ desc
查詢曝光圖
查詢曝光圖:
在 Microsoft Defender 入口網站中,選擇「狩獵 -> 進階狩獵」。
在查詢區輸入你的查詢。 使用圖結構、函數和運算子表,或以下範例來幫助你建立查詢。
選擇 執行查詢。
面向圖形的查詢範例
利用這些圖形導向查詢範例,幫助你撰寫更完善的安全暴露查詢。 範例中尋找模式,以揭示實體間的關係,從而揭示風險。 他們教你如何將情境與事件/警示訊號相關聯。
將所有邊標示為特定節點標籤的節點標籤
以下查詢會產生一個包含所有輸入節點標籤的清單,並透過連接埠連接到虛擬機器節點標籤。 它透過將表格中的ExposureGraphEdges欄位資料映射SourceNodeId到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的資料到TargetNodeIdExposureGraphNodes欄位,並使用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結構表。 - 當 和
vulnerableToRCE都NodePropertiesexposedToInternet為真時,它會檢查 (Categories) 類別是否是 (virtual_machine) 虛擬機。 - 隨著 Defender for Cloud 在 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 for Cloud 時,辨識潛在的混合攻擊路徑:
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() 和VulnerableToPrivilegeEscalation同時面向網路時,查詢會檢查這些物品Categories是否真的是) (deviceIsInternetFacing裝置。
ExposureGraphNodes
| where isnotnull(NodeProperties.rawData.IsInternetFacing)
| where isnotnull(NodeProperties.rawData.VulnerableToPrivilegeEscalation)
| where set_has_element(Categories, "device")
顯示所有登入多個重要裝置的使用者
此查詢會顯示登入多個關鍵裝置的使用者清單,以及他們登入的裝置數量。
- 它使用
ExposureGraphNodes資料建立IdentitiesAndCriticalDevices一個資料表,資料會依據關鍵性等級高於 4identity的裝置或 來篩選。 - 接著它用算
make-graph符建立一個圖結構,其中EdgeLabel為Can Authenticate As。 - 它使用運算
graph-match子來匹配 adeviceidentity與 的實例。 - 接著它會利用
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表格,包含) (device具有 RCE 漏洞且嚴重性低於四的裝置,以及 (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