Potential On-Path Relay in a TCP Flow

Identifies an IPv4 TCP connection initially observed between two Ethernet addresses and then observed on two legs through a third MAC address. This path change can follow ARP cache poisoning of a host and its gateway. The alert identifies the potential relay so an analyst can verify how traffic was redirected.

Elastic rule (View on GitHub)

 1[metadata]
 2creation_date = "2026/11/26"
 3integration = ["network_traffic"]
 4maturity = "production"
 5min_stack_comments = "Uses ES|QL FIRST with MAC address and timestamp fields and MV_INTERSECTION to identify the relay."
 6min_stack_version = "9.5.0"
 7updated_date = "2026/11/26"
 8
 9[rule]
10author = ["Elastic"]
11description = """
12Identifies an IPv4 TCP connection initially observed between two Ethernet addresses and then observed on two legs
13through a third MAC address. This path change can follow ARP cache poisoning of a host and its gateway. The alert
14identifies the potential relay so an analyst can verify how traffic was redirected.
15"""
16false_positives = [
17    """
18    Insertion of an authorized inline appliance or a route change during an active connection can produce the same path.
19    """,
20]
21from = "now-9m"
22interval = "5m"
23language = "esql"
24license = "Elastic License v2"
25name = "Potential On-Path Relay in a TCP Flow"
26note = """## Triage and analysis
27
28### Investigating Potential On-Path Relay in a TCP Flow
29
30This rule detects a TCP connection whose Ethernet path changes from a direct MAC pair to two legs through a third MAC
31address. This can indicate that ARP cache poisoning redirected an existing connection through an on-path relay.
32
33The rule requires the sensor to observe the direct path before both relay legs. It does not detect connections opened
34after poisoning is already in place, or interception that terminates and proxies the connection under a different
35Community ID instead of forwarding it.
36
37### Possible investigation steps
38
39- Look up `Esql.relay_mac` in the switch forwarding table for the capture segment. Identify the asset and switch port.
40  Compare this device with the original Ethernet peers and the expected next hop for each IP.
41- Pivot on `network.community_id` and `agent.id` around `Esql.relay_start`. Compare the MAC pairs in the flow
42  records. The original path must be at least five seconds old, and the two new legs must begin within two seconds of
43  each other while that path is active or within thirty seconds of its last packet.
44- Examine ARP captures, neighbor tables, or switch inspection logs for a new IP-to-MAC binding involving the relay.
45
46### False positive analysis
47
48- Check for a routing change, an authorized inline appliance, or a sensor receiving mirrored traffic from multiple
49  segments. Verify the path change and relay MAC with the network owner before creating an exception.
50
51### Response and remediation
52
53- If interception is confirmed, preserve the flow and ARP evidence, contain the relay at its switch port, restore the
54  correct bindings, and review credentials or sessions exposed on the affected path.
55"""
56references = [
57    "https://csirt.divd.nl/downloads/DIVD-2026-00014/DIVD-2026-00014-forensics-report.pdf",
58    "https://www.elastic.co/docs/reference/integrations/network_traffic",
59    "https://www.elastic.co/docs/reference/beats/packetbeat/configuration-flows",
60]
61risk_score = 47
62rule_id = "afd05c1d-8e53-4dc5-94c3-fd8ba0b3bf21"
63setup = """## Setup
64
65- In Elastic Network Packet Capture, enable **Flows** and set **Interface** to the Ethernet NIC receiving the traffic.
66  Use a TAP or switch mirror carrying both directions of the monitored segment. Enable promiscuous mode on the
67  receiving NIC for mirrored unicast traffic. Linux cooked captures (commonly from `any`) and loopback captures
68  can omit the Ethernet addresses. Packetbeat populates both MAC fields from the Ethernet header automatically.
69- The default **Period** (`10s`) and **Flow timeout** (`30s`) are suitable. Periodic reports let the rule evaluate
70  active connections. Keep **Map root Packetbeat fields to ECS** enabled so tagged flows carry
71  `network_traffic.flow.vlan`. On a tagged trunk, preserve the tags and enable **Configure BPF to account for VLAN
72  tags** when using Packetbeat's generated capture filter. Use one capture segment per agent for untagged traffic.
73- Within the nine-minute lookback, the same agent must report the original MAC pair and both new pairs for the same
74  Community ID and VLAN. The relay timing uses packet-derived `event.start` and `event.end`, so the reporting
75  period can exceed two seconds.
76
77Use this KQL filter in Discover to verify that the capture produces eligible flow records.
78
79```kql
80data_stream.dataset:"network_traffic.flow" and network.type:ipv4 and network.transport:tcp and
81source.mac:* and destination.mac:* and network.community_id:* and event.start:* and event.end:*

""" severity = "medium" tags = [ "Domain: Network", "Tactic: Credential Access", "Tactic: Collection", "Use Case: Threat Detection", "Use Case: Network Security Monitoring", "Data Source: Network Packet Capture", "Resources: Investigation Guide", "Rule Type: ES|QL", ] timestamp_override = "event.ingested" type = "esql"

query = ''' FROM logs-network_traffic.flow-* | WHERE network.type == "ipv4" AND network.transport == "tcp" AND agent.id IS NOT NULL AND network.community_id IS NOT NULL AND event.start IS NOT NULL AND event.end IS NOT NULL AND source.ip != destination.ip AND source.mac != destination.mac // Orient each Ethernet leg by IP so reverse-direction reports describe the same path. | EVAL Esql.peer_a = LEAST(source.ip, destination.ip), Esql.peer_b = GREATEST(source.ip, destination.ip), Esql.vlan = MV_CONCAT(TO_STRING(network_traffic.flow.vlan), "/") | EVAL mac_a = CASE(source.ip == Esql.peer_a, source.mac, destination.mac), mac_b = CASE(source.ip == Esql.peer_a, destination.mac, source.mac), Esql.leg_start = event.start | EVAL Esql.leg_key = CONCAT(mac_a, "|", mac_b) // Collapse periodic reports for each flow instance without merging a restored direct path into the earlier instance. | STATS Esql.leg_end = MAX(event.end) BY agent.id, Esql.vlan, network.community_id, Esql.peer_a, Esql.peer_b, mac_a, mac_b, Esql.leg_key, Esql.leg_start // Attach the three-leg topology to every retained instance so each direct instance can be evaluated independently. | INLINE STATS Esql.legs = COUNT_DISTINCT(Esql.leg_key), macs_a = VALUES(mac_a), macs_b = VALUES(mac_b) BY agent.id, Esql.vlan, network.community_id, Esql.peer_a, Esql.peer_b | WHERE Esql.legs == 3 AND MV_COUNT(macs_a) == 2 AND MV_COUNT(macs_b) == 2 | EVAL relay_macs = MV_INTERSECTION(macs_a, macs_b) | WHERE MV_COUNT(relay_macs) == 1 | EVAL Esql.relay_mac = MV_FIRST(relay_macs) | EVAL is_direct = mac_a != Esql.relay_mac AND mac_b != Esql.relay_mac // Preserve the start and side of every relay-leg instance for candidate pairing. | EVAL relay_candidate = CASE( NOT is_direct, CONCAT(TO_STRING(Esql.leg_start), "|", CASE(mac_a == Esql.relay_mac, "a", "b")), null ) | INLINE STATS relay_candidates = VALUES(relay_candidate) WHERE relay_candidate IS NOT NULL BY agent.id, Esql.vlan, network.community_id, Esql.peer_a, Esql.peer_b | WHERE is_direct AND MV_COUNT(relay_candidates) >= 2 | EVAL candidate_1 = relay_candidates, candidate_2 = relay_candidates, Esql.original_mac_a = mac_a, Esql.original_mac_b = mac_b, Esql.direct_start = Esql.leg_start, Esql.direct_end = Esql.leg_end | MV_EXPAND candidate_1 | MV_EXPAND candidate_2 | EVAL relay_start_1 = TO_DATETIME(MV_FIRST(SPLIT(candidate_1, "|"))), relay_start_2 = TO_DATETIME(MV_FIRST(SPLIT(candidate_2, "|"))), relay_side_1 = MV_LAST(SPLIT(candidate_1, "|")), relay_side_2 = MV_LAST(SPLIT(candidate_2, "|")) | WHERE relay_side_1 != relay_side_2 | EVAL Esql.relay_start = LEAST(relay_start_1, relay_start_2), last_leg_start = GREATEST(relay_start_1, relay_start_2) | WHERE Esql.relay_mac != Esql.original_mac_a AND Esql.relay_mac != Esql.original_mac_b AND Esql.relay_start >= Esql.direct_start + 5 seconds AND Esql.relay_start <= Esql.direct_end + 30 seconds AND last_leg_start <= Esql.relay_start + 2 seconds | SORT Esql.relay_start DESC, Esql.direct_start DESC | LIMIT 1 BY agent.id, Esql.vlan, network.community_id, Esql.peer_a, Esql.peer_b | KEEP agent.id, Esql.vlan, network.community_id, Esql.peer_a, Esql.peer_b, Esql.original_mac_a, Esql.original_mac_b, Esql.relay_mac, Esql.direct_start, Esql.direct_end, Esql.relay_start '''

[[rule.threat]] framework = "MITRE ATT&CK" [[rule.threat.technique]] id = "T1557" name = "Adversary-in-the-Middle" reference = "https://attack.mitre.org/techniques/T1557/" [[rule.threat.technique.subtechnique]] id = "T1557.002" name = "ARP Cache Poisoning" reference = "https://attack.mitre.org/techniques/T1557/002/"

[rule.threat.tactic] id = "TA0006" name = "Credential Access" reference = "https://attack.mitre.org/tactics/TA0006/" [[rule.threat]] framework = "MITRE ATT&CK" [[rule.threat.technique]] id = "T1557" name = "Adversary-in-the-Middle" reference = "https://attack.mitre.org/techniques/T1557/" [[rule.threat.technique.subtechnique]] id = "T1557.002" name = "ARP Cache Poisoning" reference = "https://attack.mitre.org/techniques/T1557/002/"

[rule.threat.tactic] id = "TA0009" name = "Collection" reference = "https://attack.mitre.org/tactics/TA0009/"

[rule.alert_suppression] group_by = ["agent.id", "network.community_id", "Esql.relay_start"] missing_fields_strategy = "doNotSuppress"

[rule.alert_suppression.duration] unit = "h" value = 1

Triage and analysis

Investigating Potential On-Path Relay in a TCP Flow

This rule detects a TCP connection whose Ethernet path changes from a direct MAC pair to two legs through a third MAC address. This can indicate that ARP cache poisoning redirected an existing connection through an on-path relay.

The rule requires the sensor to observe the direct path before both relay legs. It does not detect connections opened after poisoning is already in place, or interception that terminates and proxies the connection under a different Community ID instead of forwarding it.

Possible investigation steps

  • Look up Esql.relay_mac in the switch forwarding table for the capture segment. Identify the asset and switch port. Compare this device with the original Ethernet peers and the expected next hop for each IP.
  • Pivot on network.community_id and agent.id around Esql.relay_start. Compare the MAC pairs in the flow records. The original path must be at least five seconds old, and the two new legs must begin within two seconds of each other while that path is active or within thirty seconds of its last packet.
  • Examine ARP captures, neighbor tables, or switch inspection logs for a new IP-to-MAC binding involving the relay.

False positive analysis

  • Check for a routing change, an authorized inline appliance, or a sensor receiving mirrored traffic from multiple segments. Verify the path change and relay MAC with the network owner before creating an exception.

Response and remediation

  • If interception is confirmed, preserve the flow and ARP evidence, contain the relay at its switch port, restore the correct bindings, and review credentials or sessions exposed on the affected path.

References

Related rules

to-top