# Stocker

## <mark style="color:red;">nmap :</mark>&#x20;

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FnL9GQo3pSVYqiKMX17AU%2Fpasted_image.png?alt=media&#x26;token=e32c92e1-1c6d-45ed-86e6-190f1c7e7971" alt=""><figcaption></figcaption></figure></div>

make sure to add the stocker.htb to the etc/hosts file

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FPNmriTPJC2d0xedHlAPD%2Fpasted_image003.png?alt=media&#x26;token=13bab32f-04d4-4bf0-8d6a-4bce38bd6069" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FKPoOLFJUi8bMvR1JsWyT%2Fpasted_image004.png?alt=media&#x26;token=3cdafb06-c2c7-435d-b2b7-5db29fc6a842" alt=""><figcaption><p>Directory Enumeration : and we have no results</p></figcaption></figure></div>

## <mark style="color:red;">Directory Enumeration :</mark>&#x20;

and we have no results

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F9zVhRZdNpehvuEiKZM5y%2Fpasted_image001.png?alt=media&#x26;token=986818d7-8004-4780-8e94-78e92c8ff279" alt=""><figcaption></figcaption></figure></div>

## <mark style="color:red;">Virtual Host Enumeration :</mark>

```python
ffuf -w /usr/share/wordlists/SecLists/Discovery/DNS/subdomains-top1million-5000.txt -H "Host: FUZZ.stocker.htb" -u http://stocker.htb -fc 403,301
```

and we have found `dev.stocker.htb` subdomain

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FH1ab9jq4qSRy2o3YgNKa%2Fpasted_image002.png?alt=media&#x26;token=50e2a3bc-2881-4585-b424-a33642d075b7" alt=""><figcaption></figcaption></figure></div>

make sure to add the subdomain found to the **/etc/hosts** file

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2Fo3HGvovYHEwo692oPQXc%2Fpasted_image005.png?alt=media&#x26;token=a40352b4-4046-4f48-b0b3-4362ff5970df" alt=""><figcaption></figcaption></figure></div>

and if we browse the subdomain we will be redirected to the login page

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F0NKwMti3DRApwGUAHmgD%2Fpasted_image006.png?alt=media&#x26;token=736f80c2-7c7e-482e-b77d-6afd3a59dab7" alt=""><figcaption></figcaption></figure></div>

## <mark style="color:red;">No SQL injection :</mark>&#x20;

intercept the request of login in using burp using random credentials

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F4yEpo6UEaLNtnhf291Ja%2Fpasted_image007.png?alt=media&#x26;token=88662d27-5c89-47d5-b9e8-6ee56f754456" alt=""><figcaption></figcaption></figure></div>

now change the **content-type** to **aplication/json** and change the data sent to be json and we get redirected to an error page which is the page that will show invalid username or password

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FQaTTdAg2nQwOfMoz8PwR%2Fpasted_image008.png?alt=media&#x26;token=b5dc6f12-33f9-4e04-8cb7-90840731447f" alt=""><figcaption></figcaption></figure></div>

and this means that it accepts json data but our credentials are not valid

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F3MHJnRwPjz0rK813MHii%2Fpasted_image009.png?alt=media&#x26;token=0090cb17-2567-43b7-9c8d-220a82e526d6" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F7Dvp336a6b5fp2ZXu7Gj%2Fpasted_image012.png?alt=media&#x26;token=e950c8a3-4aa6-42e9-8853-253f24f3a288" alt=""><figcaption></figcaption></figure></div>

or using curl&#x20;

```python
curl -X POST -H "Content-Type: application/json" -d '{"username": {"$gt": ""},"password": {"$gt": ""} }' http://dev.stocker.htb/login 
```

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FY4pLw6AiCOWLHOlRLrSD%2Fpasted_image010.png?alt=media&#x26;token=614e98a6-7820-4bb4-8984-a0d13f244bda" alt=""><figcaption></figcaption></figure></div>

and if we go back to the browser we will find that we were redirected to the **/stock** directory and logged in automatically

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FC3YJ1iTuaRiMpS24PelT%2Fpasted_image011.png?alt=media&#x26;token=c9d09fec-97c3-4448-9be0-b9a911d7e13b" alt=""><figcaption></figcaption></figure></div>

intercept Submit Purchase&#x20;

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FvedK2UrtPFZZLAbIVXEi%2Fpasted_image014.png?alt=media&#x26;token=a8febf54-e6ef-446c-be35-4ce3fe76b5cf" alt=""><figcaption></figcaption></figure></div>

add some elements to your basket and then click on view cart and purchase and you will be given an pdf file&#x20;

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FjnlqLjMrT5FatLsw6Ci3%2Fpasted_image013.png?alt=media&#x26;token=b9b57cff-7bd7-44f0-aa9b-95bda04d80d2" alt=""><figcaption></figcaption></figure></div>

the title is directly rendered in the pdf so maybe it is html so let's try injecting some html&#x20;

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FmzGsphvISbgpjO8I5XZA%2Fpasted_image015.png?alt=media&#x26;token=7f1aa7f1-483b-471a-9f0c-a87159ac7d90" alt=""><figcaption></figcaption></figure></div>

let's save the pdf to a file (/api/po/orderId) is the path to the generated pdf and you will see this path if you view the generated pdf from the website&#x20;

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2Fu68sLfnj99X2KEZkZScQ%2Fpasted_image018.png?alt=media&#x26;token=1f87ff24-1c56-48ed-93a9-dd46bf974101" alt=""><figcaption></figcaption></figure></div>

and now if we open the pdf we will see that the iframe is generated and it has the file passwd content in it and from we can find out that there is 2 users with bash enabled which are **angoose** and **root**

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FVlcX4HON89JFkpmNcdT6%2Fpasted_image017.png?alt=media&#x26;token=a84e867c-c0eb-4dfd-91bb-aa30153864c8" alt=""><figcaption></figcaption></figure></div>

we dont know where is located the developement code a trick we can use is to send invalid json data so we get useful information in the errors and from the error we can see that the developement code is located at **/var/www/dev**&#x20;

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FlNkoZjzFwpPVx1sklBjj%2Fpasted_image019.png?alt=media&#x26;token=71ae9c5a-3386-4f31-8a0e-d5fc1feebf8d" alt=""><figcaption></figcaption></figure></div>

let's leak the index.js file from /var/www/dev (index.js is the entry point for javascript files)

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FG6ADjCwr0L6Ah2eyeHkl%2Fpasted_image020.png?alt=media&#x26;token=da1e1ec9-e808-4b07-8589-c9097b9b5625" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2F5nV7a5iggSEH3vq9AyU7%2Fpasted_image021.png?alt=media&#x26;token=0280ed55-b9be-4166-a4b2-0477ccf69dd2" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FJM3VRzlwfSKGmJgx59rV%2Fpasted_image022.png?alt=media&#x26;token=5c5d81fe-ea75-4949-a919-6fe3b8bea80d" alt=""><figcaption></figcaption></figure></div>

the mongodb URL contains a password that maybe useful this is the format of a mongodb URL and if we campare it with the mongodb url in the leaked index.js we will find out that the password is : <mark style="color:purple;">**IHeardPassphrasesArePrettySecure**</mark>&#x20;

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FL3GlhYXXoZfmpbHlTUnQ%2Fpasted_image026.png?alt=media&#x26;token=cdf2f683-4402-4bb2-b1eb-3c59a9976c59" alt=""><figcaption></figcaption></figure></div>

## <mark style="color:red;">SSH into angoose user using the password found in the mongodb URL :</mark>&#x20;

we have already found a user called angoose in the /etc/passwd file .

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FK89wKe0TwYdvyvzkjVx0%2Fpasted_image027.png?alt=media&#x26;token=31d7bc55-6240-4d8e-98f0-6b885a15772c" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2Fnc66u0wIhhmtMPxtzkrV%2Fpasted_image028.png?alt=media&#x26;token=8b71973f-0cbf-48b7-82e4-797958478736" alt=""><figcaption></figcaption></figure></div>

## <mark style="color:red;">Root Shell :</mark>

search node on **gtfobin**&#x20;

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FobVMgI2JrWiJkLfHHgiB%2Fpasted_image029.png?alt=media&#x26;token=cbce593f-4139-4b57-9e1e-3e717ee224ab" alt=""><figcaption></figcaption></figure></div>

we will write the code between '' and we will put it inside a file that have .js extension and then execute it with node

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FG0Gsjts5dBDvue3Opb0F%2Fpasted_image030.png?alt=media&#x26;token=45e96d24-a88e-474f-91d4-ccb4ff4232db" alt=""><figcaption></figcaption></figure></div>

we don't have permissions to move our exploit script to the /usr/local/scripts directory so we will use path traversal

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FGJPrgMJgAJp0fZFoOtZr%2Fpasted_image031.png?alt=media&#x26;token=e891231c-18cc-4fdb-bbef-972509927cce" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://1410593648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYI2noEqPw69jd0hR7Prp%2Fuploads%2FSm0qtO65REBWpI71QhDx%2Fimage.png?alt=media&#x26;token=2a4f27ab-498f-4a52-86f2-46ae4351374a" alt=""><figcaption></figcaption></figure></div>

hope you found this walkthrough easy to understand and follow

Greeting From [<mark style="color:red;">Sayonara</mark>](https://github.com/ismail-arame)
