# UltraTech

## <img src="https://2044735455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqbFWqDgEG5tczYagv1vA%2Fuploads%2FBRa0EONkZEnPWlNSv75q%2Fimage.png?alt=media&#x26;token=db3deed1-591c-4343-b3ef-9db4b2c584cb" alt="" data-size="line">ULTRATECH WRITEUP

*By Jacvbtaylor*

```
       Used openvpn and Kali Linux 
                 https://tryhackme.com/room/ultratech1
         completed Sep 15, 2022
```

### &#x20;                            **\~\_. UltraTech .\_\~**

&#x20;                                                     **\[ Your Mission ]**

&#x20;            *You have been contracted by* \
&#x20;                      *UltraTech to pentest their infrastructure.*

&#x20;         *It is a grey-box kind of assessment,* \
&#x20;                               *the only information you have is*\
&#x20;             *the company's name and their server's IP address.*

### STEP 1: Answer the questions below

*Which software is using the port 8081?*

<figure><img src="https://2044735455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqbFWqDgEG5tczYagv1vA%2Fuploads%2FWo1ozAy2ONsAxPxEDiLM%2Fimage.png?alt=media&#x26;token=5df310da-40c6-404e-bb3c-77738f39df90" alt=""><figcaption><p>node.js</p></figcaption></figure>

*Which other non-standard port is used?*

<figure><img src="https://2044735455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqbFWqDgEG5tczYagv1vA%2Fuploads%2FqZsdM3sT4nSo3De5XQW6%2Fimage.png?alt=media&#x26;token=c5d3b7e5-22f9-4b66-a859-bc7e891db7b6" alt=""><figcaption><p><em>port 31331</em></p></figcaption></figure>

*Which software using this port?*

<figure><img src="https://2044735455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqbFWqDgEG5tczYagv1vA%2Fuploads%2FNwbTUD0oJ2m9QsfS18Lb%2Fimage.png?alt=media&#x26;token=1e4607f0-81b7-4c69-b544-1c69d68c2661" alt=""><figcaption><p>Apache</p></figcaption></figure>

*Which GNU/Linux distribution seems to be used?*

Ubuntu

*The software using the port 8081 is a REST api, how many of its routes are used by the web application?*\
2&#x20;

**Summary:** \
&#x20;     Using nmap, I discovered an Ubuntu server with an API on port 8081 running node.js. The main webserver is on port 31331 using Apache.&#x20;

&#x20;                                   \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

### STEP 2:

Using scanning as my first step of reconnaissance, I now can move forward with the services I have found.&#x20;

<figure><img src="https://2044735455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqbFWqDgEG5tczYagv1vA%2Fuploads%2F9HHScV2Tb03sy10YgxUQ%2Fimage.png?alt=media&#x26;token=85297141-e8cc-4fa6-8e7e-2f604a0fb6ee" alt=""><figcaption><p>ssh</p></figcaption></figure>

<figure><img src="https://2044735455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqbFWqDgEG5tczYagv1vA%2Fuploads%2FI4npUMOZYB2cWqZRW7Ca%2Fimage.png?alt=media&#x26;token=6cbb9676-e325-4370-adf4-91fb00a10a80" alt=""><figcaption><p>ftp</p></figcaption></figure>

First I tested for a null login for port 21 & 22 ( FTP & SSH). No luck, so I move to the webservices.

Starting with the API, I began an enumeration scan to look for useful directories. While the scan was not finished, it did discover 3 folders I can look at.&#x20;

<figure><img src="https://2044735455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqbFWqDgEG5tczYagv1vA%2Fuploads%2FdTjqg8tcqhGLjumAKw8K%2Fimage.png?alt=media&#x26;token=afb3f1ef-7cd9-445e-9174-48dbbb4f28b9" alt=""><figcaption><p>auth</p></figcaption></figure>

The /auth page quickly became a good target. I will have to find a way to log into it.

<figure><img src="https://2044735455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqbFWqDgEG5tczYagv1vA%2Fuploads%2FKEuQ2EaAFj2obN2j5pVR%2Fimage.png?alt=media&#x26;token=433697dc-598b-4183-a35d-a8ad59187f80" alt=""><figcaption><p>auth/ping</p></figcaption></figure>

Next, I want to look at the webpage on port 31331. Looking at the source code, I can see most, if not all, of the files in this directory are going to be .html, so I quickly starting a scan to search for that extension. It would be useful to search .txt files, too, so I started a scan for that as well.

In total, I had these 3 scans now running:

* `gobuster dir -u http://10.10.241.189:31331 -w /usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt`
* `dirb http://10.10.241.189:31331 -X .html`
* `dirb http://10.10.241.189:31331 -X .txt`

Some important files and directories discovered:

* <http://10.10.241.189:31331/robots.txt> \
  `Allow:`\
  `* User-Agent:` \
  `* Sitemap: /utech_sitemap.txt`&#x20;
* <http://10.10.241.189:31331/utech\\_sitemap.txt\\>
  &#x20;`/` \
  `/index.html` \
  `/what.html` \
  `/partners.html`
* <http://10.10.241.189:31331/partners.html> **(private partner login)**
* <http://10.10.241.189:31331/js> \
  /`api.js` \
  `/app.js` \
  `/app.min.js`
* <http://10.10.241.189:8081/auth&#x20>;
* <http://10.10.241.189:8081/ping>

### STEP 3:

From reading the api.js file, I could see these 2 main actions occurring &#x20;

* `http://${getAPIURL()}/auth`
* `http://${getAPIURL()}/ping?ip=${window.location.hostname}`

It seemed like this could mean: `http.com//10.10.241.189:8081/ping?ip=http.com//10.10.241.189`

So I messed with this a bit in the browser and ended up getting the database name after requesting this url: `http://10.10.241.189:8081/ping?ip=*`

*"ping: utech.db.sqlite: Name or service not known"*

Hopefully I can use this URL to get more information. I first tried appending commands to the IP such as&#x20;

`10.10.241.189%7Cls`                    (10.10.241.189|ls)

`10.10.241.189%3Bls`                    (10.10.241.189;ls)

`10.10.241.189%26%26ls`             (10.10.241.189&\&ls)

But I was quickly finding a lot of filtering in place. I couldn't use a lot of symbols to append to the ping command, below are some of the basic ones I tried:

`;    &   &&   |   ()   []   {}   //`&#x20;

After numerous attempts to bypass this filter, I finally found something that worked:&#x20;

`` 10.10.241.189 `pwd` ``

<figure><img src="https://2044735455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqbFWqDgEG5tczYagv1vA%2Fuploads%2FZQt4KCWwK4TYRIyKDRI7%2Fimage.png?alt=media&#x26;token=b0fab1e4-846f-405e-8310-329ab5edb068" alt=""><figcaption><p>cat /etc/passwd</p></figcaption></figure>

So far I could see I was the www user and I could only see 2 users in the /etc/passwd so far. After sending the `ls` command through, I could see that *utech.db.sqlite* was a name of a file, and it was the only one inside my current working directory. I went ahead and concatenated that file and found a possible user/password hash

<figure><img src="https://2044735455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqbFWqDgEG5tczYagv1vA%2Fuploads%2FAZqxiUyh5Fc7tPgxHdA2%2Fimage.png?alt=media&#x26;token=38b96023-1972-42ac-affa-38f62dfee47e" alt=""><figcaption><p>sql file</p></figcaption></figure>

### STEP 4:

I ran this hash through crackstation.net and it found a matching hash for both of the users. I tried using these credentials to log into SSH but was getting this amazing message \
\
&#x20;                       *"Permission denied,* \
&#x20;                                     *please try again."*

What left me confused was the "M" in front of both usernames. I was trying to log in as user Mr00t and mr00t, with no luck. But when I took the "M" out - I was in.&#x20;

<figure><img src="https://2044735455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqbFWqDgEG5tczYagv1vA%2Fuploads%2F08bALLHitA0bREhqEIip%2Fimage.png?alt=media&#x26;token=ba16d71e-8adf-4a2f-96f3-914f5f2253d8" alt=""><figcaption><p><em>ssh</em></p></figcaption></figure>

The last requirement was for me to get the first 9 characters of the root user's private SSH key.&#x20;

User r00t wasn't allowed to run sudo but I could see that user lp1 had sudo privileges . I needed to find a way to possibly escalate to that user. Using `id` I saw r00t was part of the docker group.&#x20;

<figure><img src="https://2044735455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqbFWqDgEG5tczYagv1vA%2Fuploads%2FuEYifQdQYiRe23wxpHDz%2Fimage.png?alt=media&#x26;token=5b96c5d7-3dd7-4e05-8966-f1adf65c53af" alt=""><figcaption><p>id</p></figcaption></figure>

I wasn't sure how to accomplish this quite yet until I came across this webpage: <https://flast101.github.io/docker-privesc/>

The third option showed a way to get an interactive shell by running the following command:

**`docker run -v /:/mnt --rm -it alpine chroot /mnt sh`**

I was excited to try this command but was quickly shutdown with an error:

<figure><img src="https://2044735455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqbFWqDgEG5tczYagv1vA%2Fuploads%2F5pG7DVGzkcx9a60zxwJA%2Fimage.png?alt=media&#x26;token=02ce5c4c-ac45-4bac-85d3-d3a68bc06f4c" alt=""><figcaption><p>image</p></figcaption></figure>

The machine couldn't find the alpine image, and it couldn't pull it. My user could use the docker daemon so I checked which containers were running using `docker ps -a`

I was shown 3 containers using the bash image. Maybe we can use this instead? You bet we can

<figure><img src="https://2044735455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqbFWqDgEG5tczYagv1vA%2Fuploads%2FX7ozb9WwFGh2VnGbVJlr%2Fimage.png?alt=media&#x26;token=e6c7ddbb-11db-49ba-9b92-c58348fb0e7f" alt=""><figcaption><p>docker shell</p></figcaption></figure>

This shell was a bit of a pain to interact with. You can't tab to complete file names and you can't backspace, so the key here is to type carefully and purposefully

After entering the .ssh directory, we can now see the id\_rsa files and we can grab the characters we need.

<figure><img src="https://2044735455-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqbFWqDgEG5tczYagv1vA%2Fuploads%2FXqNGt4RUH6oO8dD8cVQi%2Fimage.png?alt=media&#x26;token=1b14c0c0-13e5-451d-9920-b058cec4d67b" alt=""><figcaption><p>private key</p></figcaption></figure>
