text code block:from logs-endpoint.events.network-* | where @timestamp > now() - 1h and host.os.type == "linux" and event.type == "start" and event.action == "connection_attempted" and network.direction == "egress" and destination.port < 32768 and not ( cidr_match(destination.ip, "127.0.0.0/8", "::1", "FE80::/10", "FF00::/8") or process.executable in ( "/opt/dbtk/bin/jsvc", "/usr/lib/dotnet/dotnet", "/usr/share/elasticsearch/jdk/bin/java", "/usr/sbin/haproxy", "/usr/bin/java", "/opt/kaspersky/kesl/libexec/kesl", "/usr/bin/dotnet", "/opt/java/openjdk/bin/java" ) or process.executable like "/var/opt/kaspersky/kesl/*kesl" or process.executable like "/usr/lib/jvm/*/java" or process.executable like "/opt/google/chrome*" or process.executable like "/var/lib/docker/*/java" or process.executable like "/usr/lib64/jvm/*/java" or process.executable like "/snap/*" or process.executable like "/home/*/.local/share/JetBrains/*" ) | keep @timestamp, host.os.type, event.type, event.action, destination.port, process.executable, destination.ip, source.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), Esql.source_ip_values = values(source.ip) 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(external, opens in a new tab or window).