Socket Filters
Adversaries may attach Berkeley Packet Filter (BPF) programs or libpcap-based filters to raw network sockets to create passive backdoors that activate only upon receipt of crafted "magic" packets. Unlike conventional backdoors that maintain open listening ports, socket filter implants remain completely dormant—consuming negligible CPU, maintaining no active connections, and appearing nowhere in netstat or ss output—until a specially crafted packet matching the filter criteria arrives on the monitored interface. Implementation uses either libpcap's pcap_setfilter() function or the POSIX setsockopt() system call with SO_ATTACH_FILTER (cBPF, optname 26) or SO_ATTACH_BPF (eBPF, optname 50). The technique requires CAP_NET_RAW or CAP_NET_ADMIN on Linux, or Administrator rights on Windows with WinPcap/Npcap installed. Confirmed real-world malware families include BPFDoor (attaches BPF filters monitoring ICMP, UDP, and TCP traffic on ports 22/80/443, triggered by a "magic" byte sequence in incoming packets to spawn a reverse shell), Penquin/Turla (installs TCP and UDP filters on the eth0 interface for C2 activation), CASTLETAP (listens for specialized ICMP packets on compromised Fortinet devices), and PITSTOP (evaluates commands on a domain socket at /data/runtime/cockpit/wd.fd using a predefined magic byte sequence). Detection is exceptionally difficult due to the passive nature of the implant: no open ports, minimal CPU overhead, and limited enterprise visibility into raw socket API usage.
// T1205.002 — Socket Filters / BPF Passive Backdoor Detection
// REQUIREMENT: Linux auditd with syslog forwarding to Microsoft Sentinel.
// Deploy these auditd rules on monitored Linux hosts:
// -a always,exit -F arch=b64 -S socket -k bpf_socket_filter
// -a always,exit -F arch=b64 -S setsockopt -k bpf_socket_filter
// -a always,exit -F arch=b64 -S execve -k bpf_socket_filter
// Signal 1 (highest fidelity) is specific to setsockopt SO_ATTACH_FILTER.
// Signal 3 requires MDE Linux agent and does not need auditd.
let LegitimateCaptureBinaries = dynamic([
"/usr/sbin/tcpdump", "/usr/bin/tcpdump",
"/usr/bin/tshark", "/usr/bin/dumpcap",
"/usr/sbin/dhclient", "/sbin/dhclient", "/usr/bin/dhclient",
"/usr/sbin/arping", "/usr/bin/ping", "/bin/ping",
"/usr/bin/nmap", "/usr/sbin/nmap",
"/usr/bin/hping3", "/usr/sbin/hping3",
"/usr/bin/scapy"
]);
// Signal 1: BPF filter attachment via setsockopt(SOL_SOCKET, SO_ATTACH_FILTER, ...)
// x86-64 Linux: syscall=54 (setsockopt), a1=1 (SOL_SOCKET=1), a2=1a (SO_ATTACH_FILTER=26=0x1a)
// This is the exact syscall BPFDoor and libpcap use to install packet filters.
let BPFFilterAttach = Syslog
| where TimeGenerated > ago(24h)
| where SyslogMessage contains "type=SYSCALL"
and SyslogMessage contains "syscall=54"
and SyslogMessage contains "a1=1"
and SyslogMessage contains "a2=1a"
| extend ProcessExe = extract(@"exe=\"([^\"]+)\"", 1, SyslogMessage)
| extend ProcessComm = extract(@"comm=\"([^\"]+)\"", 1, SyslogMessage)
| extend AuditUID = extract(@"\bauid=(\S+)", 1, SyslogMessage)
| extend HostPID = extract(@"\bpid=(\d+)", 1, SyslogMessage)
| extend HostPPID = extract(@"ppid=(\d+)", 1, SyslogMessage)
| where not(ProcessExe in~ (LegitimateCaptureBinaries))
| project TimeGenerated, HostName = Computer,
ProcessExe, ProcessComm, AuditUID, HostPID, HostPPID,
SignalType = "BPF_FILTER_SETSOCKOPT", ThreatLevel = "High";
// Signal 2: Raw packet socket creation by non-standard process
// AF_PACKET family = 17 = 0x11 (a0=11), or AF_INET+SOCK_RAW (a0=2 a1=3)
// x86-64 Linux: syscall=41 (socket())
let RawSocketCreate = Syslog
| where TimeGenerated > ago(24h)
| where SyslogMessage contains "type=SYSCALL"
and SyslogMessage contains "syscall=41"
and (
SyslogMessage contains " a0=11 " // AF_PACKET = 0x11
or (SyslogMessage contains " a0=2 " and SyslogMessage contains " a1=3 ") // AF_INET + SOCK_RAW
)
| extend ProcessExe = extract(@"exe=\"([^\"]+)\"", 1, SyslogMessage)
| extend ProcessComm = extract(@"comm=\"([^\"]+)\"", 1, SyslogMessage)
| extend AuditUID = extract(@"\bauid=(\S+)", 1, SyslogMessage)
| extend HostPID = extract(@"\bpid=(\d+)", 1, SyslogMessage)
| extend HostPPID = extract(@"ppid=(\d+)", 1, SyslogMessage)
| where not(ProcessExe in~ (LegitimateCaptureBinaries))
| project TimeGenerated, HostName = Computer,
ProcessExe, ProcessComm, AuditUID, HostPID, HostPPID,
SignalType = "RAW_SOCKET_AF_PACKET", ThreatLevel = "Medium";
// Signal 3: MDE on Linux — process execution from world-writable staging paths
// BPFDoor copies itself to /tmp or /dev/shm before attaching filters and deleting original
let BPFDoorStagingExec = DeviceProcessEvents
| where TimeGenerated > ago(24h)
| where OSPlatform has "Linux"
| where FolderPath startswith "/tmp/"
or FolderPath startswith "/dev/shm/"
or FolderPath startswith "/var/tmp/"
or FolderPath startswith "/run/shm/"
or FolderPath == "/var/run/initd.lock"
| where InitiatingProcessFileName !in~ (
"bash", "sh", "zsh", "dash", "ksh",
"apt", "apt-get", "dpkg", "yum", "dnf", "rpm",
"pip", "pip3", "make", "gcc", "cc", "g++", "cargo", "go"
)
| project TimeGenerated, HostName = DeviceName,
ProcessExe = FolderPath, ProcessComm = FileName,
AuditUID = AccountSid,
HostPID = tostring(ProcessId), HostPPID = tostring(InitiatingProcessId),
SignalType = "BPFDOOR_STAGING_PATH_EXEC", ThreatLevel = "High";
union BPFFilterAttach, RawSocketCreate, BPFDoorStagingExec
| sort by TimeGenerated desc Data Sources
Required Tables
False Positives
- Network performance monitoring agents (Datadog, New Relic, Dynatrace, Elastic Agent) that use libpcap for packet-level sampling on Linux servers — these internally call setsockopt(SO_ATTACH_FILTER) and will trigger Signal 1
- Container networking plugins in Kubernetes environments (Cilium in eBPF mode, Calico eBPF, Weave Net) that attach BPF programs to network interfaces as part of normal CNI pod networking — generates high volumes of BPF-related syscalls
- Active network security tools such as Zeek (Bro), Suricata, Snort, or Falco running in packet capture mode on network sensors — all use AF_PACKET raw sockets
- System daemons that open raw sockets for legitimate protocol handling: dhclient (DHCP), radvd (IPv6 RA), and keepalived (VRRP) use AF_INET raw sockets
- Developer environments where engineers interactively run Scapy, Python socket experiments, or custom pcap-based tooling from /tmp or home directories
- Kubernetes kube-proxy in iptables or ipvs mode and various CNI implementations executing scripts from temporary directories during pod network setup
References (11)
- https://attack.mitre.org/techniques/T1205/002/
- https://exatrack.com/public/Tricephalic_Hellkeeper.pdf
- https://www.crowdstrike.com/blog/how-to-hunt-for-decisivearchitect-and-justforfun-implant/
- https://www.leonardo.com/documents/20142/10868623/Malware+Technical+Insight+_Turla+%E2%80%9CPenquin_x64%E2%80%9D.pdf
- https://www.mandiant.com/resources/blog/fortinet-malware-ecosystem
- https://www.deepinstinct.com/blog/bpfdoor-an-active-chinese-global-surveillance-tool
- https://www.elastic.co/security-labs/a-peek-behind-the-bpfdoor
- https://blog.aquasec.com/ebpf-vulnerability-bpfdoor
- https://man7.org/linux/man-pages/man7/packet.7.html
- https://man7.org/linux/man-pages/man7/socket.7.html
- http://recursos.aldabaknocking.com/libpcapHakin9LuisMartinGarcia.pdf
Unlock Pro Content
Get the full detection package for T1205.002 including response playbook, investigation guide, and atomic red team tests.