LoFP LoFP / 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.

Techniques

Sample rules

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.

Detection logic

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.*