Introduction
This is a walkthrough on the retired htb machine called Writeup, which was rated as easy by most users, although the box had some quite tricky vectors, especially in Privilege Escalation.Enumeration on Ports and Services

Enumerating the web application

The /writeup directory


<meta name=”Generator” content=”CMS Made Simple – Copyright (C) 2004-2019. All rights reserved.” />
Exploiting CMS Made Simple
The CMS Made Simple application is vulnerable to various attacks, including several RCE ones, however they all required user authentication. As there is no version included in the banner, one of the ways to enumerate the exact version of the web application is to deploy it locally and check what documentation files are included. There’s usually either a README or a CHANGELOG in cms applications like this, which authors do not bother to delete after installation. I usually always try the following strings in the root directory:/license.txt or /LICENSE.txt /readme.txt or /README.txt /changes.txt or /CHANGES.txt /changelog.txt or /CHANGELOG.txtIn most cases, those files will be uppercased with the extension lowercase in the following format:
FILENAME.extIn the case with CMS Made Simple these are located within the docs directory, and by requesting the /CHANGELOG.txt file some valuable piece of information is being shown:

– exfiltrating version data from CHANGELOG:
Version 2.2.9.1
#!/usr/bin/env python # Exploit Title: Unauthenticated SQL Injection on CMS Made Simple <= 2.2.9 # Date: 30-03-2019 # Exploit Author: Daniele Scanu @ Certimeter Group # Vendor Homepage: https://www.cmsmadesimple.org/ # Software Link: https://www.cmsmadesimple.org/downloads/cmsms/ # Version: <= 2.2.9 # Tested on: Ubuntu 18.04 LTS # CVE : CVE-2019-9053Not going to explain the CMS Made Simple Exploit mechanism in details, but it’s a Blind SQL Injection exploit leveraging the timing between the responses and guessing each character of the result stored into the database per each character, then concatenating the character found with the next guess in case there is a match, until no match is found and this way constructing the full password hash, salt, username, and user email. I strongly suggest reading the exploit code for a more comprehensive understanding on what it does and the way it uses to exfiltrate user data as it’s something really useful and commonly used in penetration testing. As most hackthebox users run in a shared environment you may want to tweak the TIME variable, which is set to 1 second by default, and increase it to something more reliable up to 10 – the higher value you set the more reliable result you would get and the slower the script would complete. In my case I was able to exfiltrate the necessary hashes with its default settings. In case you want to have a more invisible experience on the process, you may modify the python exploit code to use a proxy when making a GET/POST request to the target, a trick often used and demonstrated by @ippsec in his videos – for example, you may alter line 114 to look as following:


# Getting available hashcat md5 modes hashcat --example-hashes | grep md5 -b1 # Cracking the hash using -m 20 hashcat -a 0 -m 20 '62def4866937f08cc13bab43bb14e6f7:5a5 99ef579066807' /usr/share/wordlists/rockyou.txt



Privilege Escalation
Privilege Escalation on this box is rather tricky, and requires you to follow the path and instance of something specific running in the process. The easiest way to find your path through is using DominicBreuker’s pspy, an application enumerating processes as they run, even those belonging to other users. While writing this I even found out there is an actual exploit for this for Ubuntu systems, even though I did it completely manually so I will show it this way. In case you are interested in the exploit I’m referring to look up for MOTD file tampering which acts into a similar way, however I just tested it and didn’t actually work, and by reviewing the source code the idea behind id is a bit different although it still uses the message at login called MOTD (Message of the Day) and it’s triggered in the exact same way by logging in to the target. I achieved privilege escalation in two steps:- By monitoring running processes using pspy. I got into a bit of a rabbit hole at first sight as the fail2ban script running as a cron job was really what was looking like a promising vector.
- After I enumerated the actual process related to the privilege escalation, I enumerated all the directories related to the process running, their related groups and permissions, and wrote a script which is supposedly run with high privileges under the path which is loaded at first place within the user defined PATH directories.

2019/09/30 10:24:53 CMD: UID=0 PID=3572 | /bin/sh /etc/update-motd.d/10-uname-> This calls the /etc/update/motd.d/10-uname script The important detail to note here is that the script /etc/update-motd.d/10-uname actually calls uname with its short path, meaning we could try to hijack its execution by creating a malicious file in our PATH environment variable, as long as we have the necessary permisisons for this:

2019/09/30 10:24:53 CMD: UID=0 PID=3571 | run-parts --lsbsysinit /etc/update-motd.d-> This is calling the run-parts script with the –lsbsysinit option, which according to the man page tells the script to “use LSB namespaces instead of classical behavior.”. The run-parts script is a script running each script or program within a provided directory, in this case /etc/update-motd.d. As there’s just the file 10-uname in it, this one will be executed with each login of the user. What’s interesting is the contents of the file, which are just running uname with some parameters:
2019/09/30 10:24:53 CMD: UID=0 PID=3570 | sh -c /usr/bin/env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin run-parts --lsbsysinit /etc/update-motd.d > /run/motd.dynamic.new-> This one is setting the environment variables and the PATH for the user, meaning in this case when a command is typed, the first place to look in will be the /usr/local/sbin directory. Then run-parts being run again with the –lsbsysinit option, and outputting the result to /run/motd.dynamic.new By tracking all the users’ directories and permissions, and having in mind that the /etc/update-motd.d/10-uname file can not be modified directly, you would note that the actual uname binary called resides within the /bin directory. As the first directory within the user PATH environment is /usr/local/bin, this would mean in case we create the file “/usr/local/bin/uname”, it will be the one called instead of the actual uname.



Upgrading the group and uid – getting a full root
In case you want to upgrade your session to a full root, you could either use a C script or do it from python like this:
python -c 'import pty; import os; os.setreuid(0,0); os.setregid(0,0); pty.spawn("/bin/bash")'Source code in C:
#include <unistd.h> #include <sys/types.h> main() { setreuid(0,0); setregid(0,0); execvp("/bin/sh", NULL); }The privilege escalation was rather tricky and requires either much observation or having the skill to already have met this on another boxes or on a real penetration testing assignment.
Additional stuff related to the CMS Made Simple login
And in case you wondered, this is the reason the CMS Made Simple password was not working within the web interface, even though its being extracted from the database:
htpasswd -b /etc/apache2/passwords jkr jkr123456

