# Copyright 2026 Tailwind Resource Group # SPDX-License-Identifier: Apache-2.0 # Provided as is, with no warranty. License: https://everythingsfine.io/license/ # # emudhra_probe # # Attach to an internal virtual that only the gateway's sideband reaches: # a standard virtual on an unused address, enabled on no VLANs. The gateway # connects to it by name. Create iRule emudhra_lib first. Uses the static:: # settings defined in emudhra_gw RULE_INIT (cache TTLs, mode, HSL pool). # Supported: BIG-IP 17.5 and later. # # Profiles: tcp + server-ssl "emudhra_probe_serverssl" with # peer-cert-mode require, ca-file ca-bundle.crt, retain-certificate enabled, # untrusted-cert-response-control ignore, expire-cert-response-control ignore, # TLS 1.3 allowed (remove no-tlsv1.3 from options; use a cipher group with # TLS 1.3 suites, e.g. f5-default), and NO server-name (SNI is injected here). # SNAT automap (or your egress SNAT) and a route so the probe reaches the internet. # # What a probe shows: the chain the destination sends to the BIG-IP's own # handshake. A server can choose its certificate by client capabilities, and an # attacker can treat the probe differently from a victim, so a probe result is # stored and logged as src=probe, apart from passive observations. # # Protocol (one line each way): # in : PROBE []\n # out: OK label=.. depth=.. match=.. fp=.. certs=.. verify=\n # ERR \n # The verdict is written to the shared "emudhra" cache and logged here, so the # gateway can fire and forget. The reply line is only read in hold mode. # Probe failures are recorded as UNKNOWN (short TTL), never as CLEAN. Every # outcome attributes the initiating client and the clients that arrived while # the probe was in flight (probe_done in emudhra_lib). when CLIENT_ACCEPTED { set pr_sni "" set pr_ip "" set pr_port "" set pr_key "" set pr_client "" set pr_done 0 set pr_hsl [HSL::open -proto UDP -pool $static::emu_hsl_pool] TCP::collect } when CLIENT_DATA { set req [TCP::payload] if {![regexp {^PROBE ([0-9a-fA-F.:%]+) ([0-9]{1,5}) ([a-z0-9._-]{1,253}|-)(?: ([0-9a-fA-F.:%]{1,64}))?\r?\n} $req -> pr_ip pr_port sni pr_client]} { if {[string length $req] < 512 && [string first "\n" $req] < 0} { TCP::collect ; return } set pr_done 1 TCP::respond "ERR badrequest\n" TCP::close return } if {$sni ne "-"} { set pr_sni $sni } if {[catch {call /Common/emudhra_lib::dest_key $pr_sni $pr_ip $pr_port} pr_key]} { set pr_key "" set pr_done 1 TCP::respond "ERR internal\n" TCP::close return } node $pr_ip $pr_port # Drop the request line; nothing is sent to the server but the handshake. # Verified on 17.5.1.9: the server side connects after this empty release. TCP::payload replace 0 [TCP::payload length] "" TCP::release } when SERVERSSL_CLIENTHELLO_SEND { if {$pr_sni ne ""} { # server_name extension: type 0, ext len, list len, name_type 0, name len, name set l [string length $pr_sni] SSL::extensions insert [binary format SSScSa* 0 [expr {$l + 5}] [expr {$l + 3}] 0 $l $pr_sni] } } when SERVERSSL_HANDSHAKE { set ders [list] set n [SSL::cert count] for {set i 0} {$i < $n} {incr i} { # An unconvertible cert stays in the list as "" so the chain cannot be CLEAN. if {[catch {call /Common/emudhra_lib::der_from_pem [X509::whole [SSL::cert $i]]} d]} { set d "" } lappend ders $d } set vr [SSL::verify_result] if {[catch {call /Common/emudhra_lib::classify_chain $ders} v]} { set v "UNKNOWN label=- depth=-1 match=- fp=- certs=$n reason=classify_error" } set pr_done 1 catch {call /Common/emudhra_lib::probe_done $pr_key $v $pr_hsl $pr_client $pr_ip $pr_port $pr_sni} clientside { TCP::respond "OK $v verify=$vr\n" TCP::close } TCP::close } when SERVER_CLOSED { if {!$pr_done} { set pr_done 1 if {$pr_key ne ""} { catch {call /Common/emudhra_lib::probe_done $pr_key "UNKNOWN label=- depth=-1 match=- fp=- certs=0 reason=server_closed" $pr_hsl $pr_client $pr_ip $pr_port $pr_sni} } clientside { TCP::respond "ERR server_closed\n" TCP::close } } } when LB_FAILED { if {!$pr_done} { set pr_done 1 if {$pr_key ne ""} { catch {call /Common/emudhra_lib::probe_done $pr_key "UNKNOWN label=- depth=-1 match=- fp=- certs=0 reason=lb_failed" $pr_hsl $pr_client $pr_ip $pr_port $pr_sni} } TCP::respond "ERR lb_failed\n" TCP::close } }