Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Web Traffic data hunt #111

Open
exigentcircumstance opened this issue Apr 15, 2020 · 8 comments
Open

Web Traffic data hunt #111

exigentcircumstance opened this issue Apr 15, 2020 · 8 comments

Comments

@exigentcircumstance
Copy link

Trying to write a script that will show me all internet/web traffic data for a specific person/machine for a specific amount of a time range.

Example: I want to see what Joe Smith did for the past 30 days with web searching.

Can't seem to find anything that will fit this nor can I seem to write a usable script in Defender.

Can anyone help? Please :)

@cheapbyte
Copy link

cheapbyte commented May 1, 2020

Try this.

// This query finds all network communication for a specific userID and Date Range and displays the Process communicating
// Modify Line 8 with the UserID you want a report on or user Partial if you are not sure
//
let TimeRangeStart = datetime(2020-04-29 20:50:01); //Fill in the start date and time
let TimeRangeEnd = datetime(2020-05-01 20:50:00); // Fill in the end date and time
// If running interactive, set the date range to 30 days or custom to cover the date range you have in the script, otherwise if running in a process, the timerange will work regardless
let partialRemoteUrlToDetect = ""; // Change this to a URL you'd like to find machines connecting to or leave blank for everything
//
DeviceNetworkEvents
| where InitiatingProcessAccountName contains "UserID" //enter the full or partial userID
| where Timestamp between ((TimeRangeStart) ..TimeRangeEnd)
and RemoteUrl has partialRemoteUrlToDetect // Can be changed to "contains" operator as explained above
| project Timestamp, InitiatingProcessAccountName, RemoteUrl, InitiatingProcessParentFileName, DeviceName, DeviceId, ReportId
// | top 1000 by RemoteUrl desc // Remove the first two slashes if you want just the top 1000

@JakKAaj
Copy link

JakKAaj commented Oct 29, 2020

I am struggling to create a query to match https://urlhaus.abuse.ch/downloads/text/ or https://urlhaus.abuse.ch/downloads/text_recent/
with DeviceNetworkEvents RemoteUrl

Can you help ?

@tali-ash
Copy link
Collaborator

tali-ash commented Nov 3, 2020

Hi JakKAaj,

You can use this example:

EmailAttachmentInfo
| where SHA256 in (externaldata(TimeGenerated:datetime, SHA256:string)
[@"https://raw.githubusercontent.com/Azure/Azure-Sentinel/master/Sample%20Data/Feeds/Microsoft.Covid19.Indicators.csv"]
with (format="csv"))

Using externaldata operator you can use list from external source in your query.
You need to save the url lists in csv/txt format(or any format supported by externaldata).

https://docs.microsoft.com/en-us/microsoft-365/security/mtp/advanced-hunting-best-practices?view=o365-worldwide#ingest-data-from-external-sources

@JakKAaj
Copy link

JakKAaj commented Nov 3, 2020 via email

@mjmelone
Copy link
Contributor

mjmelone commented Nov 16, 2020

Good morning all,
Here's how I would likely approach the issue. First, parse the URLs from urlhaus into their individual parts using the parse_url() function:

(externaldata(payload_url: string ) [@"https://urlhaus.abuse.ch/downloads/text_recent/"]
with (format="txt"))
| extend ParsedUrl = parse_url(payload_url)
| evaluate bag_unpack(ParsedUrl)
| extend Port = case(isnotempty(Port), Port, Scheme == 'http', "80", Scheme == 'https', "443", Port)

...once you have that, we should probably try to parse out the DeviceNetworkEvents in the same manner for matching:

DeviceNetworkEvents
| extend ParsedUrl = iff(RemoteUrl matches regex @'^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$', todynamic(strcat('{"Host":"', tolower(RemoteUrl), '"}')), parse_url(RemoteUrl))
| evaluate bag_unpack(ParsedUrl)

...and now put them together with some joins to perform comparisons. To achieve this, you'll need to use a function such as mvexpand followed by a comparison operator.
Also, as a former incident responder, I would probably be a bit more paranoid than most and look for simple IP matches as well as FQDN matches. Here we go:

let urlhausurls = toscalar((externaldata(payload_url: string ) [@"https://urlhaus.abuse.ch/downloads/text_recent/"]
with (format="txt"))
| extend ParsedUrl = parse_url(payload_url)
| evaluate bag_unpack(ParsedUrl)
| extend Port = case(isnotempty(Port), Port, Scheme == 'http', "80", Scheme == 'https', "443", Port)
| extend Packed = pack_all()
| summarize makelist(Packed));
DeviceNetworkEvents
| extend ParsedUrl = iff(RemoteUrl matches regex @'^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$', todynamic(strcat('{"Host":"', tolower(RemoteUrl), '"}')), parse_url(RemoteUrl))
| evaluate bag_unpack(ParsedUrl)
| extend UrlHaus = urlhausurls
| mvexpand UrlHaus 
| evaluate bag_unpack(UrlHaus, 'UrlHaus_')
| extend HostAndPortMatch = ((RemoteIP == UrlHaus_Host or Host == UrlHaus_Host) and RemotePort == UrlHaus_Port), UriStemMatch = (isnotempty(UrlHaus_Path) and Path == UrlHaus_Path)
| where HostAndPortMatch == true

Let me know if that works for you

@JakKAaj
Copy link

JakKAaj commented Nov 18, 2020 via email

@mjmelone
Copy link
Contributor

mjmelone commented Nov 18, 2020

One slight modification - using case insensitive equals

let urlhausurls = toscalar((externaldata(payload_url: string ) [@"https://urlhaus.abuse.ch/downloads/text_recent/"]
with (format="txt"))
| extend ParsedUrl = parse_url(payload_url)
| evaluate bag_unpack(ParsedUrl)
| extend Port = case(isnotempty(Port), Port, Scheme == 'http', "80", Scheme == 'https', "443", Port)
| extend Packed = pack_all()
| summarize makelist(Packed));
DeviceNetworkEvents
| extend ParsedUrl = iff(RemoteUrl matches regex @'^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$', todynamic(strcat('{"Host":"', tolower(RemoteUrl), '"}')), parse_url(RemoteUrl))
| evaluate bag_unpack(ParsedUrl)
| extend UrlHaus = urlhausurls
| mvexpand UrlHaus 
| evaluate bag_unpack(UrlHaus, 'UrlHaus_')
| extend HostAndPortMatch = ((RemoteIP == UrlHaus_Host or Host =~ UrlHaus_Host) and RemotePort == UrlHaus_Port), UriStemMatch = (isnotempty(UrlHaus_Path) and Path =~ UrlHaus_Path)
| where HostAndPortMatch == true

@JakKAaj
Copy link

JakKAaj commented Nov 23, 2020

Not sure why but the query time out in WDATP.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants