IP Lookup (Network & Commandline)
MDE IP Lookup
Query
// Set the IP address you are trying to lookup.
let LookupIP = "127.0.0.1";
let SearchWindow = 48h; //Customizable h = hours, d = days
// Collect all network evets to the RemoteIP
let NewtworkEvents = DeviceNetworkEvents
| where TimeGenerated > ago(SearchWindow)
| where RemoteIP == LookupIP
| project TimeGenerated, DeviceName, ActionType, RemoteIP, RemotePort, RemoteUrl, InitiatingProcessCommandLine, InitiatingProcessAccountSid;
// Collect all commandline references of the IP
let CommandLineReferences = DeviceProcessEvents
| where TimeGenerated > ago(SearchWindow)
| where ProcessCommandLine contains LookupIP
| project TimeGenerated, DeviceName, ActionType, FolderPath, ProcessCommandLine, AccountSid;
// Combine results
(union isfuzzy=true
(NewtworkEvents),
(CommandLineReferences)
// If you do want to have raw logs remove the summarize below.
// CommandLines and RemoteURLs can both be empty if there is no Commandline reference and a connection is only made to a IP not to a URL.
| summarize RemoteURLs = make_set(RemoteUrl), CommandLines = make_set(ProcessCommandLine), LastMention = arg_max(TimeGenerated, *) by DeviceName
// Add filter posibility to alter the search results if you only want to see commandline references. By default it includes both network and commandline references. If you only want to see commandline references uncommment the statment CommandLineReference == true
| extend CommandLineReference = iff(CommandLines == @'[""]', false, true)
//| where CommandLineReference == true
| project-reorder LastMention, DeviceName, RemoteIP
| sort by LastMention
)About this query
Explanation
This query is designed to help you investigate an IP address by looking at both network events and command line activities on devices. Here's a simple breakdown of what it does:
-
IP Address Setup: You specify an IP address (either public or private, IPv4 or IPv6) that you want to investigate.
-
Time Frame: You can set a time window (e.g., 48 hours) to limit the search to recent events.
-
Network Events Collection: The query looks for network events where the specified IP address was involved. It gathers details like the device name, action type, remote port, and any command line that initiated the process.
-
Command Line References Collection: It also searches for any command line activities that mention the IP address, collecting details like the folder path and account SID.
-
Combining Results: The query combines the network and command line data. It summarizes the findings, showing unique URLs and command lines associated with the IP, and notes the last time the IP was mentioned.
-
Filtering Option: By default, it shows both network and command line references. However, you can adjust the query to show only command line references if needed.
-
Sorting and Display: The results are sorted by the most recent mention of the IP address, making it easier to see the latest activities.
This query is useful for quickly gathering all relevant logs and command line references related to a specific IP address, which can be crucial in incident investigations.
Details

Bert-Jan Pals
Released: October 20, 2024
Tables
Keywords
Operators