from logs-endpoint.events.network-*
| where
@timestamp > now() - 1h and
host.os.type == "linux" and
event.type == "start" and
event.action == "connection_attempted"
| keep
@timestamp,
host.os.type,
event.type,
event.action,
destination.port,
process.executable,
destination.ip,
agent.id,
host.name
| stats
Esql.event_count = count(),
Esql.destination_port_count_distinct = count_distinct(destination.port),
Esql.agent_id_count_distinct = count_distinct(agent.id),
Esql.host_name_values = values(host.name),
Esql.agent_id_values = values(agent.id)
by process.executable, destination.ip
| where
Esql.agent_id_count_distinct == 1 and
Esql.destination_port_count_distinct > 100
| sort Esql.event_count asc
| limit 100
Install detection rules in Elastic Security
Detect Potential Port Scanning Activity from Compromised Host in the Elastic Security detection engine by installing this rule into your Elastic Stack.
To setup this rule, check out the installation guide for Prebuilt Security Detection Rules(opens in a new tab or window).