Refer to intro OS Version Kernel Version Running services
https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS https://github.com/rebootuser/LinEnum
Situational awareness: After revshell, gain persistence.
- What OS we dealing with?
- If we are on CentOS or RHEL our enumeration may be different than a Debian based host.
- If on FreeBDS, Solaris, or something more obscure like HP proprietary OS HP-UX or IBM AIX:
- The commands we work with are going to be different. Though some commands may be different, and we need to look up a command reference in some instances, but the principles are the same.
Regardless of system, having a thorough and repeatable process is key.
Typically a series of whoami, id, hostname, ifconfig or ip -a , and sudo -l answers:
- user
- groups
- server name? naming convention?
- subnet - netw. interfaces?
- can we sudo anything?
Including SS of above info can be helpful in clientg report to provide evidence of successful RCE and clearly identify affected system.
Step-by-step enumeration: System OS and version we're dealing with:
cat /etc/os-release
PATH - Where linux system loosk every time cmd is executed, for any executables to match name of what we type - If this is misconfigured it's leveragable to escalate privileges.
echo $PATH
ENV - All env vars set for our current user - May get lucky and find something sensitive in there such as a password.
env
Kernel version
cat /proc/version
uname -a
CPU type / version
lscpu
What login shells exist on the server?
cat /etc/shells
Defenses? Some things to look for include:
Drives and shares
lsblk
- hdds, usbs, optical etc
- If discover + can mount an add'tl drive or unmounted file system, we can find sensitive files/passwords/backups that can be leveraged to escalate privileges
lpstat
- Printers - if active or queued print jobs, can we gain access to sensitive information?
Check for mounted / unmounted drives. Can we mount unmounted and gain access to sensitive data? Find any creds in fstab for mounted drives by grepping common words i.e. password username credential etc in /etc/fstab?
cat /etc/fstab
Route table
route
netstat -rn
Determines what other networks are available via which interface.
In domain environment we definitely want to check /etc/resolv.conf - if host is configured to use internal DNS we may be able to use this as a starting point to query AD environment. Also, check ARP table to see other hosts target has communicated with
arp -a
Users
Environment enumeration also includes knowledge about users that exist on tgt system. This is because individ users often configured during installation of applications and svcs to limit service's privileges. The reason for this is to maintain sec of sys itself. If svc run as root, and this is brought under control by an attacker, the attacker automatically has highest rights over entire system. All users are stored in /etc/passwd file.
Keep note if hashes are available in /etc/passwd and /etc/shadow. Crackable. Not common, but can be seen on embedded devicews and routers.
Hash identifiers
| Algorithm | Hash |
|---|---|
| Salted MD5 | $1$... |
| SHA-256 | $5$... |
| SHA-512 | $6$... |
| BCrypt | $2a$... |
| Scrypt | $7$... |
| Argon2 | $argon2i$... |
Check what users have login shells. Once we see what shells are on system we can check each version for vulnerabilities. Outdated versions are vulnerable to certain exploits. (i.e. bash version 4.1 = shellshock)
Each user in linux assigned to a specific group or groups and thus receives special privs. For example if a folder named dev only for developers, user assigned to dev group for access. Check /etc/group
https://man7.org/linux/man-pages/man1/getent.1.html
getent cmd to list members of any interesting groups.
getent group sudo
Home directory
- Always enumerate and check system users storing sensitive data (files w passwords, configs, bash history, ssh keys etc)
- Not uncommon to find files containing creds that can be leveraged to access other systems or even gain entry into AD
- SSH keys
- Check ARP cache and see other hosts being accessed, cross-ref these against usable ssh keys.
Conf files - Low hanging fruit
- Always search .conf and .config files for user/pws etc
- Password reuse is common
find / ! -path "*/proc/*" -iname "*config*" -type f 2>/dev/null
find / -type f \( -name "*.conf" -o -name "*.config" \) 2>/dev/null
You can recursively search within files with grep and then list the filenames that match your search query to find the flag.
You can do this with:
grep -r -l 'search-query-here' /path/to/search
Mounted file systems
- FS that is attached to a particular directory on the system and can be accessed through that dir.
- Many FS such as ext4, ntfs, fat32 can be mounted.
- Each FS has their own benefits/drawbacks. IE - Some FS can only be read by OS, others are r/w eligible by user
- Mounting a FS allows user to access files+folders stored in that FS. In order to mount a FS user has to have root privs.
df -h
- When unmounted, no longer accessible by system. Can be done for various reasons (disk removed, no longer needed)
- other reasons: Files/scripts/docs/other imp. information must not be mounted and viewed by std user
- If we extend priv to root, we can mount and read these ourselves. Unmounted systems can be viewed as below:
cat /etc/fstab | grep -v "#" | column -t
- Many folder/files kept hidden on linux system so they are not obvious and accidental editing is prevented.
- Many reasons to hide. Nevertheless, locating these is not fruitless because often contain sensitive information, even with only readonly priv
All hidden files
find / -type f -name ".*" -exec ls -l {} \; 2>/dev/null | grep htb-student
All hidden directories
find / -type d -name ".*" -ls 2>/dev/null
Temporary files
- Folders visible to all users + can be read. Temporary logs and script output can be found here.
/tmp/var/tmp- used to store data temporarily - Key difference is how long data is stored. Data retention time for /var/tmp is much longer than /tmp
- All files and data stored in /var/tmp are retained for up to 30 days.
- /tmp = ten days
- All temp files stored in
/tmpare deleted immediately on restart /var/tmpused by progs to store data that must be kept between reboots
ls -l /tmp /var/tmp /dev/shm
It's worth running LINPEAS at this point in a real-world assessment to have as much data to dig through as possible. Oftentimes we can find an easy win but having this output handy can sometimes uncover nuanced issues that our manual enum missed. In practice, manual enumerate as much as possible and create our own cheat sheet of commands (and alternatives for other linux OS) Develop your own style, command preference, and even see some areas we can script ourselves. Tools are great and have their place but many fall short in being able to perform a given task when tool fails or are unable to use it on a given system.