Skip to content
Threat Feed
high advisory

Nsenter to PID Namespace for Privilege Escalation on Linux

Elastic has released a detection rule to identify the use of the `nsenter` utility targeting a Process ID (PID) with specific namespace flags on Linux systems, a technique commonly employed by attackers to escape container environments or escalate privileges by gaining host context.

Attackers frequently leverage the nsenter utility on Linux to escape containerized environments or achieve privilege escalation from a limited session by targeting the host's PID 1 namespace. This technique allows them to execute commands with host-level privileges and context. Elastic's new detection rule specifically identifies nsenter executions that specify a target PID using the -t or --target flag, alongside other namespace flags. This activity is a strong indicator of an attempt to gain unauthorized host access or escalate privileges. Defenders should correlate these events with other activities, such as subsequent file writes in critical directories like /etc, docker.sock access, or the creation of new systemd units, which suggest post-exploitation activity. While legitimate use by platform engineers for deep node debugging is possible, such instances should be rare and justifiable by existing incident response or change management tickets.

Attack Chain

  1. Initial Compromise: An attacker gains initial access to a Linux system, often within a containerized environment through an exposed service, vulnerable application, or via a limited user session on a host.
  2. Execution of nsenter: The attacker executes the nsenter utility from within the compromised environment to manipulate process namespaces.
  3. Targeting Host PID: The attacker uses the -t or --target flag with nsenter to specify a process ID, typically PID 1 of the host, indicating an intent to interact with the host's root namespace.
  4. Namespace Entry: The attacker employs additional nsenter flags (e.g., --mount, --uts, --ipc, --net, --user) to enter specific namespaces associated with the targeted host process.
  5. Host Context Acquisition: By successfully entering the host's namespaces, the attacker gains host-level context and permissions, effectively escaping container isolation or escalating privileges.
  6. Post-Exploitation Activity: The attacker then performs various actions on the host, such as modifying system files in /etc, interacting with docker.sock for container manipulation, or installing new systemd units for persistence or further access.

Impact

Successful exploitation allows an attacker to break out of container isolation or escalate privileges from a low-privileged user to root on a Linux host. This can lead to full system compromise, unauthorized data access, deployment of malware, establishment of persistence mechanisms, or lateral movement across the network. The ability to gain host context means the attacker can potentially bypass security controls designed for container isolation, affecting not only the compromised container but also the entire underlying infrastructure. Organizations running containerized applications are particularly vulnerable, facing risks to their entire container orchestration platform and hosted services.

Recommendation

  • Deploy the Auditd Manager integration on all Linux hosts to ensure process execution telemetry is captured, which is crucial for the rule provided in this brief.
  • Ensure syscall rules capture execve for utilities like nsenter so that event.category: process and event.action: executed populate with process.name and process.args in your logs.
  • Deploy the Sigma rule provided in this brief to your SIEM and tune for your environment, paying close attention to the false positive guidance regarding CNI or snap workflows.
  • Investigate nsenter executions where process.args indicate targeting of PID 1 or other sensitive host PIDs, correlating with tickets or bastion sessions for expected activity.

Detection coverage 1

Nsenter to PID Namespace via Auditd

high

Detects nsenter executions that target PID with a namespace target flag, a pattern commonly used to attach to the host init namespace from a container or session and run with host context for privilege escalation or container escape.

sigma tactics: privilege_escalation techniques: T1611 sources: process_creation, linux

Detection queries are available on the platform. Get full rules →