Skip to main content

Tuesday's Tip: Hunt Before You Are Hunted: Practical UDM Hunting Techniques

  • Nov 24, 2026 3:47 PM UTC
  • 0 replies
  • 15 views

dnehoda
Staff
Forum|alt.badge.img+19

November 24, 2026

 

Detection rules catch the attacks you already know how to describe; these four UDM hunts look for the ones they miss, and each ends in a rule you can deploy. Every query is written in the search syntax Google SecOps accepts today, with the pivots that turn a suspicious row into an answer.

 

Why hunt

 

A detection rule is a hypothesis someone already had. It fires on the pattern its author wrote down, at the threshold they chose, on the log sources they had that day. Attackers work in the space those choices leave open: a new tool, a slower pace, a log source nobody wrote rules for.

Hunting reverses the order. You start from something the attacker cannot avoid doing ("to reach the file server, they have to connect to it"), ask the data whether it happened, and read the answer yourself. Every outcome pays: you find an intrusion, you find a visibility gap, or you learn what normal looks like well enough to write a tighter rule.

The four hunts below are four stages of one intrusion. An attacker makes a foothold survive a reboot (persistence), grants themselves more access (privilege escalation), spreads to other hosts (lateral movement), and takes the data out (exfiltration). Run all four over the same week and you have a cross-section of the kill chain, not four unrelated searches.

 

The hunt loop

 

Read it left to right, then down. A query that returns nothing exposes a visibility gap, a pattern that holds becomes a rule, and a pivot that confirms compromise becomes an incident. All three hand you the next hypothesis.

 

Anatomy of a hunt query

 

Aggregated searches in Google SecOps use YARA-L 2.0 sections, not pipes. A query written as | stats ... by ... will not run; the same idea is a filter followed by match:, outcome:, order: and limit:.

Section What it does Example
Filter (no keyword) Narrows events before anything is counted. Conditions on separate lines are ANDed. metadata.event_type = "NETWORK_CONNECTION"
match: The group-by fields, with an optional time bucket (by hour, by day, by 2h). principal.hostname by day
outcome: Aggregates, each assigned to a $variable. $unique_targets = count_distinct(target.ip)
order: Sorts on an outcome variable. Ascending unless you say desc. $unique_targets desc
limit: Caps the rows returned. 50

The aggregates available in search are count, count_distinct, sum, min, max, avg, stddev, array, array_distinct, earliest and latest.

Three behaviors shape every hunt below:

  • The time range lives in the picker, not the query. Set it before you run; a statistical search covers at most 90 days.
  • There is no filter on an aggregated value. Search has no condition: section, so you cannot ask for "hosts with more than 30 targets". Sort descending, cap with limit:, and keep the threshold for the detection rule.
  • A missing field counts as an empty string or zero, not as null. Add field != "" to the filter, or every event without that field piles into one large blank row at the top of your results.

The four hunts at a glance

Hunt ATT&CK technique UDM event type The signal First pivot
1. Lateral movement T1021 Remote Services NETWORK_CONNECTION One host reaching far more internal IPs than its peers The process that opened the connections
2. Privilege escalation T1098.003 Additional Cloud Roles USER_RESOURCE_UPDATE_PERMISSIONS An IAM change by a principal outside the admin team The role granted, and to whom
3. Data exfiltration T1567 Exfiltration Over Web Service NETWORK_CONNECTION, outbound Outbound bytes far above peers, or above the host's own baseline Destination IPs and countries
4. Persistence T1053 Scheduled Task/Job SCHEDULED_TASK_CREATION A task created on a quiet server, or by an account that should not schedule work The command the task runs

Each hunt follows the same five steps: the hypothesis, the query, how to read the results, where to pivot, and the noise to expect.

Hunt 1: Lateral movement

Hypothesis. An attacker who owns one workstation needs more. Before a stolen credential is useful they have to find where it works, which means one host touching many internal addresses on admin ports (SMB 445, RDP 3389, WinRM 5985, SSH 22) in a short window.

metadata.event_type = "NETWORK_CONNECTION"
principal.hostname != ""
target.ip = /^(10\.|192\.168\.|172\.(1[6-9]|2[0-9]|3[01])\.)/
(target.port = 445 OR target.port = 3389 OR target.port = 5985 OR target.port = 22)
match:
principal.hostname by hour
outcome:
$unique_targets = count_distinct(target.ip)
$connections = count(metadata.id)
order:
$unique_targets desc
limit:
50

The regex keeps only private (RFC 1918) targets, so internet traffic does not inflate the count. The by hour bucket matters: a sweep is a burst, and a daily total hides a burst inside a normal day.

Read the results. You get one row per host per hour. A workstation reaching 5 to 10 internal IPs on these ports is ordinary; 50 or more in a single hour is a sweep. The top of the list will be legitimate: vulnerability scanners, domain controllers, patch and software-distribution servers, monitoring, backup, jump hosts. Write those down once, because they become the exclusion list for the detection rule. The hunt is what remains underneath them.

Pivot 1: what opened the connections. Take a suspicious host and group by process and port. 

***The workstation names are made up - you will need a host in your network

metadata.event_type = "NETWORK_CONNECTION"
principal.hostname = "WKSTN-0142"
match:
principal.process.file.full_path, target.port
outcome:
$targets = count_distinct(target.ip)
$first_seen = earliest(metadata.event_timestamp)
order:
$targets desc

The operating system talking SMB to a file server is normal. powershell.exe, cmd.exe, rundll32.exe or a binary in a user-writable folder opening port 445 on 40 hosts is not. Process fields are filled only by endpoint telemetry; if the row is blank, your source is a firewall and the answer is in the EDR.

Pivot 2: did any door open. A sweep is reconnaissance until a logon succeeds.

metadata.event_type = "USER_LOGIN"
principal.hostname = "WKSTN-0142"
security_result.action = "ALLOW"
match:
target.hostname, target.user.userid
outcome:
$logons = count(metadata.id)
order:
$logons desc

One account succeeding on many targets from a single workstation is the pattern to escalate. Which side of a logon lands in principal and which in target varies by parser, so open one raw event before trusting the grouping.

Noise to expect. Scanners and management servers, as above. Also developers running network tools, and VDI or NAT pools where many users share one hostname.

Hunt 2: Privilege escalation

Hypothesis. In a cloud project the cheapest escalation is not an exploit, it is an IAM binding. An attacker holding a developer's session or a leaked service account key grants a broader role to themselves or to an account they control. Legitimate IAM changes come from a small, known set of principals: the IAM admin team and the infrastructure pipeline.

metadata.event_type = "USER_RESOURCE_UPDATE_PERMISSIONS"
metadata.log_type = "GCP_CLOUDAUDIT"
principal.user.email_addresses != ""
match:
principal.user.email_addresses
outcome:
$changes = count(metadata.id)
$resources = count_distinct(target.resource.name)
$methods = array_distinct(metadata.product_event_type)
$first_change = earliest(metadata.event_timestamp)
order:
$changes asc

Read the results. Set the time range to 90 days and sort ascending, because the interesting rows are the low-volume ones, not the top of the list. A pipeline service account with 4,000 changes is doing its job. An account with two changes, both this week, that has never touched IAM before is the one to open. Cross off the admin team and the pipeline, then explain every name that is left.

Pivot: what was granted. Filter to one principal, drop the match: and outcome: sections, and read the events themselves.

metadata.event_type = "USER_RESOURCE_UPDATE_PERMISSIONS"
metadata.log_type = "GCP_CLOUDAUDIT"
principal.user.email_addresses = "dev@example.com"

For each event answer three questions:

  • Which resource? target.resource.name shows whether the binding is on one bucket or on the whole project or organization.
  • Which role, to whom? The raw audit log carries the change under policyDelta.bindingDeltas: the action (ADD), the role, and the member. Roles that deserve an immediate look are roles/owner, roles/editor, roles/iam.serviceAccountTokenCreator, roles/iam.serviceAccountUser and roles/resourcemanager.projectIamAdmin.
  • From where? Compare principal.ip and its country with the account's usual logins. A grant made from an address the user has never used is a compromised credential until shown otherwise.

Noise to expect. Terraform and CI service accounts, Google-managed service agents, and the automatic bindings created with every new project. If the caller lands in principal.user.userid on your parser version, the email field is empty; group by that field instead.

Hunt 3: Data exfiltration

Hypothesis. Data theft is bytes leaving. However the attacker packages it, the upload shows up as one host sending far more than its peers, or far more than it sent last week.

metadata.event_type = "NETWORK_CONNECTION"
network.direction = "OUTBOUND"
principal.hostname != ""
network.sent_bytes > 0
match:
principal.hostname by day
outcome:
$total_sent = sum(network.sent_bytes)
$destinations = count_distinct(target.ip)
order:
$total_sent desc
limit:
50

Read the results. network.sent_bytes is in bytes: 1 GB is about 1.07 billion and 50 GB about 53.7 billion. Compare each host on two axes.

  • Against its peers. A developer workstation at 50 GB when the rest of the team sends 1 to 2 GB deserves scrutiny.
  • Against itself. The by day bucket shows the host that sends 1 GB every day and 40 GB on Thursday.

Then read $destinations beside the total. High bytes to very few destinations is the shape of one large upload. High bytes spread over hundreds of destinations is usually backup, sync or update traffic.

Pivot: where did it go.

metadata.event_type = "NETWORK_CONNECTION"
network.direction = "OUTBOUND"
principal.hostname = "DEV-LT-077"
match:
target.ip
outcome:
$sent = sum(network.sent_bytes)
$countries = array_distinct(target.ip_geo_artifact.location.country_or_region)
$first = earliest(metadata.event_timestamp)
$last = latest(metadata.event_timestamp)
order:
$sent desc
limit:
20

For the top destination, establish who owns the address (a sanctioned cloud tenant, a personal file-sharing service, or a bare VPS), when the transfer ran ($first and $last at 02:00 on a Sunday read differently from a Tuesday afternoon), and which process sent it, from the EDR.

The slow leak. An attacker who moves 500 MB a night never tops a daily list. Rerun the first query over 30 days with by day removed, so the ranking is by total volume across the month.

Noise to expect. Backup agents, cloud sync clients, video calls, and build machines pushing artifacts. Two data caveats also apply. If all egress runs through a proxy, the proxy is the principal and you should hunt in its logs instead. And if the query returns nothing, your network parser may not set network.direction; drop that line and exclude private destinations with NOT target.ip = /^(10\.|192\.168\.|172\.(1[6-9]|2[0-9]|3[01])\.)/.

Hunt 4: Persistence

Hypothesis. A foothold that dies on reboot is worth little. Scheduled tasks and cron jobs survive a restart, need no extra tooling, and look like routine administration, which is why attackers keep using them.

metadata.event_type = "SCHEDULED_TASK_CREATION"
principal.hostname != ""
match:
principal.hostname, principal.user.userid
outcome:
$tasks_created = count(metadata.id)
$task_names = array_distinct(target.resource.name)
$first_created = earliest(metadata.event_timestamp)
order:
$tasks_created asc

UDM has a dedicated event type for this. RESOURCE_CREATION with a resource type of SCHEDULED_TASK is not a valid filter, because that resource type does not exist (the enum value is TASK).

Read the results. Sort ascending: rare is the signal. Look for task creation on servers that seldom change, by service accounts that have no reason to schedule work, and by ordinary users on servers. Read the names too. A task called GoogleUpdateTaskMachineUA2 or a random GUID on a single host is worth five minutes.

Pivot 1: how many hosts share this task. Stack-count by task name. Software deployed by IT appears on hundreds of machines; an attacker's task appears on one or a handful.

metadata.event_type = "SCHEDULED_TASK_CREATION"
target.resource.name != ""
match:
target.resource.name
outcome:
$hosts = count_distinct(principal.hostname)
order:
$hosts asc

Pivot 2: what the task runs. Open the event and read the command. These deserve escalation:

  • A binary in a writable folder: \Users\Public, \AppData\Local\Temp, \ProgramData, /tmp, /dev/shm.
  • An interpreter doing the work: powershell -enc, mshta, rundll32, regsvr32, or curl piped to a shell.
  • A task that runs as SYSTEM or root, triggered at logon or every few minutes.

If your source only logs process launches. Some log sources never emit the task event. Catch the tool that creates the task instead.

metadata.event_type = "PROCESS_LAUNCH"
target.process.command_line = /schtasks(\.exe)?\s.*\/create/ nocase

On Linux, swap the pattern for /\bcrontab\b/ and review file writes under /etc/cron.d and /var/spool/cron.

Noise to expect. Browser and office updaters, endpoint management agents, backup software and tasks pushed by group policy. The host count in Pivot 1 separates nearly all of it. Where the parser stores the task name varies by source, so confirm the field on one event first.

From hunt to detection

A hunt becomes a rule when the pattern is stable, the exclusions are known, and you would want to be woken up for it. Hunt 1 qualifies once you have listed your scanners and management servers. Here it is as a multi-event YARA-L rule.

***Data Table reference will not allow this rule to compile without first configuring it in your SecOps tenant

rule lateral_movement_internal_fanout {

meta:
author = "Tuesday Tips"
description = "One host connects to more than 30 distinct internal IPs on admin ports within 15 minutes"
severity = "MEDIUM"
mitre_attack_technique = "T1021"

events:
$e.metadata.event_type = "NETWORK_CONNECTION"
$e.principal.hostname = $host
$e.principal.hostname != ""
net.ip_in_range_cidr($e.target.ip, "10.0.0.0/8")
($e.target.port = 445 or $e.target.port = 3389 or
$e.target.port = 5985 or $e.target.port = 22)
not $e.principal.hostname in %lateral_movement_exclusions.hostname

match:
$host over 15m

outcome:
$unique_targets = count_distinct($e.target.ip)

condition:
$e and $unique_targets > 30
}

Each part of the hunt has a counterpart in the rule:

In the hunt In the rule
Filter lines events: section, each field prefixed with the event variable $e
match: principal.hostname by hour match: $host over 15m, a sliding window instead of a fixed bucket
Sort descending and read the top rows condition: with the threshold, $unique_targets > 30
The legitimate hosts you wrote down A reference list or data table, here %lateral_movement_exclusions.hostname

Take the threshold from your own results, not from this brief: set it above the busiest legitimate host that remains after exclusions. Then run the rule as a retrohunt over the last two weeks before you enable alerting, so its first night is not a surprise. Adjust the CIDR range to your own address plan.

Not every hunt should become a rule. Hunts 2 and 4 convert well, because the event is rare and the exclusions are short. Hunt 3 depends on a per-host baseline, so it works better as a scheduled search or dashboard that a person reviews weekly.

Field notes

These limits and defaults skew hunt results without raising an error.

  • Row and range caps. A statistical search returns at most 100,000 rows and covers at most 90 days. For a longer baseline, run consecutive windows.
  • Truncated arrays. array and array_distinct keep 1,000 elements chosen at random. Use them to sample values, never to prove something is absent.
  • Case sensitivity. String matches are case-sensitive unless you add nocase. principal.hostname = "wkstn-0142" will miss WKSTN-0142.
  • No regex on enums. metadata.event_type = /NETWORK_.*/ is invalid. List the event types with OR.
  • Fresh data lags. Statistical results wait for ingestion processing to finish, so the last few minutes are incomplete. Hunt on a window that ended at least an hour ago.
  • Hostnames depend on enrichment. If principal.hostname is empty for a source, group by principal.ip, and remember that DHCP can hand one address to several machines in a week.
  • A blank result is a finding. If a hunt returns nothing at all, check first whether the log source produces that event type. A visibility gap is worth reporting on its own.

Try it this week

  • Run Hunt 1 over the last 7 days and write down every legitimate host in the top 20. That list is your first exclusion list.
  • Run Hunt 2 over 90 days, sorted ascending, and get an owner's explanation for every principal outside the admin team.
  • Run Hunt 3 for one team's workstations, find the largest single-day outlier, and pivot to its destinations.
  • Run the Hunt 4 host count and explain every task that exists on only one machine.
  • Pick the hunt with the cleanest results, convert it to a rule, and retrohunt two weeks before enabling it.