Privilege and Permission Vulnerabilities: Study Guide

Fundamentals of Privilege and Permission

  • Privilege represents a specific permission granted to a person or a designated group of users.
  • Permission is defined as explicit consent to perform a particular action within a computer system.
  • Privilege escalation occurs when an entity obtains rights beyond what was originally authorized, falling into two primary classes:
    • Horizontal privilege escalation: An attacker assumes the identity and access rights of another user who holds a similar privilege level (for example, stealing session cookies, performing session hijacking, or guessing user credentials).
    • Vertical privilege escalation (also known as privilege elevation): An attacker assumes higher privileges than originally assigned, such as acquiring rootroot privileges in Unix-like systems or AdministratorAdministrator / SYSTEMSYSTEM privileges in Windows.
  • Low-privilege users frequently rely on specialized applications that execute with elevated privileges on their behalf to carry out critical system tasks:
    • The passwd utility updates credentials stored in privileged system stores.
    • The ping command creates raw network sockets.
    • The wall command broadcasts messages across user terminal devices.
  • Secure programming requires hardening privileged applications to guarantee they cannot be hijacked or subverted by malicious actors during execution.

Vertical Privilege Escalation Mechanisms

  • Hacker reconnaissance on Linux platforms systematically identifies vectors for vertical privilege escalation:
    • Scanning the host for unpatched software and operating system vulnerabilities, particularly when targeting legacy operating system installations.
    • Determining whether high-privilege system binaries or directories have insecure permissions (for example, checking if privileged executables or configuration files are writable or modifiable by unprivileged users).
    • Verifying the presence of development tools and utilities, including local compilers (such as gcc) or functioning package managers (such as aptitude), which facilitate building or downloading exploits.
    • Executing network scanning tools such as nmap to enumerate active network services, open communication ports, and listening daemons.
    • Inspecting system configuration directories such as /etc and /var for misconfigurations, leaked secrets, or incorrect file mode bits.
    • Executing a multi-stage intrusion strategy: initially compromising an unprivileged service account (such as running arbitrary code as the apache service user) and subsequently utilizing local vulnerabilities to elevate execution privileges to rootroot.
    • Searching vulnerability repositories and testing published exploits against target components.
  • Windows privilege elevation using SeDebugPrivilege:
    • Windows architecture divides execution environments into User Mode (Ring 33) and Kernel Mode (Ring 00).
    • Nearly all application code executes in Ring 33, even when run under an administrative account. This containment design ensures that application crashes can be safely managed and terminated without producing a kernel-level Blue Screen of Death (BSOD).
    • Kernel Mode (Ring 00) is reserved strictly for the core operating system, hardware device drivers, hypervisors, and core security products such as antivirus engines.
    • Every Windows process possesses an access token that defines its security context, including its user Security Identifier (SID), group SIDs, and operational privileges.
    • SeDebugPrivilege is an administrative privilege originally designed for system-level debugging tools, permitting a process to inspect, attach to, and manipulate the memory space of other processes (including those running under privileged service contexts).
    • Malicious software executing within an administrative context elevates its control by enabling the SeDebugPrivilege flag via the following Win32 API sequence:
    • Invoking OpenProcessToken to obtain a handle to the primary access token of the current process.
    • Invoking LookupPrivilegeValueA to resolve the locally unique identifier (LUID) corresponding to SE_DEBUG_NAME (SeDebugPrivilege).
    • Invoking AdjustTokenPrivileges to modify the process token state and enable SeDebugPrivilege.

Hardware-Level Protections and Bypass Techniques: SMEP and SMAP

  • Control Register 4 (CR4) in x86/x64 architectures incorporates dedicated hardware security control bits to restrict unauthorized execution and data access across privilege boundaries.

CR4 control register bit layout highlighting SMEP and SMAP bits

  • The internal bit assignments of the CR4 register control system execution states:
    • Bit 00: VME (Virtual-8086 Mode Extensions)
    • Bit 11: PVI (Protected-Mode Virtual Interrupts)
    • Bit 22: TSD (Time Stamp Disable)
    • Bit 33: DE (Debugging Extensions)
    • Bit 44: PSE (Page Size Extension)
    • Bit 55: PAE (Physical Address Extension)
    • Bit 66: MCE (Machine-Check Enable)
    • Bit 77: PGE (Page Global Enable)
    • Bit 88: PCE (Performance-Monitoring Counter Enable)
    • Bit 99: OSFXSR (Operating System Support for FXSAVE and FXRSTOR instructions)
    • Bit 1010: OSXMMEXCPT (Operating System Support for Unmasked SIMD Floating-Point Exceptions)
    • Bit 1313: VMXE (Virtual Machine Extensions Enable)
    • Bit 1414: SMXE (Safer Mode Extensions Enable)
    • Bit 1616: FSGSBASE (Enable RDFSBASE, RDGSBASE, WRFSBASE, and WRGSBASE instructions)
    • Bit 1717: PCIDE (Process-Context Identifiers Enable)
    • Bit 1818: OSXSAVE (Extended Processor States Enable)
    • Bit 2020: SMEP (Supervisor Mode Execution Prevention)
    • Bit 2121: SMAP (Supervisor Mode Access Prevention)
  • Supervisor Mode Execution Prevention (SMEP):
    • Enforces that code executing in supervisor mode (such as kernel code running in Ring 00) cannot execute instructions residing in memory pages where the user/supervisor page table attribute is set to user mode.
    • Mitigates kernel exploits where an attacker overwrites a kernel function pointer to redirect execution flow directly to malicious shellcode located in user-controlled virtual memory.
    • When SMEP is enabled (SMEP=1\text{SMEP} = 1), dereferencing and executing instructions from a user-space memory address while operating in kernel mode immediately triggers a hardware page fault exception.
  • Supervisor Mode Access Prevention (SMAP):
    • Restricts supervisor mode execution from reading or writing to user-space memory pages unless an explicit override is configured, mitigating confused-deputy attacks on kernel data structures.
  • Bypassing SMEP and SMAP via Return-Oriented Programming (ROP):
    • Attackers construct kernel-space ROP gadget chains from existing privileged instructions.
    • The ROP chain writes directly to the CR4 register to clear bit 2020 (SMEP) and bit 2121 (SMAP).
    • Once both bits are cleared to 00, execution and access controls between Ring 00 and user space are deactivated, allowing the kernel thread to execute user-space payloads without triggering CPU exceptions.

Unix Process Credentials and Identifier Management

  • Identity management in Unix-like kernels uses numeric identifiers rather than textual usernames (for example, the superuser rootroot is assigned UID 00).
  • Every process control block maintains three distinct user IDs that define its operational authority:
    • RUID (Real User ID): Identifies the user account that originally instantiated the process.
    • EUID (Effective User ID): Evaluated directly by the kernel's access control subsystem when verifying file system permissions and operational capabilities.
    • SSUID (Saved Set-User-ID): Preserves the effective user ID assigned at the most recent exec() invocation, allowing setuid processes to alternate between privileged and unprivileged operational modes.
  • Group IDs parallel user IDs across process structures:
    • RGID (Real Group ID)
    • EGID (Effective Group ID)
    • SSGID (Saved Set-Group-ID)
    • Supplemental Group IDs: An array of additional group identifiers assigned to a user account, all of which are inherited and checked during access mediation.
  • Access validation check: File system UID and GID attributes are evaluated strictly against the calling process's active EUID and EGID values.

State transitions of process credentials during setuid program execution

  • Lifecycle and execution states of a SetUID binary:
    • An unprivileged user with RUID 2525 invokes an executable owned by user 1818 that has the setuid execution bit set.
    • When exec() completes, the process initializes with RUID = 2525, EUID = 1818, and SSUID = 1818.
    • While running with EUID = 1818, the process can read and write to files owned by user 1818.
    • When the program calls i = getuid(); seteuid(i);, the EUID changes to 2525 (matching RUID), while SSUID remains cached as 1818.
    • Operating with EUID = 2525, the process accesses files owned by user 2525.
    • Because SSUID remains 1818, the process retains the capability to re-elevate its EUID back to 1818 via seteuid(18).

Unix File System Permissions and Special Execution Bits

  • The standard Unix permission bitmask occupies an 1212-bit field associated with each inode:
    • Bits 8,7,68, 7, 6: Owner/User permissions representing read (r), write (w), and execute (x).
    • Bits 5,4,35, 4, 3: Group permissions representing read (r), write (w), and execute (x).
    • Bits 2,1,02, 1, 0: Others/World permissions representing read (r), write (w), and execute (x).
  • High-order special permission bits alter standard process privilege inheritance:
    • Bit 1111: Setuid bit (set-user-ID-on-execution):
    • Instructs the operating system kernel to set the process EUID to match the owner of the executable file rather than the user invoking the binary.
    • Displayed in directory listings as s in place of the owner's x execute bit if executable permissions are present, or as S if executable permissions are absent.
    • Bit 1010: Setgid bit (set-group-ID-on-execution):
    • Instructs the operating system kernel to set the process EGID to match the group owner of the file.
    • Displayed in directory listings as s in place of the group's x execute bit, or as S if execute permissions are absent.
    • Bit 99: Restricted deletion bit (commonly termed the "sticky bit"):
    • When set on a directory, restricts file deletion and renaming operations strictly to the file owner, directory owner, or the rootroot user (a configuration applied to world-writable directories such as /tmp).
    • Historical function: Directed the virtual memory subsystem to retain the program's executable text segment in memory or swap space to accelerate subsequent loading.
    • Displayed in directory listings as t in place of the world x execute bit, or as T if world execute permissions are absent.

Temporary and Permanent Privilege Dropping Mechanics

  • Process credential inheritance under process creation primitives:
    • Child processes created via fork() and transformed via exec() inherit the parent process credentials: RUID, EUID, RGID, EGID, and supplemental group ID arrays.
    • SSUID and SSGID are not directly inherited from the parent process; they are overwritten during an exec() call with the active EUID and EGID values determined at execution time.
  • Credential transitions during temporary privilege dropping:
    • Consider an administrative user (admin, with UID = 10001000) executing a setuid executable owned by system user bin (UID = 11).
Execution PhaseSystem Call InvokedRUIDEUIDSSUID
Initial Stateexec() completion100010001111
Dropping Privilegeseteuid(1000)100010001000100011
Restoring Privilegeseteuid(1)100010001111
  • Operational constraints on non-root credential modification:
    • A process lacking root authority is restricted by the kernel: it can only change its EUID to a value that matches its current RUID or its stored SSUID.
    • Temporary privilege reduction leaves SSUID set to the privileged identifier (11).
    • Security hazard: If a memory safety vulnerability (such as an exploitable buffer overflow) occurs while running with dropped privileges, an attacker executing arbitrary code can invoke seteuid(1) to restore elevated execution privileges.
  • Permanent privilege dropping protocols:
    • To permanently renounce elevated privilege, an application must eliminate the privileged UID from both its EUID and its SSUID.
    • All three identity registers (RUID, EUID, SSUID) must be synchronized to the unprivileged account ID (typically using getuid()).
    • The setresuid() system call atomically updates all three identifiers simultaneously: setresuid(ruid, euid, suid).
    • Defensive coding rule: Because setresuid() returns 00 on success and −1-1 on failure (for example, if system limits or permission checks fail), developers must explicitly evaluate the return code and immediately abort execution if privilege revocation fails.
    • Group privileges must be dropped in parallel by updating RGID, EGID, and SSGID (via setresgid()) and clearing supplemental group memberships to prevent unauthorized group access.

System Architecture and Privilege Separation Case Studies

  • Common Unix SetUID and SetGID utilities:
    • /usr/bin/passwd: Must run setuid rootroot to authenticate users and write updated password hashes into the restricted /etc/shadow file.
    • /sbin/ping: Historically configured setuid rootroot to open raw ICMP network sockets (SOCK_RAW).
    • /usr/bin/wall: Configured setgid tty (an ad-hoc system group) to acquire write access to terminal devices (/dev/pts/*) across all active users.
    • Security imperative: SetUID/SetGID binaries must avoid executing unsanitized user commands, trusting unverified input paths, or returning sensitive data to untrusted users.
  • Privilege management in network daemon architectures:
    • Apache HTTP Server: The initial core process starts execution as rootroot to bind to privileged TCP port 8080. Following socket initialization, it forks unprivileged worker child processes that invoke setgid() and setuid() to assume an unprivileged identity (such as www-data or apache).

OpenSSH privilege separation architecture and process execution timeline

  • OpenSSH privilege separation architecture:
    • A privileged OpenSSH master monitor process binds to privileged port 2222 and listens for inbound network connections.
    • Upon receiving an incoming connection, the monitor forks an unprivileged child process dedicated to network protocol processing.
    • The unprivileged child handles public key exchange and collects user authentication credentials over the network.
    • The unprivileged child communicates with the privileged monitor over a local IPC channel, transmitting Request Auth; the monitor processes credentials against authentication databases and returns the Auth Result.
    • Following successful authentication, the privileged monitor executes a State Export and forks a user-privileged child (user privileged OpenSSH).
    • The user child process sends a Request PTY to the monitor; the privileged monitor allocates the pseudo-terminal device and issues Pass PTY back to the child.
    • The user-privileged child processes user network data and executes the interactive shell session under the authenticated user's credentials.

qmail modular architecture and privilege isolation structure

  • Modular least-privilege architecture in qmail:
    • Network and local submission boundaries:
    • qmail-smtpd receives external inbound messages from the network.
    • qmail-inject ingests outbound messages originating locally.
    • Enqueueing isolation:
    • Both ingestion components dispatch mail data to qmail-queue.
    • qmail-queue executes with setuid privileges to deposit messages securely into the centralized mail spool.
    • Queue processing and delivery dispatch:
    • qmail-send periodically inspects the queue and directs delivery operations.
    • Remote delivery branch: qmail-send invokes qmail-rspawn, which spawns qmail-remote to perform network delivery to foreign domains.
    • Local delivery branch: qmail-send invokes qmail-lspawn, which executes as rootroot to inspect destination mailboxes and fork qmail-local under the specific target user's local UID, ensuring users can never access or modify another user's mailbox files.

Discretionary Access Control (DAC) and Trojan Horse Exploitation

  • Fundamental architectural vulnerability of DAC models:
    • Discretionary Access Control grants resource access based entirely on the authenticated identity of the entity executing the request.
    • If an authorized user executes an untrusted application containing malicious instructions (a Trojan horse), those malicious instructions run with the user's full permissions.

Trojan horse exploit bypassing Discretionary Access Control (DAC)

  • Trojan horse DAC exploitation sequence:
    • Principal UU possesses ownership, read, and write permissions over sensitive File FF. Principal VV possesses no read permissions for File FF.
    • Principal VV crafts a Trojan horse embedded within an ostensibly benign utility and induces Principal UU to execute it.
    • Because Principal UU invokes the software, the application inherits Principal UU's access rights.
    • The Trojan reads the contents of File FF.
    • The Trojan writes the exfiltrated contents into File GG, which is configured with an Access Control List granting write access to Principal UU and read/write access to Principal VV.
    • Principal VV accesses File GG, successfully bypassing the confidentiality protections of File FF.
  • Vectors utilized by attackers to induce Trojan execution on Unix systems:
    • Inspecting /etc/sudoers to identify password-less execution rules: configurations such as user ALL=(ALL) NOPASSWD:ALL permit command execution without authentication challenges.
    • Inspecting /etc/group to discover administrative group memberships: discovering entries such as sudo:x:27:user confirms the account possesses administrative capabilities.
    • Hijacking the execution PATH: If the user's PATH environment variable prioritizes the current directory (for example, PATH=".:/bin:/usr/bin:"), an attacker can place a malicious executable named ls in a shared directory; when the victim executes ls, the Trojan runs instead of the system binary.
    • Modifying user SSH configurations: An executing Trojan appends the attacker's public key to the victim's ~/.ssh/authorized_keys file, granting persistent remote shell access.
    • Elevation to root: After establishing access within the victim's account, the attacker executes sudo or su to gain root control.

Foundations of Access Control Systems

  • Formal definition of access control: Regulating, for security purposes, the reading, writing, and execution of data and programs by a user directly, or by a program executing on their behalf, to protect against accidental and malicious threats.
  • Access control processing sequence:
    • The operating system must authenticate the identity of the requesting entity prior to evaluating access control rules.
    • Once identity is verified, the access control engine mediates whether the specific requested operation is permitted.
  • The three foundational elements of access control:
    • Subject: An active process or operational entity representing a human user or software application (categorized into classes such as Owner, Group, and World/Others).
    • Object: A passive system resource requiring protection and mediation (including files, memory segments, input/output devices, network sockets, and database tables).
    • Access Right: The specific operational permission a subject can perform upon an object (including read, write, execute, delete, create, and search).

Reference monitor mediating user access to system objects with auditing and authorization database

  • The Reference Monitor concept:
    • Serves as the central security kernel component mediating every access attempt directed by a user subject toward a protected system object.
    • Consults an authorization database that defines the system security policy and is maintained exclusively by the security administrator.
    • Coordinates with an independent auditing subsystem that maintains an immutable chronological record of access events and security violations across system resources.

Access Control Models and Matrix Representations

  • Core access control policy paradigms:
    • Discretionary Access Control (DAC): Access authorization is evaluated strictly from the identity of the requesting subject. Resource owners or authorized entities retain the discretion to delegate or pass their access rights to other system entities (unlike Mandatory Access Control).
    • Mandatory Access Control (MAC): Access permissions are defined centrally by the system itself rather than individual resource owners. Resources are tagged with security classification labels (for example, high security, low security); subjects are assigned security clearance levels. The system compares subject clearances directly against object labels. Entities cannot transfer access rights to others.
    • Role-Based Access Control (RBAC): Users are assigned organizational roles. Central security rules determine the access permissions assigned to each role.
  • The Access Matrix:
    • A theoretical access model mapping subjects across rows and objects across columns, where each matrix intersection contains the permissible access rights.
SubjectsFile 11File 22File 33File 44
User AAOwn, Read, WriteNoneOwn, Read, WriteNone
User BBReadOwn, Read, WriteWriteRead
User CCRead, WriteReadNoneOwn, Read, Write
  • Computational decomposition of the Access Matrix:
    • Storing the matrix column-by-column yields Access Control Lists (ACLs).
    • Storing the matrix row-by-row yields Capability Lists.
    • Storing the matrix as individual tuples in a relational schema yields an Authorization Table.

Access Control Lists (ACLs) Versus Capabilities

Decomposition of access matrix columns into Access Control Lists

  • Access Control Lists (ACLs):
    • Represents the Access Matrix decomposed by columns, binding each list directly to a specific object.
    • Each list entry specifies a subject and its allowed access rights:
    • File 11: User AA (Own, Read, Write) →\rightarrow User BB (Read) →\rightarrow User CC (Read, Write)
    • File 22: User BB (Own, Read, Write) →\rightarrow User CC (Read)
    • File 33: User AA (Own, Read, Write) →\rightarrow User BB (Write)
    • File 44: User BB (Read) →\rightarrow User CC (Own, Read, Write)
    • Operational characteristics:
    • Highly efficient for answering: "Which subjects have access rights to this resource?"
    • Inefficient for answering: "Which resources can be accessed by a specific subject?"
    • Composed of individual Access Control Entries (ACEs), typically including a default least-privilege or read-only entry for the general public.

Decomposition of access matrix rows into Capability Lists

  • Capability Lists:
    • Represents the Access Matrix decomposed by rows, distributing tickets or tokens directly to subjects.
    • Each list entry specifies an accessible object and the associated access rights:
    • User AA: File 11 (Own, Read, Write) →\rightarrow File 33 (Own, Read, Write)
    • User BB: File 11 (Read) →\rightarrow File 22 (Own, Read, Write) →\rightarrow File 33 (Write) →\rightarrow File 44 (Read)
    • User CC: File 11 (Read, Write) →\rightarrow File 22 (Read) →\rightarrow File 44 (Own, Read, Write)
    • Operational characteristics:
    • Highly efficient for answering: "Which resources can be accessed by this subject?"
    • Inefficient for answering: "Which subjects have access rights to a specific resource?"
    • System example: The low-privilege ntpd time synchronization daemon utilizes the specific capability CAP_SYS_TIME to adjust system time without acquiring full root administrative privilege. Kerberos authentication tickets also function as cryptographic capabilities.
    • Architectural requirements for capability implementations:
    • Capabilities must be unforgeable and revocable.
    • They must either be retained within protected kernel address space or, if distributed to user space, cryptographically secured to prevent tampering.
  • Authorization Table:
    • Stores access rights as normalized tuples within a relational structure: (Subject, Access Mode, Object).
    • Sample entries:
    • (User A, Own, File 1)
    • (User A, Read, File 1)
    • (User A, Write, File 1)
    • (User A, Own, File 3)
    • (User B, Read, File 1)
    • (User B, Own, File 2)

Access Control Implementations: Unix and Windows

  • Unix access control mechanics:
    • Base configuration utilizes three permission groups: Owner, Group, and Others, each configured with read, write, and execute bits (rwx).
    • Extended POSIX ACLs permit assigning explicit permissions to named users and groups beyond primary group ownership:
    • Command invocation: setfacl -m u:lisa:r file assigns user lisa explicit read access to file.

Windows XP file properties security tab displaying access control permissions

  • Windows access control architecture:
    • Extends permission structures beyond basic read, write, and execute flags to include Full Control, Modify, Read & Execute, List Folder Contents, Read, and Write, alongside explicit Allow and Deny directives.
    • Discretionary Access Control Lists (DACLs): Attached to secured objects to enumerate the specific users and security groups permitted or denied access. When a thread requests access, the security reference monitor compares the thread's access token directly against the object DACL.
    • System Access Control Lists (SACLs): Attached to secured objects to control security auditing, generating audit events in the security log when specified accounts attempt monitored access operations.
    • Access Tokens: Created by the Local Security Authority (LSA) during authentication, defining the caller's SID, group SIDs, and operational privileges.

Mandatory Access Control (MAC) and Security Models

  • Foundational structure of Mandatory Access Control:
    • Subjects are granted formal security clearances.
    • Objects are tagged with formal security classifications or integrity levels.
    • System-wide policy rules dictate access mediation; individual users cannot alter or bypass security labels.
  • Biba Integrity Model (Integrity-focused MAC):
    • Applied in modern operating system environments (such as Windows Vista and later integrity levels).
    • Primary objective: Prevent unauthorized modification and corruption of critical system data.
    • Enforces two mandatory rules:
    • "Write down": A subject can only write to or modify an object if the object's integrity level is lower than or equal to the subject's integrity level.
    • "Read up": A subject can read data from an object at a higher or equal integrity level.
    • The integrity level assigned to each file or resource is embedded directly within its Access Control List.
  • Bell-LaPadula Model (Confidentiality-focused MAC):
    • Primary objective: Prevent unauthorized disclosure and downward leakage of classified information.
    • Simple Security Property ("Read down"): A subject can only read an object if the object's security classification is lower than or equal to the subject's security clearance level (prevents reading up).
    • Star-Property (⋆\star-Property, "Write up"): A subject can only write to an object if the object's security classification is higher than or equal to the subject's security clearance level (prevents writing down).
    • Solves the DAC Trojan horse vulnerability: Even if an authenticated user with high clearance executes an untrusted Trojan, the Trojan cannot write confidential data into a lower-classification file accessible to unauthorized users.
    • Formal Bell-LaPadula constraints govern human user identities rather than arbitrary system subjects.

Role-Based Access Control (RBAC)

RBAC0 baseline model diagram showing User Assignment, Permission Assignment, and Sessions

  • The RBAC0 baseline architecture separates access administration into two decoupled mappings:
    • User Assignment (UA): Dynamic mapping connecting individual users to organizational roles (reflecting frequent organizational onboarding, role changes, and departures).
    • Permission Assignment (PA): Stable mapping connecting defined roles to specific system permissions (reflecting consistent organizational responsibilities and business functions).
    • Sessions: Dynamic, flexible one-to-many associations enabling an authenticated user to activate an authorized subset of roles during a specific working session.
  • Organizational benefits of Role-Based Access Control:
    • Data ownership alignment: Users do not personally own corporate assets; the enterprise maintains asset ownership. Access permissions are assigned strictly according to an employee's job responsibilities.
    • Hierarchical roles: RBAC supports inheritance structures where senior job roles inherit the complete set of permissions assigned to subordinate roles.
    • Least privilege enforcement: Users activate only the specific role needed for a given session, minimizing exposure.
    • Separation of Duties (SoD): Workflows can be subdivided across multiple roles so that critical operations cannot be completed by a single individual acting alone.