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
- 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.
- Execution of
nsenter: The attacker executes thensenterutility from within the compromised environment to manipulate process namespaces. - Targeting Host PID: The attacker uses the
-tor--targetflag withnsenterto specify a process ID, typicallyPID 1of the host, indicating an intent to interact with the host's root namespace. - Namespace Entry: The attacker employs additional
nsenterflags (e.g.,--mount,--uts,--ipc,--net,--user) to enter specific namespaces associated with the targeted host process. - 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.
- Post-Exploitation Activity: The attacker then performs various actions on the host, such as modifying system files in
/etc, interacting withdocker.sockfor 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
execvefor utilities likensenterso thatevent.category: processandevent.action: executedpopulate withprocess.nameandprocess.argsin 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
nsenterexecutions whereprocess.argsindicate 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
highDetects 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.
Detection queries are available on the platform. Get full rules →