Endpoint Discovery Commands Followed by IMDS Requests
Description
Detects a process that spawns multiple distinct host, user or network discovery utilities and within a short time window, accesses the cloud instance metadata service (IMDS), either directly or through a child process. Network requests to additional metadata endpoints, respective of the provider also meet this criteria.
Query · esql
FROM logs-endpoint.events.process-*, logs-endpoint.events.network-*
| WHERE host.os.type IN ("linux", "macos")
| WHERE
(
MV_CONTAINS(event.action, "exec")
AND
process.name.caseless IN (
// Linux
"ip", "ss", "hostnamectl", "uptime", "uname", "whoami", "id", "hostname",
"netstat", "arp", "ifconfig", "route", "w", "who",
"last", "getent", "dmidecode",
// macOS
"sw_vers", "system_profiler", "scutil", "networksetup", "ioreg",
"sysctl", "dscl", "dscacheutil", "csrutil", "spctl", "users", "groups"
)
)
OR destination.ip IN ("169.254.169.254", "169.254.170.2", "169.254.170.23", "100.100.100.200", "168.63.129.16")
| WHERE process.parent.executable IS NULL OR NOT (
process.parent.executable LIKE "/Library/Application Support/JAMF/*" OR
process.parent.executable LIKE "/usr/local/jamf/*" OR
process.parent.executable LIKE "/opt/puppetlabs/*" OR
process.parent.executable LIKE "/opt/chef/*" OR
process.parent.executable LIKE "/usr/lib/google-cloud-sdk/*" OR
process.parent.executable LIKE "/Applications/Docker.app/Contents/MacOS/*"
)
| EVAL
is_recon = process.name.caseless IN (
"ip", "ss", "hostnamectl", "uptime", "uname", "whoami", "id", "hostname",
"netstat", "arp", "ifconfig", "route", "w", "who",
"last", "getent", "dmidecode",
"sw_vers", "system_profiler", "scutil", "networksetup", "ioreg",
"sysctl", "dscl", "dscacheutil", "csrutil", "spctl", "users", "groups"
) AND MV_CONTAINS(event.category, "process"),
is_metadata = destination.ip IN ("169.254.169.254", "169.254.170.2", "169.254.170.23", "100.100.100.200", "168.63.129.16")
// recon events correlate on their parent, metadata events on both themselves and their parent
| EVAL
Esql.correlation_id = CASE(
is_recon,
process.parent.entity_id,
MV_APPEND(process.entity_id, process.parent.entity_id)
),
recon_command = CASE(is_recon, process.name.caseless, null),
metadata_access = CASE(is_metadata, 1, 0)
| MV_EXPAND Esql.correlation_id
| WHERE Esql.correlation_id IS NOT NULL
| STATS
Esql.host_name_values = VALUES(host.name),
Esql.host_ip_values = VALUES(host.ip),
Esql.process_name_values = VALUES(process.name),
Esql.process_command_line_values = VALUES(process.command_line),
Esql.process_executable_values = VALUES(process.executable),
Esql.process_entity_id_values = VALUES(process.entity_id),
Esql.process_parent_entity_id_values = VALUES(process.parent.entity_id),
Esql.process_parent_name_values = VALUES(process.parent.name),
Esql.process_parent_executable_values = VALUES(process.parent.executable),
Esql.process_parent_command_line_values = VALUES(process.parent.command_line),
Esql.user_name_values = VALUES(user.name),
Esql.destination_ip_values = VALUES(destination.ip),
Esql.destination_port_values = VALUES(destination.port),
Esql.network_transport_values = VALUES(network.transport),
Esql.recon_command_values = VALUES(recon_command),
Esql.recon_command_count_distinct = COUNT_DISTINCT(recon_command),
Esql.metadata_access_count = SUM(metadata_access),
Esql.first_seen = MIN(@timestamp),
Esql.last_seen = MAX(@timestamp)
BY host.id, Esql.correlation_id
| WHERE Esql.recon_command_count_distinct >= 3
AND Esql.metadata_access_count > 0
AND DATE_DIFF("seconds", Esql.first_seen, Esql.last_seen) <= 10
| KEEP host.id, Esql.*
Known false positives
- Cloud bootstrap tooling, guest agents, configuration management and monitoring agents may run discovery commands and query the instance metadata service from the same parent process. Validate the parent executable and command line and exclude approved automation.
Analyst notes
Disclaimer: This investigation guide was created using generative AI technology and has been reviewed to improve its accuracy and relevance. While every effort has been made to ensure its quality, we recommend validating the content and adapting it to suit your specific environment and operational needs.
Investigating Endpoint Discovery Commands Followed by IMDS Requests
Each result groups the activity of a single parent process on a host: the discovery commands it spawned
(Esql.recon_command_values) and the connections to the instance metadata service made by the process itself or by
one of its children. The correlation key is stored in Esql.correlation_id.
Possible investigation steps
- Review
Esql.process_parent_executable_valuesandEsql.process_parent_command_line_valuesto identify the process that drove the activity and determine whether it is an interactive shell, a script interpreter, a web application, or approved automation. - Inspect
Esql.process_command_line_valuesfor the exact discovery commands and any metadata request paths such as/latest/meta-data/iam/security-credentials/(AWS),/metadata/identity/oauth2/token(Azure), or/computeMetadata/v1/instance/service-accounts/(GCP). - Identify the user in
Esql.user_name_valuesand the session context, and check whether the activity followed a remote login, an exploit, or the execution of a newly dropped file. - Correlate the host and time window with cloud control-plane logs to determine whether instance role credentials or managed identity tokens were subsequently used from this host or from an external IP address.
- Look for follow-on behavior such as cloud CLI or SDK usage, credential staging to disk, or outbound connections to unfamiliar destinations.
False positive analysis
- Cloud-init, cloud guest agents, configuration management tools (Puppet, Chef, Salt, Ansible), MDM agents, and monitoring agents can legitimately run discovery utilities and query the metadata service. Confirm the parent executable path and exclude approved tooling by path or command line.
- In-house bootstrap or service startup scripts may collect host details and read instance metadata. Validate the script location, owner, and execution schedule.
Response and remediation
- Isolate the affected instance or host and terminate the offending process tree.
- Revoke or rotate any instance role credentials, managed identity tokens, or secrets that may have been retrieved from the metadata service, and review the permissions attached to the instance role.
- Remove any dropped scripts, binaries, or persistence mechanisms associated with the activity.
- Enforce IMDSv2 or the strongest metadata protections offered by the cloud provider and restrict metadata access to the processes that require it.