Today’s VM is the third machine in the Hackfest series:
This is a vulnerable machine i created for the Hackfest 2016 CTF http://hackfest.ca/
Difficulty : Hard
Tips:
If youre stuck enumerate more! Seriously take each service running on the system and enumerate them more!
Goals: This machine is intended to take a lot of enumeration and understanding of Linux system.
There are 4 flags on this machine 1. Get a shell 2. Get root access 3. There is a post exploitation flag on the box 4. There is something on
this box that is different from the others from this series (Quaoar and Sedna) find why its different
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.1 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 3a:48:6e:8e:3f:32:26:f8:b6:a1:c6:b1:70:73:37:75 (RSA)
| 256 04:55:e6:48:50:d6:93:d7:12:80:a0:68:bc:97:fa:33 (ECDSA)
|_ 256 c9:a9:c9:0d:df:7c:fc:a7:da:87:ef:d3:38:c3:f2:a6 (ED25519)
53/tcp open domain ISC BIND 9.10.3-P4 (Ubuntu Linux)
| dns-nsid:
|_ bind.version: 9.10.3-P4-Ubuntu
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
| http-robots.txt: 30 disallowed entries (15 shown)
| /exponent.js.php /exponent.js2.php /exponent.php
| /exponent_bootstrap.php /exponent_constants.php /exponent_php_setup.php
| /exponent_version.php /getswversion.php /login.php /overrides.php
| /popup.php /selector.php /site_rss.php /source_selector.php
|_/thumb.php
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Site doesn't have a title (text/html).
110/tcp open pop3 Dovecot pop3d
|_pop3-capabilities: AUTH-RESP-CODE CAPA UIDL SASL RESP-CODES STLS PIPELINING TOP
|_ssl-date: TLS randomness does not represent time
111/tcp open rpcbind 2-4 (RPC #100000)
| rpcinfo:
| program version port/proto service
| 100000 2,3,4 111/tcp rpcbind
| 100000 2,3,4 111/udp rpcbind
| 100003 2,3,4 2049/tcp nfs
| 100003 2,3,4 2049/udp nfs
| 100005 1,2,3 36199/tcp mountd
| 100005 1,2,3 38727/udp mountd
| 100021 1,3,4 41463/tcp nlockmgr
| 100021 1,3,4 43317/udp nlockmgr
| 100227 2,3 2049/tcp nfs_acl
|_ 100227 2,3 2049/udp nfs_acl
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
143/tcp open imap Dovecot imapd
|_imap-capabilities: have more SASL-IR OK LOGIN-REFERRALS ENABLE capabilities Pre-login LOGINDISABLEDA0001 STARTTLS IDLE listed ID LITERAL+ IMAP4rev1 post-login
|_ssl-date: TLS randomness does not represent time
443/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.1 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 3a:48:6e:8e:3f:32:26:f8:b6:a1:c6:b1:70:73:37:75 (RSA)
| 256 04:55:e6:48:50:d6:93:d7:12:80:a0:68:bc:97:fa:33 (ECDSA)
|_ 256 c9:a9:c9:0d:df:7c:fc:a7:da:87:ef:d3:38:c3:f2:a6 (ED25519)
445/tcp open netbios-ssn Samba smbd 4.3.11-Ubuntu (workgroup: WORKGROUP)
993/tcp open ssl/imaps?
|_ssl-date: TLS randomness does not represent time
995/tcp open ssl/pop3s?
|_ssl-date: TLS randomness does not represent time
2049/tcp open nfs_acl 2-3 (RPC #100227)
36199/tcp open mountd 1-3 (RPC #100005)
41463/tcp open nlockmgr 1-4 (RPC #100021)
54301/tcp open mountd 1-3 (RPC #100005)
54471/tcp open mountd 1-3 (RPC #100005)
The web server greets us with a familiar planet image. In the background, I started some Samba enumeration, but didn’t find anything interesting:
12345678
smbmap -H 192.168.159.131
[+] Finding open SMB ports....
[+] Guest SMB session established on 192.168.159.131...
[+] IP: 192.168.159.131:445 Name: 192.168.159.131
Disk Permissions
---- -----------
print$ NO ACCESS
IPC$ NO ACCESS
I prefer to leave the web server for last when there are more vectors available, so before further poking at it, I also checked the if something is shared via the NFS:
123
showmount -e 192.168.159.131
Export list for 192.168.159.131:
/tmp *
I looked for exploits for this CMS, but the interesting ones were from older versions. According to the RELEASE.md file, the version here is 2.3.8. I also found that this version should be vulnerable to CVE-2016-7095, but couldn’t find a way to exploit it. Since the VM description emphasized enumeration, I fired up gobuster to see if there’s more I might have missed on the web server:
Got a Forbidden error when trying to access the ssh creds file, but I was able to download the SimplePHPQuiz one. It contained the files for another application that doesn’t seem to be installed. I did a search for passwords and got a hit:
Inside db_conn.php I found some database credentials:
12345
//Set the database access information as constantsDEFINE('DB_USER','dbuser');DEFINE('DB_PASSWORD','dbpassword');DEFINE('DB_HOST','localhost');DEFINE('DB_NAME','quizdb');
Moving on. The /cron folder contains a bunch of PHP files that I couldn’t get anything interesting from. The /framework folder was another dead end. But when I went to /zenphoto, I saw that the Zenphoto 1.4.10 installation needed a last step of providing database credentials. It was configured with root@localhost and it got an access denied. In searchsploit I saw a local file inclusion exploit for this version of Zenphoto, so I tried to complete the installation with the previously discovered credentials. It worked and I was then prompted to create an admin user, which I did:
The path didn’t work for me. I kept looking around while logged in as admin and noticed a file upload plugin:
I enabled the elFinder plugin and now I could upload arbitrary files:
Flag #1 – Standard shell
With the PHP reverse shell uploaded, all I had to do was to go to it in the /uploaded directory and I got a shell and the first flag:
1234567891011121314151617
nc-vnlp9000listeningon[any]9000...connectto[192.168.159.129]from(UNKNOWN)[192.168.159.131]38806LinuxOrcus4.4.0-45-generic#66-Ubuntu SMP Wed Oct 19 14:12:05 UTC 2016 i686 i686 i686 GNU/Linux12:02:20up25min,0users,loadaverage:0.07,0.02,0.00USERTTYFROMLOGIN@IDLEJCPUPCPUWHATuid=33(www-data)gid=33(www-data)groups=33(www-data)/bin/sh:0:can'taccesstty;jobcontrolturnedoff$ls/var/www9bd556e5c961356857d6d527a7973560-zen-cart-v1.5.4-12302014.zipa0c4f0d176f87ceda9b9890af09ed644-Adem-master.zipb873fef091715964d207daa19d320a99-zenphoto-zenphoto-1.4.10.tar.gzflag.txthtmlzenphoto-zenphoto-1.4.10$catflag.txt868c889965b7ada547fae81f922e45c4
Flag #2 – Getting root
Remembering the NFS share that didn’t get us anywhere earlier, I checked the /etc/exports file and found something really interesting and good for us:
1
/tmp*(rw,no_root_squash)
Not only we had write permissions on the share, which I haven’t tried, but no root squash means that our root user can leave a SUID shell owned by root on the share for our www-data user after we copy it there with our low-privilege shell: