Red Menshen & BPFDoor

DATE: 2026-07-21TARGET: Red Menshen / BPFDoor

1. Executive Summary

Red Menshen is an APT group active since 2018 that primarily targets telecommunications companies, logistics infrastructure, and government institutions in the Middle East and Asia. Its principal targets are public-facing Linux and Unix servers.

The defining feature that separates Red Menshen from conventional APT groups is its custom backdoor, BPFDoor. Traditional malware establishes C2 communication by opening and listening on a system port; BPFDoor opens no port. Instead, it uses the Linux kernel’s packet-filtering architecture, cBPF, to create a raw socket (AF_PACKET).

This allows the malware to inspect network traffic directly at Layer 2 before it reaches host-based firewalls (iptables, nftables) or the network stack. BPFDoor does not appear as a listener in standard network-monitoring tools such as netstat or ss. After compromising a host, it remains passive and initiates C2 communication only when triggered by a specific “Magic Packet” sent by the attacker: a custom hexadecimal payload delivered over ICMP, TCP, or UDP. This architecture has allowed the group to maintain long-term persistence in target networks without detection.

2. Campaign Timeline

Red Menshen’s operations and the BPFDoor malware have evolved to evade EDR and SIEM detection mechanisms:

2.1. Notable Campaigns

Analysis of Red Menshen’s known operations indicates that the group focuses on cyber espionage and network-intelligence collection rather than financial gain.

Campaign 1: Telecommunications Intrusions in Asia and the Middle East (2018–2021)

Campaign 2: Government and Logistics Infrastructure Operations (2021–2022)

3. MITRE ATT&CK TTP Mapping

This section maps the specific techniques used by Red Menshen and BPFDoor on target systems to MITRE ATT&CK.

3.1. Process Name Spoofing

id: T1036.004
tactic: Defense Evasion
technique: Masquerading (Task Name/Process Spoofing)
platform: Linux

Technique Description

After establishing itself and starting execution, BPFDoor manipulates its process name to conceal its presence. It overwrites the argv[0] argument so that it appears to be a legitimate Linux daemon such as /sbin/udevd, dbus-daemon, systemd-journal, or kswapd0, reducing the likelihood of drawing attention from administrators and EDR products.

Execution and PoC

After calling fork(), the child process changes its own command-line argument.

//BPFDoor process spoofing örneği (C Pseudocode)
strncpy(argv[0], "/sbin/udevd -d", strlen(argv[0]));

As a result, commands such as ps aux or top display the spoofed daemon name instead of the malware’s actual name.

Detection Methods

Process-name manipulation can be detected through inconsistencies in /proc. Although the cmdline value of a spoofed process changes, the exe symbolic link that points to the underlying binary continues to reveal the malware’s original path.

Defense

3.2. Magic Packet & Raw Socket Listening

id: T1205
tactic: Defense Evasion, Command and Control
technique: Traffic Signaling (Magic Packet)
platform: Linux

Technique Description

Conventional backdoors bind to and listen on a specific TCP or UDP port for C2 communication. BPFDoor instead captures packets directly at Layer 2 through an AF_PACKET socket. Its embedded cBPF filter accepts only packets containing a specific attacker-controlled magic-packet hexadecimal pattern. All other traffic continues into the operating system’s normal network stack without being dropped.

Execution and PoC

The malware creates a raw socket to avoid opening a port and applies its filter in the kernel with SO_ATTACH_FILTER.

//AF_PACKET ile raw socket açılması
int sock = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));

//Kernel'a cBPF filtresinin uygulanması
setsockopt(sock, SOL_SOCKET, SO_ATTACH_FILTER, &bpf_filter_struct, sizeof(bpf_filter_struct));

When the magic packet reaches the system, the BPF filter captures it before iptables rules take effect and executes the backdoor commands.

Detection Methods

Defense

3.3. Boot Script Manipulation

id: T1037.004
tactic: Persistence
technique: Boot or Logon Initialization Scripts: rc.common
platform: Linux

Technique Description

BPFDoor targets system startup scripts so that it can become active in memory again after a reboot. Rather than creating a new and suspicious service file, it inserts its execution command into existing, trusted init.d scripts such as those for iptables, rsyslog, or sshd.

Execution and PoC

The attacker typically downloads the malware to a temporary filesystem such as /dev/shm or /tmp and appends its execution command to a legitimate shell script.

#Yasal bir init.d script'ine zararlı payload'un eklenmesi
echo "/dev/shm/kswapd0 &" >> /etc/rc.d/init.d/rsyslog

When the system starts the rsyslog service during boot, it also launches the BPFDoor binary in the background, which then opens its raw socket.

Detection Methods

File Integrity Monitoring can detect unauthorized changes to system startup files.

Defense

3.4. Binary Deletion & Environment Wiping

id: T1070.004
tactic: Defense Evasion
technique: Indicator Removal on Host: File Deletion
platform: Linux

Technique Description

Immediately after beginning execution in memory, the malware deletes its own binary from the filesystem to hinder static analysis and avoid leaving artifacts on disk. The process continues to run, but the file can no longer be accessed from disk. It also clears environment variables to remove variable traces created during execution.

Execution and PoC

After fork(), BPFDoor deletes its file path through the unlink() syscall and clears the environ pointer.

//Binary'nin diskten silinmesi ve environment temizliği
unlink(argv[0]);
clearenv();

The malware remains active in memory, but incident-response teams cannot find its file on disk to calculate its hash or perform static analysis.

Detection Methods

A process whose source file has been deleted while it continues to execute is one of the strongest Linux memory-analysis indicators.

ls -l /proc/*/exe | grep "deleted"

Defense

4. Malware Anatomy: BPFDoor and ZayoELF Analysis

Static-analysis tools and dynamic behavioral monitoring reveal characteristics that distinguish BPFDoor from conventional backdoors. This section profiles the malware and its runtime anatomy using ZayoELF Analyzer for static analysis.

4.1. Static Analysis Profile

Analysis of the BPFDoor binary with ZayoELF produced the following findings:


Figure 1: Entropy analysis

Figure 2: Variant without retained symbols

Figure 3: Variant with retained symbols

Figure 4: String analysis

4.2. Dynamic Analysis and cBPF Integration

At runtime, BPFDoor’s primary function is to inspect and filter network traffic at Layer 2. It uses classic BPF (cBPF) rather than modern eBPF, providing backward compatibility and support for a broader range of Linux kernels.

  1. Raw Socket Initialization: The malware calls socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)) to begin listening on every network interface available to the device.
  2. Filter Attachment: The compiled cBPF bytecode in the C source—a struct sock_fprog structure—is attached to the raw socket through setsockopt with SO_ATTACH_FILTER.
  3. Network Stack Bypass: The cBPF filter runs before the operating system’s iptables or firewalld rules. The malware receives only packets containing the magic packet pattern. Nonmatching traffic is not dropped and continues through the operating system’s normal network stack.

5. Campaign Execution Flow & Architecture

The typical BPFDoor attack chain used by Red Menshen and the malware’s position in the network architecture are described below.

5.1. BPFDoor Network Architecture

The following diagram shows how BPFDoor captures an incoming network packet before it encounters the operating system’s firewall rules.

[Attacker (C2)]
      │
      ▼ (Magic Packet - TCP/UDP/ICMP)
[Public-Facing Linux Server]
      │
      ▼
[Network Interface Card (NIC)]
      │
      ▼ (L2 Data Link Layer)
+---------------------------------------------------+
| Linux Kernel                                      |
|                                                   |
|  [cBPF Filter] <─────────────── (AF_PACKET) ────┐ |
|        │ (Match? YES)                           │ |
|        ▼                                        │ |
|  [BPFDoor Process] ─────────────────────────────┘ |
|  (Executes bind shell or reverse shell)           |
|                                                   |
|        │ (Match? NO)                              |
|        ▼                                          |
|  [Standard Network Stack (TCP/IP)]                |
|        │                                          |
|        ▼                                          |
|  [Host Firewall (iptables / nftables)]            |
+---------------------------------------------------+

5.2. Operational Lifecycle

  1. Initial Access: The attacker typically exploits vulnerabilities in public-facing web, VPN, or router systems, or obtains initial access through brute force.
  2. Execution & Masquerading: The BPFDoor payload is downloaded to a directory such as /dev/shm or /tmp. On execution, it calls fork() and changes the child process name (argv[0]) to /sbin/udevd or kswapd0, concealing itself as a legitimate daemon.
  3. Persistence: The malware’s execution command is injected into a legitimate /etc/init.d/ script, such as an rsyslog or iptables startup file.
  4. Defense Evasion (Cleanup): The malware deletes its own executable from disk with unlink() and clears its environment variables with clearenv(), removing static artifacts from forensic examination.
  5. Signaling: The malware begins passive listening through a raw socket and remains silent until the attacker sends a magic packet.
  6. Action on Objectives: After detecting the magic packet, BPFDoor either opens a bind shell or connects a reverse shell to the attacker’s IP address. When the connection closes, it returns to passive listening mode.

6. Indicators of Compromise (IoC)

Because BPFDoor’s stealth architecture allows static hashes to change rapidly, detection should focus on behavioral and host-based anomalies.

Host-Based Indicators

Category Indicator Description
Process Name (Spoofed) kswapd0, /sbin/udevd -d, dbus-daemon, systemd-journal False process names used by the malware to conceal itself.
Suspicious Paths /dev/shm/, /tmp/, /var/tmp/, /run/ Directories where the malware is temporarily written, executed, and later deleted.
Syscall Anomalies socket(AF_PACKET), setsockopt(SO_ATTACH_FILTER), unlink(), clearenv() The sequence used to open a raw socket, attach a cBPF filter, and clear the environment.
Process State (deleted) Indicates that the source file of a running process has been deleted from disk.
Capabilities CAP_NET_RAW An unauthorized process using packet-capture privileges in EDR or Linux process logs.

7. Threat Hunting Notes

The following threat-hunting hypotheses can help identify BPFDoor variants that evade signature-based detection:

Hunt 1: Detecting Processes That Open Raw Sockets (AF_PACKET)

-a always,exit -F arch=b64 -S socket -F a0=17 -k raw_socket_creation
#a0=17 (AF_PACKET)

Hunt 2: Analyzing “Deleted” Binaries Running in Memory

ls -al /proc/*/exe | grep "deleted"

(Note: Some services may enter this state during normal system updates. Results pointing to /dev/shm or /tmp can be treated as critical.)

Hunt 3: Process Execution Spoofing (argv vs. exe Mismatch)

for pid in $(ls /proc | grep -E '^[0-9]+$'); do 
  exe_path=$(readlink -f /proc/$pid/exe 2>/dev/null); 
  cmdline=$(tr '\0' ' ' < /proc/$pid/cmdline 2>/dev/null); 
  #Analiz için bu ikiliyi karşılaştır
done

8. MITRE ATT&CK Matrix Summary

Tactic Technique ID
Initial Access Exploit Public-Facing Application T1190
Execution Command and Scripting Interpreter T1059
Persistence Boot or Logon Initialization Scripts: rc.common T1037.004
Defense Evasion Masquerading: Task Name/Process Spoofing T1036.004
Defense Evasion Indicator Removal on Host: File Deletion T1070.004
Command and Control Traffic Signaling (Magic Packet) T1205

9. Conclusion

BPFDoor demonstrates the limitations of conventional network-based detection. Its portless architecture, use of classic BPF filters, and behavior-driven concealment techniques make signature-only approaches insufficient. Behavioral analysis, system-call monitoring, and threat-hunting operations are therefore critical in modern Linux environments.

10. References