This is an Ubuntu 22.04 machine running an e-learning web site made with of Chamillo LMS (Learning Management System). The version installed is Chamillo 1.11, which is vulnerable to unrestricted file upload (CVE-2023-4220) . Exploiting this vulnerability we get initial to access to the system, then move laterally to a low-priv user reusing database credentials found in a PHP configuration file. Regarding escalation, we abuse an overly permissive sudo script that allows the user to update file permissions with setfacl.
Download and run the exploit (exploit.py), it provides instant RCE. First we'll use it to discover the host is running Linux, then we verify nc is installed.
Everything is ready, so just start a listener and send a payload.
A reverse shell is received on port 1919.
It is a shell for user www-data so let's carry out a database password hunt in the /var/www/chamilo directory.
We have find a database password, let's check if it belongs to any of the host users.
For example, let's try if it works for user mtz
It seems that's the case and we can retrieve user flag.
ROOT
Start from the low-priv shell for user mtz and take the opportunity to enumerate the user and the system.
Check sudo configuration.
Inspect the script /opt/acl.sh
It seems the script modifies any file's permissions with setfacl binary. There are 2 conditions: the target must be a file and be inside mtz home directory.
Create a symbolic link to /etc/passwdin mtz home directory, then update its permissions so we can add new users.
All that's left is to add a new superuser and spawn a root shell.
> whoami && id
mtz
uid=1000(mtz) gid=1000(mtz) groups=1000(mtz)
> uname -a && cat /etc/os-release
Linux permx 5.15.0-113-generic #123-Ubuntu SMP Mon Jun 10 08:16:17 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
PRETTY_NAME="Ubuntu 22.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
> sudo -l
Matching Defaults entries for mtz on permx:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty
User mtz may run the following commands on permx:
(ALL : ALL) NOPASSWD: /opt/acl.sh
#!/bin/bash
if [ "$#" -ne 3 ]; then
/usr/bin/echo "Usage: $0 user perm file"
exit 1
fi
user="$1"
perm="$2"
target="$3"
if [[ "$target" != /home/mtz/* || "$target" == *..* ]]; then
/usr/bin/echo "Access denied."
exit 1
fi
# Check if the path is a file
if [ ! -f "$target" ]; then
/usr/bin/echo "Target must be a file."
exit 1
fi
/usr/bin/sudo /usr/bin/setfacl -m u:"$user":"$perm" "$target"