24 Sep 2021 / Document No D21.100.133 Prepared By: Polarbearer Machine Author (S) : Polarbearer & Gibparadox Difficulty: Classification: Official
24 Sep 2021 / Document No D21.100.133 Prepared By: Polarbearer Machine Author (S) : Polarbearer & Gibparadox Difficulty: Classification: Official
Difficulty: Medium
Classification: Official
Synopsis
Pit is a medium difficulty Linux machine that focuses on SNMP enumeration and exploitation, while
introducing basic SELinux restrictions and web misconfigurations. By enumerating SNMP via the default
insecure public community, information about filesystems and users can be obtained. This allows
attackers to discover and gain access to a vulnerable SeedDMS instance, which was incorrectly patched by
applying Apache .htaccess rules to an Nginx server where they are not effective. Exploiting CVE-2019-
12744 results in Remote Command Execution (with some SELinux restrictions) and subsequent access to a
Cockpit console via password reuse. Privileges are escalated by writing a Bash script that is executed as an
SNMP extension when the corresponding OID is queried.
Skills Required
SNMP enumeration
Web enumeration
Basic Linux knowledge
Skills Learned
SNMP extensions
Exploiting CVE-2019-12744
Basic awareness about possible SELinux restrictions
Enumeration
Nmap
TCP
ports=$(nmap -p- --min-rate=1000 -T4 10.10.10.241 | grep ^[0-9] | cut -d '/' -f1 | tr
'\n' ',' | sed s/,$//)
nmap -sC -sV -p$ports 10.10.10.241
Nmap reveals that OpenSSH and nginx are listening on their default ports. Additionally, a service listening
on port 9090 is using a TLS certificate with commonName dms-pit.htb .
UDP
SNMP
The snmpwalk command can be used to verify SNMP access using the default public community.
Since walking the whole SNMP tree may be too time consuming, we will query for specific OIDs focusing on
the information we are interested in. We start with disk information:
Querying SNMP for standard OIDs (filesystems, network settings, etc.) does not provide us with any useful
information, so we further enumerate potential custom extensions by querying the corresponding OID:
Nginx
Browsing by IP address takes us to the default Nginx Red Hat page:
Having discovered the common name dms-pit.htb from previous enumeration, we can add a
corresponding entry to /etc/hosts and then browse to http://dms-pit.htb :
Knowing a directory named seeddms51x/seeddms exists under /var/www/html , we try accessing it via the
URL http://dms-pit.htb/seeddms51x/seeddms/ . This takes us to the SeedDMS login screen:
Cockpit
Browsing to port 9090 takes us to the CentOS Cockpit login page. We don't have any valid credentials at this
point, so we are unable to proceed further.
Foothold
After a few failed attempts, we manage to obtain access to SeedDMS using credentials michelle:michelle
for the user discovered earlier.
According to the attached CHANGELOG file, a Remote Command Execution vulnerability was patched in
version 5.1.11:
--------------------------------------------------------------------------------
Changes in version 5.1.11
--------------------------------------------------------------------------------
- fix for CVE-2019-12744 (Remote Command Execution through unvalidated
file upload), add .htaccess file to data directory, better documentation
for installing seeddms
SECURITY CONSIDERATIONS
=======================
configured in your web server! If you do so, there is good change that
If you can't place the data directory outside of document root, that either
----------------------------------------------
```
<ifModule mod_authz_core.c>
</ifModule>
<ifModule !mod_authz_core.c>
</ifModule>
<ifModule mod_autoindex.c>
IndexIgnore *
</ifModule>
```
This information matches with the available PoC for CVE-2019-12744, which exploits unvalidated file upload
to the data directory. As the example clearly states, the .htaccess settings are meant for Apache, while
the web server running on the target system is nginx. As we can see by looking at the quickstart archive, this
is configured by default. We can confirm it by requesting the .htaccess file:
curl http://dms-pit.htb/seeddms51x/data/.htaccess
Since nginx ignores .htaccess files, there is a chance we might still be able to upload arbitrary files and
access them to obtain remote code execution.
Next we navigate to the Docs/Users/michelle folder (where we have write permissions), select the Add
document menu item and upload the file:
Notice that only the Name and Local file fields are required. The file is successfully uploaded:
We can now grab the document ID ( 36 in this example) from the link URL:
http://dms-pit.htb/seeddms51x/seeddms/out/out.ViewDocument.php?documentid=36&showtree=1
According to the PoC, the uploaded web shell should be accessible at /data/1048576/<document
id>/1.php?cmd=<command> .
curl http://dms-pit.htb/seeddms51x/data/1048576/36/1.php?cmd=id
Any reverse/bind shell attempt seems to be blocked (possibly by SELinux), so we attempt to read interesting
files instead. Specifically, we are interested in the conf/settings.xml file:
curl http://dms-pit.htb/seeddms51x/data/1048576/36/1.php?
cmd=cat%20/var/www/html/seeddms51x/conf/settings.xml
Among other things, the settings.xml file contains database access information:
SSH password authentication is disabled, but the retrieved password ied^ieY6xoquu can be used to login
as michelle from the Cockpit console on port 9090.
From the Terminal page we can obtain an interactive shell and finally read the user flag.
Privilege Escalation
As noted previously, the /usr/bin/monitor script is called by snmpd. We can read it:
We don't have read or execute permissions on the /usr/local/monitoring directory, but the + sign in
the file listing indicates that ACLs have been set on the directory:
This means we have write access to the directory, which allows us to write arbitrary scripts and have them
executed (with root privileges) by snmpd. SELinux rules, as they did earlier, prevent us from opening TCP
connections, so a bind/reverse shell won't work. Additionally, SELinux blocks access to the root.txt file,
which makes it impossible to just echo it and read the flag via SNMP. Somehing we can do, instead, is write
our public SSH key into root 's authorized_keys file. We create the following check_key.sh script inside
the monitoring directory: