Query Details

URL Lookup (Network & Commandline)

MDE URL Lookup

Query

// Set the URL you are trying to lookup.
// Lookup in this query is done with a contains, if this results in to many false positives add www. before the rest of the url.
let LookupURL = "test.com";
let SearchWindow = 48h; //Customizable h = hours, d = days
// Collect all network evets to the RemoteIP
let NewtworkEvents = DeviceNetworkEvents
     | where TimeGenerated > ago(SearchWindow)
     | where RemoteUrl contains LookupURL
     | project TimeGenerated, DeviceName, ActionType, RemoteIP, RemotePort, RemoteUrl, InitiatingProcessCommandLine, InitiatingProcessAccountSid;
// Collect all commandline references of the URL
let CommandLineReferences = DeviceProcessEvents
     | where TimeGenerated > ago(SearchWindow)
     | where ProcessCommandLine contains LookupURL
     | 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 RemoteIPs = make_set(RemoteIP), 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, RemoteUrl
     | sort by LastMention
)

About this query

Explanation

This query is designed to help with incident investigations by looking up a specific URL in both network events and command line references on devices. Here's a simplified breakdown of what the query does:

  1. URL Setup: You specify a URL (or device name) you want to investigate by setting the LookupURL variable.

  2. Time Frame: You define a time window (SearchWindow) for how far back you want to look in the logs. This is customizable in hours or days.

  3. Network Events Collection: The query searches through network events (DeviceNetworkEvents) to find any occurrences of the specified URL. It gathers details like timestamp, device name, action type, remote IP, remote port, and the command line that initiated the process.

  4. Command Line References Collection: It also searches through command line events (DeviceProcessEvents) to find any command lines that contain the specified URL. It collects similar details as in the network events.

  5. Combining Results: The query combines the results from both network and command line searches. It summarizes the data to show unique remote IPs and command lines, and identifies the last time the URL was mentioned on each device.

  6. Filtering Option: By default, the query includes both network and command line references. However, you can choose to see only command line references by uncommenting a specific line in the query.

  7. Output: The results are sorted by the last mention of the URL, showing the device name and remote URL.

This query is useful for quickly identifying all logs and command line references related to a specific URL, which can help in detecting potential malicious activities like remote downloads or executions.

Details

Bert-Jan Pals profile picture

Bert-Jan Pals

Released: October 20, 2024

Tables

DeviceNetworkEventsDeviceProcessEvents

Keywords

DeviceNetworkEventsCommandlineReferencesIPAddressURLLogsRemoteDownloadsExecutionsFilesMaliciousActivityTimestampDeviceNameActionTypeRemoteIPRemotePortRemoteUrlInitiatingProcessCommandLineInitiatingProcessAccountSidProcessCommandLineAccountSidFolderPath

Operators

letagocontainsprojectunionisfuzzysummarizemake_setarg_maxbyextendiffproject-reordersort

MITRE Techniques

Actions

GitHub