It was an easy machine from Hack The Box with:
-
Redis
unauthenticated RCE. - SSH user private key in some system folder.
- Webmin package update RCE with Metasploit.
1. Enumeration
First things first lets add
10.10.10.160
in
/etc/hosts
as
postman.htb
and enumerate our machine with
nmap
to discover open ports and services.
I ran initial
nmap
and got some stuff, but that wasn’t enough. So, lets run
nmap
with all ports to see what’s really running on this machine.
We found
http
on port
80, 10000
,
ssh
on
port
22
and
the interesting one was
Redis
on port
6347
.
So, lets go to the browser to see what is running on those ports
80, 10000
.
Web Enumeration
The home page on port
80
was
sort of nothing just a little scroll to top button:
Lets check the other port
postman.htb:10000
:
It shows us an
SSL
error, so lets add
https
:
Now it’s sort of
login
page for some web app called Webmin, so let us
search what it is.
“Webmin is a web-based interface for system administration for Unix. Using any modern web browser, you can setup user accounts, Apache, DNS, file sharing and much more.”
So, it’s an app able to configure and manage Unix system files.
I tried to intercept the login request with
burp
to see what can I do with it, but it seems well-configured and
there is no way to brute force because the response time for
each request and that could take very long time. Don’t forget
it’s an easy box.
Redis Enumeration
“Redis is an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability. It supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, bitmaps, streams, and spatial indexes.”
Now we still have
Redis
on port
6347
.
I don’ know much about it, so let’s search about
Redis
database and how to connect to it with Linux. After searching, I
found
Redis
Command Line Interface to interact with
Redis
servers.
After installing
redis-cli
and trying to connect to
postman.htb
it. We got an access without any sort of authentication. I spend
some time learning basic
Redis
commands to see what can I do with it until I got something.
The command above just shows us where’s the config file for this
Redis
instance and we got
.ssh
as config file. I struggled with this a lot thinking what I can
do to take advantage of that config file.
2. Exploitation
We know that the machine run
ssh
service so I found that I can put something on the
Redis
memory, copy it into a random file let say
~/ssh/authorized_keys
as config file in order to gain access with
ssh
.
Let us generate
ssh
key:
Now we have the key. Our goal is to put it into the
Redis
server memory and after that we can transfer it into a file, in
a way that the
authorized_keys
is still a valid file.
To store the key into the
Redis
memory, we should use the
RDP
format.
“RDB format is a binary representation of the in-memory store.”
By adding some padding around
ssh
public key we generated.
Now
key.txt
is our public key with new lines. We can write this inside
Redis
memory using
redis-cli
.
The writing process takes some steps and I love writing code, so
let’s automate our process with the following
python
script:
The script does the following steps:
-
Flushing
Redis
memory to start writing our key. -
Sending our padded
ssh
public key toRedis
memory. -
Setting
Redis
config directory to be.ssh
. -
Setting
authorized_keys
as aRedis
config file. - Saving the config settings.
Now we’re able to gain access via
ssh
using our private key:
3. User Enumeration
Let’s see available users exist in the system:
We already on
redis
,
so we can see what user
Matt
can do on the system:
Oh! We found some sort of
ssh
private key inside
/opt/id_rsa.bak
. Let’s copy it into our machine and extract it using
ssh2john
.
Own User
Now we’re able to use our friend
john
to crack the
matt.priv
and own user:
And we got
computer2008
as a
ssh
password. I tried to connect with
ssh
,
but something went wrong.
So I tried to switch to user
Matt
from
redis
user and it worked.
4. Root
As we remember we got a Webmin app running on
port
10000
.
Now we can see what version is running on the box and search for
any vulnerabilities with
searchsploit
.
We found
Package Updates RCE
with
Metasploit
module. Let’s run it and own root: