Iniciar sesión

Finding beacons

15 min · 2 ejercicio(s)

Malware that is controlled remotely (command and control, C2) calls home regularly: same process, same destination, similar small payload, roughly fixed intervals. This is called beaconing (MITRE ATT&CK T1071).

A statistical hunt for beacons:

FROM lab-endpoint
| WHERE event.category == "network" AND NOT CIDR_MATCH(destination.ip, "10.0.0.0/8")
| STATS connections = COUNT(*),
        avg_bytes   = AVG(source.bytes),
        first       = MIN(@timestamp),
        last        = MAX(@timestamp)
     BY host.name, process.name, destination.ip
| EVAL minutes = DATE_DIFF("minute", first, last)
| WHERE connections > 10
| SORT connections DESC

Things to look for:

  • Many connections, small average size. A browser downloads a lot, a beacon only says "any tasks for me?".
  • Unusual process. powershell.exe or an unknown binary talking to the internet is suspicious, chrome.exe is not.
  • Duration. A beacon keeps going for hours.

🔎 Profundiza: funciones, errores habituales y práctica

Beacon features you can compute

| Feature | ES|QL | |---|---| | Number of connections | COUNT(*) | | Payload size and its variation | AVG(source.bytes), STD_DEV(source.bytes) | | Duration of the activity | DATE_DIFF("minute", MIN(@timestamp), MAX(@timestamp)) | | Regularity | connections per minute: count / minutes close to a constant | | Spread | COUNT_DISTINCT(host.name) per destination: C2 is usually contacted by few hosts |

Jitter

Real C2 frameworks add random jitter (e.g. 60 s ± 20 %). Don't look for exact intervals. Look for low variation in size and a stable rate over a long time.

Reduce noise

  • Exclude known good destinations (update services, SaaS) with NOT CIDR_MATCH(...) or a lookup index of allowed ranges.
  • Focus on unusual processes: script hosts, Office applications, binaries in user-writable paths (process.executable LIKE "C:\\Users\\*").
  • Many beacons use HTTPS on 443, so port alone is not a filter.

From hunt to rule

A good hunting query can become an ES|QL detection rule in Elastic Security. The rule runs your query on a schedule and creates an alert for every row it returns.

Ejercicios prácticos de esta lección

Resuelve estos ejercicios con una consulta en el laboratorio Elasticsearch real. Inicia sesión gratis para acceder al laboratorio, las pistas y la corrección automática.

  1. 1. Find the C2 server

    One process on a Windows workstation (host.os.family) connects to the same external IP over and over with small payloads (average below 1,000 bytes). What is the destination IP?

  2. 2. Which process beacons?

    Which process name talks to that C2 server?