# Basic Pentesting

Try this challenge in [TryHackMe: **Basic Pentesting**](https://tryhackme.com/r/room/basicpentestingjt)

> In doing this challenge, I learned the following skills and tools:
>
> * **brute forcing** - using <mark style="color:orange;">**hydra**</mark>
> * **hash cracking** - using <mark style="color:orange;">**ssh2john**</mark>, <mark style="color:orange;">**john**</mark>
> * **service enumeration** - using <mark style="color:orange;">**nmap**</mark>, <mark style="color:orange;">**gobuster**</mark>
> * **Linux Enumeration** - using <mark style="color:orange;">**enum4linux**</mark>, <mark style="color:orange;">**linpeas**</mark>

## Web App Testing and Privilege Escalation

### Find the services exposed by the machine

Run <mark style="color:orange;">**nmap**</mark> and save it in basicpentest directory

{% code lineNumbers="true" %}

```bash
mkdir basicpentest
nmap -sC -sV 10.10.X.X -oN basicpentest/initial
```

{% endcode %}

{% hint style="info" %}
Just change the **`10.10.X.X`** to the IP address assigned to your target machine
{% endhint %}

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2FqTagQQnUhoqC9MNF62Br%2FScreenshot_2024-08-15_at_15.19.14.png?alt=media&#x26;token=38a67366-550e-4f94-b43a-3b38b39ef5e2" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2F0Qn0yJ4k1x6KmWWsDtQv%2FScreenshot_2024-08-15_at_15.20.19.png?alt=media&#x26;token=808e8607-0174-40ae-9022-bb2c86a5ce36" alt="" width="563"><figcaption></figcaption></figure>

Check it in the browser: **`http://10.10.X.X`**

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2FTxbVFDs2Zt75vPhjpYMF%2FScreenshot_2024-08-15_at_15.22.49.png?alt=media&#x26;token=514dea65-5138-414d-940c-54a7970a9928" alt="" width="563"><figcaption></figcaption></figure>

&#x20;Try to **`View Page Source`**. There is a note in green there to <mark style="color:green;">**check their dev note section**</mark>.&#x20;

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2FvbUpnUqxGFBo9ANa6cJa%2FScreenshot_2024-08-15_at_15.23.10.png?alt=media&#x26;token=b68f5158-1ac5-48f3-8aed-8374f22696d8" alt="" width="563"><figcaption></figcaption></figure>

So let's check if there is a **`/dev`** directory.

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2FzJeBgXH71ohX14qP0U0z%2FScreenshot_2024-08-15_at_15.23.28.png?alt=media&#x26;token=f89cdc7b-2013-4752-aff4-52af0e8d2d01" alt="" width="563"><figcaption></figcaption></figure>

We get **Not Found** responses from both paths, but we can see information disclosure in the responses that are worth noting.

{% hint style="info" %}
**Apache/2.4.18 (Ubuntu) Server at 10.10.X.X Port 80**
{% endhint %}

### What is the name of the hidden directory on the web server (enter name without /)?

Using <mark style="color:orange;">**gobuster**</mark> let's try to figure out what directories are available to the server.

{% code overflow="wrap" %}

```bash
gobuster dir -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -u http://10.10.X.X
```

{% endcode %}

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2FgUl7EUTm7UqcS2BoEp8u%2Fimage.png?alt=media&#x26;token=d6cb02da-3949-44aa-85ea-89465338a2af" alt="" width="563"><figcaption></figcaption></figure>

Even without finishing the scan, we get the directory **`/development`**.

When we access the directory, we'll see two text files, **`dev.txt`** and **`j.txt`**. Let's open both.&#x20;

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2Fo2eAWYLYkWsHcV04NHVG%2Fimage.png?alt=media&#x26;token=25ec684a-1f82-46fa-9096-772e8dbb7e13" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2F1KJybQMXl833n3bqNxem%2Fimage.png?alt=media&#x26;token=e42d27c8-016a-4eb7-9fac-2e8468254aa6" alt=""><figcaption></figcaption></figure>

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2Fc0BvIxew6aNaNYdxlNrI%2Fimage.png?alt=media&#x26;token=c1215184-433d-4999-962d-9cffc070e1cb" alt=""><figcaption></figcaption></figure>

### User brute-forcing to find the username & password

We found users `jan` & `kay` via <mark style="color:orange;">**enum4linux**</mark>

```bash
/usr/bin/enum4linux -a 10.10.X.X | tee enum4linux.lo
```

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2F0iMq7iawZKFh9lhY4jox%2FScreenshot_2024-08-15_at_16.09.59.png?alt=media&#x26;token=0ff4739d-9e6f-4e0b-bcbd-8209b9f133f2" alt="" width="563"><figcaption></figcaption></figure>

Using <mark style="color:orange;">**hydra**</mark>, we now know the password

```bash
hydra -l jan -P /usr/share/wordlists/rockyou.txt ssh://10.10.X.X
```

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2F7NRFPkKAHdMWCPKilRJz%2FScreenshot_2024-08-15_at_16.23.42.png?alt=media&#x26;token=42053d47-0b9d-42e3-a2d2-b2d72eb26359" alt="" width="563"><figcaption></figcaption></figure>

Now that we know jan’s credentials, we used them to log in via SSH

Check folders and see if we can find interesting files

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2FCA4gH1u6SXPlO7CZzlUe%2FScreenshot_2024-08-15_at_16.47.53.png?alt=media&#x26;token=3bb74a72-644e-45c6-b234-ee042ae2a50f" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2FQ2ofQnHLiM8VpAuxf2rV%2FScreenshot_2024-08-15_at_16.53.25.png?alt=media&#x26;token=5474a8d8-1ee4-4923-94a8-79b00c0f637d" alt="" width="563"><figcaption></figcaption></figure>

Since most actions led to denied permissions, we ran <mark style="color:orange;">**linpeas**</mark> in the machine to check possible privilege escalation methods.

To copy `linpeas.sh` to the machine in the `/dev/shm` folder:

```bash
scp linpeas.sh jan@10.10.X.X:/tmp
```

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2FCEKF9JYpY2seOiinb3Ah%2FScreenshot_2024-08-16_at_12.53.41.png?alt=media&#x26;token=221f540a-02b4-4c9e-84e3-aa266e9dd54a" alt="" width="563"><figcaption></figcaption></figure>

Check if the linpeas file is transferred successfully

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2FTUSqr3eBR5MxhoDoLJew%2F01236c21-9255-4754-8f69-207e7deb036a.png?alt=media&#x26;token=5f49fbdc-761a-4d66-9be0-df85142760b9" alt="" width="563"><figcaption></figcaption></figure>

Make linpeas executable:

```bash
chmod +x linpeas.sh 
```

Then execute linpeas:

```bash
./linpeas.sh
```

From the linpeas results, we found private SSH keys in the path `/home/kay/.ssh/id_rsa`

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2FPKJHmuUFv9ByYdf00fXE%2FScreenshot_2024-08-16_at_13.23.47.png?alt=media&#x26;token=44766fda-aa8d-4e5b-9c2d-6d931d6fc5ca" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2F7nTln8ykL08Y0KGkIsJ9%2FScreenshot_2024-08-16_at_13.42.42.png?alt=media&#x26;token=8d53c253-63a7-47bf-965b-3817ffa6adaf" alt="" width="563"><figcaption></figcaption></figure>

Open the id\_rsa file then copy the contents

```bash
cat id_rsa
```

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2FsmtFUdExAkHYbd2irGVW%2FScreenshot_2024-08-16_at_13.43.14.png?alt=media&#x26;token=a402fa20-caab-46ac-ac44-fc6a1a5e6d69" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2Fpe5dVMD9EUICu3LalkIR%2FScreenshot_2024-08-16_at_13.43.36.png?alt=media&#x26;token=33ae6ca7-f195-4f0b-93d0-ee7b5ad27710" alt="" width="563"><figcaption></figcaption></figure>

In your Kali machine, paste the contents into a file named `kay_id_rsa`

```bash
nano kay_id_rsa
```

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2Frgn04xNeYXPLbN0dB5mi%2FScreenshot_2024-08-16_at_13.45.24.png?alt=media&#x26;token=179d0802-1b92-4d4b-bfeb-24d9a0ee1263" alt="" width="563"><figcaption></figcaption></figure>

Change the permissions of the file to read-writable only by you

```bash
chmod 600 kay_id_rsa
```

Try logging in to the machine using the user Kay’s id\_rsa

```bash
ssh -i kay_id_rsa kay@10.10.X.X
```

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2FMVvPNFSUNGD9UWJ5Tjov%2FScreenshot_2024-08-16_at_13.47.05.png?alt=media&#x26;token=db1978dd-1f79-4223-9cce-a72fca210d4a" alt="" width="563"><figcaption></figcaption></figure>

We find that a passphrase is needed for this file.

To figure out the passphrase for kay’s id\_rsa, we used <mark style="color:orange;">**ssh2john**</mark> in the JohnTheRIpper module

```bash
ssh2john ~/kay_id_rsa
```

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2Ffe9YjyBh4y9kkwlOaGyW%2FScreenshot_2024-08-16_at_14.24.31.png?alt=media&#x26;token=7e9c7eb1-a25e-43c6-b874-80fa7c3a1bbe" alt="" width="563"><figcaption></figcaption></figure>

We need to save this in a text file to be decrypted via <mark style="color:orange;">**john**</mark>

```bash
ssh2john ~/kay_id_rsa > ~/kay_id_rsa_john.txt
```

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2FgLJj2oKKs9DybULlqOO5%2FScreenshot_2024-08-16_at_13.48.55.png?alt=media&#x26;token=abffe199-183a-4576-9586-b1bdf09fa7ec" alt="" width="563"><figcaption></figcaption></figure>

Using john, we decrypted the file and got the passphrase

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2FMNzxxcdxKaAhrUmnJNlK%2FScreenshot_2024-08-16_at_14.23.57.png?alt=media&#x26;token=4999ecb6-d1a9-4188-9d93-74097ac307fa" alt="" width="563"><figcaption></figcaption></figure>

We can now log in using kay’s credentials

```bash
ssh -i kay_id_rsa kay@10.10.X.X
```

{% hint style="success" %}
We opened the **pass.bak** file and then the password was revealed
{% endhint %}

<figure><img src="https://290105472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F89FZKOizBQcf0e0Qdrp8%2Fuploads%2FAXJ2mwmg4j1ZWcPoreLs%2Fimage.png?alt=media&#x26;token=95f214b7-a35e-4f2c-8192-0cb9dc6009ea" alt=""><figcaption></figcaption></figure>
